Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zacharylai's avatar

Best suggestion for managing fund/credit in a site

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|

0 likes
2 replies
jlrdw's avatar

You can do the accounting to however makes sense, as long as year-end is correct for tax. But any payments should be done through an authorized payment Gateway.

There are a few bookkeeping rules but the IRS site if you are in the United States clearly covers the different techniques that is authorized.

laracoft's avatar

@zacharylai

I see 3 questions

  1. Does purchase of services from other users need double entry accounting? Usually yes, if you want to trace who has transferred money to whom.
  2. Will the new scenario change the double entry requirement? Same answer as 1.
  3. Pros and cons of single vs double entry accounting?

This is an accounting question, accountants and bookkeepers use double entry accounting as a way to raise the barrier against fraud and mistakes. It is better you consult an accountant who is familiar with your project, but It is unlikely that single entries accounting will do the job.

However, in IT and especially web based accounting code, we are more concerned about race conditions. So you need to familiarize yourself with MySQL transactions in order to have a robust solution.

Please or to participate in this conversation.