getCashAccount(); $newBalance = $cashAccount->balance + $amount; $cashAccount->update(['balance' => $newBalance]); return CashTransaction::create([ 'cash_account_id' => $cashAccount->id, 'created_by_id' => auth()->id(), 'amount' => $amount, 'balance_after' => $newBalance, 'type' => $type, 'description' => $description, ]); } private function debitCash(int $amount, string $description, CashTransactionType $type = CashTransactionType::EXPENSE): CashTransaction { $cashAccount = $this->getCashAccount(); if ($cashAccount->balance < $amount) { throw ValidationException::withMessages([ 'amount' => 'Saldo tidak mencukupi.', ]); } $newBalance = $cashAccount->balance - $amount; $cashAccount->update(['balance' => $newBalance]); return CashTransaction::create([ 'cash_account_id' => $cashAccount->id, 'created_by_id' => auth()->id(), 'amount' => $amount, 'balance_after' => $newBalance, 'type' => $type, 'description' => $description, ]); } }