Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Double Entry Accounting System Database Design?

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??

like image 626
Jignesh Manek Avatar asked Nov 19 '11 06:11

Jignesh Manek


People also ask

How will you design database for accounting?

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).

What is double entry in database?

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.

What are the 2 types of entries for double bookkeeping?

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.

What is the format of double-entry system?

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”.


2 Answers

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).

like image 197
ruakh Avatar answered Sep 29 '22 20:09

ruakh


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).

like image 40
Ken Avatar answered Sep 29 '22 20:09

Ken