diff --git a/app/Services/AnalysisService.php b/app/Services/AnalysisService.php index be71919..39e9580 100644 --- a/app/Services/AnalysisService.php +++ b/app/Services/AnalysisService.php @@ -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, ]; }