1
0
forked from poc/pds
Files
poc-pds1/routes/console.php
2025-07-09 10:32:45 +05:30

172 lines
5.8 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');
// $rules = [
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'InvoiceMail',
// 'argument' => 'InvoiceMail',
// ],
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'SerialInvoiceMail',
// 'argument' => 'SerialInvoiceMail',
// ],
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'MaterialInvoiceMail',
// 'argument' => 'MaterialInvoiceMail',
// ],
// ];
// foreach ($rules as $rule) {
// $scheduleType = AlertMailRule::where('module', $rule['module'])
// ->where('rule_name', $rule['rule_name'])
// ->value('schedule_type');
// switch ($scheduleType) {
// case 'Live':
// Schedule::command("send:invoice-report {$rule['argument']}")->everyMinute();
// break;
// case 'Hourly':
// Schedule::command("send:invoice-report {$rule['argument']}")->hourly();
// break;
// case 'Daily':
// Schedule::command("send:invoice-report {$rule['argument']}")->dailyAt('07:59');
// break;
// default:
// Schedule::command("send:invoice-report {$rule['argument']}")->hourly();
// break;
// }
// }
// // Production Report Scheduling
// $productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
// ->where('rule_name', 'ProductionMail')
// ->value('schedule_type');
// // $this->info($productionScheduleType);
// // \Log::info('Production Schedule Type: ' . $productionScheduleType);
// switch ($productionScheduleType) {
// case 'Live':
// Schedule::command('send:production-report')->everyMinute();
// break;
// case 'Hourly':
// Schedule::command('send:production-report')->hourly();
// break;
// case 'Daily':
// Schedule::command('send:production-report')->dailyAt('07:59');
// break;
// default:
// Schedule::command('send:production-report')->hourly();
// break;
// }
// app()->booted(function () {
// $schedule = app(Schedule::class);
// // Dynamic rules for invoice reports
// $rules = [
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'InvoiceMail',
// 'argument' => 'InvoiceMail',
// ],
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'SerialInvoiceMail',
// 'argument' => 'SerialInvoiceMail',
// ],
// [
// 'module' => 'InvoiceValidation',
// 'rule_name' => 'MaterialInvoiceMail',
// 'argument' => 'MaterialInvoiceMail',
// ],
// ];
// foreach ($rules as $rule) {
// $scheduleType = AlertMailRule::where('module', $rule['module'])
// ->where('rule_name', $rule['rule_name'])
// ->value('schedule_type');
// switch ($scheduleType) {
// case 'Live':
// $schedule->command("send:invoice-report {$rule['argument']}")->everyMinute();
// break;
// case 'Hourly':
// $schedule->command("send:invoice-report {$rule['argument']}")->hourly();
// break;
// case 'Daily':
// $schedule->command("send:invoice-report {$rule['argument']}")->dailyAt('07:59');
// break;
// default:
// $schedule->command("send:invoice-report {$rule['argument']}")->hourly();
// break;
// }
// }
// // Production Report Scheduling
// $productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
// ->where('rule_name', 'ProductionMail')
// ->value('schedule_type');
// switch ($productionScheduleType) {
// case 'Live':
// $schedule->command('send:production-report')->everyMinute();
// break;
// case 'Hourly':
// $schedule->command('send:production-report')->hourly();
// break;
// case 'Daily':
// $schedule->command('send:production-report')->dailyAt('07:59');
// break;
// default:
// $schedule->command('send:production-report')->hourly();
// break;
// }
// });
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");
switch ($rule->schedule_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;
}
}
});