Answer the question
In order to leave comments, you need to log in
What is the best way to implement the billing logic?
Hello Habr.
There are two collections of income and expenses:
приход средств
дата
сумма
статус (не поддтвержден, подтвержден, отменен)
расход средств
дата
сумма
счет
остаток
период
закрыт (да, нет)
дата начала
дата окончания
остаток в начале
остаток при окончании
Answer the question
In order to leave comments, you need to log in
You yourself, with each new example, expanded the task itself: +increase speed, +increase reliability, +find the location and cause of the problem and the ability to get the status at any point in time, ...
What do other models mean? what other problems need to be solved?
ps The last option given is quite good, but it imposes a limitation - the data must be sequential (to get the next record, the latest record is needed), which can ugly fall on horizontal scaling when the collection is spread over several physical nodes (but this problem is completely solved, either by global locks per object - in this case, 'account', or by introducing additional type collections - data on the last change, to be honest, this is the same implementation of a global lock, but through this collection ...)
Those. your task will be expanded and supplemented, I'm afraid, as if not indefinitely as new problems appear, generated by the next solution of the previous one ... I recommend stopping somewhere right away.
I had such a task, with clarification: number of lines: hundreds of thousands, grouping by accounts
as a result looked like this:
operation is:
transaction id (up to 20 operations per transaction came out in real life)
account
date
amount (plus or minus)
description
boolean type (main transaction, commission, cost, etc.)
cached_balance_after_operation
cached_cost_of_ruble
cached_weighted_average_rate
cached values were recalculated by triggers in the database when changing
a transaction, this is a bank transfer, for example. when transferring from one LLC to another, 3 operations occur. write-off credit and payment to the bank.
I hope it will be helpful.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question