From 5088e30ffa8264cd762a4a3981b0148f2acd4273 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 4 Sep 2026 17:16:03 +0530 Subject: [PATCH 1/3] Added send panel box report command page --- app/Console/Commands/SendPanelBoxReport.php | 117 ++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 app/Console/Commands/SendPanelBoxReport.php diff --git a/app/Console/Commands/SendPanelBoxReport.php b/app/Console/Commands/SendPanelBoxReport.php new file mode 100644 index 0000000..115007e --- /dev/null +++ b/app/Console/Commands/SendPanelBoxReport.php @@ -0,0 +1,117 @@ +argument('schedule_type'); + $plantId = (int) $this->argument('plant'); + $machineId = (int) $this->argument('machine_id'); + + $mailRules = \App\Models\AlertMailRule::where('module', 'PanelBoxReport') + ->where('rule_name', 'PanelBoxNotOkReportMail') + ->where('schedule_type', $scheduleType) + ->where('plant', $plantId) + ->where('machine_id', $machineId) + ->get(); + + $emails = $mailRules + ->pluck('email') + ->filter() + ->flatMap(function ($email) { + return array_map('trim', explode(',', $email)); + }) + ->unique() + ->values() + ->toArray(); + + $ccEmails = $mailRules + ->pluck('cc_emails') + ->filter() + ->flatMap(function ($email) { + return array_map('trim', explode(',', $email)); + }) + ->unique() + ->values() + ->toArray(); + + $plants = $plantId == 0 + ? Plant::all() + : Plant::where('id', $plantId)->get(); + + if ($plants->isEmpty()) { + $this->error('No valid plant(s) found.'); + return; + } + + $plant = Plant::find($plantId); + + $plantName = $plant?->name ?? $plantId; + + $machine = Machine::find($machineId); + + $machineName = $machine?->work_center ?? $machineId; + + if (strtolower($scheduleType) == 'daily') { + $startDate = now()->subDay()->setTime(8, 0, 0); + $endDate = now()->setTime(8, 0, 0); + } else { + $startDate = now()->setTime(8, 0, 0); + $endDate = now()->copy()->addDay()->setTime(8, 0, 0); + } + + $records = ProductionCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $machineId) + ->whereBetween('created_at', [$startDate, $endDate]) + ->where('status', 'NotOk') + ->select('serial_number') + ->distinct() + ->get(); + + if ($records->isEmpty()) { + $this->info('No panel box records found.'); + return; + } + + // Send mail to mapped email IDs + Mail::to($emails) + ->cc($ccEmails) + ->send( + new PanelBoxReportMail( + $records, + $plantId, + $machineId, + $plantName, + $machineName, + ) + ); + + $this->info('Panel box report mail sent successfully.'); + } +} From 3f6bda41445384f1fc9551193f9c584648ef1418 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 4 Sep 2026 17:16:40 +0530 Subject: [PATCH 2/3] Added panel box report mail pages --- app/Mail/PanelBoxReportMail.php | 71 ++++ .../views/mail/panel-box-report.blade.php | 323 ++++++++++++++++++ 2 files changed, 394 insertions(+) create mode 100644 app/Mail/PanelBoxReportMail.php create mode 100644 resources/views/mail/panel-box-report.blade.php diff --git a/app/Mail/PanelBoxReportMail.php b/app/Mail/PanelBoxReportMail.php new file mode 100644 index 0000000..5b5bbc9 --- /dev/null +++ b/app/Mail/PanelBoxReportMail.php @@ -0,0 +1,71 @@ +records = $records; + $this->plantId = $plantId; + $this->machineId = $machineId; + $this->plantName = $plantName; + $this->machineName = $machineName; + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: 'Panel Box Inspection Report Mail', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + $greeting = 'Dear Sir'; + return new Content( + view: 'mail.panel-box-report', + with: [ + 'company' => 'CRI Digital Manufacturing Solutions', + 'greeting' => $greeting, + 'wishes' => 'Thanks & Regards,
CRI Digital Manufacturing Solutions', + ], + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/mail/panel-box-report.blade.php b/resources/views/mail/panel-box-report.blade.php new file mode 100644 index 0000000..b4111f5 --- /dev/null +++ b/resources/views/mail/panel-box-report.blade.php @@ -0,0 +1,323 @@ + + + + + + + + + + +
+ +
+ + {{-- HEADER --}} +
+
+ Panel Box Inspection Report +
+ +
+ NOT OK Serial Number Report +
+
+ + + {{-- PLANT / MACHINE INFORMATION --}} +
+ + + + + + + + + + + +
+
Plant
+
+ {{ $plantName }} +
+
+
Machine
+
+ {{ $machineName }} +
+
+
Report Date
+
+ {{ now()->format('d M Y') }} +
+
+ +
+ + + {{-- SUMMARY --}} +
+ +
+ NOT OK Inspections +
+ +
+ {{ $records->count() }} +
+ +
+ Panel box serial numbers requiring attention +
+ +
+ + + {{-- SERIAL NUMBER LIST --}} +
+ +
+ NOT OK Serial Numbers +
+ + + + + + + + + + + + + + @foreach($records as $index => $record) + + + + + + + + + + + + @endforeach + + + +
S.NoSerial NumberStatus
+ {{ $index + 1 }} + + + {{ $record->serial_number }} + + + + NOT OK + +
+ +
+ + + {{-- FOOTER --}} + + +
+ +
+ + + From 4749f07f5a61856b1c44783ab7f61e02d53d7766 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 4 Sep 2026 17:19:22 +0530 Subject: [PATCH 3/3] Added panel box report in scheduler page --- app/Console/Commands/Scheduler.php | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Scheduler.php b/app/Console/Commands/Scheduler.php index 8b1711e..13e441d 100644 --- a/app/Console/Commands/Scheduler.php +++ b/app/Console/Commands/Scheduler.php @@ -433,7 +433,6 @@ class Scheduler extends Command } } - //..Laser Stop Final Report $laserStopFinalReport = AlertMailRule::where('module', 'LaserStopReport') @@ -472,6 +471,45 @@ class Scheduler extends Command break; } } + + //..Panel Box Final Report + + $panelBoxFinalReport = AlertMailRule::where('module', 'PanelBoxReport') + ->where('rule_name', 'PanelBoxNotOkReportMail') + ->select('plant', 'schedule_type', 'machine_id') + ->distinct() + ->get(); + + foreach ($panelBoxFinalReport as $rule) { + switch ($rule->schedule_type) { + case 'Live': + // Run every minute + \Artisan::call('send:panel-box-report', [ + 'schedule_type' => $rule->schedule_type, + 'plant' => $rule->plant, + 'machine_id' => $rule->machine_id, + ]); + break; + case 'Hourly': + if (now()->minute == 0) { + \Artisan::call('send:panel-box-report', [ + 'schedule_type' => $rule->schedule_type, + 'plant' => $rule->plant, + 'machine_id' => $rule->machine_id, + ]); + } + break; + case 'Daily': + if (now()->format('H:i') == '08:00') { + \Artisan::call('send:panel-box-report', [ + 'schedule_type' => $rule->schedule_type, + 'plant' => $rule->plant, + 'machine_id' => $rule->machine_id, + ]); + } + break; + } + } } /**