diff --git a/app/Filament/Pages/BulkStickerPrinting.php b/app/Filament/Pages/BulkStickerPrinting.php index 45599f4e5b..d8913be383 100644 --- a/app/Filament/Pages/BulkStickerPrinting.php +++ b/app/Filament/Pages/BulkStickerPrinting.php @@ -873,19 +873,6 @@ class BulkStickerPrinting extends Page implements HasForms return; } - // if($stickerId == 'SelfPriming Monoblock Pump Dual'){ - // if ($fromSerNo % 2 == 0 || $toSerNo % 2 != 0) { - - // Notification::make() - // ->danger() - // ->title('Invalid Serial Number') - // ->body('For SelfPriming Monoblock Pump Dual, serial numbers must be even.') - // ->send(); - - // return; - // } - // } - $pOrderExist = ClassCharacteristic::where('plant_id',$plantId)->where('aufnr', $pOrder)->first(); if(!$pOrderExist){ @@ -916,17 +903,6 @@ class BulkStickerPrinting extends Page implements HasForms } } - // $updatePrintStatusCompleted = StickerOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->where('sticker_id', $stickerId)->where('from_serial_number', $fromSerNo)->where('to_serial_number', $toSerNo)->where('sticker_id', $stickerId)->where('print_status', 'Printed')->first(); - - // if ($updatePrintStatusCompleted) { - // Notification::make() - // ->danger() - // ->title('Duplicate Sticker') - // ->body("Already StickerId '$stickerId' generated successfully for Production Order '$pOrder' and plant '$plantName'.") - // ->send(); - // return; - // } - $existingSticker = StickerOrder::where('plant_id', $plantId) ->where('production_order', $pOrder) ->where('sticker_id', $stickerId) @@ -956,10 +932,9 @@ class BulkStickerPrinting extends Page implements HasForms return; } - $stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get(); - // dd($plantId, $stickerMappingMasterItems); + $stickerMappingMasterItem = StickerMappingMaster::where('plant_id', $plantId)->first(); - if (!$stickerMappingMasterItems) { + if (!$stickerMappingMasterItem) { Notification::make() ->danger() @@ -969,115 +944,62 @@ class BulkStickerPrinting extends Page implements HasForms return; } - $structure = null; - $stickerMappingMasterItem = null; + // foreach ($stickerMappingMasterItems as $mapping) { - foreach ($stickerMappingMasterItems as $mapping) { + // // Check sticker_structure1_id to sticker_structure8_id + // for ($i = 1; $i <= 8; $i++) { - // Check sticker_structure1_id to sticker_structure8_id - for ($i = 1; $i <= 8; $i++) { + // $column = "sticker_structure{$i}_id"; - $column = "sticker_structure{$i}_id"; + // $structureId = $mapping->{$column}; - $structureId = $mapping->{$column}; + // if (empty($structureId)) { + // continue; + // } - if (empty($structureId)) { - continue; - } + // // Find structure detail + // $detail = StickerStructureDetail::find($structureId); - // Find structure detail - $detail = StickerStructureDetail::find($structureId); + // if (!$detail) { + // continue; + // } - if (!$detail) { - continue; - } + // // Check whether this structure belongs to selected sticker + // if ((string) $detail->sticker_id === (string) $stickerId) { - // Check whether this structure belongs to selected sticker - if ((string) $detail->sticker_id === (string) $stickerId) { + // $structure = $detail; - $structure = $detail; + // // Keep the mapping record also + // $stickerMappingMasterItem = $mapping; - // Keep the mapping record also - $stickerMappingMasterItem = $mapping; + // break 2; + // } + // } + // } - break 2; - } - } - } - if (!$structure) { + $checkItem = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->where('sticker_structure1_id', $structure->id)->first(); + + $itemCode = Item::where('id', $pOrderExist->item_id)->value('code'); + + if (!$checkItem) { Notification::make() ->danger() - ->title('Sticker Structure Not Found') - ->body("No sticker structure found for selected sticker ID '{$stickerId}'.") + ->title('Item Not Found') + ->body("Item code '$itemCode' not found in sticker mapping master for selected sticker ID '{$stickerId}'.") ->send(); return; } - $itemCharacteristicId = $stickerMappingMasterItem->item_id; - - $itemCode = Item::where('id', $itemCharacteristicId)->value('code'); - - if (!$itemCharacteristicId) { - - Notification::make() - ->danger() - ->title('Item Characteristic Not Found') - ->body('No item characteristic is configured in sticker mapping.') - ->send(); - return; - } - - $itemCharacteristic1 = ClassCharacteristic::where('plant_id', $plantId)->where('item_id',$itemCharacteristicId)->first(); + $itemCharacteristic1 = ClassCharacteristic::where('plant_id', $plantId)->where('aufnr', $pOrder)->where('item_id', $pOrderExist->item_id)->first(); if (!$itemCharacteristic1) { Notification::make() ->danger() ->title('Item Not Found') - ->body("Item code '{$itemCode}' was not found in class characteristic.") - ->send(); - return; - } - - $itemCharacteristicPodr = ClassCharacteristic::where('plant_id', $plantId)->where('aufnr', $pOrder)->where('item_id', $itemCharacteristicId)->first(); - - if (!$itemCharacteristicPodr) { - - Notification::make() - ->danger() - ->title('Item Not Found') - ->body("Item code '{$itemCode}' with Job Number '{$pOrder}' was not found against plant '{$plantName}'.") - ->send(); - - return; - } - - $itemCodeMis = $pOrderExist->item_id; - - $itemCodeInPOrd = Item::where('id', $itemCodeMis)->where('plant_id', $plantId)->first(); - - $itemCodeInStickerMapping = Item::where('id', $itemCharacteristicId)->where('plant_id', $plantId)->first(); - - if($itemCodeMis != $itemCharacteristicId){ - Notification::make() - ->danger() - ->title('Item Mismatch Found') - ->body("sticker mapping Item code '{$itemCodeInPOrd->code}' and item code '{$itemCodeInStickerMapping->code}' for Job Number '{$pOrder}' was not mapped in sticker mapping against plant '{$plantName}'.") - ->send(); - - return; - } - - $itemCode = Item::where('id', $itemCharacteristicId)->where('plant_id',$plantId)->value('code'); - - if (!$itemCode) { - - Notification::make() - ->danger() - ->title('Item Not Found') - ->body("Item code '{$itemCode}' found in item master.") + ->body("Item code '{$itemCode}' was not found against job number '$pOrder' in class characteristic.") ->send(); return; } @@ -1110,7 +1032,7 @@ class BulkStickerPrinting extends Page implements HasForms } $itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId) - ->where('item_id', $itemCharacteristicId) + ->where('item_id', $checkItem->item_id) ->where('machine_id', $matchedMachineId) ->where('aufnr', $pOrder) ->first(); @@ -1166,30 +1088,7 @@ class BulkStickerPrinting extends Page implements HasForms $totalStickers = ($toSerNo - $fromSerNo) + 1; - $item = Item::where('id', $itemCharacteristicId)->where('plant_id', $plantId)->first(); - - // $updatePrintStatus = StickerOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->where('from_serial_number', $fromSerNo)->where('to_serial_number', $toSerNo)->first(); - - // if (!$updatePrintStatus) { - // StickerOrder::create([ - // 'plant_id' => $plantId, - // 'item_id' => $item->id, - // 'production_order' => $pOrder, - // 'serial_number' => $fromSerNo, - // 'to_serial_number' => $toSerNo, - // 'sticker_id' => $stickerId, - // 'print_status' => 'Printed', - // ]); - - // Notification::make() - // ->success() - // ->title('Sticker Generated') - // ->body("{$totalStickers} sticker(s) generated successfully.") - // ->seconds(3) - // ->send(); - - // return; - // } + $item = Item::where('id', $checkItem->item_id)->where('plant_id', $plantId)->first(); $from = (int) $fromSerNo; $to = (int) $toSerNo;