Comments (3)
tldr; You dont
Your question seems odd. In classical accounting the ledger is not mutable. You should never manipulate the entry in the ledger after it is written. Imagine you have a physical book for classical double accounting. There you can only write with permanent ink into the T-Tables. There is no erasing or manipulating of entries in the ledger. At the moment you start to manipulate the entries in the ledger, you can not trust it anymore.
In accounting it is important that you can always determine the balance of any relevant accounts. There is no semi state of an entry. So if I ask you how much credit a customer has, than you can not say based on the entries, that it is 100 € and after 2 minutes, after you manipulated the entries, tell me it is 200 €. I repeat: If your entries show me at 12 oclock pm that the customer has 100€ then you can not say at 12:02 oclock pm that it is 200 €, because some pending transaction finalized, even though the amount of entries did not change. Imagine you want to file your taxes. You can not say, hey my fiscal year starts in january and I wrote the invoices for january on 31st December 2022 so all my income in january is part of my previous fiscal year, even though my customers transfer the money on 1st January 2023. At the moment you have the actual power of disposition of the money it is relevant for the ledger. So yeah, I can found a company and write invoices with a value of 1 billion Euro, but that doesnt mean, that I have 1 billion euro in my pocket and can do with the money as I please.
Transactions are not Schroedingers Cat.
So if you can not manipulate the ledger entry, this means that you have to use a different approach. And this means using of more T-Tables or using of more Entries. What does this mean?
Incoming Money/Assets:
Customer A sends you money via Bitcoin. You register the incoming bitcoin transaction from the rpc channel from bitcoind. You write the transaction into CustomerA:pending so you can already show the customer on your website that you see the transaction. Then you wait till the bitcoin transaction is over the treshold of necessary confirmations and you accept it as written into the blockchain and then transfer the pending amount from CustomerA:pending to CustomerA:account. But if the bitcoin transactions fails e.g. because of double spending, then you transfer the pending amount to CustomerA:failed or somewhere else.. But for detemining the balance you only use CustomerA:account, as it is the single point of truth for the balance of the customer. So thats why you dont directly transfer the pending transaction to CustomerA:account.
In classical banking you would say, that the unconfirmed bitcoin transaction is an avis/Remittance advice and the confirmed bitcoin transaction is the finalized banking transaction. And only finalized transactions are relevant in booking.
Outgoing Money/Assets:
Customer A wants to withdraw/refund from his account. You transfer money from customerA:account to customerA:pending if it is someting like bitcoin. Or you immediatly deduce the money from the account and say, the money is gone. Doesnt matter if you put it on pending or immediatly set it as succeeeded, as the customer will complain if the money did not transfer on his account. Then you need anyway to look into it. But if it is a bank transaction you just know that you sent the money, so it is just necessary to keep the bank transaction id in your ledger entry to keep it traceable.
If in any case a transaction fails, you can make a Storno which is basically the void method of an LedgerEntry in medici.
And always keep in mind, that the ledger is YOUR single point of truth. Meaning: You first write the entry into the ledger and then you trigger the relevant process. E.g. You sell gold online. The process is: Customer orders x amount of gold, you check if the customer has enough credit in his account by atomically reducing the amount of money for the order and then if it is sucessfully written into the ledger, you trigger the following process which ends with you sending out the gold. This means, that if the ledger has an issue and/or you fail at writing into the ledger (e.g. not enough balance), you just throw an error and dont send the gold out.
Imagine the bad alternative: Customer orders Gold, you check that the customer as enough money, prepare the Gold for sending and ship it away, and in the last step you write into your ledger. This would mean, that if your ledger has some issue, your customer gets anyway the x amount of gold but your ledger does not reflect that because of the error. The customer has still "enough" money in his account as the amount was never reduced from the account of the customer. So he can order again x amount of gold. Resulting in you losing the money by basically gifting the gold to the customer. Again: YOUR ledger is YOUR single point of truth. It doesnt mean, that it is perfect, nor does it mean that it is even correct. You can have accounting errors. But!: An accounting error should be never to your disadvantage and in best case not to the disadvantage of the customer. A customer will complain about accounting errors to his disadvantage, but never to his advantage.
So e.g. customer sends money and it never shows in his account. That doesnt mean, that he lies or that he wants to defraud you. You will check the claim of the custome and validate if he really sent money to you. You see it is in the bank account. You check your ledger and see that you missed his money transfer. Then you add manually the transaction to your ledger as you determine that it is the truth. Again: It is YOUR single point of truth.
So be always really conservative when doing accounting related operations.
Looking foward for your feedback
from medici.
hey @Uzlopak , this exactly what I wanted to do. your suggestion really helped. thanks a lot!!
from medici.
Transactions are not Schroedingers Cat.
👏
from medici.
Related Issues (20)
- Mongoose connection string HOT 1
- Missing changelog for 6.0.0 HOT 2
- Value Added Tax HOT 4
- Question: Future Posting Date HOT 5
- start_date and end_date filter on balance API doesn't work correctly if an exisiting balance snapshot is present HOT 1
- Getting Error in Local Dev Server HOT 5
- Intent to ship v7.0 HOT 4
- How to add a Opening Balance to a Book HOT 1
- How to find balance for a previous date ? HOT 1
- Can we know if Debit balance is intentionally given as "negative" value ? HOT 3
- Mongoose Specify Connection HOT 4
- Set Timestamp for Journal Entry HOT 7
- Question: do you have an UI for this or do you plan to build one? HOT 3
- last version not released? HOT 3
- new release HOT 3
- Questions on the implementation HOT 10
- Question: Why MongoDB? Have you considered iterating to a relational db? HOT 1
- demo or sample
- Failing to get started HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from medici.