i am going to create a database for double-entry accounting system in MySQL.
i recently read the article: http://homepages.tcp.co.uk/~m-wigley/gc_wp_ded.html
i found in this article that it would be convenient to have three tables ACCOUNT, JOURNAL and POSTING:
ACCOUNT(accountID, accountName)
JOURNAL(journalID, journalType)
POSTING(postingID, journalID, accountID, amount)
the article described that if an account is debited, value of the 'amount' field will be positive, else it will be negative.
now for the POSTING table above, i have other two options as well..
(1) POSTING(postingID, journalID, accountID, isDr, amount)
in this option, 'isDr' field is a boolean. if the account is debited, isDr field will contain value "true", otherwise "false". and the 'amount' field will always have a positive value.
(2) POSTING(postingID, journalID, accountID, debitAmount, creditAmount)
here, if the account is debited, i will store amount in 'debitAmount' field, else i will store it in 'creditAmount' field.
so, exactly which option from above three is better to use??
The process of designing database (for accounting) begins with a reality (or accounting reality) that is expressed using elements of a conceptual data model. The process of designing a database for accounting is best described through a flow chart (Figure : 14.4).
In a 'double entry' system each value is stored twice, once as a credit (a positive value), once as a debit (a negative value). There are a number of rules that control these values. These rules would be recognised by any trained accountant although they may not understand how it is stored in a relational database.
Debits and credits are essential to the double entry system. In accounting, a debit refers to an entry on the left side of an account ledger, and credit refers to an entry on the right side of an account ledger.
In a double-entry accounting system, transactions are composed of debits and credits. The debits and credits must be equal in order for the system to remain balanced. For example, if a business pays its electricity bill for $1,200, then it will record an increase to “utilities expense” and a decrease to “cash”.
This is subjective, but I think option #0 (the one where a single amount
field is either positive or negative) is best. Option #1 will cause you a lot of pain whenever you want to do math that includes both credits and debits, since you'll have to consult the isDr
field to determine whether to multiply by -1
. Option #2 is not well-normalized, since the expressions debitAmount IS NULL
and creditAmount IS NOT NULL
will be equivalent (and if they ever differ, then your database is in an inconsistent state).
Option #0 has a draw back which I recently faced with:
There are some cases which require the amount written/recorded and also seen as minus(-) on the credit side on the ledgers, instead of showing its amount as positive(+) at the debit side. (also vice versa)
Option #0 fails in that (if not flagged as debit or credit, or not solved in some another way)
You need to ask this your accountant. (if any minus(-) amount needs to be recored and seen on the credit side (and vice versa).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With