Chnaged logic in sticker order reprint #1258

Merged
jothi merged 1 commits from ranjith-dev into master 2026-10-15 10:37:08 +00:00

View File

@@ -904,9 +904,9 @@ class StickerOrderReprint extends Page implements HasForms
return;
}
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get();
$stickerMappingMasterItem = StickerMappingMaster::where('plant_id', $plantId)->first();
if (!$stickerMappingMasterItems) {
if (!$stickerMappingMasterItem) {
Notification::make()
->danger()
@@ -916,78 +916,37 @@ class StickerOrderReprint extends Page implements HasForms
return;
}
$structure = null;
$stickerMappingMasterItem = null;
foreach ($stickerMappingMasterItems as $mapping) {
$checkItem = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->where('sticker_structure1_id', $structure->id)->first();
// Check sticker_structure1_id to sticker_structure8_id
for ($i = 1; $i <= 8; $i++) {
$itemCode = Item::where('id', $pOrderExist->item_id)->value('code');
$column = "sticker_structure{$i}_id";
$plantCode = Plant::where('id', $plantId)->value('code');
$structureId = $mapping->{$column};
if (empty($structureId)) {
continue;
}
// Find structure detail
$detail = StickerStructureDetail::find($structureId);
if (!$detail) {
continue;
}
// Check whether this structure belongs to selected sticker
if ((string) $detail->sticker_id === (string) $stickerId) {
$structure = $detail;
// Keep the mapping record also
$stickerMappingMasterItem = $mapping;
break 2;
}
}
}
if (!$structure) {
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;
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('Class Characteristic Not Found')
->body("Class characteristic '{$itemCharacteristicId}' was not found.")
->title('Item Not Found')
->body("Item code '{$itemCode}' was not found against job number '$pOrder' in class characteristic.")
->send();
return;
}
$stickerOrderExist = StickerOrder::where('plant_id', $plantId)
->where('item_id',$itemCharacteristicId)
->where('item_id',$pOrderExist->item_id)
->where('sticker_id', $stickerId)
->where('production_order', $pOrder)
->first();
@@ -1002,18 +961,38 @@ class StickerOrderReprint extends Page implements HasForms
return;
}
$itemCode = Item::where('id',$itemCharacteristicId)->where('plant_id',$plantId)->value('code');
$matchedMachineId = null;
if (!$itemCode) {
$matchedMachineId = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->where('sticker_structure1_id', $structure->id)->where('sticker1_machine_id', $machineId)->first();
if (!$matchedMachineId) {
Notification::make()
->danger()
->title('Item Not Found')
->body('No item code found for the selected item characteristic.')
->title('Machine Not Found')
->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in sticker mapping master.")
->send();
return;
}
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
->where('item_id', $checkItem->item_id)
->where('machine_id', $machineId)
->where('aufnr', $pOrder)
->first();
if(!$itemCharacteristic){
Notification::make()
->danger()
->title('Record Not Found')
->body("Record not found in class characteristic against job '$pOrder', item '$itemCode' and plant '$plantCode'.")
->send();
return;
}
$elements = StickerDetail::where('sticker_structure_detail_id',$structure->id)->get();
if ($elements->isEmpty()) {
@@ -1029,30 +1008,30 @@ class StickerOrderReprint extends Page implements HasForms
//..
$matchedMachineId = null;
// $matchedMachineId = null;
for ($i = 1; $i <= 8; $i++) {
// for ($i = 1; $i <= 8; $i++) {
$machineColumn = "sticker{$i}_machine_id";
// $machineColumn = "sticker{$i}_machine_id";
if ((string) $stickerMappingMasterItem->{$machineColumn} == (string) $machineId) {
// if ((string) $stickerMappingMasterItem->{$machineColumn} == (string) $machineId) {
$matchedMachineId = $stickerMappingMasterItem->{$machineColumn};
// $matchedMachineId = $stickerMappingMasterItem->{$machineColumn};
break;
}
}
// break;
// }
// }
if (!$matchedMachineId) {
// if (!$matchedMachineId) {
Notification::make()
->danger()
->title('Machine Not Found')
->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in the selected sticker mapping.")
->send();
// Notification::make()
// ->danger()
// ->title('Machine Not Found')
// ->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in the selected sticker mapping.")
// ->send();
return;
}
// return;
// }
// $updatePrintStatusExist = StickerOrder::where('plant_id', $plantId)->where('sticker_id',$stickerId)->where('production_order', $pOrder)->where('from_serial_number', '<=', $fromSerNo)->where('to_serial_number', '>=', $toSerNo)->first();
@@ -1090,11 +1069,11 @@ class StickerOrderReprint extends Page implements HasForms
return;
}
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
->where('item_id', $itemCharacteristicId)
->where('machine_id', $matchedMachineId)
->where('aufnr', $pOrder)
->first();
// $itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
// ->where('item_id', $itemCharacteristicId)
// ->where('machine_id', $matchedMachineId)
// ->where('aufnr', $pOrder)
// ->first();
// dd($itemCharacteristic);