diff --git a/app/Jobs/ProcessAccountDataJob.php b/app/Jobs/ProcessAccountDataJob.php index 71bd8da..e88b105 100644 --- a/app/Jobs/ProcessAccountDataJob.php +++ b/app/Jobs/ProcessAccountDataJob.php @@ -90,17 +90,24 @@ // 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([ + // Prepare balance data for bulk insert/update + $balanceData = [ 'account_number' => $data['account_number'], - 'period' => $this->period - ]); + 'period' => $this->period, + 'actual_balance' => empty($data['open_actual_bal']) ? 0 : $data['open_actual_bal'], + 'cleared_balance' => empty($data['open_cleared_bal']) ? 0 : $data['open_cleared_bal'], + 'created_at' => now(), + 'updated_at' => now() + ]; - // Set the balances - $accountBalance->actual_balance = $data['open_actual_bal'] ?? 0; - $accountBalance->cleared_balance = $data['open_cleared_bal'] ?? 0; - - $accountBalance->save(); - Log::info("Saved balance for account {$data['account_number']} for period {$this->period}"); + // Use updateOrInsert to reduce queries + AccountBalance::updateOrInsert( + [ + 'account_number' => $data['account_number'], + 'period' => $this->period + ], + $balanceData + ); } $processedCount++; diff --git a/app/Jobs/ProcessStmtEntryDataJob.php b/app/Jobs/ProcessStmtEntryDataJob.php index b572509..b539609 100644 --- a/app/Jobs/ProcessStmtEntryDataJob.php +++ b/app/Jobs/ProcessStmtEntryDataJob.php @@ -73,7 +73,13 @@ if ($data['stmt_entry_id'] !== 'stmt_entry_id') { // Bersihkan trans_reference dari \\BNK jika ada if (isset($data['trans_reference'])) { - $data['trans_reference'] = str_replace('\\BNK', '', $data['trans_reference']); + $cleanedRef = preg_replace('/\\\\.*$/', '', $data['trans_reference']); + //$firstTwoChars = substr($cleanedRef, 0, 2); + /*$data['trans_reference'] = (in_array($firstTwoChars, ['FT', 'TT','AA'])) + ? substr($cleanedRef, 0, 12) + : $cleanedRef;*/ + + $data['trans_reference'] = $cleanedRef; } StmtEntry::updateOrCreate(