diff --git a/app/Filament/Pages/StickerOrderReprint.php b/app/Filament/Pages/StickerOrderReprint.php index 10134aef..6ff00e47 100644 --- a/app/Filament/Pages/StickerOrderReprint.php +++ b/app/Filament/Pages/StickerOrderReprint.php @@ -1090,7 +1090,7 @@ class StickerOrderReprint extends Page implements HasForms return; } - $stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get(); + $stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->get(); if ($stickerMappingMasterItems->isEmpty()) { Notification::make() @@ -1208,35 +1208,27 @@ class StickerOrderReprint extends Page implements HasForms for ($i = 1; $i <= 8; $i++) { $structureColumn = "sticker_structure{$i}_id"; + $machineColumn = "sticker{$i}_machine_id"; + + $mappedStructureId = $stickerMappingMasterItem->{$structureColumn} ?? null; if ( - (string) $stickerMappingMasterItem->{$structureColumn} - == (string) $structure->id + $mappedStructureId !== null && + (string) $mappedStructureId === (string) $structure->id ) { - $machineColumn = "sticker{$i}_machine_id"; - - $matchedMachineId = $stickerMappingMasterItem->{$machineColumn}; - + $matchedMachineId = $stickerMappingMasterItem->{$machineColumn} ?? null; break; } } - if ($matchedMachineId == null || (string) $matchedMachineId != (string) $machineId) - { + $selectedMachineId = trim((string) $machineId); + $mappedMachineId = trim((string) $matchedMachineId); + + if ($mappedMachineId === '' || $mappedMachineId !== $selectedMachineId) { Notification::make() ->danger() ->title('Machine Mapping Mismatch') - ->body("Selected machine '{$machineId}' does not match the machine mapped to the selected sticker.") - ->send(); - - return; - } - - if ((string) $matchedMachineId != (string) $machineId) { - Notification::make() - ->danger() - ->title('Machine Not Found') - ->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' against sticker '$stickerId' in sticker mapping master.") + ->body("Selected machine '{$selectedMachineId}' does not match the mapped machine '{$mappedMachineId}'.") ->send(); return;