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 <ddeni05@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Modules\Webstatement\Models\Account;
|
use Modules\Webstatement\Models\Account;
|
||||||
|
use Modules\Webstatement\Models\AccountBalance;
|
||||||
|
|
||||||
class ProcessAccountDataJob implements ShouldQueue
|
class ProcessAccountDataJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
@@ -92,6 +93,27 @@
|
|||||||
$account = Account::firstOrNew(['account_number' => $data['account_number']]);
|
$account = Account::firstOrNew(['account_number' => $data['account_number']]);
|
||||||
$account->fill($data);
|
$account->fill($data);
|
||||||
$account->save();
|
$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++;
|
$processedCount++;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user