Added select for not ok button in panel check list livewire page #913

Merged
jothi merged 1 commits from ranjith-dev into master 2026-08-20 03:52:03 +00:00
2 changed files with 147 additions and 42 deletions

View File

@@ -28,6 +28,8 @@ public $records = [];
public $showChecklist = false; public $showChecklist = false;
public bool $selectForNotOk = false;
// public $skipChecklistValidation = false; // public $skipChecklistValidation = false;
// protected $listeners = ['focus-item-id' => 'handleFocus', 'trigger-create' => 'doCreate',]; // protected $listeners = ['focus-item-id' => 'handleFocus', 'trigger-create' => 'doCreate',];
@@ -66,6 +68,8 @@ public $records = [];
public function saveChecklist() public function saveChecklist()
{ {
if (empty($this->checklist) || count($this->checklist) != count($this->records)) { if (empty($this->checklist) || count($this->checklist) != count($this->records)) {
Notification::make() Notification::make()
->title('Incomplete Checklist') ->title('Incomplete Checklist')
@@ -116,6 +120,61 @@ public $records = [];
return; 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([ $qualityValidation = PanelBoxValidation::create([
'plant_id' => $this->data['plant_id'] ?? null, 'plant_id' => $this->data['plant_id'] ?? null,
'line_id' => $this->data['line_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_supplier' => $this->data['panel_box_supplier'] ?? null,
'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null, 'panel_box_serial_number' => $this->data['panel_box_serial_number'] ?? null,
'panel_box_code' => $this->data['panel_box_code'] ?? 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, 'created_by' => $this->data['created_by'] ?? null,
'updated_by' => $this->data['updated_by'] ?? null,
]); ]);
if (! $qualityValidation || ! $qualityValidation->exists) { if (! $qualityValidation || ! $qualityValidation->exists) {
@@ -148,57 +209,93 @@ public $records = [];
return; 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']) $characteristic = ProductCharacteristicsMaster::find($characteristicId);
->where('line_id', $this->data['line_id'])
->where('name', $characteristic->name)
->where('item_id', $itemId)
->first();
// if (($characteristic?->inspection_type ?? null) === 'Value') { $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id'])
// if ($characteristic && is_numeric($value) && (($value >= $characteristic->lower && $value <= $characteristic->upper) || $value == $characteristic->lower || $value == $characteristic->upper) ->where('line_id', $this->data['line_id'])
// ) { ->where('name', $characteristic->name)
// $status = 'Ok'; ->where('item_id', $itemId)
// } else { ->first();
// $status = 'NotOk';
// }
// }
// else {
// $status = $value;
// }
if (($itemCharacteristic?->inspection_type ?? null) === 'Value') { if (($itemCharacteristic?->inspection_type ?? null) === 'Value') {
if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper if ($itemCharacteristic && is_numeric($value) && $value >= $itemCharacteristic->lower && $value <= $itemCharacteristic->upper
) { ) {
$status = 'Ok'; $status = 'Ok';
} else { } else {
$status = 'NotOk'; $status = 'NotOk';
}
} }
} else {
else { $status = $value;
$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, else {
'item_id' => $itemId ?? null,
'line_id' => $this->data['line_id'] ?? null, //All validations Passed
'machine_id' => $characteristic?->machine_id ?? null, foreach ($this->checklist as $characteristicId => $value) {
'production_order' => $this->data['production_order'] ?? null,
'serial_number' => $this->data['serial_number'] ?? null,
'characteristic_name' => $characteristic?->name ?? null, $characteristic = ProductCharacteristicsMaster::find($characteristicId);
'observed_value' => $value ?? null,
'status' => $status, $itemCharacteristic = ProductCharacteristicsMaster::where('plant_id', $this->data['plant_id'])
'inspection_status' => $finalInspectionStatus ?? null, ->where('line_id', $this->data['line_id'])
'created_by' => $this->data['created_by'] ?? null, ->where('name', $characteristic->name)
'updated_by' => $this->data['updated_by'] ?? null, ->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) { if (! $prod) {

View File

@@ -119,6 +119,14 @@
@endif @endif
<div class="border-t mt-6 pt-4 flex justify-end gap-3"> <div class="border-t mt-6 pt-4 flex justify-end gap-3">
<label class="flex items-center gap-2">
<input
type="checkbox"
wire:model.live="selectForNotOk"
>
<span>Select for Not Ok</span>
</label>
<button <button
type="button" type="button"
wire:click="cancel" wire:click="cancel"