Files
pds/routes/console.php
2025-07-10 15:08:32 +05:30

69 lines
1.9 KiB
PHP

<?php
use App\Models\AlertMailRule;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\Scheduling\Schedule;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
// Schedule::command('send:invoice-report');
// Schedule::command('send:production-report');
// app()->booted(function () {
// $schedule = app(Schedule::class);
// $productionRules = AlertMailRule::where('module', 'ProductionQuantities')
// ->where('rule_name', 'ProductionMail')
// ->get();
// $types = $productionRules->pluck('schedule_type')->unique();
// foreach ($types as $type) {
// $command = $schedule->command("send:production-report", [$type]);
// switch ($type) {
// case 'Live':
// $command->everyMinute();
// break;
// case 'Hourly':
// $command->hourly();
// break;
// case 'Daily':
// $command->dailyAt('07:59');
// break;
// }
// }
// });
app()->booted(function () {
$schedule = app(Schedule::class);
$productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail')
->get();
// Loop each mail rule individually (plant + schedule_type)
foreach ($productionRules as $rule) {
$type = $rule->schedule_type;
$plantId = $rule->plant;
$command = $schedule->command('send:production-report', [$type, $plantId]);
switch ($type) {
case 'Live':
$command->everyMinute();
break;
case 'Hourly':
$command->hourly();
break;
case 'Daily':
$command->dailyAt('07:59');
break;
}
}
});