diff --git a/app/Filament/Resources/PanelBoxValidationResource.php b/app/Filament/Resources/PanelBoxValidationResource.php index 080505f..ee5ea66 100644 --- a/app/Filament/Resources/PanelBoxValidationResource.php +++ b/app/Filament/Resources/PanelBoxValidationResource.php @@ -28,6 +28,8 @@ use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ImportAction; use App\Filament\Exports\PanelBoxValidationExporter; use App\Filament\Imports\PanelBoxValidationImporter; +use Filament\Forms\Components\Actions; +use Filament\Forms\Components\Actions\Action; class PanelBoxValidationResource extends Resource { @@ -41,7 +43,7 @@ class PanelBoxValidationResource extends Resource public $data = []; - // public bool $showChecklist = false; + public bool $showChecklist = false; public static function form(Form $form): Form { @@ -239,10 +241,6 @@ class PanelBoxValidationResource extends Resource $set('pqLineError', null); } - // if(!$state){ - // $set('serial_exists', false); - // } - $pOrder = $get('production_order'); if (! $pOrder) { $set('prodOrdError', "Production Order can't be empty."); @@ -278,11 +276,12 @@ class PanelBoxValidationResource extends Resource // Proceed with validation logic for new scanned QR code if (! $state || trim($state) == '') { + $set('serial_exists', false); $set('validationError', null); return; } - // // Check if QR format contains '|' + // Check if QR format contains '|' if ($state && str_contains($state, '|')) { @@ -566,11 +565,10 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); - // $set('serial_exists', false); + $set('serial_exists', false); return; } - $supplier = $parts[0]; $panelBoxCode = $parts[1]; $panelBoxSerialNo = implode('/', array_slice($parts, 2)); @@ -587,6 +585,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } @@ -599,6 +598,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } @@ -611,6 +611,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){ @@ -620,6 +621,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } else if($existInMaster->supplier_number != $supplier){ @@ -629,6 +631,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } else if($existInMaster->inspection_lot_number != $inspecLotNo){ @@ -638,6 +641,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } else if($existInMaster->quantity == '' || $existInMaster->quantity == null){ @@ -647,6 +651,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){ @@ -656,6 +661,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } @@ -668,6 +674,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } @@ -680,6 +687,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); return; } @@ -695,6 +703,7 @@ class PanelBoxValidationResource extends Resource ->danger() ->send(); $set('item_id', null); + $set('serial_exists', false); $set('validationError', null); return; } @@ -702,6 +711,7 @@ class PanelBoxValidationResource extends Resource if (strlen($itemCode) < 6) { $set('validationError', 'Item code must be at least 6 digits.'); $set('part_validation_type', null); + $set('serial_exists', false); $set('show_validation_image', false); $set('part_validation_type_options', []); $set('validation1_image_url', null); @@ -710,6 +720,7 @@ class PanelBoxValidationResource extends Resource } elseif (! ctype_alnum($itemCode)) { $set('validationError', 'Item Code should contain alpha-numeric values.'); $set('item_id', null); + $set('serial_exists', false); $set('part_validation_type', null); $set('show_validation_image', false); $set('part_validation_type_options', []); @@ -745,6 +756,7 @@ class PanelBoxValidationResource extends Resource $set('show_validation_image', false); $set('part_validation_type_options', []); $set('validation1_image_url', null); + $set('serial_exists', false); return; } else { @@ -756,6 +768,7 @@ class PanelBoxValidationResource extends Resource $set('part_validation_type', null); $set('show_validation_image', false); $set('validation1_image_url', null); + $set('serial_exists', false); return; } elseif (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) { @@ -768,6 +781,7 @@ class PanelBoxValidationResource extends Resource $set('show_validation_image', false); $set('part_validation_type_options', []); $set('validation1_image_url', null); + $set('serial_exists', false); return; } @@ -793,23 +807,23 @@ class PanelBoxValidationResource extends Resource } } - $serialExists = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->first(); + $serialExists = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->latest()->first(); - // if ($serialExists) { - // $set('serial_exists', true); - // } else { - // $set('serial_exists', false); - // } - - if ($serialExists && ! $get('id')) { - $set('validationError', 'Serial number already exists in panel box validation.'); - $set('sticker_master_id', null); - $set('uom', null); - $set('serial_number', null); - - return; + if ($serialExists) { + $set('serial_exists', true); + } else { + $set('serial_exists', false); } + // if ($serialExists && ! $get('id')) { + // $set('validationError', 'Serial number already exists in panel box validation.'); + // $set('sticker_master_id', null); + // $set('uom', null); + // $set('serial_number', null); + + // return; + // } + $set('validationError', null); foreach ($serialFields as $column) { @@ -923,12 +937,6 @@ class PanelBoxValidationResource extends Resource $set('part_validation_type_options', $options); }) - // ->extraAttributes(fn ($get) => [ - // 'class' => $get('validationError') ? 'border-red-500' : '', - // 'id' => 'item_id', - // 'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); return false; }", - // ]) - ->extraAttributes(fn ($get) => [ 'class' => $get('validationError') ? 'border-red-500' : '', 'id' => 'item_id', @@ -960,6 +968,78 @@ class PanelBoxValidationResource extends Resource ]) ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null) ->hintColor('danger'), + Forms\Components\Hidden::make('serial_exists') + ->default(false), + + Forms\Components\Actions::make([ + Action::make('rework') + ->label('Yes, Rework') + ->color('warning') + ->requiresConfirmation() + ->modalHeading('Confirm Rework') + ->modalDescription('Have you reworked this serial number?') + ->modalSubmitActionLabel('Yes, Continue') + ->visible(fn ($get) => $get('serial_exists') == true) + ->action(function ($get, $livewire) { + + $serialNumber = $get('serial_number'); + $plantId = $get('plant_id'); + $pOrder = $get('production_order'); + $inspecLotNo = $get('inspection_lot_number'); + + // $serialRecords = PanelBoxValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->get(); + + // if ($serialRecords->isNotEmpty()) { + + // $alreadyExists = $serialRecords->contains(function ($record) use ($pOrder, $inspecLotNo) { + // return $record->production_order == $pOrder + // && $record->inspection_lot_number == $inspecLotNo; + // }); + + // if ($alreadyExists) { + // Notification::make() + // ->title('Invalid Rework') + // ->body( + // 'This document number and inspection lot number have already been used for this serial number. Please provide a new document number and inspection lot number.' + // ) + // ->danger() + // ->send(); + + // return; + // } + // } + + $alreadyExists = PanelBoxValidation::where('serial_number', $serialNumber) + ->where('plant_id', $plantId) + ->where('production_order', $pOrder) + ->where('inspection_lot_number', $inspecLotNo) + ->first(); + + if ($alreadyExists) { + Notification::make() + ->title('Invalid Rework') + ->body( + 'This document number and inspection lot number have already been used for this serial number. Please provide a new document number and inspection lot number.' + ) + ->danger() + ->send(); + + return; + } + else + { + // $livewire->showChecklist = true; + $data = $livewire->data; + + if ($livewire->checkIfHasCharacteristics($data)) { + + $livewire->showChecklist = true; + $livewire->dispatch('close-modal'); + return; + } + } + }), + ]), Forms\Components\Hidden::make('part_validation_type_options') ->default([]) ->reactive() @@ -1767,6 +1847,11 @@ class PanelBoxValidationResource extends Resource ->alignCenter() ->searchable() ->sortable(), + Tables\Columns\TextColumn::make('rework_count') + ->label('Rework Count') + ->alignCenter() + ->searchable() + ->sortable(), Tables\Columns\TextColumn::make('created_at') ->label('Created At') ->alignCenter()