diff --git a/app/Filament/Resources/StickerPrintingResource/Pages/CreateStickerPrinting.php b/app/Filament/Resources/StickerPrintingResource/Pages/CreateStickerPrinting.php index efe73a3..ef4a5f8 100644 --- a/app/Filament/Resources/StickerPrintingResource/Pages/CreateStickerPrinting.php +++ b/app/Filament/Resources/StickerPrintingResource/Pages/CreateStickerPrinting.php @@ -77,6 +77,54 @@ class CreateStickerPrinting extends CreateRecord $sNumber = $this->form->getState()['serial_number'] ?? null; + $pattern1 = '/^(?[^|]+)\|(?[^|]+)\|?$/i'; + + $pattern2 = '/^(?[^|]+)\|(?[^|]+)\|(?.+)$/i'; + + $pattern3 = '/^(?[^|]+)$/i'; + + + if (preg_match($pattern1, $sNumber, $matches) || preg_match($pattern2, $sNumber, $matches) || preg_match($pattern3, $sNumber, $matches)) { + + $serial = $matches['serial_number']; + + if (Str::length($serial) < 9) { + Notification::make() + ->title('Invalid Serial Number') + ->body("Serial number should conatin minimum 9 digits '$serial'.") + ->warning() + ->send(); + return; + } + else if(!ctype_alnum($serial)) { + Notification::make() + ->title('Invalid Serial Number') + ->body("Serial number should be alphanumeric '$serial'.") + ->warning() + ->send(); + return; + } + $extractedSerialNumber = $matches['serial_number']; + $sNumber = $extractedSerialNumber; + } + else + { + Notification::make() + ->title('Invalid Format') + ->body("Serial number must be in the format 'itemcode|serialnumber' or 'itemcode|serialnumber|batchnumber'. or just 'serialnumber'.") + ->warning() + ->send(); + + // Reset only serial number field + $this->form->fill([ + 'plant_id' => $plant, + 'reference_number' => $ref, + 'serial_number' => '', + ]); + return; + } + + if(empty($this->plantId) || empty($ref) || empty($this->serial_number)) { Notification::make() ->title('Unknown: Incomplete Data!')