diff --git a/app/Console/GenerateClosingBalanceReportCommand.php b/app/Console/GenerateClosingBalanceReportCommand.php index 66a7ca7..d5d26ae 100644 --- a/app/Console/GenerateClosingBalanceReportCommand.php +++ b/app/Console/GenerateClosingBalanceReportCommand.php @@ -25,6 +25,7 @@ class GenerateClosingBalanceReportCommand extends Command protected $signature = 'webstatement:generate-closing-balance-report {account_number : Nomor rekening untuk generate laporan} {period : Period laporan format YYYYMMDD, contoh: 20250515} + {group=DEFAULT : Group transaksi QRIS atau DEFAULT} {--user_id=1 : ID user yang menjalankan command (default: 1)}'; /** @@ -32,7 +33,7 @@ class GenerateClosingBalanceReportCommand extends Command * * @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. @@ -47,10 +48,11 @@ class GenerateClosingBalanceReportCommand extends Command // Get parameters $accountNumber = $this->argument('account_number'); $period = $this->argument('period'); + $group = $this->argument('group'); $userId = $this->option('user_id'); // Validate parameters - if (!$this->validateParameters($accountNumber, $period, $userId)) { + if (!$this->validateParameters($accountNumber, $period, $group, $userId)) { return Command::FAILURE; } @@ -61,12 +63,13 @@ class GenerateClosingBalanceReportCommand extends Command Log::info('Console command: Starting closing balance report generation', [ 'account_number' => $accountNumber, 'period' => $period, + 'group' => $group, 'user_id' => $userId, 'command' => 'webstatement:generate-closing-balance-report' ]); // Create report log entry - $reportLog = $this->createReportLog($accountNumber, $period, $userId); + $reportLog = $this->createReportLog($accountNumber, $period, $group, $userId); if (!$reportLog) { $this->error('Failed to create report log entry'); @@ -74,14 +77,15 @@ class GenerateClosingBalanceReportCommand extends Command return Command::FAILURE; } - // Dispatch the job - GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id); + // Dispatch the job with group parameter + GenerateClosingBalanceReportJob::dispatch($accountNumber, $period, $reportLog->id, $group); DB::commit(); $this->info("Closing Balance report generation job queued successfully!"); $this->info("Account Number: {$accountNumber}"); $this->info("Period: {$period}"); + $this->info("Group: {$group}"); $this->info("Report Log ID: {$reportLog->id}"); $this->info('The report will be generated in the background.'); $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', [ 'account_number' => $accountNumber, 'period' => $period, + 'group' => $group, 'report_log_id' => $reportLog->id, 'user_id' => $userId ]); @@ -105,6 +110,7 @@ class GenerateClosingBalanceReportCommand extends Command Log::error('Console command: Error generating closing balance report', [ 'account_number' => $accountNumber, 'period' => $period, + 'group' => $group, 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() @@ -120,10 +126,11 @@ class GenerateClosingBalanceReportCommand extends Command * * @param string $accountNumber * @param string $period + * @param string $group * @param int $userId * @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 if (empty($accountNumber)) { @@ -147,6 +154,13 @@ class GenerateClosingBalanceReportCommand extends Command 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 $user = User::find($userId); if (!$user) { @@ -163,10 +177,11 @@ class GenerateClosingBalanceReportCommand extends Command * * @param string $accountNumber * @param string $period + * @param string $group * @param int $userId * @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 { // Convert period string to Carbon date @@ -176,6 +191,7 @@ class GenerateClosingBalanceReportCommand extends Command 'account_number' => $accountNumber, 'period' => $period, 'report_date' => $reportDate, // Required field yang sebelumnya missing + 'group_name' => strtoupper($group), // Tambahkan group_name ke log 'status' => 'pending', 'user_id' => $userId, 'created_by' => $userId, // Required field yang sebelumnya missing @@ -190,6 +206,7 @@ class GenerateClosingBalanceReportCommand extends Command 'report_log_id' => $reportLog->id, 'account_number' => $accountNumber, 'period' => $period, + 'group' => $group, 'report_date' => $reportDate->format('Y-m-d'), 'user_id' => $userId ]); @@ -200,6 +217,7 @@ class GenerateClosingBalanceReportCommand extends Command Log::error('Console command: Error creating report log', [ 'account_number' => $accountNumber, 'period' => $period, + 'group' => $group, 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() diff --git a/app/Jobs/GenerateClosingBalanceReportJob.php b/app/Jobs/GenerateClosingBalanceReportJob.php index 5a38255..5b620b9 100644 --- a/app/Jobs/GenerateClosingBalanceReportJob.php +++ b/app/Jobs/GenerateClosingBalanceReportJob.php @@ -365,15 +365,6 @@ class GenerateClosingBalanceReportJob implements ShouldQueue 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 * Membangun baris data laporan dari transaksi