fix(export): update global sequence tracking and correct formatting issues
- Perbaiki penggunaan `sequence_no` dalam proses ekspor data dengan menambahkan pelacakan global sequence (`globalSequence`) di seluruh chunk, sehingga memastikan urutan yang konsisten dan tepat. - Gantikan penggunaan indeks lokal chunk dengan `globalSequence` di setiap entri dalam data proses. - Tambahkan komentar untuk menjelaskan fungsi tambahan terkait pelacakan sequence global. - Koreksi format narasi pada nilai `'FT.OUT'` yang sebelumnya salah menggunakan `'FT.IN'`. - Tambahkan pemeriksaan dan pembaruan pada logika penyimpanan data untuk meningkatkan kejelasan dan efisiensi.
This commit is contained in:
@@ -93,16 +93,20 @@
|
|||||||
|
|
||||||
Log::info("Processing {$totalCount} statement entries for account: {$this->account_number}");
|
Log::info("Processing {$totalCount} statement entries for account: {$this->account_number}");
|
||||||
|
|
||||||
|
// Track the global sequence number across chunks
|
||||||
|
$globalSequence = 0;
|
||||||
|
|
||||||
// Proses data dalam chunk untuk mengurangi penggunaan memori
|
// Proses data dalam chunk untuk mengurangi penggunaan memori
|
||||||
StmtEntry::with(['ft', 'transaction'])
|
StmtEntry::with(['ft', 'transaction'])
|
||||||
->where('account_number', $this->account_number)
|
->where('account_number', $this->account_number)
|
||||||
->where('booking_date', $this->period)
|
->where('booking_date', $this->period)
|
||||||
->orderBy('date_time', 'ASC')
|
->orderBy('date_time', 'ASC')
|
||||||
->orderBy('trans_reference', 'ASC')
|
->orderBy('trans_reference', 'ASC')
|
||||||
->chunk($this->chunkSize, function ($entries) use (&$runningBalance) {
|
->chunk($this->chunkSize, function ($entries) use (&$runningBalance, &$globalSequence) {
|
||||||
$processedData = [];
|
$processedData = [];
|
||||||
|
|
||||||
foreach ($entries as $index => $item) {
|
foreach ($entries as $item) {
|
||||||
|
$globalSequence++; // Increment the global sequence counter
|
||||||
$runningBalance += (float) $item->amount_lcy;
|
$runningBalance += (float) $item->amount_lcy;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -124,7 +128,7 @@
|
|||||||
$processedData[] = [
|
$processedData[] = [
|
||||||
'account_number' => $this->account_number,
|
'account_number' => $this->account_number,
|
||||||
'period' => $this->period,
|
'period' => $this->period,
|
||||||
'sequence_no' => $index + 1,
|
'sequence_no' => $globalSequence,
|
||||||
'transaction_date' => $transactionDate,
|
'transaction_date' => $transactionDate,
|
||||||
'reference_number' => $item->trans_reference,
|
'reference_number' => $item->trans_reference,
|
||||||
'transaction_amount' => $item->amount_lcy,
|
'transaction_amount' => $item->amount_lcy,
|
||||||
@@ -136,7 +140,7 @@
|
|||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
// var_dump($processedData);
|
||||||
// Simpan data dalam batch untuk kinerja yang lebih baik
|
// Simpan data dalam batch untuk kinerja yang lebih baik
|
||||||
if (!empty($processedData)) {
|
if (!empty($processedData)) {
|
||||||
DB::table('processed_statements')->insert($processedData);
|
DB::table('processed_statements')->insert($processedData);
|
||||||
@@ -178,7 +182,7 @@
|
|||||||
if ($narrParam->_id == 'FTIN') {
|
if ($narrParam->_id == 'FTIN') {
|
||||||
$fmt = 'FT.IN';
|
$fmt = 'FT.IN';
|
||||||
} else if ($narrParam->_id == 'FTOUT') {
|
} else if ($narrParam->_id == 'FTOUT') {
|
||||||
$fmt = 'FT.IN';
|
$fmt = 'FT.OUT';
|
||||||
} else {
|
} else {
|
||||||
$fmt = $narrParam->_id;
|
$fmt = $narrParam->_id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user