From 59d186e3b56ab6cbc564a1a81e4d0f28feb097d5 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Fri, 23 May 2025 19:34:39 +0700 Subject: [PATCH] feat(webstatement): simpan saldo pembukaan ke model AccountBalance - Tambahkan use statement untuk model `AccountBalance` di `ProcessAccountDataJob`. - Simpan saldo pembukaan (`open_actual_bal` dan `open_cleared_bal`) dari data akun yang diproses ke model `AccountBalance`. - Gunakan `firstOrNew` untuk memastikan data saldo pembukaan unik berdasarkan nomor akun dan periode tertentu. - Tambahkan log untuk mencatat penyimpanan saldo pembukaan yang berhasil dilakukan. - Pastikan penyimpanan hanya dilakukan jika data saldo tersedia di input (`isset` pada `open_actual_bal` atau ` Signed-off-by: Daeng Deni Mardaeni --- app/Jobs/ProcessAccountDataJob.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/Jobs/ProcessAccountDataJob.php b/app/Jobs/ProcessAccountDataJob.php index 04137a6..439cfcf 100644 --- a/app/Jobs/ProcessAccountDataJob.php +++ b/app/Jobs/ProcessAccountDataJob.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Modules\Webstatement\Models\Account; + use Modules\Webstatement\Models\AccountBalance; class ProcessAccountDataJob implements ShouldQueue { @@ -92,6 +93,27 @@ $account = Account::firstOrNew(['account_number' => $data['account_number']]); $account->fill($data); $account->save(); + + // Store the opening balances in the AccountBalance model for this period + if (isset($data['open_actual_bal']) || isset($data['open_cleared_bal'])) { + $accountBalance = AccountBalance::firstOrNew([ + 'account_number' => $data['account_number'], + 'period' => $period + ]); + + // Set the balances + if (isset($data['open_actual_bal'])) { + $accountBalance->actual_balance = $data['open_actual_bal']; + } + + if (isset($data['open_cleared_bal'])) { + $accountBalance->cleared_balance = $data['open_cleared_bal']; + } + + $accountBalance->save(); + Log::info("Saved balance for account {$data['account_number']} for period $period"); + } + $processedCount++; } } catch (Exception $e) {