Added laser consolidate report mail pages #936

Merged
jothi merged 1 commits from ranjith-dev into master 2026-08-25 03:35:43 +00:00
3 changed files with 808 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
<?php
namespace App\Console\Commands;
use App\Mail\LaserStopMail;
use App\Models\ClassCharacteristic;
use App\Models\Machine;
use App\Models\Plant;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class LaserStopConsolidateReport extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send:laser-stop-consolidate-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', '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.');
}
}

View File

@@ -0,0 +1,70 @@
<?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 LaserStopMail extends Mailable
{
use Queueable, SerializesModels;
public $records;
public $plantId;
public $machineId;
public $plantName;
public $machineName;
/**
* Create a new message instance.
*/
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 Marking - Consolidated Stoppage Report',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
$greeting = '<b>Dear Sir</b>';
return new Content(
view: 'mail.laser-stop-final-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,626 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Laser Marking Stopped Consolidated Report</title>
</head>
<body style="margin:0; padding:0; background-color:#eef2f7; font-family:Arial, Helvetica, sans-serif;">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
style="background-color:#eef2f7; padding:35px 10px;">
<tr>
<td align="center">
<!-- MAIN CONTAINER -->
<table width="760" cellpadding="0" cellspacing="0" border="0"
style="max-width:760px; width:100%; background:#ffffff; border-radius:14px; overflow:hidden;">
<tr>
<td style="background:#111827; padding:28px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="middle">
<!-- Company -->
<div style="
font-size:12px;
color:#94a3b8;
text-transform:uppercase;
letter-spacing:1.5px;
font-weight:bold;
">
CRI Digital Manufacturing
</div>
<!-- Title -->
<div style="
font-size:28px;
color:#ffffff;
font-weight:bold;
margin-top:7px;
line-height:34px;
">
Laser Marking Stoppage Report
</div>
<!-- Subtitle -->
<div style="
font-size:13px;
color:#cbd5e1;
margin-top:7px;
">
Consolidated report of machine stoppage records
</div>
</td>
<!-- Report Icon -->
<td align="right" valign="middle">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center"
style="
width:54px;
height:54px;
background:#1e293b;
border:1px solid #475569;
border-radius:12px;
color:#ffffff;
font-size:23px;
font-weight:bold;
">
LMSR
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:4px; background:#2563eb; font-size:0; line-height:0;">
&nbsp;
</td>
</tr>
<tr>
<td style="padding:28px 32px 12px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<!-- LEFT -->
<td width="50%" valign="top">
<div style="
font-size:11px;
color:#94a3b8;
text-transform:uppercase;
letter-spacing:1px;
font-weight:bold;
">
Report Type
</div>
<div style="
font-size:15px;
color:#1e293b;
font-weight:bold;
margin-top:5px;
">
Consolidated Report
</div>
</td>
<!-- RIGHT -->
<td width="50%" valign="top" align="right">
<div style="
font-size:11px;
color:#94a3b8;
text-transform:uppercase;
letter-spacing:1px;
font-weight:bold;
">
Generated On
</div>
<div style="
font-size:15px;
color:#1e293b;
font-weight:bold;
margin-top:5px;
">
{{ now()->format('d M Y, h:i A') }}
</div>
</td>
</tr>
</table>
</td>
</tr>
@php
$reportStart = now()->subDay()->setTime(8, 0, 0);
$reportEnd = now()->setTime(8, 0, 0);
@endphp
<tr>
<td style="padding:15px 32px 20px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
style="
background:#f8fafc;
border:1px solid #e2e8f0;
border-radius:10px;
">
<tr>
<td style="padding:17px 18px;">
<div style="
font-size:14px;
color:#1e293b;
font-weight:bold;
">
Laser Marking Stoppage Summary
</div>
<div style="
font-size:12px;
color:#64748b;
line-height:19px;
margin-top:5px;
">
The following laser marking machine stoppage records were identified
during the reporting period from
<strong>
{{ $reportStart->format('d M Y, h:i A') }}
</strong>
to
<strong>
{{ $reportEnd->format('d M Y, h:i A') }}
</strong>.
Please review the details and take the necessary action.
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding:5px 32px 15px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div style="
font-size:19px;
font-weight:bold;
color:#111827;
">
Stoppage Details
</div>
<div style="
font-size:12px;
color:#94a3b8;
margin-top:4px;
">
{{ $records->count() }} record(s) found
</div>
</td>
<td align="right" valign="bottom">
<div style="
display:inline-block;
background:#eff6ff;
color:#1d4ed8;
border:1px solid #bfdbfe;
padding:6px 10px;
border-radius:6px;
font-size:10px;
font-weight:bold;
text-transform:uppercase;
">
Consolidated
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding:0 32px 30px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
style="
border-collapse:collapse;
font-size:12px;
border:1px solid #e2e8f0;
border-radius:8px;
overflow:hidden;
">
<!-- TABLE HEADER -->
<thead>
<tr style="background:#1e293b;">
<th align="center"
style="
padding:13px 8px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
No
</th>
<th align="left"
style="
padding:13px 9px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
Plant
</th>
<th align="left"
style="
padding:13px 9px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
Machine
</th>
<th align="left"
style="
padding:13px 9px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
Production Order
</th>
<th align="left"
style="
padding:13px 9px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
Item Code
</th>
<th align="left"
style="
padding:13px 9px;
color:#ffffff;
font-size:11px;
font-weight:bold;
border-right:1px solid #334155;
">
Serial Number
</th>
<th align="center"
style="
padding:13px 8px;
color:#ffffff;
font-size:11px;
font-weight:bold;
">
Status
</th>
<th align="center"
style="
padding:13px 8px;
color:#ffffff;
font-size:11px;
font-weight:bold;
">
Stopped At
</th>
<th align="center"
style="
padding:13px 8px;
color:#ffffff;
font-size:11px;
font-weight:bold;
">
Stopped By
</th>
</tr>
</thead>
<tbody>
@foreach($records as $index => $record)
<tr style="background:{{ $index % 2 == 0 ? '#ffffff' : '#f8fafc' }};">
<td align="center"
style="
padding:14px 8px;
border-bottom:1px solid #e5e7eb;
color:#64748b;
font-weight:bold;
">
{{ $index + 1 }}
</td>
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#334155;
white-space: nowrap;
">
{{ $plantName }}
</td>
<!-- MACHINE -->
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#1e293b;
font-weight:bold;
">
{{ $machineName }}
</td>
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#1e293b;
font-weight:bold;
">
{{ $record->aufnr }}
</td>
<!-- ITEM CODE -->
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#475569;
">
{{ $record->item?->code ?? $record->item_id }}
</td>
<!-- SERIAL NUMBER -->
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#475569;
">
{{ $record->gernr }}
</td>
<!-- STATUS -->
<td align="center"
style="
padding:14px 8px;
border-bottom:1px solid #e5e7eb;
">
<span style="
display:inline-block;
background:#fff1f2;
color:#be123c;
border:1px solid #fecdd3;
padding:5px 9px;
border-radius:20px;
font-size:9px;
font-weight:bold;
letter-spacing:.5px;
">
STOPPED
</span>
</td>
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#1e293b;
font-weight:bold;
white-space: nowrap;
">
{{ $record->stopped_datetime }}
</td>
<td style="
padding:14px 9px;
border-bottom:1px solid #e5e7eb;
color:#1e293b;
font-weight:bold;
white-space: nowrap;
">
{{ $record->stopped_by }}
</td>
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
<tr>
<td style="padding:0 32px 28px 32px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0"
style="
background:#fffbeb;
border:1px solid #fde68a;
border-radius:9px;
">
<tr>
<td width="6"
style="
background:#f59e0b;
border-radius:9px 0 0 9px;
">
&nbsp;
</td>
<td style="padding:15px 17px;">
<div style="
font-size:13px;
font-weight:bold;
color:#92400e;
">
Action Required
</div>
<div style="
font-size:12px;
color:#78350f;
line-height:18px;
margin-top:4px;
">
Please review the above stopped machine records
and take the necessary corrective action.
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="
background:#f8fafc;
padding:22px 32px;
border-top:1px solid #e2e8f0;
">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
<div style="
font-size:12px;
color:#64748b;
line-height:19px;
">
This is an automated report from
<strong style="color:#334155;">
CRI Digital Manufacturing
</strong>.
<br>
Please do not reply to this automated notification.
</div>
<div style="
margin-top:12px;
font-size:11px;
color:#94a3b8;
">
© {{ date('Y') }} {{ $company }}
&nbsp;&nbsp;
Automated Laser Marking Stopped Consolidated Report
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>