Open arsonus opened 3 years ago
Update scopeClosingBalance to mimic your calculations in Account::sectionBalances()
/**
* Account::scopeClosingBalance()
*
* @since 0.0.1
* @access public
* @author Arsonus Digital
*/
public function scopeClosingBalance(Builder $builder, $startAt, $endAt = null)
{
return $builder->selectRaw("SUM(opening.amount) + SUM(current.amount) + SUM(movement.amount) as amount")
->openingBalance(ReportingPeriod::year($endAt))
->currentBalance(ReportingPeriod::periodStart($endAt), $startAt)
->selectSub(static::currentBalance($startAt, $endAt)->selectRaw("SUM(current.amount) as amount"), "movement");
}
Hi arsonus,
Thanks a lot for your suggestion. I've been thinking about shifting the responsibility for aggregation of values for the reports from php (loops) to the underlying db (raw sql) I just happen to have a weakness in the latter. I'll definitely be looking into your code above to see if I can incorporate it into the next release. The performance gains should be impressive!
Thanks again, Cheers
My pleasure ekmungai,
i went further during these holidays and was able to get many of the aggregations to work by using Common Table Expressions (CTE). I will share a Gist with you once i get back to it, all the changes basically happened in the Account class so it wouldn't be difficult incorporating.
Happy New Year man, Cheers
Hi arsonus,
Great to hear. I'll be looking forward to seeing the gist.
Happy 2021!
Cheers
Great job man.
I do really like what you have done, i was thinking, wouldn't it's usage benefit from using the full power of Laravel Eloquent?
I see you are doing loops through all accounts for calculations, Please review below and let me know your thoughts, haven't tried it, just an idea that came in mind to easily query reports with any combinations.
By making use of scopes, one can then for example query Gross Profit: