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