Merge pull request 'Chnaged logic in sticker order reprint' (#1258) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s

Reviewed-on: #1258
This commit was merged in pull request #1258.
This commit is contained in:
2026-10-15 10:37:08 +00:00

View File

@@ -904,9 +904,9 @@ class StickerOrderReprint extends Page implements HasForms
return; return;
} }
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get(); $stickerMappingMasterItem = StickerMappingMaster::where('plant_id', $plantId)->first();
if (!$stickerMappingMasterItems) { if (!$stickerMappingMasterItem) {
Notification::make() Notification::make()
->danger() ->danger()
@@ -916,78 +916,37 @@ class StickerOrderReprint extends Page implements HasForms
return; 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 $itemCode = Item::where('id', $pOrderExist->item_id)->value('code');
for ($i = 1; $i <= 8; $i++) {
$column = "sticker_structure{$i}_id"; $plantCode = Plant::where('id', $plantId)->value('code');
$structureId = $mapping->{$column}; if (!$checkItem) {
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) {
Notification::make() Notification::make()
->danger() ->danger()
->title('Sticker Structure Not Found') ->title('Item Not Found')
->body("No sticker structure found for selected sticker ID '{$stickerId}'.") ->body("Item code '$itemCode' not found in sticker mapping master for selected sticker ID '{$stickerId}'.")
->send(); ->send();
return; return;
} }
$itemCharacteristicId = $stickerMappingMasterItem->item_id; $itemCharacteristic1 = ClassCharacteristic::where('plant_id', $plantId)->where('aufnr', $pOrder)->where('item_id', $pOrderExist->item_id)->first();
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();
if (!$itemCharacteristic1) { if (!$itemCharacteristic1) {
Notification::make() Notification::make()
->danger() ->danger()
->title('Class Characteristic Not Found') ->title('Item Not Found')
->body("Class characteristic '{$itemCharacteristicId}' was not found.") ->body("Item code '{$itemCode}' was not found against job number '$pOrder' in class characteristic.")
->send(); ->send();
return; return;
} }
$stickerOrderExist = StickerOrder::where('plant_id', $plantId) $stickerOrderExist = StickerOrder::where('plant_id', $plantId)
->where('item_id',$itemCharacteristicId) ->where('item_id',$pOrderExist->item_id)
->where('sticker_id', $stickerId) ->where('sticker_id', $stickerId)
->where('production_order', $pOrder) ->where('production_order', $pOrder)
->first(); ->first();
@@ -1002,18 +961,38 @@ class StickerOrderReprint extends Page implements HasForms
return; 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() Notification::make()
->danger() ->danger()
->title('Item Not Found') ->title('Machine Not Found')
->body('No item code found for the selected item characteristic.') ->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in sticker mapping master.")
->send(); ->send();
return; 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(); $elements = StickerDetail::where('sticker_structure_detail_id',$structure->id)->get();
if ($elements->isEmpty()) { 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() // Notification::make()
->danger() // ->danger()
->title('Machine Not Found') // ->title('Machine Not Found')
->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in the selected sticker mapping.") // ->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in the selected sticker mapping.")
->send(); // ->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(); // $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; return;
} }
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId) // $itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
->where('item_id', $itemCharacteristicId) // ->where('item_id', $itemCharacteristicId)
->where('machine_id', $matchedMachineId) // ->where('machine_id', $matchedMachineId)
->where('aufnr', $pOrder) // ->where('aufnr', $pOrder)
->first(); // ->first();
// dd($itemCharacteristic); // dd($itemCharacteristic);