From 752c3cb0da20043b1e568dc068959e8bcd2e0b57 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 10 Jul 2025 11:21:53 +0530 Subject: [PATCH] changed logic for sending mails for only have schedule types in production report --- app/Console/Commands/SendProductionReport.php | 8 ++++++-- routes/console.php | 14 ++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendProductionReport.php b/app/Console/Commands/SendProductionReport.php index 3e2065e..21d5f97 100644 --- a/app/Console/Commands/SendProductionReport.php +++ b/app/Console/Commands/SendProductionReport.php @@ -17,7 +17,8 @@ class SendProductionReport extends Command * * @var string */ - protected $signature = 'send:production-report'; + //protected $signature = 'send:production-report'; + protected $signature = 'send:production-report {schedule_type}'; /** * The console command description. @@ -32,8 +33,11 @@ class SendProductionReport extends Command public function handle() { - $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities') + $scheduleType = $this->argument('schedule_type'); + + $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities') ->where('rule_name', 'ProductionMail') + ->where('schedule_type', $scheduleType) ->get(); $emails = $mailRules->pluck('email')->unique()->toArray(); diff --git a/routes/console.php b/routes/console.php index 611af45..e8b884a 100644 --- a/routes/console.php +++ b/routes/console.php @@ -141,31 +141,25 @@ Artisan::command('inspire', function () { app()->booted(function () { $schedule = app(Schedule::class); - // Get all production rules with logging $productionRules = AlertMailRule::where('module', 'ProductionQuantities') ->where('rule_name', 'ProductionMail') ->get(); - foreach ($productionRules as $rule) { - $command = $schedule->command("send:production-report"); + $types = $productionRules->pluck('schedule_type')->unique(); - switch ($rule->schedule_type) { + foreach ($types as $type) { + $command = $schedule->command("send:production-report", [$type]); + switch ($type) { case 'Live': $command->everyMinute(); - // Log::info("Scheduled Live production report for"); break; - case 'Hourly': $command->hourly(); - //Log::info("Scheduled Hourly production report for {$rule->email}"); break; - case 'Daily': $command->dailyAt('07:59'); - // Log::info("Scheduled Daily production report for {$rule->email}"); break; } } }); -