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,42 +175,10 @@ 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();
|
||||||
->leftJoin('temp_funds_transfer as ft', 'ft._id', '=', 's.trans_reference')
|
|
||||||
->leftJoin('data_captures as dc', 'dc.id', '=', 's.trans_reference')
|
|
||||||
->select([
|
|
||||||
's.trans_reference',
|
|
||||||
's.booking_date',
|
|
||||||
's.amount_lcy',
|
|
||||||
'ft.debit_acct_no',
|
|
||||||
'ft.debit_value_date',
|
|
||||||
DB::raw('CASE WHEN s.amount_lcy::numeric < 0 THEN s.amount_lcy::numeric ELSE NULL END AS debit_amount'),
|
|
||||||
'ft.credit_acct_no',
|
|
||||||
'ft.bif_rcv_acct',
|
|
||||||
'ft.bif_rcv_name',
|
|
||||||
'ft.credit_value_date',
|
|
||||||
DB::raw('CASE WHEN s.amount_lcy::numeric > 0 THEN s.amount_lcy::numeric ELSE NULL END AS credit_amount'),
|
|
||||||
'ft.at_unique_id',
|
|
||||||
'ft.bif_ref_no',
|
|
||||||
'ft.atm_order_id',
|
|
||||||
'ft.recipt_no',
|
|
||||||
'ft.api_iss_acct',
|
|
||||||
'ft.api_benff_acct',
|
|
||||||
DB::raw('COALESCE(ft.date_time, dc.date_time, s.date_time) AS date_time'),
|
|
||||||
'ft.authoriser',
|
|
||||||
'ft.remarks',
|
|
||||||
'ft.payment_details',
|
|
||||||
'ft.ref_no',
|
|
||||||
'ft.merchant_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
|
// Process data in chunks untuk memory efficiency
|
||||||
$query->chunk($this->chunkSize, function ($transactions) use (&$reportData, &$runningBalance, &$sequenceNo) {
|
$query->chunk($this->chunkSize, function ($transactions) use (&$reportData, &$runningBalance, &$sequenceNo) {
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$sequenceNo++;
|
$sequenceNo++;
|
||||||
@@ -219,34 +189,7 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
// Format transaction date
|
// Format transaction date
|
||||||
$transactionDate = $this->formatDateTime($transaction->date_time);
|
$transactionDate = $this->formatDateTime($transaction->date_time);
|
||||||
|
|
||||||
$reportData[] = [
|
$reportData[] = $this->buildReportDataRow($transaction, $sequenceNo, $transactionDate, $runningBalance);
|
||||||
'sequence_no' => $sequenceNo,
|
|
||||||
'trans_reference' => $transaction->trans_reference,
|
|
||||||
'booking_date' => $transaction->booking_date,
|
|
||||||
'transaction_date' => $transactionDate,
|
|
||||||
'amount_lcy' => $transaction->amount_lcy,
|
|
||||||
'debit_acct_no' => $transaction->debit_acct_no,
|
|
||||||
'debit_value_date' => $transaction->debit_value_date,
|
|
||||||
'debit_amount' => $transaction->debit_amount,
|
|
||||||
'credit_acct_no' => $transaction->credit_acct_no,
|
|
||||||
'bif_rcv_acct' => $transaction->bif_rcv_acct,
|
|
||||||
'bif_rcv_name' => $transaction->bif_rcv_name,
|
|
||||||
'credit_value_date' => $transaction->credit_value_date,
|
|
||||||
'credit_amount' => $transaction->credit_amount,
|
|
||||||
'at_unique_id' => $transaction->at_unique_id,
|
|
||||||
'bif_ref_no' => $transaction->bif_ref_no,
|
|
||||||
'atm_order_id' => $transaction->atm_order_id,
|
|
||||||
'recipt_no' => $transaction->recipt_no,
|
|
||||||
'api_iss_acct' => $transaction->api_iss_acct,
|
|
||||||
'api_benff_acct' => $transaction->api_benff_acct,
|
|
||||||
'authoriser' => $transaction->authoriser,
|
|
||||||
'remarks' => $transaction->remarks,
|
|
||||||
'payment_details' => $transaction->payment_details,
|
|
||||||
'ref_no' => $transaction->ref_no,
|
|
||||||
'merchant_id' => $transaction->merchant_id,
|
|
||||||
'term_id' => $transaction->term_id,
|
|
||||||
'closing_balance' => $runningBalance
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,6 +201,106 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
return $reportData;
|
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('data_captures as dc', 'dc.id', '=', 's.trans_reference')
|
||||||
|
->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.booking_date',
|
||||||
|
's.amount_lcy',
|
||||||
|
'ft.debit_acct_no',
|
||||||
|
'ft.debit_value_date',
|
||||||
|
DB::raw('CASE WHEN s.amount_lcy::numeric < 0 THEN s.amount_lcy::numeric ELSE NULL END AS debit_amount'),
|
||||||
|
'ft.credit_acct_no',
|
||||||
|
'ft.bif_rcv_acct',
|
||||||
|
'ft.bif_rcv_name',
|
||||||
|
'ft.credit_value_date',
|
||||||
|
DB::raw('CASE WHEN s.amount_lcy::numeric > 0 THEN s.amount_lcy::numeric ELSE NULL END AS credit_amount'),
|
||||||
|
'ft.at_unique_id',
|
||||||
|
'ft.bif_ref_no',
|
||||||
|
'ft.atm_order_id',
|
||||||
|
'ft.recipt_no',
|
||||||
|
'ft.api_iss_acct',
|
||||||
|
'ft.api_benff_acct',
|
||||||
|
DB::raw('COALESCE(ft.date_time, dc.date_time, s.date_time) AS date_time'),
|
||||||
|
'ft.authoriser',
|
||||||
|
'ft.remarks',
|
||||||
|
'ft.payment_details',
|
||||||
|
'ft.ref_no',
|
||||||
|
'ft.merchant_id',
|
||||||
|
'ft.term_id'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build report data row from transaction
|
||||||
|
* Membangun baris data laporan dari transaksi
|
||||||
|
*/
|
||||||
|
private function buildReportDataRow($transaction, int $sequenceNo, string $transactionDate, float $runningBalance): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'sequence_no' => $sequenceNo,
|
||||||
|
'trans_reference' => $transaction->trans_reference,
|
||||||
|
'booking_date' => $transaction->booking_date,
|
||||||
|
'transaction_date' => $transactionDate,
|
||||||
|
'amount_lcy' => $transaction->amount_lcy,
|
||||||
|
'debit_acct_no' => $transaction->debit_acct_no,
|
||||||
|
'debit_value_date' => $transaction->debit_value_date,
|
||||||
|
'debit_amount' => $transaction->debit_amount,
|
||||||
|
'credit_acct_no' => $transaction->credit_acct_no,
|
||||||
|
'bif_rcv_acct' => $transaction->bif_rcv_acct,
|
||||||
|
'bif_rcv_name' => $transaction->bif_rcv_name,
|
||||||
|
'credit_value_date' => $transaction->credit_value_date,
|
||||||
|
'credit_amount' => $transaction->credit_amount,
|
||||||
|
'at_unique_id' => $transaction->at_unique_id,
|
||||||
|
'bif_ref_no' => $transaction->bif_ref_no,
|
||||||
|
'atm_order_id' => $transaction->atm_order_id,
|
||||||
|
'recipt_no' => $transaction->recipt_no,
|
||||||
|
'api_iss_acct' => $transaction->api_iss_acct,
|
||||||
|
'api_benff_acct' => $transaction->api_benff_acct,
|
||||||
|
'authoriser' => $transaction->authoriser,
|
||||||
|
'remarks' => $transaction->remarks,
|
||||||
|
'payment_details' => $transaction->payment_details,
|
||||||
|
'ref_no' => $transaction->ref_no,
|
||||||
|
'merchant_id' => $transaction->merchant_id,
|
||||||
|
'term_id' => $transaction->term_id,
|
||||||
|
'closing_balance' => $runningBalance
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format datetime string
|
* Format datetime string
|
||||||
* Memformat string datetime
|
* Memformat string datetime
|
||||||
|
|||||||
Reference in New Issue
Block a user