From 68bc729856a63df224b46f8897b43cb6ea4ec149 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 12 Aug 2026 10:20:46 +0530 Subject: [PATCH] Added logic in for plant name in sticker pdf service --- app/Services/StickerPdfService.php | 90 ++++++++++++++---------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/app/Services/StickerPdfService.php b/app/Services/StickerPdfService.php index 8853c67..70dc76d 100644 --- a/app/Services/StickerPdfService.php +++ b/app/Services/StickerPdfService.php @@ -67,7 +67,7 @@ class StickerPdfService $pdf->AddPage(); - $pdf->SetFont('dejavusans', 'B', 10); + $pdf->SetFont('helvetica', 'B', 10); foreach ($elements as $row) { @@ -794,40 +794,35 @@ class StickerPdfService // ->header('Content-Disposition', 'inline; filename="sticker.pdf"'); } - public function generatePdf1(string $stickerId, Collection $dynamicElements, ?ItemCharacteristic $itemCharacteristic, ?string $serialNumber, $serNo) + public function generatePdf1(string $stickerId, Collection $dynamicElements, ?ItemCharacteristic $itemCharacteristic, $serNo, $itemCode, $plantId) { $dynamicValueMap = []; $itemCode = $itemCharacteristic?->item?->code ?? ''; + $plantName = $itemCharacteristic?->plant?->name ?? ''; + $plantAddress = $itemCharacteristic?->plant?->address ?? ''; + foreach ($dynamicElements as $element) { $column = $element->characteristics_type; $value = ''; - - if ( - $itemCharacteristic && - $column && - Schema::hasColumn('item_characteristics', $column) - ) { + if ($itemCharacteristic && $column && Schema::hasColumn('item_characteristics', $column)) + { $value = $itemCharacteristic->{$column}; } $dynamicValueMap[$element->id] = [ - 'design_type' => $element->design_element_type, // Text / Image + 'design_type' => $element->design_element_type, 'value' => $value, ]; } - $structure = StickerStructureDetail::where('sticker_id', $stickerId) - ->first(); + $structure = StickerStructureDetail::where('sticker_id', $stickerId)->first(); $structureId = $structure->id; - $elements = StickerDetail::where( - 'sticker_structure_detail_id', - $structureId - )->get(); + $elements = StickerDetail::where('sticker_structure_detail_id',$structureId)->get(); $width = (float) $structure->sticker_width; $height = (float) $structure->sticker_height; @@ -847,17 +842,6 @@ class StickerPdfService $pdf->AddPage(); - // if (!empty($serialNumber)) { - // $pdf->SetFont('helvetica', 'B', 10); - // $pdf->SetTextColor(0, 0, 0); - - // // HARD-CODED POSITION (mm) - // $x = 40; // change as needed - // $y = 60; // change as needed - - // $pdf->Text($x, $y, (string) $serialNumber); - // } - $pdf->SetFont('helvetica', 'B', 10); foreach ($elements as $row) { @@ -866,11 +850,20 @@ class StickerPdfService case 'Text': - $pdf->SetFont( - $row->string_font ?? 'helvetica', - '', - (int) ($row->string_size ?? 10) - ); + if (str_contains($row->string_value, '₹')) { + $pdf->SetFont( + 'dejavusans', + '', + (int) ($row->string_size ?? 10) + ); + } else { + + $pdf->SetFont( + $row->string_font ?? 'helvetica', + '', + (int) ($row->string_size ?? 10) + ); + } $pdf->SetTextColor( ...$this->hexToRgb($row->element_colour ?? '#000000') @@ -880,10 +873,22 @@ class StickerPdfService if ( $row->element_type == 'Dynamic' && - isset($dynamicValueMap[$row->id]) + isset($dynamicValueMap[$row->id]) && $row->characteristics_type != 'item_code' && $row->characteristics_type != 'serial_number' ) { $textValue = $dynamicValueMap[$row->id]['value']; } + if ($row->characteristics_type == 'item_code') { + $textValue = $itemCode ?? ''; + } + if ($row->characteristics_type == 'serial_number') { + $textValue = $serNo ?? ''; + } + if ($row->characteristics_type == 'plant_name') { + $textValue = $plantName. ')' ?? ''; + } + if ($row->characteristics_type == 'plant_address') { + $textValue = $plantAddress ?? ''; + } $pdf->Text( (float) ($row->string_x_value ?? 0), @@ -897,7 +902,8 @@ class StickerPdfService if ( ($row->element_type) == 'Dynamic' ) { - $qrContent = $serNo ?? ''; + // $qrContent = $serNo ?? ''; + $qrContent = $itemCode . '|' . $serNo; $pdf->write2DBarcode( $qrContent, 'QRCODE,H', @@ -920,7 +926,6 @@ class StickerPdfService break; } - case 'Image': $imagePath = null; @@ -928,7 +933,7 @@ class StickerPdfService if ( $row->element_type == 'Dynamic' && isset($dynamicValueMap[$row->id]) && - ! empty($dynamicValueMap[$row->id]['value']) + !empty($dynamicValueMap[$row->id]['value']) ) { $imageName = strtolower($dynamicValueMap[$row->id]['value']).'.png'; @@ -1020,20 +1025,9 @@ class StickerPdfService } } - // $pdfContent = $pdf->Output('', 'S'); // 'S' returns string + $pdfContent = $pdf->Output('', 'S'); - // // Encode as base64 - // return base64_encode($pdfContent); - - - // $pdfContent = $pdf->Output('', 'S'); - - // return response($pdfContent) - // ->header('Content-Type', 'application/pdf') - // ->header('Content-Disposition', 'inline; filename="sticker.pdf"'); - $pdfContent = $pdf->Output('', 'S'); // 'S' returns the PDF as a string - - // Return the PDF as a response + // Return the PDF as a response try { $pdfContent = $pdf->Output('', 'S'); // 'S' returns the PDF as a string return response($pdfContent)