refactor(webstatement): split generateReportData dan dukung closing balance per group akun
- Refactor generateReportData jadi fungsi kecil (query builder, selector, row builder) - Tambah dukungan multi group akun (DEFAULT, QRIS) pada closing balance job - Pisahkan akun QRIS dan sesuaikan struktur dispatch dan account list - Tingkatkan maintainability, scalability, dan clarity proses
This commit is contained in:
@@ -64,16 +64,6 @@ class GenerateClosingBalanceReportBulkCommand extends Command
|
|||||||
'IDR1354400010001',
|
'IDR1354400010001',
|
||||||
'IDR1728500010001',
|
'IDR1728500010001',
|
||||||
'IDR1728600010001',
|
'IDR1728600010001',
|
||||||
'IDR1354500010001',
|
|
||||||
'IDR1354500020001',
|
|
||||||
'IDR1354500030001',
|
|
||||||
'IDR1354500040001',
|
|
||||||
'IDR1354500050001',
|
|
||||||
'IDR1354500060001',
|
|
||||||
'IDR1354500070001',
|
|
||||||
'IDR1354500080001',
|
|
||||||
'IDR1354500090001',
|
|
||||||
'IDR1354500100001',
|
|
||||||
'IDR1720500010001',
|
'IDR1720500010001',
|
||||||
'1078333878',
|
'1078333878',
|
||||||
'1081647484',
|
'1081647484',
|
||||||
@@ -89,6 +79,19 @@ class GenerateClosingBalanceReportBulkCommand extends Command
|
|||||||
'IDR1354200010001'
|
'IDR1354200010001'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private $qrisAccount = [
|
||||||
|
'IDR1354500010001',
|
||||||
|
'IDR1354500020001',
|
||||||
|
'IDR1354500030001',
|
||||||
|
'IDR1354500040001',
|
||||||
|
'IDR1354500050001',
|
||||||
|
'IDR1354500060001',
|
||||||
|
'IDR1354500070001',
|
||||||
|
'IDR1354500080001',
|
||||||
|
'IDR1354500090001',
|
||||||
|
'IDR1354500100001',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
* Menjalankan proses generate laporan closing balance untuk banyak rekening dengan periode range
|
* Menjalankan proses generate laporan closing balance untuk banyak rekening dengan periode range
|
||||||
@@ -281,7 +284,7 @@ class GenerateClosingBalanceReportBulkCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Jika tidak ada parameter accounts, gunakan default list
|
// Jika tidak ada parameter accounts, gunakan default list
|
||||||
$accountList = ['DEFAULT' => $this->defaultAccounts];
|
$accountList = ['DEFAULT' => $this->defaultAccounts, 'QRIS' => $this->qrisAccount];
|
||||||
|
|
||||||
// Filter by client jika ada (untuk backward compatibility)
|
// Filter by client jika ada (untuk backward compatibility)
|
||||||
if ($clientFilter) {
|
if ($clientFilter) {
|
||||||
@@ -378,7 +381,7 @@ class GenerateClosingBalanceReportBulkCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch the job
|
// Dispatch the job
|
||||||
GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id);
|
GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id, $groupName);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
protected $accountNumber;
|
protected $accountNumber;
|
||||||
protected $period;
|
protected $period;
|
||||||
protected $reportLogId;
|
protected $reportLogId;
|
||||||
|
protected $groupName;
|
||||||
protected $chunkSize = 1000;
|
protected $chunkSize = 1000;
|
||||||
protected $disk = 'local';
|
protected $disk = 'local';
|
||||||
|
|
||||||
@@ -37,11 +38,12 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
* @param string $period
|
* @param string $period
|
||||||
* @param int $reportLogId
|
* @param int $reportLogId
|
||||||
*/
|
*/
|
||||||
public function __construct(string $accountNumber, string $period, int $reportLogId)
|
public function __construct(string $accountNumber, string $period, int $reportLogId, string $groupName='DEFAULT')
|
||||||
{
|
{
|
||||||
$this->accountNumber = $accountNumber;
|
$this->accountNumber = $accountNumber;
|
||||||
$this->period = $period;
|
$this->period = $period;
|
||||||
$this->reportLogId = $reportLogId;
|
$this->reportLogId = $reportLogId;
|
||||||
|
$this->groupName = $groupName ?? 'DEFAULT';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,11 +175,69 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
$runningBalance = $openingBalance;
|
$runningBalance = $openingBalance;
|
||||||
$sequenceNo = 0;
|
$sequenceNo = 0;
|
||||||
|
|
||||||
// Query berdasarkan SQL yang diberikan user
|
// Build query berdasarkan group name
|
||||||
$query = DB::table('stmt_entry as s')
|
$query = $this->buildTransactionQuery();
|
||||||
|
|
||||||
|
// Process data in chunks untuk memory efficiency
|
||||||
|
$query->chunk($this->chunkSize, function ($transactions) use (&$reportData, &$runningBalance, &$sequenceNo) {
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$sequenceNo++;
|
||||||
|
|
||||||
|
// Calculate running balance
|
||||||
|
$runningBalance += (float) $transaction->amount_lcy;
|
||||||
|
|
||||||
|
// Format transaction date
|
||||||
|
$transactionDate = $this->formatDateTime($transaction->date_time);
|
||||||
|
|
||||||
|
$reportData[] = $this->buildReportDataRow($transaction, $sequenceNo, $transactionDate, $runningBalance);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Log::info('Report data generated', [
|
||||||
|
'total_records' => count($reportData),
|
||||||
|
'final_balance' => $runningBalance
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $reportData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build transaction query based on group name
|
||||||
|
* Membangun query transaksi berdasarkan group name
|
||||||
|
*/
|
||||||
|
private function buildTransactionQuery()
|
||||||
|
{
|
||||||
|
// Tentukan tabel berdasarkan group name
|
||||||
|
$tableName = $this->getTableNameByGroup();
|
||||||
|
|
||||||
|
$query = DB::table($tableName . ' as s')
|
||||||
->leftJoin('temp_funds_transfer as ft', 'ft._id', '=', 's.trans_reference')
|
->leftJoin('temp_funds_transfer as ft', 'ft._id', '=', 's.trans_reference')
|
||||||
->leftJoin('data_captures as dc', 'dc.id', '=', 's.trans_reference')
|
->leftJoin('data_captures as dc', 'dc.id', '=', 's.trans_reference')
|
||||||
->select([
|
->select($this->getSelectFields())
|
||||||
|
->where('s.account_number', $this->accountNumber)
|
||||||
|
->where('s.booking_date', $this->period)
|
||||||
|
->orderBy('s.booking_date')
|
||||||
|
->orderBy('date_time');
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get table name based on group name
|
||||||
|
* Mendapatkan nama tabel berdasarkan group name
|
||||||
|
*/
|
||||||
|
private function getTableNameByGroup(): string
|
||||||
|
{
|
||||||
|
return $this->groupName === 'QRIS' ? 'stmt_entry' : 'stmt_entry_details';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get select fields for the query
|
||||||
|
* Mendapatkan field select untuk query
|
||||||
|
*/
|
||||||
|
private function getSelectFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
's.trans_reference',
|
's.trans_reference',
|
||||||
's.booking_date',
|
's.booking_date',
|
||||||
's.amount_lcy',
|
's.amount_lcy',
|
||||||
@@ -202,24 +262,16 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
'ft.ref_no',
|
'ft.ref_no',
|
||||||
'ft.merchant_id',
|
'ft.merchant_id',
|
||||||
'ft.term_id'
|
'ft.term_id'
|
||||||
])
|
];
|
||||||
->where('s.account_number', $this->accountNumber)
|
}
|
||||||
->where('s.booking_date', $this->period)
|
|
||||||
->orderBy('s.booking_date')
|
|
||||||
->orderBy('date_time');
|
|
||||||
|
|
||||||
// Process data in chunks
|
/**
|
||||||
$query->chunk($this->chunkSize, function ($transactions) use (&$reportData, &$runningBalance, &$sequenceNo) {
|
* Build report data row from transaction
|
||||||
foreach ($transactions as $transaction) {
|
* Membangun baris data laporan dari transaksi
|
||||||
$sequenceNo++;
|
*/
|
||||||
|
private function buildReportDataRow($transaction, int $sequenceNo, string $transactionDate, float $runningBalance): array
|
||||||
// Calculate running balance
|
{
|
||||||
$runningBalance += (float) $transaction->amount_lcy;
|
return [
|
||||||
|
|
||||||
// Format transaction date
|
|
||||||
$transactionDate = $this->formatDateTime($transaction->date_time);
|
|
||||||
|
|
||||||
$reportData[] = [
|
|
||||||
'sequence_no' => $sequenceNo,
|
'sequence_no' => $sequenceNo,
|
||||||
'trans_reference' => $transaction->trans_reference,
|
'trans_reference' => $transaction->trans_reference,
|
||||||
'booking_date' => $transaction->booking_date,
|
'booking_date' => $transaction->booking_date,
|
||||||
@@ -248,15 +300,6 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
'closing_balance' => $runningBalance
|
'closing_balance' => $runningBalance
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
Log::info('Report data generated', [
|
|
||||||
'total_records' => count($reportData),
|
|
||||||
'final_balance' => $runningBalance
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $reportData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format datetime string
|
* Format datetime string
|
||||||
|
|||||||
Reference in New Issue
Block a user