transactions as $transaction) { if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue; if ((int) $transaction->type === TransactionType::TOP_UP) $topups += (float) $transaction->amount; if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount; if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount; if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount; } $auditBalance = ($topups + $credit) - ($payments + $debit); Log::info('Wallet audit completed', [ 'wallet_id' => $model->id, 'topups' => $topups, 'credit' => $credit, 'payments' => $payments, 'debit' => $debit, 'audit_balance' => $auditBalance, ]); $model->amount = $auditBalance; return $this->handler($model); } }