I have an issue that touches both accounting and database principles. I have a table called Payments that, among other columns has this structure:
-------------------------------
id | amount | type
-------------------------------
1 | 100.00 | payment
2 | 200.00 | payment
3 | 50.00 | refund
4 | 130.00 | refund
5 | 500.00 | payment
So currently, I am storing payments and refunds as positive amounts and indicating a transaction type in a different column. When we pull up reports, I check for the type and put in parentheses the amount [for e.g, (50.00) ]
However, the question now is, one could also potentially store the same information as :
-------------------------------
id | amount | type
-------------------------------
1 | 100.00 | payment
2 | 200.00 | payment
3 | -50.00 | refund
4 | -130.00 | refund
5 | 500.00 | payment
The main argument for which is that we can run a SUM() on this column to quickly get a balance, and also a question of 'Why store a positive amount when technically money is going out.'
My question is:
What is the correct way of storing payments and refunds in a database? The first implementation was there because I went with my gut - storing it as negative to indicate a refund felt wrong to me. The idea behind it being that, as this answer put it:
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).
( The original stack overflow question can be found here )
This answer also claims that
Using one column for everything and then using negative numbers for either debits or credits doesn't work ...
But I'm struggling to see why the case in the question is wrong. I'm also trying to find a case where it would not work here, and also to see if storing negative amounts is wrong, or whether storing it both positive is also wrong.
To re-iterate, what is the correct way of storing payments and refunds in a database? Since this involves financial transactions, I want to make sure that I am doing it the correct way, if such a thing exists.