Merge pull request 'Added mail logic for immediate laser stopped alert' (#926) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #926
This commit was merged in pull request #926.
This commit is contained in:
2026-08-24 04:22:54 +00:00
4 changed files with 499 additions and 1 deletions

View File

@@ -394,11 +394,89 @@ class Scheduler extends Command
break;
}
}
//..Laser Stop Report
$laserStopReport = AlertMailRule::where('module', 'LaserStopAlert')
->where('rule_name', 'LaserStopAlertMail')
->select('plant', 'schedule_type', 'machine_id')
->distinct()
->get();
foreach ($laserStopReport as $rule) {
switch ($rule->schedule_type) {
case 'Live':
// Run every minute
\Artisan::call('send:laser-stop-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
'machine_id' => $rule->machine_id,
]);
break;
case 'Hourly':
if (now()->minute == 0) {
\Artisan::call('send:laser-stop-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
'machine_id' => $rule->machine_id,
]);
}
break;
case 'Daily':
if (now()->format('H:i') == '07:59') {
\Artisan::call('send:laser-stop-report', [
'schedule_type' => $rule->schedule_type,
'plant' => $rule->plant,
'machine_id' => $rule->machine_id,
]);
}
break;
}
}
//..Laser Stop Final Report
// $laserStopFinalReport = AlertMailRule::where('module', 'LaserStopReport')
// ->where('rule_name', 'LaserStopMail')
// ->select('plant', 'schedule_type', 'machine_id')
// ->distinct()
// ->get();
// foreach ($laserStopFinalReport as $rule) {
// switch ($rule->schedule_type) {
// case 'Live':
// // Run every minute
// \Artisan::call('send:laser-stop-consolidate-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// 'machine_id' => $rule->machine_id,
// ]);
// break;
// case 'Hourly':
// if (now()->minute == 0) {
// \Artisan::call('send:laser-stop-consolidate-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// 'machine_id' => $rule->machine_id,
// ]);
// }
// break;
// case 'Daily':
// if (now()->format('H:i') == '07:59') {
// \Artisan::call('send:laser-stop-consolidate-report', [
// 'schedule_type' => $rule->schedule_type,
// 'plant' => $rule->plant,
// 'machine_id' => $rule->machine_id,
// ]);
// }
// break;
// }
// }
}
/**
* Helper to call Artisan commands with parameters.
*/
*/
protected function callArtisanCommand($commandName, $rule)
{
\Artisan::call($commandName, [

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Console\Commands;
use App\Mail\LaserStopReportMail;
use App\Models\ClassCharacteristic;
use App\Models\Machine;
use App\Models\Plant;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class SendLaserStopReport extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send:laser-stop-report {schedule_type} {plant} {machine_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$scheduleType = $this->argument('schedule_type');
$plantId = (int) $this->argument('plant');
$machineId = (int) $this->argument('machine_id');
$mailRules = \App\Models\AlertMailRule::where('module', 'LaserStopAlert')
->where('rule_name', 'LaserStopAlertMail')
->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;
$records = ClassCharacteristic::where('is_stopped', 2)
->where('plant_id', $plantId)
->where('machine_id', $machineId)
->get();
if ($records->isEmpty()) {
$this->info('No laser stop records found.');
return;
}
$recordIds = $records->pluck('id');
// Send mail to mapped email IDs
Mail::to($emails)
->cc($ccEmails)
->send(
new LaserStopReportMail(
$records,
$plantId,
$machineId,
$plantName,
$machineName,
)
);
ClassCharacteristic::whereIn('id', $recordIds)
->update([
'is_stopped' => 1,
]);
$this->info('Laser stop report mail sent successfully.');
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class LaserStopReportMail extends Mailable
{
use Queueable, SerializesModels;
public $records;
public $plantId;
public $machineId;
public $plantName;
public $machineName;
public function __construct($records,$plantId,$machineId, $plantName, $machineName)
{
$this->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 Stopped Alert',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
$greeting = '<b>Dear Sir</b>';
return new Content(
view: 'mail.laser-stop-report',
with: [
'company' => 'CRI Digital Manufacturing Solutions',
'greeting' => $greeting,
'wishes' => 'Thanks & Regards,<br>CRI Digital Manufacturing Solutions',
],
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}

View File

@@ -0,0 +1,240 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Laser Stopped Report</title>
</head>
<body style="margin:0; padding:0; background-color:#f4f6f8; font-family:Arial, Helvetica, sans-serif;">
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#f4f6f8; padding:30px 10px;">
<tr>
<td align="center">
<!-- Main Container -->
<table width="700" cellpadding="0" cellspacing="0" border="0"
style="max-width:700px; width:100%; background:#ffffff; border-radius:12px; overflow:hidden; box-shadow:0 4px 15px rgba(0,0,0,0.08);">
<!-- Header -->
<tr>
<td style="background:#1f2937; padding:25px 30px;">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="font-size:13px; color:#cbd5e1; letter-spacing:1px; text-transform:uppercase;">
CRI Digital Manufacturing
</div>
<div style="font-size:28px; font-weight:bold; color:#ffffff; margin-top:6px;">
Laser Stop Alert
</div>
<div style="font-size:13px; color:#cbd5e1; margin-top:6px;">
Laser machine stoppage notification
</div>
</td>
<td align="right" valign="middle">
<div style="width:48px; height:48px; background:#ef4444; border-radius:50%; text-align:center; line-height:48px; color:#ffffff; font-size:22px; font-weight:bold;">
!
</div>
</td>
</tr>
</table>
</td>
</tr>
<!-- Alert -->
<tr>
<td style="padding:25px 30px 10px 30px;">
<div style="background:#fff7ed; border-left:5px solid #f97316; padding:15px 18px; border-radius:6px;">
<div style="font-size:16px; font-weight:bold; color:#9a3412;">
Laser Stop Detected
</div>
<div style="font-size:13px; color:#7c2d12; margin-top:5px;">
The following laser stop records require your attention.
</div>
</div>
</td>
</tr>
<!-- Report Title -->
<tr>
<td style="padding:20px 30px 10px 30px;">
<div style="font-size:18px; font-weight:bold; color:#111827;">
Stopped Machine Records
</div>
<div style="font-size:13px; color:#64748b; margin-top:4px;">
Total records: {{ $records->count() }}
</div>
</td>
</tr>
<!-- Table -->
<tr>
<td style="padding:10px 30px 30px 30px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
style="border-collapse:collapse; font-size:13px;">
<thead>
<tr style="background:#1f2937;">
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
No
</th>
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Plant
</th>
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Machine
</th>
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Production Order
</th>
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Item Code
</th>
<th align="left"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Serial Number
</th>
<th align="center"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Status
</th>
<th align="center"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Stopped At
</th>
<th align="center"
style="padding:12px 10px; color:#ffffff; font-weight:bold;">
Stopped By
</th>
</tr>
</thead>
<tbody>
@foreach($records as $index => $record)
<tr style="background:{{ $index % 2 == 0 ? '#ffffff' : '#f8fafc' }};">
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151;">
{{ $index + 1 }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151; white-space: nowrap;">
{{ $plantName }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151; font-weight:bold;">
{{ $machineName }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151;">
{{ $record->aufnr }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151;">
{{ $record->item?->code ?? $record->item_id }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151;">
{{ $record->gernr }}
</td>
<td align="center"
style="padding:13px 10px; border-bottom:1px solid #e5e7eb;">
<span style="display:inline-block; background:#fee2e2; color:#b91c1c; padding:5px 10px; border-radius:20px; font-size:11px; font-weight:bold;">
STOPPED
</span>
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151; white-space: nowrap;">
{{ $record->stopped_datetime }}
</td>
<td style="padding:13px 10px; border-bottom:1px solid #e5e7eb; color:#374151; white-space: nowrap;">
{{ $record->stopped_by }}
</td>
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
<!-- Footer -->
<tr>
<td style="background:#f8fafc; padding:20px 30px; border-top:1px solid #e5e7eb;">
<div style="font-size:12px; color:#64748b; text-align:center;">
This is an automated notification from
<strong style="color:#374151;">CRI Digital Manufacturing</strong>.
<br>
Please take the necessary action regarding the stopped machine.
<br><br>
© {{ date('Y') }} {{ $company }}<br>
Automated Laser Stop Alert Mail
{{-- <span style="color:#94a3b8;">
Laser Stop Report {{ now()->format('d M Y, h:i A') }}
</span> --}}
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>