Added multi qr code logic in sticker pdf service
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 21s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Laravel Pint / pint (pull_request) Successful in 3m27s
Laravel Larastan / larastan (pull_request) Failing after 6m46s

This commit is contained in:
dhanabalan
2026-09-28 10:15:02 +05:30
parent 214c065a34
commit 4230fd90f3

View File

@@ -1120,6 +1120,9 @@ class StickerPdfService
if ($row->characteristics_type == 'date_of_test') {
$textValue = $dateOfTest;
}
if ($row->characteristics_type == 'to_serial_number') {
$textValue = 'TO__SERIAL_NUMBER__';
}
// if ($row->characteristics_type == 'zmm_grwt_pump_dual') {
// $column = 'zmm_grwt_pump';
// $textValue = $itemCharacteristic?->{$column} != null
@@ -1204,8 +1207,26 @@ class StickerPdfService
}
elseif ($row->design_element_type == 'QR') {
// if ($row->element_type == 'Dynamic') {
// $qrValue = '__DYNAMIC_QR__';
// }
// if ($row->element_type == 'Dynamic') {
// $qrValue = '__DYNAMIC_QR2__';
// }else {
// $qrValue = $row->qr_value ?? '';
// }
if ($row->element_type == 'Dynamic') {
$qrValue = '__DYNAMIC_QR__';
if ($row->characteristics_type == 'serial_number') {
$qrValue = '__DYNAMIC_QR__';
}
elseif ($row->characteristics_type == 'to_serial_number') {
$qrValue = '__DYNAMIC_QR2__';
}
else {
$qrValue = '__DYNAMIC_QR__';
}
} else {
$qrValue = $row->qr_value ?? '';
}
@@ -1283,6 +1304,7 @@ class StickerPdfService
'tmargin' => (float) $structure->sticker_tmargin,
'rmargin' => (float) $structure->sticker_rmargin,
'bmargin' => (float) $structure->sticker_bmargin,
'sticker_id' => $stickerId,
'itemCode' => $itemCode,
'elements' => $templateElements,
];
@@ -1441,6 +1463,7 @@ class StickerPdfService
{
$stickerWidth = (float) $template['width'];
$stickerHeight = (float) $template['height'];
$stickerId = $template['sticker_id'] ?? null;
// $gap = 5.0;
@@ -1481,135 +1504,315 @@ class StickerPdfService
// Generate every serial
for ($serial = $fromSerial; $serial <= $toSerial; $serial++)
{
$pdf->AddPage();
$qrContent = $itemCode . '|' . $serial;
if ($stickerId != 'SelfPriming Monoblock Pump Dual') {
foreach ($template['elements'] as $element) {
for ($serial = $fromSerial; $serial <= $toSerial; $serial++)
{
$pdf->AddPage();
$qrContent = $itemCode . '|' . $serial;
if ($element['type'] == 'text') {
foreach ($template['elements'] as $element) {
$textValue = $element['value'];
if ($element['type'] == 'text') {
if ($textValue == '__SERIAL_NUMBER__') {
$textValue = (string) $serial;
}
$textValue = $element['value'];
$pdf->SetFont($element['font'],'',$element['size']);
if ($textValue == '__SERIAL_NUMBER__') {
$textValue = (string) $serial;
}
$rgb = $this->hexToRgb($element['color']);
$pdf->SetFont($element['font'],'',$element['size']);
$pdf->SetTextColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
$rgb = $this->hexToRgb($element['color']);
$pdf->Text(
$element['x'],
$element['y'] + $currentY,
(string) $textValue
);
}
elseif ($element['type'] == 'qr') {
$pdf->SetTextColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
$qrValue = $element['value'];
if ($qrValue == '__DYNAMIC_QR__') {
$qrValue = $qrContent;
}
$pdf->write2DBarcode(
$qrValue,
'QRCODE,H',
$element['x'],
$element['y'] + $currentY,
$element['size'],
$element['size']
);
}
elseif ($element['type'] == 'image') {
if (!empty($element['path']) && file_exists($element['path']))
{
$pdf->Image(
$element['path'],
$pdf->Text(
$element['x'],
$element['y'] + $currentY,
$element['width'],
$element['height']
(string) $textValue
);
}
elseif ($element['type'] == 'qr') {
$qrValue = $element['value'];
if ($qrValue == '__DYNAMIC_QR__') {
$qrValue = $qrContent;
}
$pdf->write2DBarcode(
$qrValue,
'QRCODE,H',
$element['x'],
$element['y'] + $currentY,
$element['size'],
$element['size']
);
}
elseif ($element['type'] == 'image') {
if (!empty($element['path']) && file_exists($element['path']))
{
$pdf->Image(
$element['path'],
$element['x'],
$element['y'] + $currentY,
$element['width'],
$element['height']
);
}
}
elseif ($element['type'] == 'shape') {
$rgb = $this->hexToRgb(
$element['color']
);
$pdf->SetDrawColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
$pdf->SetLineWidth(
$element['pen_size']
);
if ($element['name'] == 'Line') {
$pdf->Line(
$element['x1'],
$element['y1'] + $currentY,
$element['x2'],
$element['y2'] + $currentY
);
}
elseif ($element['name'] == 'Rectangle') {
$x = min($element['x1'],$element['x2']);
$y = min($element['y1'],$element['y2']);
$width = abs($element['x2'] - $element['x1']);
$height = abs($element['y2'] - $element['y1']);
$pdf->Rect(
$x,
$y + $currentY,
$width,
$height,
'D'
);
}
elseif ($element['name'] == 'CurvedRectangle')
{
$x = min($element['x1'],$element['x2']);
$y = min($element['y1'],$element['y2']);
$width = abs($element['x2'] - $element['x1']);
$height = abs($element['y2'] - $element['y1']);
$pdf->RoundedRect(
$x,
$y + $currentY,
$width,
$height,
$element['radius'],
'1111',
'D'
);
}
}
}
elseif ($element['type'] == 'shape') {
$rgb = $this->hexToRgb(
$element['color']
);
// $currentY += $stickerHeight + $gap;
}
$pdf->SetDrawColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
return $pdf->Output('', 'S');
}
if($stickerId == 'SelfPriming Monoblock Pump Dual'){
for ($serial = $fromSerial; $serial <= $toSerial; $serial += 2) {
$pdf->SetLineWidth(
$element['pen_size']
);
if ($element['name'] == 'Line') {
$pdf->AddPage();
$pdf->Line(
$element['x1'],
$element['y1'] + $currentY,
$element['x2'],
$element['y2'] + $currentY
$firstSerial = $serial;
$secondSerial = $serial + 1;
foreach ($template['elements'] as $element) {
if ($element['type'] == 'text') {
$textValue = $element['value'];
if ($textValue == '__SERIAL_NUMBER__') {
$textValue = (string) $firstSerial;
}
if ($textValue == 'TO__SERIAL_NUMBER__') {
if ($secondSerial <= $toSerial) {
$textValue = (string) $secondSerial;
} else {
$textValue = '';
}
}
$pdf->SetFont(
$element['font'],
'',
$element['size']
);
$rgb = $this->hexToRgb($element['color']);
$pdf->SetTextColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
$pdf->Text(
$element['x'],
$element['y'] + $currentY,
(string) $textValue
);
}
elseif ($element['name'] == 'Rectangle') {
elseif ($element['type'] == 'qr') {
$x = min($element['x1'],$element['x2']);
$y = min($element['y1'],$element['y2']);
$qrValue = $element['value'];
$width = abs($element['x2'] - $element['x1']);
if ($qrValue == '__DYNAMIC_QR__') {
$height = abs($element['y2'] - $element['y1']);
$qrValue = $itemCode . '|' . $firstSerial;
}
elseif ($qrValue == '__DYNAMIC_QR2__') {
$pdf->Rect(
$x,
$y + $currentY,
$width,
$height,
'D'
);
if ($secondSerial <= $toSerial) {
$qrValue = $itemCode . '|' . $secondSerial;
} else {
$qrValue = '';
}
}
if ($qrValue != '') {
$pdf->write2DBarcode(
$qrValue,
'QRCODE,H',
$element['x'],
$element['y'] + $currentY,
$element['size'],
$element['size']
);
}
}
elseif ($element['name'] == 'CurvedRectangle')
{
$x = min($element['x1'],$element['x2']);
$y = min($element['y1'],$element['y2']);
elseif ($element['type'] == 'image') {
$width = abs($element['x2'] - $element['x1']);
if (
!empty($element['path']) &&
file_exists($element['path'])
) {
$height = abs($element['y2'] - $element['y1']);
$pdf->Image(
$element['path'],
$element['x'],
$element['y'] + $currentY,
$element['width'],
$element['height']
);
}
}
elseif ($element['type'] == 'shape') {
$pdf->RoundedRect(
$x,
$y + $currentY,
$width,
$height,
$element['radius'],
'1111',
'D'
$rgb = $this->hexToRgb($element['color']);
$pdf->SetDrawColor(
$rgb[0],
$rgb[1],
$rgb[2]
);
$pdf->SetLineWidth(
$element['pen_size']
);
if ($element['name'] == 'Line') {
$pdf->Line(
$element['x1'],
$element['y1'] + $currentY,
$element['x2'],
$element['y2'] + $currentY
);
}
elseif ($element['name'] == 'Rectangle') {
$x = min(
$element['x1'],
$element['x2']
);
$y = min(
$element['y1'],
$element['y2']
);
$width = abs(
$element['x2'] - $element['x1']
);
$height = abs(
$element['y2'] - $element['y1']
);
$pdf->Rect(
$x,
$y + $currentY,
$width,
$height,
'D'
);
}
elseif ($element['name'] == 'CurvedRectangle') {
$x = min(
$element['x1'],
$element['x2']
);
$y = min(
$element['y1'],
$element['y2']
);
$width = abs(
$element['x2'] - $element['x1']
);
$height = abs(
$element['y2'] - $element['y1']
);
$pdf->RoundedRect(
$x,
$y + $currentY,
$width,
$height,
$element['radius'],
'1111',
'D'
);
}
}
}
}
// $currentY += $stickerHeight + $gap;
return $pdf->Output('', 'S');
}
return $pdf->Output('', 'S');
}
public function generatePdfBySerial($item, $serNo, $plantId, $refNumber)