From 0fa69f33984eb1218f4457371d8b284e0f4fb289 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 23 Dec 2025 11:14:45 +0530 Subject: [PATCH] Added dynamic logic in pdf controller --- app/Http/Controllers/PdfController.php | 63 ++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index d3915b2..8856cdb 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -4,8 +4,10 @@ namespace App\Http\Controllers; use App\Models\GrMaster; use App\Models\Item; +use App\Models\ItemCharacteristic; use App\Models\Plant; use App\Models\ProcessOrder; +use App\Models\StickerDetail; use App\Models\StickerStructureDetail; use App\Models\User; use App\Services\StickerPdfService; @@ -893,25 +895,60 @@ class PdfController extends Controller // } - public function generate(string $stickerId) - { + // public function generate(string $stickerId) + // { + // $stickerId = trim($stickerId); + + // $elements = StickerStructureDetail::where('sticker_id', $stickerId) + // ->first(); + + // $pdfService = new StickerPdfService(); + // return $pdfService->generate($stickerId, $elements->toArray()); + // } + + public function generate(Request $request, $stickerId) + { + $plantId = $request->query('plant_id'); + $itemCharacteristicId = $request->query('item_characteristic_id'); $stickerId = trim($stickerId); - $elements = StickerStructureDetail::where('sticker_id', $stickerId) - ->first(); + if ($plantId && $itemCharacteristicId) + { + $plantId = $request->query('plant_id'); + $itemCharacteristicId = $request->query('item_characteristic_id'); - if (!$elements) { - Notification::make() - ->title('Sticker not found') - ->body("Sticker ID '{$stickerId}' does not exist.") - ->danger() - ->send(); + $sticId = StickerStructureDetail::where('sticker_id', $stickerId)->first(); - return; + $sId = $sticId->id; + + $dynamicElements = StickerDetail::where('sticker_structure_detail_id', $sId) + ->where('element_type', 'Dynamic') + ->get(); + + $itemCharacteristic = null; + + if ($plantId && $itemCharacteristicId) { + $itemCharacteristic = ItemCharacteristic::where('plant_id', $plantId) + ->where('id', $itemCharacteristicId) + ->first(); + } + + $pdfService = new StickerPdfService(); + + return $pdfService->generate1( + $stickerId, + $dynamicElements, + $itemCharacteristic + ); } + else + { + $elements = StickerStructureDetail::where('sticker_id', $stickerId) + ->first(); - $pdfService = new StickerPdfService(); - return $pdfService->generate($stickerId, $elements->toArray()); + $pdfService = new StickerPdfService(); + return $pdfService->generate($stickerId, $elements->toArray()); + } } }