feat(console): tambah parameter group pada GenerateClosingBalanceReportCommand
Perubahan yang dilakukan: - Menambahkan parameter `group` sebagai argument wajib pada signature command - Memperbarui deskripsi command untuk mencantumkan informasi tentang parameter `group` - Menambahkan validasi `group` agar hanya menerima nilai yang diizinkan: `QRIS` dan `DEFAULT` - Memperbarui method `validateParameters()` untuk mendukung validasi nilai `group` - Memperbarui method `createReportLog()` agar menyimpan `group_name` ke database - Menambahkan `group` ke semua entri log untuk keperluan tracking dan debugging - Menyesuaikan pemanggilan `GenerateClosingBalanceReportJob` dengan menyertakan parameter `group` - Menambahkan informasi `group` pada pesan output console untuk feedback pengguna - Menjamin konsistensi dengan implementasi `GenerateClosingBalanceReportJob` yang telah mendukung parameter `group` - Meningkatkan fleksibilitas command untuk mendukung multiple jenis transaksi Manfaat: - Memungkinkan generate laporan closing balance berdasarkan tipe transaksi - Logging lebih informatif dan terstruktur berdasarkan kelompok transaksi - Command lebih fleksibel dan extensible untuk kebutuhan selanjutnya - Validasi ketat memastikan data yang diproses sesuai spesifikasi sistem Refs: #closing-balance-refactor
This commit is contained in:
@@ -25,6 +25,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
protected $signature = 'webstatement:generate-closing-balance-report
|
protected $signature = 'webstatement:generate-closing-balance-report
|
||||||
{account_number : Nomor rekening untuk generate laporan}
|
{account_number : Nomor rekening untuk generate laporan}
|
||||||
{period : Period laporan format YYYYMMDD, contoh: 20250515}
|
{period : Period laporan format YYYYMMDD, contoh: 20250515}
|
||||||
|
{group=DEFAULT : Group transaksi QRIS atau DEFAULT}
|
||||||
{--user_id=1 : ID user yang menjalankan command (default: 1)}';
|
{--user_id=1 : ID user yang menjalankan command (default: 1)}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +33,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Generate Closing Balance report untuk nomor rekening dan periode tertentu';
|
protected $description = 'Generate Closing Balance report untuk nomor rekening, periode, dan group tertentu';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
@@ -47,10 +48,11 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
// Get parameters
|
// Get parameters
|
||||||
$accountNumber = $this->argument('account_number');
|
$accountNumber = $this->argument('account_number');
|
||||||
$period = $this->argument('period');
|
$period = $this->argument('period');
|
||||||
|
$group = $this->argument('group');
|
||||||
$userId = $this->option('user_id');
|
$userId = $this->option('user_id');
|
||||||
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (!$this->validateParameters($accountNumber, $period, $userId)) {
|
if (!$this->validateParameters($accountNumber, $period, $group, $userId)) {
|
||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,12 +63,13 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
Log::info('Console command: Starting closing balance report generation', [
|
Log::info('Console command: Starting closing balance report generation', [
|
||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
|
'group' => $group,
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
'command' => 'webstatement:generate-closing-balance-report'
|
'command' => 'webstatement:generate-closing-balance-report'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Create report log entry
|
// Create report log entry
|
||||||
$reportLog = $this->createReportLog($accountNumber, $period, $userId);
|
$reportLog = $this->createReportLog($accountNumber, $period, $group, $userId);
|
||||||
|
|
||||||
if (!$reportLog) {
|
if (!$reportLog) {
|
||||||
$this->error('Failed to create report log entry');
|
$this->error('Failed to create report log entry');
|
||||||
@@ -74,14 +77,15 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch the job
|
// Dispatch the job with group parameter
|
||||||
GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id);
|
GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id, $group);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
$this->info("Closing Balance report generation job queued successfully!");
|
$this->info("Closing Balance report generation job queued successfully!");
|
||||||
$this->info("Account Number: {$accountNumber}");
|
$this->info("Account Number: {$accountNumber}");
|
||||||
$this->info("Period: {$period}");
|
$this->info("Period: {$period}");
|
||||||
|
$this->info("Group: {$group}");
|
||||||
$this->info("Report Log ID: {$reportLog->id}");
|
$this->info("Report Log ID: {$reportLog->id}");
|
||||||
$this->info('The report will be generated in the background.');
|
$this->info('The report will be generated in the background.');
|
||||||
$this->info('Check the closing_balance_report_logs table for progress.');
|
$this->info('Check the closing_balance_report_logs table for progress.');
|
||||||
@@ -90,6 +94,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
Log::info('Console command: Closing balance report job dispatched successfully', [
|
Log::info('Console command: Closing balance report job dispatched successfully', [
|
||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
|
'group' => $group,
|
||||||
'report_log_id' => $reportLog->id,
|
'report_log_id' => $reportLog->id,
|
||||||
'user_id' => $userId
|
'user_id' => $userId
|
||||||
]);
|
]);
|
||||||
@@ -105,6 +110,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
Log::error('Console command: Error generating closing balance report', [
|
Log::error('Console command: Error generating closing balance report', [
|
||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
|
'group' => $group,
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'trace' => $e->getTraceAsString()
|
'trace' => $e->getTraceAsString()
|
||||||
@@ -120,10 +126,11 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
*
|
*
|
||||||
* @param string $accountNumber
|
* @param string $accountNumber
|
||||||
* @param string $period
|
* @param string $period
|
||||||
|
* @param string $group
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function validateParameters(string $accountNumber, string $period, int $userId): bool
|
private function validateParameters(string $accountNumber, string $period, string $group, int $userId): bool
|
||||||
{
|
{
|
||||||
// Validate account number
|
// Validate account number
|
||||||
if (empty($accountNumber)) {
|
if (empty($accountNumber)) {
|
||||||
@@ -147,6 +154,13 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate group parameter
|
||||||
|
$allowedGroups = ['QRIS', 'DEFAULT'];
|
||||||
|
if (!in_array(strtoupper($group), $allowedGroups)) {
|
||||||
|
$this->error('Invalid group parameter. Allowed values: ' . implode(', ', $allowedGroups));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate user exists
|
// Validate user exists
|
||||||
$user = User::find($userId);
|
$user = User::find($userId);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@@ -163,10 +177,11 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
*
|
*
|
||||||
* @param string $accountNumber
|
* @param string $accountNumber
|
||||||
* @param string $period
|
* @param string $period
|
||||||
|
* @param string $group
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @return ClosingBalanceReportLog|null
|
* @return ClosingBalanceReportLog|null
|
||||||
*/
|
*/
|
||||||
private function createReportLog(string $accountNumber, string $period, int $userId): ?ClosingBalanceReportLog
|
private function createReportLog(string $accountNumber, string $period, string $group, int $userId): ?ClosingBalanceReportLog
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Convert period string to Carbon date
|
// Convert period string to Carbon date
|
||||||
@@ -176,6 +191,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
'report_date' => $reportDate, // Required field yang sebelumnya missing
|
'report_date' => $reportDate, // Required field yang sebelumnya missing
|
||||||
|
'group_name' => strtoupper($group), // Tambahkan group_name ke log
|
||||||
'status' => 'pending',
|
'status' => 'pending',
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
'created_by' => $userId, // Required field yang sebelumnya missing
|
'created_by' => $userId, // Required field yang sebelumnya missing
|
||||||
@@ -190,6 +206,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
'report_log_id' => $reportLog->id,
|
'report_log_id' => $reportLog->id,
|
||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
|
'group' => $group,
|
||||||
'report_date' => $reportDate->format('Y-m-d'),
|
'report_date' => $reportDate->format('Y-m-d'),
|
||||||
'user_id' => $userId
|
'user_id' => $userId
|
||||||
]);
|
]);
|
||||||
@@ -200,6 +217,7 @@ class GenerateClosingBalanceReportCommand extends Command
|
|||||||
Log::error('Console command: Error creating report log', [
|
Log::error('Console command: Error creating report log', [
|
||||||
'account_number' => $accountNumber,
|
'account_number' => $accountNumber,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
|
'group' => $group,
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'trace' => $e->getTraceAsString()
|
'trace' => $e->getTraceAsString()
|
||||||
|
|||||||
@@ -365,15 +365,6 @@ class GenerateClosingBalanceReportJob implements ShouldQueue
|
|||||||
return $reportData;
|
return $reportData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build report data row from transaction
|
* Build report data row from transaction
|
||||||
* Membangun baris data laporan dari transaksi
|
* Membangun baris data laporan dari transaksi
|
||||||
|
|||||||
Reference in New Issue
Block a user