Changed logic for slowness downloading pdf in bulk sticker pdf #1264
@@ -914,7 +914,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Duplicate Sticker')
|
||||
->body("Serial Number '$fromSerNo' or '$toSerNo' already exists in a generated sticker for Production Order '$pOrder' and plant '$plantName'.")
|
||||
->body("Serial Number '$fromSerNo' or '$toSerNo' already exists in a generated sticker '$stickerId' for Production Order '$pOrder' and plant '$plantName'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
@@ -932,51 +932,118 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get();
|
||||
// $stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get();
|
||||
|
||||
if (!$stickerMappingMasterItems) {
|
||||
// if (!$stickerMappingMasterItems) {
|
||||
|
||||
// Notification::make()
|
||||
// ->danger()
|
||||
// ->title('Sticker Mapping Not Found')
|
||||
// ->body("No sticker mapping found for plant ID '{$plantId}'.")
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// foreach ($stickerMappingMasterItems as $mapping) {
|
||||
|
||||
// for ($i = 1; $i <= 8; $i++) {
|
||||
|
||||
// $column = "sticker_structure{$i}_id";
|
||||
|
||||
// $structureId = $mapping->{$column};
|
||||
|
||||
// if (empty($structureId)) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $detail = StickerStructureDetail::find($structureId);
|
||||
|
||||
// if (!$detail) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if ((string) $detail->sticker_id === (string) $stickerId) {
|
||||
|
||||
// $structure = $detail;
|
||||
|
||||
// $stickerMappingMasterItem = $mapping;
|
||||
|
||||
// break 2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//.New Logic
|
||||
|
||||
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get();
|
||||
|
||||
if ($stickerMappingMasterItems->isEmpty()) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Sticker Mapping Not Found')
|
||||
->body("No sticker mapping found for plant ID '{$plantId}'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$structureIds = $stickerMappingMasterItems
|
||||
->flatMap(function ($mapping) {
|
||||
$ids = [];
|
||||
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
$column = "sticker_structure{$i}_id";
|
||||
|
||||
if (!empty($mapping->{$column})) {
|
||||
$ids[] = $mapping->{$column};
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
})
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
$detailsById = StickerStructureDetail::whereIn('id', $structureIds)
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
$structure = null;
|
||||
$stickerMappingMasterItem = null;
|
||||
|
||||
foreach ($stickerMappingMasterItems as $mapping) {
|
||||
|
||||
// Check sticker_structure1_id to sticker_structure8_id
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
|
||||
$column = "sticker_structure{$i}_id";
|
||||
|
||||
$structureId = $mapping->{$column};
|
||||
|
||||
if (empty($structureId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find structure detail
|
||||
$detail = StickerStructureDetail::find($structureId);
|
||||
$detail = $detailsById->get($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()
|
||||
->danger()
|
||||
->title('Sticker Mapping Not Found')
|
||||
->body("No mapping found for sticker ID '{$stickerId}' and plant ID '{$plantId}'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// $checkItem = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->where('sticker_structure1_id', $structure->id)->first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user