From f0af6853eef651d51fc2beefe7b8f61150259cec Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 8 Jul 2026 09:55:07 +0530 Subject: [PATCH] Added updated logic in panel box validation --- app/Livewire/PanelCheckList.php | 55 ++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/app/Livewire/PanelCheckList.php b/app/Livewire/PanelCheckList.php index a793906..841bf04 100644 --- a/app/Livewire/PanelCheckList.php +++ b/app/Livewire/PanelCheckList.php @@ -151,19 +151,38 @@ public $records = []; $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) + $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 (($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; + // } + + 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; - // } + else { + $status = $value; + } - ProductionCharacteristic::create([ + $prod = ProductionCharacteristic::create([ 'plant_id' => $this->data['plant_id'] ?? null, 'item_id' => $itemId ?? null, 'line_id' => $this->data['line_id'] ?? null, @@ -178,6 +197,15 @@ public $records = []; ]); } + if (! $prod) { + Notification::make() + ->title('Failed to save Panel Box Validation') + ->body('Something went wrong while inserting data.') + ->danger() + ->send(); + return; + } + $this->showChecklist = false; $this->dispatch('checklist-saved'); @@ -214,11 +242,24 @@ public $records = []; $characteristic = ProductCharacteristicsMaster::find($characteristicId); + $itemCode = $this->data['item_id']; + + $itemId = Item::where('plant_id', $characteristic->plant_id)->where('code', $itemCode)->value('id'); + + $characteristic = ProductCharacteristicsMaster::find($characteristicId); + + $limit = ProductCharacteristicsMaster::where('plant_id', $characteristic->plant_id) + ->where('line_id', $characteristic->line_id) + ->where('name', $characteristic->name) + ->where('item_id', $itemId) + ->first(); + if (! $characteristic || ! is_numeric($value)) { return 'Not Ok'; } + // return ($value >= $characteristic->lower && $value <= $characteristic->upper) ? 'Ok' : 'Not Ok'; - return ($value >= $characteristic->lower && $value <= $characteristic->upper) ? 'Ok' : 'Not Ok'; + return ($value >= $limit->lower && $value <= $limit->upper) ? 'Ok' : 'Not Ok'; }