Q
Q
Qixing2015-01-26 15:11:18
PHP
Qixing, 2015-01-26 15:11:18

What is the best way to implement financial accounting?

Good afternoon. Interested in some notes, opinions, articles on the algorithm for calculating the finances of different accounts with a minimum load on the system.
There are several accounts, all of which receive, spend or transfer (transaction) funds.
I'm running a table in a database. id, typeTransaction, accountId, datetime, sum, totalsum
Id, Transaction type (incoming, outgoing or transfer), Account, date, transaction amount, final amount after the transaction
When adding a transaction in chronological order - I just + - to the necessary account.
The question is, how best to organize the recalculation when editing an operation from the archive (let's say three days ago, when more than 1000 operations are already ahead)
I have two thoughts
1) We update the record in the database + do a recalculation (consistent addition and subtraction of amounts from the date of the updated record using the sum - foreach field and crappy sql queries) - the bad thing is that if you edited the record 1 year ago (well, anything can happen) then a long recalculation, but exactly.
2) We get the still unedited record from the database and save diffSum - the difference between the new and old sum of the current record. We update. And then with one sql query set sumTotal = sumtotal + diffSum.
Here the load is minimal and only 1-2 SQL queries.
Who has any thoughts on this and other ideas in terms of the reliability of numbers and calculations? Thank you!
In fact, the same zenmoney and easyfinance work flawlessly. I would like to know what their algorithms and database schemes are.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question