last day (29 days later) » 

1:42 PM
10
A: Relational Data Model for Double-Entry Accounting

PerformanceDBA 01 Jan 2020 • Third edition & Two Graphics corrected A. Preliminary Your Approach First and foremost, I must commend your attitude. In these darks days, when young people think that they can: a. "code" without tertiary education b. code even a moderately complex app, so that it doe...

 
@Alex. For errors and specific questions, please leave comments here, so that there is a record with the Answer. For discussion, the mods have opened a chat, which has less restrictions than the comments. They delete the comments.
@AntC. As you know, the Mods have already stated "Comments are not for extended discussion; this conversation has been moved to chat". Your comments demonstrate an absence of understanding basic accounting. I can't provide a Tutorial 9try Google), but I am happy to answer specific questions.
 
Perhaps a business Transaction is a single row is a bit wrong since OTC transfer consist of 3 rows. I guess you mean a doubly entry is a single row, and there are many double-entries per business transaction.
 
@Alex. 1) I did not state that (please do not follow the comments of those who are confused). A Business Transaction is two entries in paper-based accounts; one entry for each Credit/Debit leg. That is affected by a single row in my database. 2) OTC_Transfer is three business Transactions in the DEA sense, not one. As long as that is understood, it can be viewed as one large Business Transaction. 3) Nevertheless, I have added a few words of clarity throughout. And one additional code segment. Happy New Year.
@user806. 1) Yes. In [5 [1.1] ] the customer AccountNo 123 Alex is Credited, the Ledger[Account]No 990 HouseCash is Debited. The customer Account is external, HouseCash is external. 2) It is no problem at all to expand the simple Ledger I have given, by adding whatever Ledger.Ledger[Account]Nos to suit your needs.
@Alex. Graphics improved, PDF updated.
 
In new version Credit 100 345 Mary must be Credit 100 345 John (Transaction #4). The best is the enemy of the good :)
 
@Alex. Thanks. What a great proverb. But Scripture commands us to "Be you therefore perfect, as also your heavenly Father is perfect." [Matthew 5:48]. Errors in graphics corrected. PDF updated.
@Alex. This Answer is of course complete for the purpose. However, someone else asked for an expansion of the Ledger, which I provided here. You may be interested.
 
1:42 PM
Please correct if I am wrong: The [661] FeeRegular (also [662] FeeTransaction) are RR (aka revenue), 'Cr' increases it, so we apply Cr. The '[990] HouseCash` is AA (Asset) so we have to increase it when deposit happens, we apply Dr because it increases Asset. But why it's an Asset? House owes that money to ext. account holders. I could treat [990] vice versa: it's AL and we decrease it by applying Dr. So what is it then?
 
@Alex. 1) Money represents value, it cannot be created or destroyed, only moved. I do not use "increase/decrease" due to the implication. A DEA Cr leg is credit, Dr leg is debit. 2) 661,662 is RR . 3) 990 is AL Liability because that money needs to be paid to the Ext Acct holder on demand. 4) As detailed in § 5.1.1, a Dp deposit is an AccountTransaction that Dr debits LedgerNo 990 (Income=Dr) and Cr credits external AccountNo 123 (Giver=Cr). In a naïve sense only, both are "increased", because money moved into the system.
@Alex. I have upgraded all the graphics to show that further level of detail, and the PDF. Note that it is not an error to move money from one Liability/Expense Ledger Account to another Liability/Expense, or to an Asset/Revenue.
 
Sounds reasonable, but it's kinda contradicts with TransactionLedger_IsValid_ck CHECK ( TransactionLedger_IsValid_fn( LedgerNo, LedgerNo_Dr ) = 1 ) -- check one is Asset and the other is Liability from another answer?
Also, the comment from @AntC is interesting, usually in a more complex system you not only have pending, but I would call it long running transactions with several states, where one large transaction affects many ledgers and ext. accounts, where you can "rollback" (+ add new) all the multi ext. account/ledgers transactions when state changes. You have to keep references to Transactions. (Here I am already referring to extended ledger model where Transaction is further normalised). It's obviously a material for another referred Q which is in progress ATM.
 
@Alex.1) Contradiction. You are correct. What I was attempting to show in that A is that reasonability can be checked via constraint. Will fix it up later. 2) AntC's comments are simply attacks, not worthy of a response, which will only serve to validate his invalid points. 3) "pending" is 500 Suspense. There I have advised Estimates & Unpaid Invoices to be placed under Suspense. Thinking in terms of a "long-running transaction" with "several states" is incorrect. Instead, perceive Accounts: each Account LedgerNo (state) is independent, with money moving out from one Account ...
and in to another Account, via a single business transaction. Therefore there never is one transaction that affects many Ext Accounts (or other Ledger Accounts): each is a separate business transaction. There is no rollback, no need to keep "references".
 
