diff --git a/app/Livewire/PanelCheckList.php b/app/Livewire/PanelCheckList.php index fad45bb..01e180f 100644 --- a/app/Livewire/PanelCheckList.php +++ b/app/Livewire/PanelCheckList.php @@ -69,14 +69,16 @@ public $records = []; public function saveChecklist() { + if(!$this->selectForNotOk){ - if (empty($this->checklist) || count($this->checklist) != count($this->records)) { - Notification::make() - ->title('Incomplete Checklist') - ->body('Please complete all checklist fields before submitting.') - ->danger() - ->send(); - return; + if (empty($this->checklist) || count($this->checklist) != count($this->records)) { + Notification::make() + ->title('Incomplete Checklist') + ->body('Please complete all checklist fields before submitting.') + ->danger() + ->send(); + return; + } } $item = Item::where('code', $this->data['item_id'])->first(); @@ -209,10 +211,58 @@ public $records = []; return; } + // if($this->selectForNotOk){ + + // 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($this->selectForNotOk){ - foreach ($this->checklist as $characteristicId => $value) { + foreach ($this->records as $record) { + $characteristicId = $record['id']; + + $value = $this->checklist[$characteristicId] ?? null; $characteristic = ProductCharacteristicsMaster::find($characteristicId); @@ -223,8 +273,10 @@ public $records = []; ->first(); if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { - - if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper + if ($value == null || $value == '') { + $status = null; + } + else if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper ) { $status = 'Ok'; } else { @@ -232,7 +284,7 @@ public $records = []; } } else { - $status = $value; + $status = !empty($value) ? $value : null; } $prod = ProductionCharacteristic::create([ @@ -251,7 +303,6 @@ public $records = []; 'updated_by' => $this->data['updated_by'] ?? null, ]); } - } else { @@ -267,7 +318,7 @@ public $records = []; ->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 ) {