Added laser consolidate report mail pages
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 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 19s
Laravel Pint / pint (pull_request) Successful in 4m19s
Laravel Larastan / larastan (pull_request) Failing after 5m16s

This commit is contained in:
dhanabalan
2026-08-25 09:05:17 +05:30
parent ed05cca5d7
commit 553c742021
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 [];
}
}