diff --git a/app/Filament/Imports/StickerMasterImporter.php b/app/Filament/Imports/StickerMasterImporter.php index 89da4bb..2bc4fc0 100644 --- a/app/Filament/Imports/StickerMasterImporter.php +++ b/app/Filament/Imports/StickerMasterImporter.php @@ -163,12 +163,23 @@ class StickerMasterImporter extends Importer public function resolveRecord(): ?StickerMaster { $warnMsg = []; - $plantCod = $this->data['plant']; - $itemCod = $this->data['item']; + $plantCod = trim($this->data['plant']); + $itemCod = trim($this->data['item']); + $panelCod = trim($this->data['panel_box_code']); $plant = null; $item = null; $plantId = null; $itemId = null; + $parts = null; + $validParts = null; + $part1 = trim($this->data['part_validation1']); + $part2 = trim($this->data['part_validation2']); + $part3 = trim($this->data['part_validation3']); + $part4 = trim($this->data['part_validation4']); + $part5 = trim($this->data['part_validation5']); + $laserPart1 = trim($this->data['laser_part_validation1']); + $laserPart2 = trim($this->data['laser_part_validation2']); + $createdBy = Filament::auth()->user()->name; $updatedBy = Filament::auth()->user()->name; if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { @@ -194,6 +205,23 @@ class StickerMasterImporter extends Importer } else { $itemId = $item->id; + if (! $laserPart1) { + $laserPart1 = $laserPart2; + $laserPart2 = null; + } + + if (Str::length($panelCod) > 0 && (Str::length($panelCod) < 6 || ! ctype_alnum($panelCod))) { + $warnMsg[] = 'Invalid panel box code found'; + } elseif ($panelCod) { + $parts = [$part1, $part2, $part3, $part4]; + $validParts = array_values(array_filter($parts, fn ($p) => ! empty($p))); + [$part1, $part2, $part3, $part4] = array_pad($validParts, 4, ''); + } else { + $parts = [$part1, $part2, $part3, $part4, $part5]; + $validParts = array_values(array_filter($parts, fn ($p) => ! empty($p))); + [$part1, $part2, $part3, $part4, $part5] = array_pad($validParts, 5, ''); + } + if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') { $warnMsg[] = 'Serial number motor must be 1 or empty'; } @@ -233,9 +261,6 @@ class StickerMasterImporter extends Importer if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') { $warnMsg[] = 'Warranty card must be 1 or empty'; } - if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) { - $warnMsg[] = 'Invalid panel box code found'; - } if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) { $warnMsg[] = 'Load rate must be greater than or equal to 0'; } @@ -280,14 +305,14 @@ class StickerMasterImporter extends Importer 'tube_sticker_pump' => $this->data['tube_sticker_pump'], 'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'], 'warranty_card' => $this->data['warranty_card'], - 'part_validation1' => $this->data['part_validation1'], - 'part_validation2' => $this->data['part_validation2'], - 'part_validation3' => $this->data['part_validation3'], - 'part_validation4' => $this->data['part_validation4'], - 'part_validation5' => $this->data['part_validation5'], - 'laser_part_validation1' => $this->data['laser_part_validation1'], - 'laser_part_validation2' => $this->data['laser_part_validation2'], - 'panel_box_code' => $this->data['panel_box_code'], + 'part_validation1' => $part1, + 'part_validation2' => $part2, + 'part_validation3' => $part3, + 'part_validation4' => $part4, + 'part_validation5' => $part5, + 'laser_part_validation1' => $laserPart1, + 'laser_part_validation2' => $laserPart2, + 'panel_box_code' => $panelCod, 'load_rate' => $this->data['load_rate'], 'bundle_quantity' => $this->data['bundle_quantity'], 'material_type' => $this->data['material_type'], diff --git a/app/Filament/Resources/StickerMasterResource.php b/app/Filament/Resources/StickerMasterResource.php index 705fb66..ea54c67 100644 --- a/app/Filament/Resources/StickerMasterResource.php +++ b/app/Filament/Resources/StickerMasterResource.php @@ -66,7 +66,7 @@ class StickerMasterResource extends Resource $set('item_description', null); $set('item_error', null); $set('panel_box_code', null); - $set('load_rate', null); + $set('load_rate', 0); $set('bundle_quantity', null); $set('material_type', null); $set('part_validation1', null); @@ -220,7 +220,7 @@ class StickerMasterResource extends Resource ->label('Part Validation 2') ->nullable() ->reactive() - ->disabled(fn (Get $get) => empty($get('part_validation1'))) + ->readOnly(fn (callable $get) => empty($get('part_validation1'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('updated_by', Filament::auth()->user()?->name); }), @@ -229,7 +229,7 @@ class StickerMasterResource extends Resource ->label('Part Validation 3') ->nullable() ->reactive() - ->disabled(fn (Get $get) => empty($get('part_validation2'))) + ->readOnly(fn (callable $get) => empty($get('part_validation1')) || empty($get('part_validation2'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('updated_by', Filament::auth()->user()?->name); }), @@ -238,7 +238,7 @@ class StickerMasterResource extends Resource ->label('Part Validation 4') ->nullable() ->reactive() - ->disabled(fn (Get $get) => empty($get('part_validation3'))) + ->readOnly(fn (callable $get) => empty($get('part_validation1')) || empty($get('part_validation2')) || empty($get('part_validation3'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('updated_by', Filament::auth()->user()?->name); }), @@ -247,7 +247,7 @@ class StickerMasterResource extends Resource ->label('Part Validation 5 (Capacitor QR)') ->nullable() ->reactive() - ->disabled(fn (Get $get) => empty($get('part_validation4')) && empty($get('panel_box_code'))) + ->readOnly(fn (callable $get) => (empty($get('part_validation1')) || empty($get('part_validation2')) || empty($get('part_validation3')) || empty($get('part_validation4'))) && empty($get('panel_box_code'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('updated_by', Filament::auth()->user()?->name); }), @@ -264,7 +264,7 @@ class StickerMasterResource extends Resource ->label('Laser Part Validation 2') ->nullable() ->reactive() - ->disabled(fn (Get $get) => empty($get('laser_part_validation1'))) + ->readOnly(fn (callable $get) => empty($get('laser_part_validation1'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('updated_by', Filament::auth()->user()?->name); }), diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index 9ee2500..f91dd8f 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -746,7 +746,8 @@ class PdfController extends Controller 'status_code' => 'ERROR', 'status_description' => "Coil number can't be empty!", ], 404); - } elseif (! is_numeric($coilNo) || Str::length($coilNo) <= 0 || ! preg_match('/^\d{1,}$/', $coilNo)) { // !ctype_digit($data['plant_code']) + } elseif (! is_numeric($coilNo) || Str::length($coilNo) <= 0 || !preg_match('/^\d+(\.\d+)?$/', $coilNo) + ) { // !ctype_digit($data['plant_code']) return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid coil number found!',