Well, I'm a little late to the party, but there are interesting answers here, and I thought I should add my own technique.
To answer the question: should you store values as positive amounts and the flag as debit or credit?
Short answer: you do not need to add a flag, because any system automatically applies the flag “debit” or “credit” when you save the number in the correct signed form. It's a sign "-". Should you store values in one of two columns, debit or credit? Absolutely not! Why keep an empty field for every transaction in the system? A single column with the correct sign value is much easier to manage.
A longer answer to the question: “Accounting and database design”, storage of the amount of debit and credit.
It is completely simple and durable, if you understand that you need to store double entries. When you publish a journal in the nominal register, you offer the user a debit field and a credit field for each line in the journal. In your application, you allow only one of the fields to have a value (for each row), and it must be a positive unsigned value. When you write a transaction, if you have a debit, you simply write it as it is. If you have a value in the credit field, you change it and write it as a negative number. The database sees only one significant value in one column, in a row (record). Since any accountant will tell you that the journal entry should be balanced, so the database entries for the journal transaction lines will be added to zero. Application code should provide log balance.
Now consider the purchase account that the user adds to the system. Say we have this (unlikely) account for Widget:
£ 500 for steel bar
£ 100 for an envelope box
£ 10,000 for a lathe
£ 2120 purchase tax
£ 12,720 bill total
The application writes one entry to the document table. It has one-to-many links to the transaction table. For a three-line account, the application contains 5 transaction lines.
£ 500 related to cost of sales, general p & l account. Debit balance = expense when in p & l
£ 100 associated with Stationery, the p & l general ledger account. Debit balance = expense when in p & l
£ 10,000 related to machine, balance sheet account. Debit balance = asset when in bs.
£ 2120 associated with Input Tax Reclaimable, bs gl. Debit balance = asset, we owe money to a tax man
- £ 12,720 associated with Creditors Control, bs gl. Credit balance = liability, we owe this provider
£ 0.00 total value of 5 entries recorded in the transaction table.
Now consider the sales account that the user adds:
£ 250 for premium widgets
£ 250 for standard widgets
£ 100 sales tax
£ 600 total bills
Again, one entry is written to the document table. For a two-line invoice, 4 transaction lines are recorded. Since this is a sales invoice, the application must change the values behind the scenes. Invoice accounts are accounts, but the user does not expect to add them as negative values.
£ 250 - Associated with Premium Widget Sales, p & l gl account. Credit balance = income / profit when in p & l
£ 250 - related to standard widget sales, p & l gl account. Credit balance = income / profit when in p & l
£ 100 - linked to the exit of Tax Payable, bs gl account. Credit balance = liability when in BS. We owe this money to a tax person.
£ 600 associated with Debtors Control, bs gl. Debit balance = asset, we owe this client.
£ 0.00 total value of 4 entries recorded in the transaction table.
It is perfectly normal to add negative lines to the invoice if you want to pay tribute to something returned. Before writing transactions, they simply handle all the other lines. As a rule, you issue a credit note containing lines written as debit sales revenue, which reduces the cost of sales in p & l.
If the system performs inventory management, quantities are recorded in the transaction lines and they are associated with the Product table.
Bank records are often caught by non-book keepers. They say we put money in our bank so that we credited the account. Think about the fact that the bank is a person external to the business. When you transfer your money for safe storage, it becomes a debtor and must return your money on demand. Thus, bank receipts are recorded as debit and payments that are recorded as loans. When we receive a payment from a client, we write two lines of transactions:
£ 600 linked to bank account, bs gl account. Debit balance = increases the value of the asset, we have more money.
£ 600 - linked to Debtors Control, bs gl account. Credit balance = reduces the value of the asset, we owe less money.
£ 0.00 total value of 2 entries recorded in the transaction table.
If you follow this, you’ll see that GBP 600 is credited to the Debtors Control account when the invoice for the sale is issued, and GBP 600 written on it when the payment was received. Net balance = $ 0.00, which should now be our customer.
Thus, with the right design, relationships, and indexes, all reporting is done from a combination of documents and transactions.
What is it. Each time you summarize a transaction table, it should always return zero. No need to support two columns. An application must do two things: it must be encoded so that it applies the correct signature to various types of transactions, and it needs to present the transaction in one of two columns, depending on whether it is> 0 or <0. Thus, you You can have your own trial balance, books and registers of suppliers, bank and cash accounts and a general ledger that are well formatted in debit and credit columns.
Creating a system in which both sides of a double-entry are recorded in a single transaction is attractive. If one transaction fails, it will not unbalance the accounts. You will still only have one column for the value signed. You must record two foreign keys for each transaction, one for the value of what you wrote, which can be a positive or negative value for representing debits or credits, and the other foreign key for recording the account that you publish the opposite (the value is "double post "). You may also need to write gl fk for two tax control accounts, one for the tax control account and one for the input tax control account. Thus, you can link your transaction line to four gl accounts, and not to one (plus links for customer tables, suppliers, and products that apply to both methods). Control accounts will have a very large volume of transactions associated with them. An account with 10 lines will contain 10 transactions, and not just one document. You would need to calculate the tax element for each line of the account individually, and not as a total for the document (you can do this anyway). Finally, you will have to have a special arrangement for a journal entry document, which can include 10 lines as debit, all offset by one line as credit, so a single transaction approach does not work here.