refactor(webstatement): pisahkan pengolahan data saldo dari data akun
- Menambahkan properti baru `$balanceData` untuk memisahkan data saldo dari data akun. - Menyimpan nilai `open_actual_bal` dan `open_cleared_bal` dalam `$balanceData` sebelum menghapusnya dari data akun. - Mengubah parameter `saveAccountBalance` dari array data akun menjadi hanya `accountNumber`. - Memanfaatkan `$balanceData` untuk mengatur nilai `actual_balance` dan `cleared_balance` dalam proses penyimpanan ke model `AccountBalance`. - Mengurangi potensi error dan membuat kode lebih modular dengan memisahkan pengolahan data saldo dari data akun. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
private int $processedCount = 0;
|
private int $processedCount = 0;
|
||||||
private int $errorCount = 0;
|
private int $errorCount = 0;
|
||||||
|
|
||||||
|
private $balanceData = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*/
|
*/
|
||||||
@@ -147,6 +149,16 @@
|
|||||||
if (empty($data['closure_date']) || $data['closure_date'] == "" || $data['closure_date'] == null) {
|
if (empty($data['closure_date']) || $data['closure_date'] == "" || $data['closure_date'] == null) {
|
||||||
$data['closure_date'] = null;
|
$data['closure_date'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store balance data separately before removing from Account data
|
||||||
|
$this->balanceData = [
|
||||||
|
'open_actual_bal' => empty($data['open_actual_bal']) ? 0 : $data['open_actual_bal'],
|
||||||
|
'open_cleared_bal' => empty($data['open_cleared_bal']) ? 0 : $data['open_cleared_bal'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Remove balance fields from Account data
|
||||||
|
unset($data['open_actual_bal']);
|
||||||
|
unset($data['open_cleared_bal']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveRecord(array $data, int $rowCount, string $filePath)
|
private function saveRecord(array $data, int $rowCount, string $filePath)
|
||||||
@@ -159,7 +171,7 @@
|
|||||||
$account->fill($data);
|
$account->fill($data);
|
||||||
$account->save();
|
$account->save();
|
||||||
|
|
||||||
$this->saveAccountBalance($data);
|
$this->saveAccountBalance($data['account_number']);
|
||||||
$this->processedCount++;
|
$this->processedCount++;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -168,17 +180,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveAccountBalance(array $data)
|
private function saveAccountBalance(string $accountNumber)
|
||||||
: void
|
: void
|
||||||
{
|
{
|
||||||
// Store the opening balances in the AccountBalance model for this period
|
// Store the opening balances in the AccountBalance model for this period
|
||||||
if (isset($data['open_actual_bal']) || isset($data['open_cleared_bal'])) {
|
if (isset($this->balanceData['open_actual_bal']) || isset($this->balanceData['open_cleared_bal'])) {
|
||||||
// Prepare balance data for bulk insert/update
|
// Prepare balance data for bulk insert/update
|
||||||
$balanceData = [
|
$balanceData = [
|
||||||
'account_number' => $data['account_number'],
|
'account_number' => $accountNumber,
|
||||||
'period' => $this->period,
|
'period' => $this->period,
|
||||||
'actual_balance' => empty($data['open_actual_bal']) ? 0 : $data['open_actual_bal'],
|
'actual_balance' => $this->balanceData['open_actual_bal'],
|
||||||
'cleared_balance' => empty($data['open_cleared_bal']) ? 0 : $data['open_cleared_bal'],
|
'cleared_balance' => $this->balanceData['open_cleared_bal'],
|
||||||
'created_at' => now(),
|
'created_at' => now(),
|
||||||
'updated_at' => now()
|
'updated_at' => now()
|
||||||
];
|
];
|
||||||
@@ -186,7 +198,7 @@
|
|||||||
// Use updateOrInsert to reduce queries
|
// Use updateOrInsert to reduce queries
|
||||||
AccountBalance::updateOrInsert(
|
AccountBalance::updateOrInsert(
|
||||||
[
|
[
|
||||||
'account_number' => $data['account_number'],
|
'account_number' => $accountNumber,
|
||||||
'period' => $this->period
|
'period' => $this->period
|
||||||
],
|
],
|
||||||
$balanceData
|
$balanceData
|
||||||
|
|||||||
Reference in New Issue
Block a user