Creating app here three tables are associated with transactions, 1) cashbook 2) customers,
Now in my cashbook table I have two columns credit & debit,
How do I sum all credit or debits of specific user with specific date.
Thanks,
Here is my query which returns collections, So how can sum all credit and debit column in the all collections?
1 ) one way to iterate over transaction and calculate the running total
Formula
$closingBalance = $userPaymentHistory->debit - $userPaymentHistory->credit;
depends on your legder and company's accounting
running total contains all the balance calculation
2 ) second way to calculate over database
select credit , debit ,
FORMAT (SUM(credit) OVER ( ORDER BY id ) - SUM(debit) OVER ( ORDER BY id ),2) AS balance
from relevant_table