info('Starting answered calls reports generation...'); if ($this->option('date')) { $date = Carbon::parse($this->option('date'))->format('Y-m-d'); $this->newLine(); $count = $service->generateDailyAnsweredCalls( $date, fn($msg) => $this->line(" [{$date}] {$msg}") ); $this->newLine(); $this->info("Generated {$count} answered calls for {$date}"); if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { \Log::info("Answered calls report generated", [ 'date' => $date, 'answered_calls' => $count, ]); } return Command::SUCCESS; } $startDate = $this->option('start-date') ? Carbon::parse($this->option('start-date')) : Carbon::today(); $endDate = $this->option('end-date') ? Carbon::parse($this->option('end-date')) : Carbon::today(); if ($startDate->gt($endDate)) { $this->error('Start date must be before or equal end date'); return Command::FAILURE; } $totalDays = $startDate->clone()->diffInDays($endDate) + 1; $padLen = strlen((string) $totalDays); $dayIndex = 0; $totalRecords = 0; $overallStart = microtime(true); $this->line("Range: {$startDate->format('Y-m-d')} → {$endDate->format('Y-m-d')} ({$totalDays} days)"); while ($startDate->lte($endDate)) { $dayIndex++; $date = $startDate->format('Y-m-d'); $prefix = sprintf('[Day %s/%d] %s', str_pad($dayIndex, $padLen, ' ', STR_PAD_LEFT), $totalDays, $date); $this->newLine(); $count = $service->generateDailyAnsweredCalls( $date, fn($msg) => $this->line(" {$prefix} {$msg}") ); $totalRecords += $count; $startDate->addDay(); } $totalElapsed = round(microtime(true) - $overallStart, 1); $this->newLine(); $this->info("Total answered calls generated: {$totalRecords} in {$totalElapsed}s"); $this->info('Answered calls reports generation completed!'); if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { \Log::info('Answered calls reports generated', [ 'start_date' => $this->option('start-date'), 'end_date' => $this->option('end-date'), 'total_answered_calls' => $totalRecords, ]); } return Command::SUCCESS; } }