7 Commits

Author SHA1 Message Date
f612551288 Merge pull request 'removed required option in alert mail for schedule type' (#61) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Reviewed-on: #61
2025-12-03 03:17:05 +00:00
dhanabalan
8d1e616777 removed required option in alert mail for schedule type
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / review (pull_request) Failing after 31s
Laravel Pint / pint (pull_request) Successful in 2m22s
Laravel Larastan / larastan (pull_request) Failing after 3m1s
2025-12-03 08:46:49 +05:30
4f84735eaf Merge pull request 'correction of alert mail rule logic for invoice data report' (#60) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Reviewed-on: #60
2025-12-03 03:05:35 +00:00
dhanabalan
534ac222fa correction of alert mail rule logic for invoice data report
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / review (pull_request) Failing after 51s
Laravel Larastan / larastan (pull_request) Failing after 3m1s
Laravel Pint / pint (pull_request) Successful in 2m47s
2025-12-03 08:35:03 +05:30
45b8c1fbb4 Merge pull request 'corrected logic for mail triggering' (#59) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Reviewed-on: #59
2025-12-02 11:13:56 +00:00
dhanabalan
005ea2cf87 corrected logic for mail triggering
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Laravel Pint / pint (pull_request) Failing after 13m36s
Laravel Larastan / larastan (pull_request) Failing after 3m16s
Gemini PR Review / review (pull_request) Failing after 23s
2025-12-02 16:42:37 +05:30
6015968043 Merge pull request 'Update .github/workflows/gemini-pr-review.yaml' (#58) from actions/gemini-pr-review-patch into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Reviewed-on: #58
2025-12-02 10:57:48 +00:00
4 changed files with 290 additions and 95 deletions

View File

@@ -0,0 +1,202 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
use App\Models\AlertMailRule;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
class Scheduler extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
// protected $signature = 'app:scheduler';
protected $signature = 'custom:scheduler';
/**
* The console command description.
*
* @var string
*/
// protected $description = 'Command description';
protected $description = 'Manually trigger scheduler logic';
/**
* Execute the console command.
*/
// public function handle()
// {
// //
// }
public function handle()
{
// --- Production Rules ---
$productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($productionRules as $rule) {
switch ($rule->schedule_type) {
case 'Live':
// Run every minute
\Artisan::call('send:production-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
break;
case 'Hourly':
if (now()->minute == 0) {
\Artisan::call('send:production-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
case 'Daily':
if (now()->format('H:i') == '07:59') {
\Artisan::call('send:production-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
}
}
// --- Invoice Validation Rules ---
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
->where('rule_name', 'InvoiceMail')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($invoiceRules as $rule) {
switch ($rule->schedule_type) {
case 'Live':
// Run every minute
\Artisan::call('send:invoice-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
break;
case 'Hourly':
if (now()->minute == 0) {
\Artisan::call('send:invoice-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
case 'Daily':
if (now()->format('H:i') == '07:59') {
\Artisan::call('send:invoice-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
}
}
// foreach ($invoiceRules as $rule) {
// switch ($rule->schedule_type) {
// case 'Live':
// try {
// Artisan::call('send:invoice-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// ]);
// Log::info('Invoice report sent | Plant: '.$rule->plant);
// } catch (\Throwable $e) {
// Log::error("Invoice Live Failed ({$rule->plant}): ".$e->getMessage());
// }
// break;
// case 'Hourly':
// if (now()->minute == 0) {
// Artisan::call('send:invoice-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// ]);
// }
// break;
// case 'Daily':
// if (now()->format('H:i') == '07:59') {
// Artisan::call('send:invoice-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// ]);
// }
// break;
// }
// }
// --- Invoice Data Report Rules ---
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
->where('rule_name', 'InvoiceDataMail')
->select('plant', 'schedule_type')
->distinct()
->get();
foreach ($invoiceDataRules as $rule) {
switch ($rule->schedule_type) {
case 'Live':
// Run every minute
\Artisan::call('send:invoice-data-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
break;
case 'Hourly':
if (now()->minute == 0) {
\Artisan::call('send:invoice-data-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
case 'Daily':
if (now()->format('H:i') == '10:00') {
\Artisan::call('send:invoice-data-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
}
break;
}
}
}
/**
* Helper to call Artisan commands with parameters.
*/
protected function callArtisanCommand($commandName, $rule)
{
\Artisan::call($commandName, [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
]);
$this->info("Executed {$commandName} for plant: {$rule->plant}");
\Log::info("Executed {$commandName} for plant: {$rule->plant}");
}
}

View File

@@ -2,11 +2,11 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Mail\test;
use App\Models\InvoiceValidation; use App\Models\InvoiceValidation;
use App\Models\Plant; use App\Models\Plant;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use App\Mail\test;
class SendInvoiceReport extends Command class SendInvoiceReport extends Command
{ {
@@ -16,8 +16,7 @@ class SendInvoiceReport extends Command
* @var string * @var string
*/ */
// protected $signature = 'app:send-invoice-report'; // protected $signature = 'app:send-invoice-report';
protected $signature = 'send:invoice-report{schedule_type} {plant}'; protected $signature = 'send:invoice-report {schedule_type} {plant}';
/** /**
* The console command description. * The console command description.
@@ -29,12 +28,10 @@ class SendInvoiceReport extends Command
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
$schedule = $this->argument('schedule_type'); $schedule = $this->argument('schedule_type');
//$scheduleType = $this->argument('scheduleType'); // $scheduleType = $this->argument('scheduleType');
$plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants $plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name'); $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
@@ -52,18 +49,14 @@ class SendInvoiceReport extends Command
: [$plantIdArg]; : [$plantIdArg];
$no = 1; $no = 1;
if (strtolower($schedule) == 'daily') if (strtolower($schedule) == 'daily') {
{
$startDate = now()->subDay()->setTime(8, 0, 0); $startDate = now()->subDay()->setTime(8, 0, 0);
$endDate = now()->setTime(8, 0, 0); $endDate = now()->setTime(8, 0, 0);
} } else {
else
{
$startDate = now()->setTime(8, 0, 0); $startDate = now()->setTime(8, 0, 0);
$endDate = now()->copy()->addDay()->setTime(8, 0, 0); $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
} }
foreach ($plantIds as $plantId) foreach ($plantIds as $plantId) {
{
$plant = Plant::find($plantId); $plant = Plant::find($plantId);
$plantName = $plant ? $plant->name : $plantId; $plantName = $plant ? $plant->name : $plantId;
@@ -89,7 +82,7 @@ class SendInvoiceReport extends Command
$scannedInvoiceQuan = InvoiceValidation::where('plant_id', $plantId) $scannedInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
->where('scanned_status', 'Scanned') ->where('scanned_status', 'Scanned')
->where(function($query) { ->where(function ($query) {
$query->whereNull('quantity') $query->whereNull('quantity')
->orWhere('quantity', 0); ->orWhere('quantity', 0);
}) })
@@ -128,7 +121,7 @@ class SendInvoiceReport extends Command
$scannedMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId) $scannedMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
->where('quantity', 1) ->where('quantity', 1)
->whereNotNull('serial_number') ->whereNotNull('serial_number')
->where('serial_number','!=', '') ->where('serial_number', '!=', '')
->whereBetween('updated_at', [$startDate, $endDate]) ->whereBetween('updated_at', [$startDate, $endDate])
->count(); ->count();
@@ -164,7 +157,7 @@ class SendInvoiceReport extends Command
$scannedBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId) $scannedBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
->where('quantity', '>', 1) ->where('quantity', '>', 1)
->whereNotNull('serial_number') ->whereNotNull('serial_number')
->where('serial_number','!=', '') ->where('serial_number', '!=', '')
->whereBetween('updated_at', [$startDate, $endDate]) ->whereBetween('updated_at', [$startDate, $endDate])
->count(); ->count();
@@ -193,7 +186,6 @@ class SendInvoiceReport extends Command
} }
} }
// Send to MaterialInvoiceMail recipients (material + bundle table) // Send to MaterialInvoiceMail recipients (material + bundle table)
if ($mailRules->has('MaterialInvoiceMail')) { if ($mailRules->has('MaterialInvoiceMail')) {
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray(); $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
@@ -212,16 +204,14 @@ class SendInvoiceReport extends Command
// Show preview in console // Show preview in console
$this->info('--- Serial Invoice Table ---'); $this->info('--- Serial Invoice Table ---');
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $serialTableData); $this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $serialTableData);
$this->info('--- Material Invoice Table ---'); $this->info('--- Material Invoice Table ---');
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $materialTableData); $this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $materialTableData);
$this->info('--- Bundle Invoice Table ---'); $this->info('--- Bundle Invoice Table ---');
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData); $this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData);
$this->info($contentVars['wishes'] ?? ''); $this->info($contentVars['wishes'] ?? '');
} }
} }

View File

@@ -70,7 +70,6 @@ class AlertMailRuleResource extends Resource
->label('CC Emails'), ->label('CC Emails'),
Forms\Components\Select::make('schedule_type') Forms\Components\Select::make('schedule_type')
->label('Schedule Type') ->label('Schedule Type')
->required()
->options([ ->options([
'Live' => 'Live', 'Live' => 'Live',
'Hourly' => 'Hourly', 'Hourly' => 'Hourly',

View File

@@ -2,8 +2,6 @@
use Illuminate\Foundation\Inspiring; use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use App\Models\AlertMailRule;
use Illuminate\Console\Scheduling\Schedule;
@@ -11,87 +9,93 @@ Artisan::command('inspire', function () {
$this->comment(Inspiring::quote()); $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote'); })->purpose('Display an inspiring quote');
Artisan::command('auto:scheduler', function () {
$this->call('custom:scheduler');
})->everyMinute();
// Schedule::command('send:invoice-report'); // Schedule::command('send:invoice-report');
// Schedule::command('send:production-report'); // Schedule::command('send:production-report');
app()->booted(function () { // app()->booted(function () {
$schedule = app(Schedule::class); // $schedule = app(Schedule::class);
// $schedule->command('report:send-daily-production')->dailyAt('07:59'); // // $schedule->command('report:send-daily-production')->dailyAt('07:59');
// Production report scheduling // // Production report scheduling
$productionRules = AlertMailRule::where('module', 'ProductionQuantities') // $productionRules = AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail') // ->where('rule_name', 'ProductionMail')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($productionRules as $rule) { // foreach ($productionRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:production-report', [$type, $plantId]); // $command = $schedule->command('send:production-report', [$type, $plantId]);
// ->appendOutputTo(storage_path('logs/scheduler.log')); // // ->appendOutputTo(storage_path('logs/scheduler.log'));
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('07:59'); // $command->dailyAt('07:59');
break; // break;
} // }
} // }
// Invoice report scheduling // // Invoice report scheduling
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation') // $invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($invoiceRules as $rule) { // foreach ($invoiceRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:invoice-report', [$type, $plantId]); // $command = $schedule->command('send:invoice-report', [$type, $plantId]);
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('07:59'); // $command->dailyAt('07:59');
break; // break;
} // }
} // }
// Invoice Data Report Scheduling // // Invoice Data Report Scheduling
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport') // $invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
->select('plant', 'schedule_type') // ->select('plant', 'schedule_type')
->distinct() // ->distinct()
->get(); // ->get();
foreach ($invoiceDataRules as $rule) { // foreach ($invoiceDataRules as $rule) {
$type = $rule->schedule_type; // $type = $rule->schedule_type;
$plantId = $rule->plant; // $plantId = $rule->plant;
$command = $schedule->command('send:invoice-data-report', [$type, $plantId]); // $command = $schedule->command('send:invoice-data-report', [$type, $plantId]);
switch ($type) { // switch ($type) {
case 'Live': // case 'Live':
$command->everyMinute(); // $command->everyMinute();
break; // break;
case 'Hourly': // case 'Hourly':
$command->hourly(); // $command->hourly();
break; // break;
case 'Daily': // case 'Daily':
$command->dailyAt('10:00'); // $command->dailyAt('10:00');
break; // break;
} // }
} // }
}); // });