1
0
forked from poc/pds
Files
poc-pds1/routes/console.php
2025-07-12 14:35:29 +05:30

73 lines
2.1 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);
//Production report scheduling
$productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail')
//->select('plant', 'schedule_type')
->select('plant', 'schedule_type')
->distinct()
->get();
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;
}
}
//Invoice report scheduling
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($invoiceRules as $rule) {
$type = $rule->schedule_type;
$plantId = $rule->plant;
$command = $schedule->command('send:invoice-report', [$type, $plantId]);
switch ($type) {
case 'Live':
$command->everyMinute();
break;
case 'Hourly':
$command->hourly();
break;
case 'Daily':
$command->dailyAt('07:59');
break;
}
}
});