feat: optimize cash overview calculations for total balance, deposits, and withdrawals
This commit is contained in:
parent
083cde60f9
commit
95df2e9dc7
@ -184,11 +184,14 @@ public function getCashOverview(?string $startDate, ?string $endDate): array
|
||||
$transactions = $cashAccount->cashTransactions();
|
||||
$this->applyDateFilter($transactions, $startDate, $endDate, 'cash_transactions.created_at');
|
||||
|
||||
$totalDeposit = (clone $transactions)->where('type', CashTransactionType::DEPOSIT)->sum('amount');
|
||||
$totalWithdrawal = (clone $transactions)->where('type', CashTransactionType::WITHDRAWAL)->sum('amount');
|
||||
|
||||
return [
|
||||
'total_balance' => $cashAccount->balance,
|
||||
'total_balance' => (int) $totalDeposit - (int) $totalWithdrawal,
|
||||
'total_transactions' => (clone $transactions)->count(),
|
||||
'total_deposit' => (int) (clone $transactions)->where('type', CashTransactionType::DEPOSIT)->sum('amount'),
|
||||
'total_withdrawal' => (int) (clone $transactions)->where('type', CashTransactionType::WITHDRAWAL)->sum('amount'),
|
||||
'total_deposit' => (int) $totalDeposit,
|
||||
'total_withdrawal' => (int) $totalWithdrawal,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user