I am building an site, which user can deposit fund into. The fund will deducted whenever the user uses a services provided. Is it necessary to build my system to accommodate a double-entries accounting to manage the fund or am I over-complicating this and this will be completely unnecessary.
Let say if in later period, the fund deposit can also be use to purchase other services from other users? Will this scenario change the requirement?
What is the pro and con of using single-entry in my database design vs double-entries in my database design?
For now i am thinking of a design with 3 tables
accounts
| id
| user_id
| type
| opening_balance
| currency_id
| created_at
trx
| id
| trx_code
| debit_id
| credit_id
| trx_date
| amount
| cr_balance
| db_balance
| description
account_summaries
| id
| account_id
| balance
| cr_total
| db_total
| period(mth/daily/week/annual)|
To clarify for each table
Accounts each row will be for each account type ( user fund, cashbook, paypal) for each user
trx are the transaction, there will be a trx_code ( withdrawal(W), deposit(D), purchase(P) ). The debit_id & credit_id will refer to a row in accounts. The date of that transaction, the amount then the balance of that credit account and balance of the ref debit account.
account_summaries are the closing balance for each account. It will be daily closing, monthly closing and yearly closing.
Eg:
Account
|id|user_id|type|opening_balance|currency_id|created_at|comment|
|:--|:-----|:--|:--|:--|:--|--:|
|1|adam|fund|0.00|USD|yy-mm-dd-hs| adam's fund|
|2|adam|paypal|0.00|USD|yy-mm-dd hs| adam's paypal (external)|
|3|null|fund|0.00|USD|yy-mm-dd hs| *sys. fund|
trx
|id|trx_code|debit_id|credit_id|trx_date|amount|cr_balance|db_balance|desc|
|:--|:--|:--|:--|:--|:--|:--|:--|--:|
|1|Deposit|2|1|yymmddhs|100.00|100.00|-100.00|adam deposit $100|
|2|Purchase|1|3|yymmddhs|10.00|10.00|90.00|adam purchase cert for $10|
account_summaries
|id|account_id|balance|cr_total|db_total|period|desc|
|:--|:--|:--|:--|:--|:--|--:|
|1|1|90.00|100.00|10.00|daily|end day balance for adam fund|
|2|3|10.00|10.00|0.00|daily|end day balance for sys fund|