diff --git a/app/Console/Commands/LaserStopConsolidateReport.php b/app/Console/Commands/LaserStopConsolidateReport.php new file mode 100644 index 0000000..af8c627 --- /dev/null +++ b/app/Console/Commands/LaserStopConsolidateReport.php @@ -0,0 +1,112 @@ +argument('schedule_type'); + $plantId = (int) $this->argument('plant'); + $machineId = (int) $this->argument('machine_id'); + + $mailRules = \App\Models\AlertMailRule::where('module', 'LaserStopReport') + ->where('rule_name', 'LaserStopMail') + ->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; + } + if (strtolower($scheduleType) == 'daily') { + $startDate = now()->subDay()->setTime(8, 0, 0); + $endDate = now()->setTime(8, 0, 0); + } + + $plant = Plant::find($plantId); + + $plantName = $plant?->name ?? $plantId; + + $machine = Machine::find($machineId); + + $machineName = $machine?->work_center ?? $machineId; + + $records = ClassCharacteristic::where('is_stopped', '!=', 0) + ->where('plant_id', $plantId) + ->where('machine_id', $machineId) + ->whereBetween('created_at', [$startDate, $endDate]) + ->get(); + + if ($records->isEmpty()) { + $this->info('No laser stop records found.'); + return; + } + + // Send mail to mapped email IDs + Mail::to($emails) + ->cc($ccEmails) + ->send( + new LaserStopMail( + $records, + $plantId, + $machineId, + $plantName, + $machineName, + ) + ); + + $this->info('Laser stop final report mail sent successfully.'); + } +} diff --git a/app/Mail/LaserStopMail.php b/app/Mail/LaserStopMail.php new file mode 100644 index 0000000..2916470 --- /dev/null +++ b/app/Mail/LaserStopMail.php @@ -0,0 +1,70 @@ +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: 'Laser Marking - Consolidated Stoppage Report', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + $greeting = 'Dear Sir'; + return new Content( + view: 'mail.laser-stop-final-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/laser-stop-final-report.blade.php b/resources/views/mail/laser-stop-final-report.blade.php new file mode 100644 index 0000000..b0c0cda --- /dev/null +++ b/resources/views/mail/laser-stop-final-report.blade.php @@ -0,0 +1,626 @@ + + + + + + + Laser Marking Stopped Consolidated Report + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + @php + $reportStart = now()->subDay()->setTime(8, 0, 0); + $reportEnd = now()->setTime(8, 0, 0); + @endphp + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + +
+ CRI Digital Manufacturing +
+ + +
+ Laser Marking Stoppage Report +
+ + +
+ Consolidated report of machine stoppage records +
+ +
+ + + + + +
+ LMSR +
+ +
+ +
+   +
+ + + + + + + + + + + + + + +
+ +
+ Report Type +
+ +
+ Consolidated Report +
+ +
+ +
+ Generated On +
+ +
+ {{ now()->format('d M Y, h:i A') }} +
+ +
+ +
+ + + + + + + + + +
+ +
+ Laser Marking Stoppage Summary +
+ +
+ The following laser marking machine stoppage records were identified + during the reporting period from + + {{ $reportStart->format('d M Y, h:i A') }} + + to + + {{ $reportEnd->format('d M Y, h:i A') }} + . + Please review the details and take the necessary action. +
+ +
+ +
+ + + + + + + + + + + +
+ +
+ Stoppage Details +
+ +
+ {{ $records->count() }} record(s) found +
+ +
+ +
+ Consolidated +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach($records as $index => $record) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @endforeach + + + +
+ No + + Plant + + Machine + + Production Order + + Item Code + + Serial Number + + Status + + Stopped At + + Stopped By +
+ {{ $index + 1 }} + + {{ $plantName }} + + {{ $machineName }} + + {{ $record->aufnr }} + + {{ $record->item?->code ?? $record->item_id }} + + {{ $record->gernr }} + + + + STOPPED + + + + {{ $record->stopped_datetime }} + + {{ $record->stopped_by }} +
+ +
+ + + + + + + + + + + +
+   + + +
+ Action Required +
+ +
+ Please review the above stopped machine records + and take the necessary corrective action. +
+ +
+ +
+ + + + + + + + + +
+ +
+ + This is an automated report from + + + CRI Digital Manufacturing + . + +
+ + Please do not reply to this automated notification. + +
+ + +
+ + © {{ date('Y') }} {{ $company }} + +  •  + + Automated Laser Marking Stopped Consolidated Report + +
+ +
+ +
+ +
+ + +