From 3978cc12d0419b40b4c6a76dcd3c66453d57416f Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 26 Nov 2026 15:56:24 +0530 Subject: [PATCH] Added wrapping logic in test certificate page --- app/Services/StickerPdfService.php | 95 ++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/app/Services/StickerPdfService.php b/app/Services/StickerPdfService.php index 9649dcf2..69ffdc14 100644 --- a/app/Services/StickerPdfService.php +++ b/app/Services/StickerPdfService.php @@ -1056,6 +1056,7 @@ class StickerPdfService $dynamicValueMap = []; $itemCode = $itemCharacteristic?->item?->code ?? $itemCode ?? ''; + $itemDesc = $itemCharacteristic?->item?->description ?? $itemDesc ?? ''; $plantName = $itemCharacteristic?->plant?->name ?? ''; $plantAddress = $itemCharacteristic?->plant?->address ?? ''; @@ -1101,6 +1102,7 @@ class StickerPdfService if ($row->element_type == 'Dynamic' && isset($dynamicValueMap[$row->id]) && !in_array($row->characteristics_type, [ 'item_code', + 'item_description', 'serial_number', 'plant_name', 'plant_address', @@ -1114,6 +1116,9 @@ class StickerPdfService if ($row->characteristics_type == 'item_code') { $textValue = $itemCode; } + if ($row->characteristics_type == 'item_description') { + $textValue = chunk_split($itemDesc, 24, "\n"); + } if ($row->characteristics_type == 'serial_number') { $textValue = '__SERIAL_NUMBER__'; } @@ -1306,7 +1311,7 @@ class StickerPdfService $cName = Company::where('name', 'ZIRANTEC')->first(); $plantRegdUnit = Plant::where('company_id', $cName->id)->first(); - $textValue = $plantRegdUnit->tollfree; + $textValue = $plantRegdUnit->tollfree ?? ''; } } @@ -1391,6 +1396,8 @@ class StickerPdfService elseif ($row->design_element_type == 'Image') { $imagePath = null; + $xImage = null; + $yImage = null; $signOffTypes = ['tested_by', 'verified_by', 'approved_by']; @@ -1418,15 +1425,65 @@ class StickerPdfService $imageName = strtolower($dynamicValueMap[$row->id]) . '.png'; $imagePath = public_path('images/' . ltrim($imageName, '/')); + + // if($stickerId == 'SelfPriming Monoblock Pump' && $imageName == 'cri.png'){ + // $xImage = 5; + // $yImage = 4; + // } + // else{ + // $xImage = (float) ($row->image_x ?? 0); + // $yImage = (float) ($row->image_y ?? 0); + // } + if ($imageName == 'cri.png') { + + $alignmentRow = $elements->firstWhere( + 'characteristics_type', + 'cri_image_alignment' + ); + + $xImage = (float) ($alignmentRow->image_x ?? $row->image_x ?? 0); + $yImage = (float) ($alignmentRow->image_y ?? $row->image_y ?? 0); + + } else { + + $xImage = (float) ($row->image_x ?? 0); + $yImage = (float) ($row->image_y ?? 0); + } } + $imageWidth = (float) ($row->image_width ?? 0); + $imageHeight = (float) ($row->image_height ?? 0); + + if ( + ($imageWidth <= 0 || $imageHeight <= 0) && + $imagePath && + file_exists($imagePath) + ) { + $imageSize = getimagesize($imagePath); + + if ($imageSize) { + if ($imageWidth <= 0) { + $imageWidth = $imageSize[0] * 25.4 / 200;; + } + + if ($imageHeight <= 0) { + $imageHeight = $imageSize[1] * 25.4 / 200; + } + } + } + + $templateElements[] = [ 'type' => 'image', 'path' => $imagePath, - 'x' => (float) ($row->image_x ?? 0), - 'y' => (float) ($row->image_y ?? 0), - 'width' => (float) ($row->image_width ?? 0), - 'height' => (float) ($row->image_height ?? 0), + // 'x' => (float) ($row->image_x ?? 0), + // 'y' => (float) ($row->image_y ?? 0), + // 'width' => (float) ($row->image_width ?? 0), + // 'height' => (float) ($row->image_height ?? 0), + 'x' => $xImage, + 'y' => $yImage, + 'width' => $imageWidth, + 'height' => $imageHeight, ]; } elseif ($row->design_element_type == 'Shape') { @@ -1746,7 +1803,33 @@ class StickerPdfService } } - $pdf->Text($x, $y, (string) $textValue); + // $pdf->Text($x, $y, (string) $textValue); + if (str_contains((string) $textValue, "\n")) { + + $pdf->SetXY($x, $y); + + $pdf->MultiCell( + $stickerWidth - $x - 2, + 5, + (string) $textValue, + 0, + 'L', + false, + 1, + $x, + $y, + true, + 0, + false, + true, + 0, + 'T', + false + ); + + } else { + $pdf->Text($x, $y, (string) $textValue); + } } elseif ($element['type'] == 'qr') {