Accounting Software In Yii With Best Relation

I want to create a accounting software using tables like this

(most tables have opening_balance field)

tbl_company

tbl_branch

tbl_customer

tbl_vendor

tbl_bank

tbl_category

tbl_product

tbl_purchase

tbl_sale

tbl_expense

tbl_payment

tbl_receipt

tbl_type


id

tablename

note

and records are in tbl_type

1, tbl_branch/cash dealing

2, tbl_customer

3, tbl_vendor

4, tbl_bank

like this

All are ok.

In tbl_payment, tbl_receipt or tbl_expence fields like following


id

date

sourcetype

source

amount

targettype

target

narration

in this table sourcetype related/join to tbl_type(id) also targettype relate/join to tbl_type(id)

for example in tbl_payment table record like

1, 2012-10-05,1,1,1000,3,1,checking

2, 2012-10-05,4,2,500,3,2, cheque no/net transfer ref no

in first record

sourcetype and source are 1 and 1 means cash and branch_id

targettype and target are 3 and 1 means vendor and vendor_id

in second record

sourcetype and source are 4 and 2 means bank account and bankaccount_id

targettype and target are 3 and 2 means vendor and vendor_id

same as receipt and expect also

in this case source and target columns are refer/link/join to multiple table based on sourcetype and targettype

IS THIS RIGHT APPROACH?

IF YES, HOW CAN I JOIN IT?

IF NO, WHICH IS THE BEST WAY?

PLEASE HELP ME…Thank you very much

Anybody help me… Please…