From 4e969142a7cf5046db4020dc5ca3b106a22b638e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 28 Nov 2026 07:50:39 +0530 Subject: [PATCH] changed logic in panel box validation checklist --- app/Livewire/PanelCheckList.php | 65 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/app/Livewire/PanelCheckList.php b/app/Livewire/PanelCheckList.php index ec7460f9..22906d44 100644 --- a/app/Livewire/PanelCheckList.php +++ b/app/Livewire/PanelCheckList.php @@ -123,11 +123,11 @@ public $records = []; $itemId = $itemAgaPlant->id; - $exists = PanelBoxValidation::where('plant_id', $this->data['plant_id'] ?? null) - ->where('serial_number', $this->data['serial_number'] ?? null) - ->first(); + // $exists = PanelBoxValidation::where('plant_id', $this->data['plant_id'] ?? null) + // ->where('serial_number', $this->data['serial_number'] ?? null) + // ->first(); - $plan = Plant::find($this->data['plant_id']); + // $plan = Plant::find($this->data['plant_id']); // if ($exists) { // Notification::make() @@ -193,7 +193,7 @@ public $records = []; } } - $qualityValidation = null; + $panelBoxSaved = null; $latestReworkRecord = PanelBoxValidation::where('plant_id', $this->data['plant_id'] ?? null)->where('serial_number', $this->data['serial_number'] ?? null)->where('panel_box_supplier', $this->data['panel_box_supplier'] ?? null)->first(); @@ -211,27 +211,17 @@ public $records = []; if($latestReworkRecord){ $userName = Filament::auth()->user()?->name; - $reworkCount = $latestReworkRecord - ? ((int) $latestReworkRecord->rework_count + 1) - : 0; - try{ - $latestReworkRecord->update([ - 'rework_count' => $reworkCount, - 'status' => $this->selectForNotOk ? 'NotOk' : 'Ok', - 'updated_by' => $userName, - ]); - } - catch (\Illuminate\Database\QueryException $e) { - Notification::make() - ->title('Duplicate Record') - ->body("Duplicate serial number found against doc number '{$this->data['production_order'] }' and inspection lot number '{$this->data['inspection_lot_number']}'.") - ->danger() - ->send(); - return; - } + $reworkCount = $latestReworkRecord ? ((int) $latestReworkRecord->rework_count + 1) : 0; + + $panelBoxSaved = $latestReworkRecord->update([ + 'rework_count' => $reworkCount, + 'status' => $this->selectForNotOk ? 'NotOk' : 'Ok', + 'updated_at' => now(), + 'updated_by' => $userName, + ]); } else{ - $qualityValidation = PanelBoxValidation::create([ + $panelBoxSaved = PanelBoxValidation::create([ 'plant_id' => $this->data['plant_id'] ?? null, 'line_id' => $this->data['line_id'] ?? null, 'sticker_master_id' => $this->data['sticker_master_id'] ?? null, @@ -257,14 +247,15 @@ public $records = []; ]); } - // if (! $qualityValidation || ! $qualityValidation->exists) { - // Notification::make() - // ->title('Failed to save Panel Box Validation') - // ->body('Something went wrong while inserting data.') - // ->danger() - // ->send(); - // return; - // } + if (! $panelBoxSaved) { + Notification::make() + ->title('Failed to Save Panel Box Validation') + ->body('Unable to save or update Panel Box Validation. Please try again.') + ->danger() + ->send(); + + return; + } // if($this->selectForNotOk){ @@ -311,6 +302,7 @@ public $records = []; // } + $insertedCount = 0; if($this->selectForNotOk){ $notOkCharacteristics = []; @@ -459,11 +451,16 @@ public $records = []; } if (! $prod) { + $insertedCount++; + } + + if ($insertedCount != count($this->records)) { Notification::make() - ->title('Failed to save Panel Box Validation') - ->body('Something went wrong while inserting data.') + ->title('Failed to Save Production Characteristics') + ->body('One or more characteristic records were not inserted.') ->danger() ->send(); + return; } -- 2.49.1