I am currently building a finance application that contains "accounts"
Each account has a balance that is dynamically generated based on platform charges vs payments. e.g simplified example.
$account->balance = $account->transactions->sum('amount') + ($account->charges->sum('amount'))
It's obviously very simple however as the data is not persisted it is impossible for to run queries, sort by balance on.
Is it best practice to store a static balance for accounts ? I can obviously update the balance using events whenever a new charge or transaction is reconciled against the account. I would be interested to know solutions to this problem.
The application is Laravel but I don't believe that is important in this scenario.