Lottery could be an example of "transaction" which affects many accounts, it starts and ends with massive "airdrop" of winnings. Affects many accounts. Let's call them ApplicationTransaction for instance. Or Trade with 2 sides where House can be a middleman, must take assets of each side, move it to special LedgerAccount, keep a record of transfers related to specific ApplicationTransaction or (Operation), could last for a while, have several states, attributes. The Q: stackoverflow.com/questions/59961159/….
I am guessing your point is to create a LedgerAccount per instance of such operation. So if one of dozens operations in a system is to Sell a building to a group of people (ext. accounts) there will be a LedgerAccount per each building. Building could be in process of construction and if something goes wrong you refund participants, pay penalty, etc. That trade could be cancelled one day due to some reason, you move funds back, penalty, etc. Transaction table accumulates track of transfers/buyers by current design.
 
Re "Lottery ..."
Please delete that comment from this Answer, and place the content in your new Question.
 
1:46 PM
Re "I am guessing ... "
Building, etc.
That is covered, completely, in my [Job Costing Answer](https://stackoverflow.com/a/59857806/484814)
 
1:58 PM
Will improve the question, it's evening and I am a bit in the myst already.
 
----
Only of the many problems at SO is, the Question must be clear, and single, in order to facilitate an Answer that actually answers the Question. As you know, SO boffins are quick to down-vote or close a Question. So please constrain your questions. If you honestly have a Lottery app, then detail that and forget about Buildings. If you honestly buy/sell Buildings to groups (consortia) then detail that and forget about Lotteries.
There are laws that govern each app area. After 40 years of building databases, I know a fair number of them.
Myst: no worries. Goodnight.
 
I have to say. That is a great data model you erected. Imitation is the highest form of compliment. Thank you.
 
No way it's a lottery app, I tried to quickly made up a number of use cases to highlight that system is not just money holding app. The p2p trading without orderbook and matching engine is more close to reality. Editing Q hard.
 
 
2 hours later…
4:05 PM
> That is covered, completely, in my
Perhaps was a bad example, The "Trade" example suggests that there will be thousands of LedgerAccounts which is kinda not a Ledger's job. With some form of escrow trade you define a single LedgerAccount (LL) which is responsible for holding funds for thousands of Trades and you reference collateral transfers per trade in another table related to Trade instance.
 
4:17 PM
I have edited my Q, the Lottery example perhaps also falls into category of system which is described in "Job Costing" where LedgerAccount could be appropriate in case it's a real world lottery once a week/month, but I am talking about some automated high frequency business processes, polluting it with LedgerAccount does not really looking good. I see Ledger's and Ext. Account as real human and House accounts for revenue, deposits, withdrawals.
Regarding ID field, I don't think brokers for example using anything but form of sequence or UUID, tbh I don't feel comfotable with (AccountNo, DateTime) as a primary key, it shouldn't cause some time resolution issues limiting number of records per second, but there is absolutely no reason to not define surrogates as an identified for transaction. This kind of data is not going to paper, the DateTime is indeed still must be there for reports
 
5:03 PM
> Trade Escrow Account

1. That's fine. But then you must declare that the escrow Accounts are NOT Double-Entry., and therefore the Ledger Accounts for that/those escrow Accounts are aggregates.
2. The rolled up Ledger entry, usually on per Day, is called a Journal Entry.
3. What is the "Ledger's job", other than to define the Accouts for the business, to the needs of the business ?
4. Why does it matter what you feel, why is that more relevant than the science, the logic for making scientific decisions ?
5. Noting that this will be done by a computer system, and not manually on paper, what is the difference between
making thousands of transactions against an escrow account plus 1 Journal Entry
vs
making thousands LedgerTransactions
?
Giving you instructions, answering your Question is one thing. Convincing you is another. I checked in for the first, as per SO protocol. I have not agreed to provide the second.
 
5:25 PM
The LedgerAccounts are aggregates already ... they are not "hundreds of thousands of disposable LedgerAccounts". Choose the granularity you want:
- One LedgerAccount per House/Building (correct for Job Costing; Estimate vs Actual; Unpaid vs Paid Invoices, regardless of num of building purchased/sold)
- One LedgerAccount per "Trade Expenses" plus a Journal Entry per day
--- One for Suspense/Estimate and a second for Actual/Paid (gives balancing of those two), again with one Journal Entry per day
- some othe oprion
 
5:47 PM
We are not making an account per each deposit/withdrawal that's an example of what I also call "ApplicationTransaction"
> "and therefore the Ledger Accounts for that/those escrow Accounts are aggregates"
Would be appreciated for some hints, I am guessing I have to designate LedgerAccount by ("DE", "AG") and reflect it in a `CurrentBalance`.
 
6:41 PM
I see, they are intermediaries which we don't count in Job Costing, we can modify CurrentBalance view and produce some extra column called AccountAggregate but count these transactions in Balance as XactTypeCodeExt='Ep (-)'/'Ew(+)'. The Account holder will see its balance decreased and special balance which reflects his funds on hold.
 

  last day (29 days later) »