From f10a95e8744f2bf5a8f50ef66c1111a2259863c3 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 4 Sep 2026 14:54:58 +0530 Subject: [PATCH] Added panel box alert mail logic in panel check list --- app/Livewire/PanelCheckList.php | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/app/Livewire/PanelCheckList.php b/app/Livewire/PanelCheckList.php index 42ea3db..99e6eb7 100644 --- a/app/Livewire/PanelCheckList.php +++ b/app/Livewire/PanelCheckList.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use App\Mail\PanelBoxNotOkAlert; use App\Models\AlertMailRule; use App\Models\Item; use App\Models\Line; @@ -9,6 +10,7 @@ use App\Models\PanelBoxValidation; use App\Models\Plant; use App\Models\ProductCharacteristicsMaster; use App\Models\ProductionCharacteristic; +use App\Models\StickerMaster; use Filament\Facades\Filament; use Livewire\Component; use Filament\Notifications\Notification; @@ -322,6 +324,8 @@ public $records = []; if($this->selectForNotOk){ + $notOkCharacteristics = []; + foreach ($this->records as $record) { $characteristicId = $record['id']; @@ -336,6 +340,13 @@ public $records = []; ->where('item_id', $itemId) ->first(); + $specVal = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id']) + ->where('item_id', $itemId) + ->where('line_id', $this->data['line_id']) + ->where('machine_id', $characteristic?->machine_id) + ->where('name', $characteristic?->name) + ->first(); + if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { if ($value == null || $value == '') { $status = null; @@ -366,6 +377,46 @@ public $records = []; 'created_by' => $this->data['created_by'] ?? null, 'updated_by' => $this->data['updated_by'] ?? null, ]); + + $notOkCharacteristics[] = [ + 'characteristic_name' => $characteristic?->name ?? null, + 'observed_value' => $value ?? null, + 'lower' => $specVal?->lower, + 'upper' => $specVal?->upper, + 'status' => $status, + ]; + } + + $plant = Plant::find($this->data['plant_id']); + + $plantName = $plant?->name; + + $code = $itemAgaPlant->code; + + $mailRule = AlertMailRule::where('plant', $plant->id)->where('module', 'PanelBoxAlert') + ->where('rule_name', 'PanelBoxAlertMail') + ->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', '')) + ->first(); + + if ($mailRule && !empty($mailRule->email)) { + + $mail = Mail::to($mailRule->email); + + if (!empty($mailRule->cc_emails)) { + $ccEmails = array_filter( + array_map('trim', explode(',', $mailRule->cc_emails)) + ); + + $mail->cc($ccEmails); + } + + $mail->send(new PanelBoxNotOkAlert( + $plantName, + $code ?? null, + $this->data['serial_number'] ?? null, + $this->data['panel_box_supplier'] ?? null, + $notOkCharacteristics + )); } } else { @@ -373,7 +424,6 @@ public $records = []; //All validations Passed foreach ($this->checklist as $characteristicId => $value) { - $characteristic = ProductCharacteristicsMaster::find($characteristicId); $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id'])