Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accounting and Database design, storing debit and credit amount

QUESTION: In the case below should I have stored all my amount as positives decimal amounts then flag the amount as either being a "Debit" or "Credit" rather than storing debits as negative amount and credits as positive amount?


In my database design, I store "debit" as negative amount, and credit as positive amount.

Now in reporting sometimes the results come out wrong because if you do this

TotalAmount = Amount-Fee, and if withdraw amount is $100, and fee is $1.

You would end up with -$100-$1 = -$101, which is the incorrect result!.

like image 996
001 Avatar asked Feb 22 '11 14:02

001


People also ask

How do you maintain credit and debit in accounting?

All debit accounts are meant to be entered on the left side of a ledger while the credits are on the right side. For a general ledger to be balanced, credits and debits must be equal. Debits increase asset, expense, and dividend accounts, while credits decrease them.

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

A database is a shared collection of inter-related data tables which meet the various informational needs of an organization. Thus, an accounting database stores the accounting data. It is a collection of accounting data which is inter-related to depict the various aspects of the accounting information system.

What is debit and credit in bank accounting?

When your bank account is debited, money is taken out of the account. The opposite of a debit is a credit, in which case money is added to your account.


2 Answers

As accounting is all based on journal entries, it might be best for your data model to follow from that. This would mean having two columns in your table, one for debit and one for credit. You then leave it up to the application to determine what should be considered a "positive" value and what should be considered "negative". (The question always arises - positive from whose point of view? When you transfer money between bank accounts, it a "negative" for one account but a "positive" for the other.)

It's a while since I worked on this kind of thing, but I seem to remember that it is possible for the debit AND credit columns to contain both positive AND negative values. Accountants have a different way of thinking about numbers than us programmers, so when writing software for them, it can simplify things if you try to work with their conventions.

like image 67
Mike Chamberlain Avatar answered Sep 29 '22 21:09

Mike Chamberlain


Using one column for everything and then using negative numbers for either debits or credits doesn't work, as you've discovered. Accounting values are not scalars -- they are vectors which contain an enum (debit or credit) and a fixed-point decimal number (which can be positive or negative).

Any accounting transaction must contain an equal number of debits and credits. If it doesn't, it's not a valid transaction.

Likewise, an account balance is also that same sort of vector. At any instant in time, the total debits and the total credits across all the accounts in an accounting system must be equal to each other, or else something broke.

Another way of looking at this is to think of an accounting value as a complex number, where debits are real and credits are imaginary. This means that 4 debits + 3 credits = 4 + 3i. This makes it obvious that you can't simplify that any further by collapsing the imaginary term into a negative real term -- it's not the same number line axis. It would be the same as claiming that 4 + 3i = 4 - 3. Not valid math.

If a database could store complex numbers natively, then complex numbers would actually be a good way of storing accounting data, would probably clear up a lot of the confusion that programmers usually have about accounting, and would lead to all sorts of interesting properties. For instance, a balanced transaction would always have a phase angle of 45 degrees, as would a balanced set of accounts. But most databases need you to decompose the complex number into its real and imaginary terms before storage, and store those terms in different columns -- in the accounting world, the names of those two columns are "debits" and "credits", respectively.

P.S.: I'm aware that some folks do use negative for credits and positive for debits, but this takes great care to do right, and is fragile. You have to keep track of the normal balance of any account every time you touch it -- for instance, since an asset account has a debit normal balance, then you can use a positive number to increase it. But a liability account has a negative normal balance, so an increase in that account's value is a negative number. You can't sum those two values together at any time -- they aren't the same thing. A debit is something you have, while a credit is something you owe. Putting both in the same column in a database table smells bad.

like image 26
stevegt Avatar answered Sep 29 '22 21:09

stevegt