From b0f13d9b570b4ebe7ee7b1a1a7e0d39bb9934344 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 18 Jun 2026 17:15:01 +0530 Subject: [PATCH] Added logic in panel box --- .../Resources/PanelBoxValidationResource.php | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/app/Filament/Resources/PanelBoxValidationResource.php b/app/Filament/Resources/PanelBoxValidationResource.php index d625d91..fbbf495 100644 --- a/app/Filament/Resources/PanelBoxValidationResource.php +++ b/app/Filament/Resources/PanelBoxValidationResource.php @@ -228,47 +228,11 @@ class PanelBoxValidationResource extends Resource } // // Check if QR format contains '|' - if (strpos($state, '|') == false) { - $set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number)'); - $set('part_validation_type', null); - $set('show_validation_image', false); - $set('part_validation_type_options', []); - $set('validation1_image_url', null); - return; - } - - if (! preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $state)) { - $splits = explode('|', $state); - $iCode = trim($splits[0]); - $sNumber = isset($splits[1]) ? trim($splits[1]) : null; - - if (! ctype_alnum($iCode)) { - $set('validationError', 'Item code must contain alpha-numeric values.'); - $set('part_validation_type', null); - $set('show_validation_image', false); - $set('part_validation_type_options', []); - $set('validation1_image_url', null); - - return; - } elseif (strlen($iCode) < 6) { - $set('validationError', 'Item code must be at least 6 digits.'); - $set('part_validation_type', null); - $set('show_validation_image', false); - $set('part_validation_type_options', []); - $set('validation1_image_url', null); - - return; - } elseif (! ctype_alnum($sNumber)) { - $set('validationError', 'Serial Number must contain alpha-numeric values.'); - $set('part_validation_type', null); - $set('show_validation_image', false); - $set('part_validation_type_options', []); - $set('validation1_image_url', null); - - return; - } elseif (strlen($sNumber) < 9) { - $set('validationError', 'Serial Number must be at least 9 digits.'); + if ($state && str_contains($state, '|')) + { + if (strpos($state, '|') == false) { + $set('validationError', 'Scan valid QR code. (Ex: Item_Code|Serial_Number)'); $set('part_validation_type', null); $set('show_validation_image', false); $set('part_validation_type_options', []); @@ -276,17 +240,67 @@ class PanelBoxValidationResource extends Resource return; } - // } - } else { - $set('validationError', null); + if (! preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $state)) { + $splits = explode('|', $state); + $iCode = trim($splits[0]); + $sNumber = isset($splits[1]) ? trim($splits[1]) : null; + + if (! ctype_alnum($iCode)) { + $set('validationError', 'Item code must contain alpha-numeric values.'); + $set('part_validation_type', null); + $set('show_validation_image', false); + $set('part_validation_type_options', []); + $set('validation1_image_url', null); + + return; + } elseif (strlen($iCode) < 6) { + $set('validationError', 'Item code must be at least 6 digits.'); + $set('part_validation_type', null); + $set('show_validation_image', false); + $set('part_validation_type_options', []); + $set('validation1_image_url', null); + + return; + } elseif (! ctype_alnum($sNumber)) { + $set('validationError', 'Serial Number must contain alpha-numeric values.'); + $set('part_validation_type', null); + $set('show_validation_image', false); + $set('part_validation_type_options', []); + $set('validation1_image_url', null); + + return; + } elseif (strlen($sNumber) < 9) { + $set('validationError', 'Serial Number must be at least 9 digits.'); + $set('part_validation_type', null); + $set('show_validation_image', false); + $set('part_validation_type_options', []); + $set('validation1_image_url', null); + + return; + } + // } + + } else { + $set('validationError', null); + } } - $parts = explode('|', $state); + if ($state && str_contains($state, '|')) { - $itemCode = trim($parts[0]); // Extract item code // 123456|123456789 + $parts = explode('|', $state); - $serialNumber = trim($parts[1]); + $itemCode = trim($parts[0]); // Extract item code // 123456|123456789 + + $serialNumber = trim($parts[1]); + } + else + { + $parts = explode('/', $state); + + $itemCode = trim($parts[1] ?? ''); // item code + $serialNumber = trim($parts[2] ?? ''); // serial number + } // Store serial number before resetting fields $previousSerialNumber = $serialNumber;