From b717ea701f86da67c4faad89e9cc0097ce61bfbe Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 16 Oct 2026 11:54:36 +0530 Subject: [PATCH] Changed logic for slowness downloading pdf in bulk sticker pdf --- app/Filament/Pages/BulkStickerPrinting.php | 95 ++++++++++++++++++---- 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/app/Filament/Pages/BulkStickerPrinting.php b/app/Filament/Pages/BulkStickerPrinting.php index eba1f686..7a5cf437 100644 --- a/app/Filament/Pages/BulkStickerPrinting.php +++ b/app/Filament/Pages/BulkStickerPrinting.php @@ -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(); -- 2.49.1