From 579daf6a8348c51d8156933898e413f5d405fbd8 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 20 Aug 2026 09:21:48 +0530 Subject: [PATCH] Added select for not ok button in panel check list livewire page --- app/Livewire/PanelCheckList.php | 181 ++++++++++++++---- .../views/livewire/panel-check-list.blade.php | 8 + 2 files changed, 147 insertions(+), 42 deletions(-) diff --git a/app/Livewire/PanelCheckList.php b/app/Livewire/PanelCheckList.php index 28f4663..fad45bb 100644 --- a/app/Livewire/PanelCheckList.php +++ b/app/Livewire/PanelCheckList.php @@ -28,6 +28,8 @@ public $records = []; public $showChecklist = false; + public bool $selectForNotOk = false; + // public $skipChecklistValidation = false; // protected $listeners = ['focus-item-id' => 'handleFocus', 'trigger-create' => 'doCreate',]; @@ -66,6 +68,8 @@ public $records = []; public function saveChecklist() { + + if (empty($this->checklist) || count($this->checklist) != count($this->records)) { Notification::make() ->title('Incomplete Checklist') @@ -116,6 +120,61 @@ public $records = []; return; } + if(!$this->selectForNotOk){ + + // First validate all checklist values + foreach ($this->checklist as $characteristicId => $value) { + + $characteristic = ProductCharacteristicsMaster::find($characteristicId); + + $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id']) + ->where('line_id', $this->data['line_id']) + ->where('name', $characteristic->name) + ->where('item_id', $itemId) + ->first(); + + if (!$itemCharacteristic) { + Notification::make() + ->title('Characteristic Not Found') + ->body("Characteristic '{$characteristic?->name}' was not found.") + ->danger() + ->send(); + + return; + } + + if ($itemCharacteristic->inspection_type == 'Value') { + + if ( + !is_numeric($value) || + $value < $itemCharacteristic->lower || + $value > $itemCharacteristic->upper + ) { + Notification::make() + ->title('Invalid Value Selected') + ->body("'{$characteristic->name}' must be between {$itemCharacteristic->lower} and {$itemCharacteristic->upper}.") + ->danger() + ->send(); + return; + } + } + else { + + // Visual inspection must always be OK + if (strtolower(trim($value)) != 'ok') { + + Notification::make() + ->title('Inspection Failed') + ->body("You selected 'NotOk' for '{$characteristic->name}'. Please select 'OK' to continue.") + ->danger() + ->send(); + + return; + } + } + } + } + $qualityValidation = PanelBoxValidation::create([ 'plant_id' => $this->data['plant_id'] ?? null, 'line_id' => $this->data['line_id'] ?? null, @@ -135,7 +194,9 @@ public $records = []; 'panel_box_supplier' => $this->data['panel_box_supplier'] ?? null, 'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null, 'panel_box_code' => $this->data['panel_box_code'] ?? null, + 'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null, 'created_by' => $this->data['created_by'] ?? null, + 'updated_by' => $this->data['updated_by'] ?? null, ]); if (! $qualityValidation || ! $qualityValidation->exists) { @@ -148,57 +209,93 @@ public $records = []; return; } - foreach ($this->checklist as $characteristicId => $value) { + if($this->selectForNotOk){ - // $status = 'Ok'; + foreach ($this->checklist as $characteristicId => $value) { - $characteristic = ProductCharacteristicsMaster::find($characteristicId); - $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id']) - ->where('line_id', $this->data['line_id']) - ->where('name', $characteristic->name) - ->where('item_id', $itemId) - ->first(); + $characteristic = ProductCharacteristicsMaster::find($characteristicId); - // if (($characteristic?->inspection_type ?? null) === 'Value') { - // if ($characteristic && is_numeric($value) && (($value >= $characteristic->lower && $value <= $characteristic->upper) || $value == $characteristic->lower || $value == $characteristic->upper) - // ) { - // $status = 'Ok'; - // } else { - // $status = 'NotOk'; - // } - // } - // else { - // $status = $value; - // } + $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id']) + ->where('line_id', $this->data['line_id']) + ->where('name', $characteristic->name) + ->where('item_id', $itemId) + ->first(); - if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { + if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { - if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper - ) { - $status = 'Ok'; - } else { - $status = 'NotOk'; + if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper + ) { + $status = 'Ok'; + } else { + $status = 'NotOk'; + } } - } - else { - $status = $value; + else { + $status = $value; + } + + $prod = ProductionCharacteristic::create([ + 'plant_id' => $this->data['plant_id'] ?? null, + 'item_id' => $itemId ?? null, + 'line_id' => $this->data['line_id'] ?? null, + 'machine_id' => $characteristic?->machine_id ?? null, + 'production_order' => $this->data['production_order'] ?? null, + 'serial_number' => $this->data['serial_number'] ?? null, + 'characteristic_name' => $characteristic?->name ?? null, + 'observed_value' => $value ?? null, + 'status' => $status, + 'inspection_status' => $finalInspectionStatus ?? null, + 'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null, + 'created_by' => $this->data['created_by'] ?? null, + 'updated_by' => $this->data['updated_by'] ?? null, + ]); } - $prod = ProductionCharacteristic::create([ - 'plant_id' => $this->data['plant_id'] ?? null, - 'item_id' => $itemId ?? null, - 'line_id' => $this->data['line_id'] ?? null, - 'machine_id' => $characteristic?->machine_id ?? null, - 'production_order' => $this->data['production_order'] ?? null, - 'serial_number' => $this->data['serial_number'] ?? null, - 'characteristic_name' => $characteristic?->name ?? null, - 'observed_value' => $value ?? null, - 'status' => $status, - 'inspection_status' => $finalInspectionStatus ?? null, - 'created_by' => $this->data['created_by'] ?? null, - 'updated_by' => $this->data['updated_by'] ?? null, - ]); + } + else { + + //All validations Passed + foreach ($this->checklist as $characteristicId => $value) { + + + $characteristic = ProductCharacteristicsMaster::find($characteristicId); + + $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id']) + ->where('line_id', $this->data['line_id']) + ->where('name', $characteristic->name) + ->where('item_id', $itemId) + ->first(); + + if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { + + if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper + ) { + $status = 'Ok'; + } else { + $status = 'NotOk'; + } + } + else { + $status = $value; + } + + $prod = ProductionCharacteristic::create([ + 'plant_id' => $this->data['plant_id'] ?? null, + 'item_id' => $itemId ?? null, + 'line_id' => $this->data['line_id'] ?? null, + 'machine_id' => $characteristic?->machine_id ?? null, + 'production_order' => $this->data['production_order'] ?? null, + 'serial_number' => $this->data['serial_number'] ?? null, + 'characteristic_name' => $characteristic?->name ?? null, + 'observed_value' => $value ?? null, + 'status' => $status, + 'inspection_status' => $finalInspectionStatus ?? null, + 'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null, + 'created_by' => $this->data['created_by'] ?? null, + 'updated_by' => $this->data['updated_by'] ?? null, + ]); + } } if (! $prod) { diff --git a/resources/views/livewire/panel-check-list.blade.php b/resources/views/livewire/panel-check-list.blade.php index 4099007..5def0d2 100644 --- a/resources/views/livewire/panel-check-list.blade.php +++ b/resources/views/livewire/panel-check-list.blade.php @@ -119,6 +119,14 @@ @endif
+ +