From ef90f8361f2b8505e1d80b2175c7706c63f2e749 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 16 Jul 2026 11:15:40 +0700 Subject: [PATCH] feat: clear cache for default account after cash transactions to ensure data consistency --- app/Services/Finance/CashService.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Services/Finance/CashService.php b/app/Services/Finance/CashService.php index 6a30249..0227a27 100644 --- a/app/Services/Finance/CashService.php +++ b/app/Services/Finance/CashService.php @@ -95,6 +95,8 @@ function () use ($cashAccount, $validated, $user): CashTransaction { 'Gagal melakukan setoran kas', ); + $this->cacheForget('finance:default_account'); + $this->pushNotificationService->sendToRoles( '💰 Setoran Kas', "Setoran kas baru {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.", @@ -138,6 +140,8 @@ function () use ($cashAccount, $validated, $user): CashTransaction { 'Gagal melakukan tarik kas', ); + $this->cacheForget('finance:default_account'); + $this->pushNotificationService->sendToRoles( '🏦 Tarik Kas', "Tarik kas {$transaction->amount_formatted} dengan keterangan: {$transaction->description} oleh {$user->profile?->full_name}.", @@ -155,7 +159,7 @@ public function recordOutgoing( User $user, ?CashAccount $cashAccount = null, ): CashTransaction { - return $this->runInTransaction( + $transaction = $this->runInTransaction( function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction { $account = CashAccount::query()->lockForUpdate()->findOrFail( ($cashAccount ?? $this->getDefaultAccount())->id, @@ -187,6 +191,10 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr }, 'Gagal mencatat transaksi keluar kas', ); + + $this->cacheForget('finance:default_account'); + + return $transaction; } public function recordIncoming( @@ -196,7 +204,7 @@ public function recordIncoming( User $user, ?CashAccount $cashAccount = null, ): CashTransaction { - return $this->runInTransaction( + $transaction = $this->runInTransaction( function () use ($reference, $amount, $description, $user, $cashAccount): CashTransaction { $account = CashAccount::query()->lockForUpdate()->findOrFail( ($cashAccount ?? $this->getDefaultAccount())->id, @@ -222,6 +230,10 @@ function () use ($reference, $amount, $description, $user, $cashAccount): CashTr }, 'Gagal mencatat transaksi masuk kas', ); + + $this->cacheForget('finance:default_account'); + + return $transaction; } public function updateDeposit(CashTransaction $transaction, array $validated, User $user): void @@ -250,6 +262,8 @@ function () use ($transaction, $validated): void { 'Gagal memperbarui setoran kas', ); + $this->cacheForget('finance:default_account'); + $this->pushNotificationService->sendToRoles( '✏️ Transaksi Kas Diperbarui', "Transaksi kas dengan keterangan {$transaction->description} diperbarui menjadi senilai {$transaction->amount_formatted} oleh {$user->profile?->full_name}.", @@ -283,6 +297,8 @@ function () use ($transaction): void { 'Gagal menghapus transaksi kas', ); + $this->cacheForget('finance:default_account'); + $this->pushNotificationService->sendToRoles( '🗑️ Transaksi Kas Dihapus', "Transaksi kas senilai {$amountFormatted} dengan keterangan {$description} telah dihapus oleh {$user->profile?->full_name}.", @@ -317,6 +333,8 @@ function () use ($transaction, $amount, $description): void { }, 'Gagal memperbarui transaksi kas referensi', ); + + $this->cacheForget('finance:default_account'); } public function deleteReferencedTransaction(CashTransaction $transaction): void @@ -338,6 +356,8 @@ function () use ($transaction): void { }, 'Gagal menghapus transaksi kas referensi', ); + + $this->cacheForget('finance:default_account'); } private function recalculateBalances(CashAccount $cashAccount): void