From dc289d96ec748f18640daf5a18f4fa620b4cd51b Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 6 Nov 2026 15:43:17 +0530 Subject: [PATCH] Added validation gainst production order checking logic in panel box validation --- .../Resources/PanelBoxValidationResource.php | 500 +++++++++--------- 1 file changed, 263 insertions(+), 237 deletions(-) diff --git a/app/Filament/Resources/PanelBoxValidationResource.php b/app/Filament/Resources/PanelBoxValidationResource.php index 73f37edb..4424a6e4 100644 --- a/app/Filament/Resources/PanelBoxValidationResource.php +++ b/app/Filament/Resources/PanelBoxValidationResource.php @@ -289,276 +289,276 @@ class PanelBoxValidationResource extends Resource // Check if QR format contains '|' - // 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', []); - // $set('validation1_image_url', null); + 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', []); + $set('validation1_image_url', null); - // return; - // } + 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 (! 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); + 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 (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 (! 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; - // } + return; + } - // $existInMasterPo = PanelGrMaster::where('document_number', $pOrder)->where('plant_id', $plantId)->first(); + $existInMasterPo = PanelGrMaster::where('document_number', $pOrder)->where('plant_id', $plantId)->first(); - // if(!$existInMasterPo){ - // Notification::make() - // ->title('Panel GR Record') - // ->body("Production Order (Or) Doc No'{$pOrder}' not found against plant code '{$plaCode}' in Panel Gr master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$existInMasterPo){ + Notification::make() + ->title('Panel GR Record') + ->body("Production Order (Or) Doc No'{$pOrder}' not found against plant code '{$plaCode}' in Panel Gr master.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $iId = Item::where('code', $iCode)->where('plant_id', $plantId)->first(); + $iId = Item::where('code', $iCode)->where('plant_id', $plantId)->first(); - // if(!$iId){ - // Notification::make() - // ->title('Item not found') - // ->body("Item code'{$iCode}' not found against plant code '{$plaCode}' in item master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$iId){ + Notification::make() + ->title('Item not found') + ->body("Item code'{$iCode}' not found against plant code '{$plaCode}' in item master.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $existInMaster = PanelGrMaster::where('document_number', $pOrder)->where('item_id', $iId->id)->where('plant_id', $plantId)->first(); + $existInMaster = PanelGrMaster::where('document_number', $pOrder)->where('item_id', $iId->id)->where('plant_id', $plantId)->first(); - // if(!$existInMaster){ - // Notification::make() - // ->title('Panel GR Record Not Found') - // ->body("No Panel GR record found for Production Order (Or) Doc No'{$pOrder}' and for Item '{$iCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Supplier Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // // else if($existInMaster->supplier_number != $supplier){ - // // Notification::make() - // // ->title('Panel GR Found') - // // ->body("Supplier code not match for Production Order (Or) Doc No'{$pOrder}' and Item '{$iCode}'.") - // // ->danger() - // // ->send(); - // // $set('item_id', null); - // // return; - // // } - // else if($existInMaster->quantity == '' || $existInMaster->quantity == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Quantity cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Invoice Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$existInMaster){ + Notification::make() + ->title('Panel GR Record Not Found') + ->body("No Panel GR record found for Production Order (Or) Doc No'{$pOrder}' and for Item '{$iCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Supplier Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + // else if($existInMaster->supplier_number != $supplier){ + // Notification::make() + // ->title('Panel GR Found') + // ->body("Supplier code not match for Production Order (Or) Doc No'{$pOrder}' and Item '{$iCode}'.") + // ->danger() + // ->send(); + // $set('item_id', null); + // return; + // } + else if($existInMaster->quantity == '' || $existInMaster->quantity == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Quantity cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Invoice Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$iCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $sticker = StickerMaster::where('plant_id', $plantId)->where('item_id', $iId->id)->first(); + $sticker = StickerMaster::where('plant_id', $plantId)->where('item_id', $iId->id)->first(); - // if(!$sticker){ - // Notification::make() - // ->title('Unknown Item Code') - // ->body("Item code not found '{$iId->code}' in sticker master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // } + if(!$sticker){ + Notification::make() + ->title('Unknown Item Code') + ->body("Item code not found '{$iId->code}' in sticker master.") + ->danger() + ->send(); + $set('item_id', null); + } - // $existQuanInPanel = PanelBoxValidation::where('plant_id', $plantId)->where('production_order', $pOrder)->where('sticker_master_id', $sticker->id)->count(); + $existQuanInPanel = PanelBoxValidation::where('plant_id', $plantId)->where('production_order', $pOrder)->where('sticker_master_id', $sticker->id)->count(); - // if ($existQuanInPanel >= (int) $existInMaster->quantity) { - // Notification::make() - // ->title('Quantity Completed') - // ->body("Panel box quantity '{$existQuanInPanel}' exceeds the available quantity '{$existInMaster->quantity}' in Panel GR Master for Production Order '{$pOrder}' and Item '{$iCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // } else { - // $set('validationError', null); - // } - // } - // if (str_contains($state, '|')) { + if ($existQuanInPanel >= (int) $existInMaster->quantity) { + Notification::make() + ->title('Quantity Completed') + ->body("Panel box quantity '{$existQuanInPanel}' exceeds the available quantity '{$existInMaster->quantity}' in Panel GR Master for Production Order '{$pOrder}' and Item '{$iCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + } else { + $set('validationError', null); + } + } + if (str_contains($state, '|')) { - // $parts = array_map('trim', explode('|', $state)); + $parts = array_map('trim', explode('|', $state)); - // if (count($parts) != 2) { - // Notification::make() - // ->title('Invalid QR Format') - // ->body('Expected format: ItemCode|SerialNumber') - // ->danger() - // ->send(); + if (count($parts) != 2) { + Notification::make() + ->title('Invalid QR Format') + ->body('Expected format: ItemCode|SerialNumber') + ->danger() + ->send(); - // return; - // } + return; + } - // $itemCode = $parts[0]; - // $serialNumber = $parts[1]; + $itemCode = $parts[0]; + $serialNumber = $parts[1]; - // if($serialNumber == '' || $serialNumber == null){ - // Notification::make() - // ->title('Unknown Serial number') - // ->body("Serial number can't be empty!") - // ->danger() - // ->send(); + if($serialNumber == '' || $serialNumber == null){ + Notification::make() + ->title('Unknown Serial number') + ->body("Serial number can't be empty!") + ->danger() + ->send(); - // $set('item_id', null); - // return; - // } - // elseif (! ctype_alnum($serialNumber)) { - // $set('validationError', 'Serial Number should contain alpha-numeric values.'); - // $set('item_id', null); - // return; - // } + $set('item_id', null); + return; + } + elseif (! ctype_alnum($serialNumber)) { + $set('validationError', 'Serial Number should contain alpha-numeric values.'); + $set('item_id', null); + return; + } - // $existInMasterPo = PanelGrMaster::where('document_number', $pOrder)->where('plant_id', $plantId)->first(); + $existInMasterPo = PanelGrMaster::where('document_number', $pOrder)->where('plant_id', $plantId)->first(); - // if(!$existInMasterPo){ - // Notification::make() - // ->title('Panel GR Record') - // ->body("Production Order (Or) Doc No'{$pOrder}' not found against plant code '{$plaCode}' in Panel Gr master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$existInMasterPo){ + Notification::make() + ->title('Panel GR Record') + ->body("Production Order (Or) Doc No'{$pOrder}' not found against plant code '{$plaCode}' in Panel Gr master.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $iId = Item::where('code', $itemCode)->where('plant_id', $plantId)->first(); + $iId = Item::where('code', $itemCode)->where('plant_id', $plantId)->first(); - // if(!$iId){ - // Notification::make() - // ->title('Item not found') - // ->body("Item code'{$itemCode}' not found against plant code '{$plaCode}' in item master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$iId){ + Notification::make() + ->title('Item not found') + ->body("Item code'{$itemCode}' not found against plant code '{$plaCode}' in item master.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $existInMaster = PanelGrMaster::where('document_number', $pOrder)->where('item_id', $iId->id)->where('plant_id', $plantId)->first(); + $existInMaster = PanelGrMaster::where('document_number', $pOrder)->where('item_id', $iId->id)->where('plant_id', $plantId)->first(); - // if(!$existInMaster){ - // Notification::make() - // ->title('Panel GR Record Not Found') - // ->body("No Panel GR record found for Production Order (Or) Doc No'{$pOrder}' and for Item '{$itemCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Supplier Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // // else if($existInMaster->supplier_number != $supplier){ - // // Notification::make() - // // ->title('Panel GR Found') - // // ->body("Supplier code not match for Production Order (Or) Doc No'{$pOrder}' and Item '{$iCode}'.") - // // ->danger() - // // ->send(); - // // $set('item_id', null); - // // return; - // // } - // else if($existInMaster->quantity == '' || $existInMaster->quantity == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Quantity cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } - // else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){ - // Notification::make() - // ->title('Panel GR Found') - // ->body("Invoice Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if(!$existInMaster){ + Notification::make() + ->title('Panel GR Record Not Found') + ->body("No Panel GR record found for Production Order (Or) Doc No'{$pOrder}' and for Item '{$itemCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + else if($existInMaster->supplier_number == '' || $existInMaster->supplier_number == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Supplier Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + // else if($existInMaster->supplier_number != $supplier){ + // Notification::make() + // ->title('Panel GR Found') + // ->body("Supplier code not match for Production Order (Or) Doc No'{$pOrder}' and Item '{$iCode}'.") + // ->danger() + // ->send(); + // $set('item_id', null); + // return; + // } + else if($existInMaster->quantity == '' || $existInMaster->quantity == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Quantity cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } + else if($existInMaster->invoice_number == '' || $existInMaster->invoice_number == null){ + Notification::make() + ->title('Panel GR Found') + ->body("Invoice Number cannot be empty Panel GR record found for Production Order '{$pOrder}' and Item '{$itemCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // $sticker = StickerMaster::where('plant_id', $plantId)->where('item_id', $iId->id)->first(); + $sticker = StickerMaster::where('plant_id', $plantId)->where('item_id', $iId->id)->first(); - // if(!$sticker){ - // Notification::make() - // ->title('Unknown Item Code') - // ->body("Item code not found '{$iId->code}' in sticker master.") - // ->danger() - // ->send(); - // $set('item_id', null); - // } + if(!$sticker){ + Notification::make() + ->title('Unknown Item Code') + ->body("Item code not found '{$iId->code}' in sticker master.") + ->danger() + ->send(); + $set('item_id', null); + } - // $existQuanInPanel = PanelBoxValidation::where('plant_id', $plantId)->where('production_order', $pOrder)->where('sticker_master_id', $sticker->id)->count(); + $existQuanInPanel = PanelBoxValidation::where('plant_id', $plantId)->where('production_order', $pOrder)->where('sticker_master_id', $sticker->id)->count(); - // if ($existQuanInPanel >= (int) $existInMaster->quantity) { - // Notification::make() - // ->title('Quantity Completed') - // ->body("Panel box quantity '{$existQuanInPanel}' exceeds the available quantity '{$existInMaster->quantity}' in Panel GR Master for Production Order '{$pOrder}' and Item '{$itemCode}'.") - // ->danger() - // ->send(); - // $set('item_id', null); - // return; - // } + if ($existQuanInPanel >= (int) $existInMaster->quantity) { + Notification::make() + ->title('Quantity Completed') + ->body("Panel box quantity '{$existQuanInPanel}' exceeds the available quantity '{$existInMaster->quantity}' in Panel GR Master for Production Order '{$pOrder}' and Item '{$itemCode}'.") + ->danger() + ->send(); + $set('item_id', null); + return; + } - // } + } if (str_contains($state, '/')) { $parts = explode('/', $state); @@ -794,6 +794,32 @@ class PanelBoxValidationResource extends Resource return; } + $plantCode = Plant::where('id', $plantId)->value('code'); + + if($plantCode != $supplier){ + Notification::make() + ->title('Supplier Mismatch') + ->body("Supplier code '$supplier' mismatch with selected plant code '$plantCode'.") + ->danger() + ->send(); + $set('item_id', null); + $set('serial_exists', false); + return; + } + + if($existInMasterProdOrder->item_id != $iId){ + $itemCodePOrd = Item::where('id', $existInMasterProdOrder->item_id)->value('code'); + + Notification::make() + ->title('Panel Box Code Mismatch') + ->body("Scanned Panel Box Code '$itemCode' not matched with produciton order item code '$itemCodePOrd'.") + ->danger() + ->send(); + $set('item_id', null); + $set('serial_exists', false); + return; + } + if($existInMasterProdOrder->quantity == '' || $existInMasterProdOrder->quantity == null){ Notification::make() ->title('Production Order Found') -- 2.49.1