Merge pull request 'Added tollfree and feed rule in sticker pdf service and multiple sticker method' (#1289) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s

Reviewed-on: #1289
This commit was merged in pull request #1289.
This commit is contained in:
2026-10-22 11:21:22 +00:00

View File

@@ -1182,13 +1182,45 @@ class StickerPdfService
$textValue = $plantRegdAddress->reg_address;
}
else if($textValue == 'ZIRANTECH'){
$cName = Company::where('name', 'ZIRANTECH')->first();
else if($textValue == 'ZIRANTEC'){
$cName = Company::where('name', 'ZIRANTEC')->first();
$plantRegdAddress = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdAddress->reg_address;
}
}
if ($row->characteristics_type == 'feed_address') {
$column = 'zmm_brand';
$textValue = $itemCharacteristic?->{$column} != null
? $itemCharacteristic->{$column}
: '';
if($textValue == 'TORMAC'){
$cName = Company::where('name', 'TORMAC')->first();
$plantRegdAddress = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdAddress->feed_address;
}
else if($textValue == 'CRI'){
$cName = Company::where('name', 'CRI')->first();
$plantRegdAddress = Plant::where('company_id', $cName->id)->where('id', $plantId)->first();
$textValue = $plantRegdAddress->feed_address;
}
else if($textValue == 'GENVIK'){
$cName = Company::where('name', 'GENVIK')->first();
$plantRegdAddress = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdAddress->feed_address;
}
else if($textValue == 'ZIRANTEC'){
$cName = Company::where('name', 'ZIRANTEC')->first();
$plantRegdAddress = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdAddress->feed_address;
}
}
if ($row->characteristics_type == 'regd_unit') {
$column = 'zmm_brand';
@@ -1245,6 +1277,38 @@ class StickerPdfService
$textValue = $cName->name;
}
}
if ($row->characteristics_type == 'tollfree') {
$column = 'zmm_brand';
$textValue = $itemCharacteristic?->{$column} != null
? $itemCharacteristic->{$column}
: '';
if($textValue == 'TORMAC'){
$cName = Company::where('name', 'TORMAC')->first();
$plantRegdUnit = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdUnit->tollfree;
}
else if($textValue == 'CRI'){
$cName = Company::where('name', 'CRI')->first();
$plantRegdUnit = Plant::where('company_id', $cName->id)->where('id', $plantId)->first();
$textValue = $plantRegdUnit->tollfree;
}
else if($textValue == 'GENVIK'){
$cName = Company::where('name', 'GENVIK')->first();
$plantRegdUnit = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdUnit->tollfree;
}
else if($textValue == 'ZIRANTEC'){
$cName = Company::where('name', 'ZIRANTEC')->first();
$plantRegdUnit = Plant::where('company_id', $cName->id)->first();
$textValue = $plantRegdUnit->tollfree;
}
}
if (str_contains($row->string_value ?? '', '₹')) {
@@ -1261,30 +1325,15 @@ class StickerPdfService
if (!empty($row->string_font)) {
$fontFile = storage_path('app/private/fonts/' . $row->string_font . '.ttf');
Log::info($fontFile, [
'font' => $row->string_font,
]);
if (file_exists($fontFile)) {
\Log::info('TCPDF FONT DEBUG', [
'K_PATH_FONTS' => defined('K_PATH_FONTS') ? K_PATH_FONTS : 'NOT DEFINED',
'fontFile' => $fontFile,
'php_sapi' => PHP_SAPI,
]);
$font = TCPDF_FONTS::addTTFfont(
$fontFile,
'TrueTypeUnicode',
'',
32
);
Log::info('FONT CONVERSION RESULT', [
'result' => $font,
]);
} else {
Log::warning('FONT FILE NOT FOUND', [
'font_file' => $fontFile,
]);
$font = 'helvetica';
}
} else {
@@ -1302,6 +1351,7 @@ class StickerPdfService
'font' => $font,
'size' => (int) ($row->string_size ?? 10),
'color' => $row->element_colour ?? '#000000',
'string_align' => strtolower($row->string_align ?? ''),
];
}
elseif ($row->design_element_type == 'QR') {
@@ -1558,7 +1608,7 @@ class StickerPdfService
// }
public function generateBulkFromTemplate(array $template,$fromSerial,$toSerial,string $itemCode)
public function generateBulkFromTemplate(array $template,$fromSerial,$toSerial,string $itemCode, ?string $randomSerials = null)
{
$stickerWidth = (float) $template['width'];
$stickerHeight = (float) $template['height'];
@@ -1655,11 +1705,42 @@ class StickerPdfService
$rgb[2]
);
$pdf->Text(
$element['x'],
$element['y'] + $currentY,
(string) $textValue
);
// $pdf->Text(
// $element['x'],
// $element['y'] + $currentY,
// (string) $textValue
// );
$alignment = strtolower($element['string_align'] ?? '');
$pdf->SetFont($element['font'], '', $element['size']);
$x = (float) $element['x'];
$y = $element['y'] + $currentY;
// $textWidth = $pdf->GetStringWidth((string) $textValue);
if ($alignment == 'center') {
if($stickerId == 'Sewage PumpSet Test Certificate' || $stickerId == 'Submersible Mixer Test Certificate' || $stickerId == 'Pump Test Certificate' || $stickerId == 'Submersible Aerator Pump Test Certificate'){
$leftMargin = 10; // mm from left edge
$rightMargin = 24; // mm from right edge
$usableWidth = $stickerWidth - $leftMargin - $rightMargin;
$textWidth = $pdf->GetStringWidth((string) $textValue);
// start x = left margin + half of the leftover space
$x = $leftMargin + (($usableWidth - $textWidth) / 2);
// if text is wider than the usable area, don't go past the left margin
if ($textWidth > $usableWidth) {
$x = $leftMargin;
}
}
}
$pdf->Text($x, $y, (string) $textValue);
}
elseif ($element['type'] == 'qr') {
@@ -1962,6 +2043,445 @@ class StickerPdfService
}
}
//..Multiple Serial Numbers
public function generateMultipleBulkFromTemplate(array $template, array $serialNumbersArray,string $itemCode, ?string $randomSerials = null)
{
$stickerWidth = (float) $template['width'];
$stickerHeight = (float) $template['height'];
$stickerId = $template['sticker_id'] ?? null;
// $gap = 5.0;
// $count = ($toSerial - $fromSerial) + 1;
// $totalHeight =
// ($stickerHeight * $count)
// +
// ($gap * ($count - 1));
$orientation = $stickerWidth > $stickerHeight ? 'L' : 'P';
// $pdf = new TCPDF(
// 'P',
// 'mm',
// [
// $stickerWidth,
// $stickerHeight
// ],
// true,
// 'UTF-8',
// false
// );
$pdf = new TCPDF($orientation, 'mm', [$stickerWidth, $stickerHeight], true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins(
0,
0,
0,
0
);
$pdf->SetAutoPageBreak(false, 0);
// $pdf->AddPage();
$currentY = 0;
// Generate every serial
if ($stickerId != 'SelfPriming Monoblock Pump Dual') {
foreach ($serialNumbersArray as $serial) {
$serial = (string) $serial;
$pdf->AddPage();
$qrContent = $itemCode . '|' . $serial;
$serialString = (string) $serial;
$serialDate = '';
if (strlen($serialString) >= 4) {
$year = substr($serialString, 0, 2);
$month = substr($serialString, 2, 2);
if ((int) $month >= 1 && (int) $month <= 12) {
$serialDate = \Carbon\Carbon::createFromFormat(
'y-m',
$year . '-' . $month
)->format('M-y');
}
}
foreach ($template['elements'] as $element) {
if ($element['type'] == 'text') {
$textValue = $element['value'];
if ($textValue == '__SERIAL_NUMBER__') {
$textValue = (string) $serial;
}
if ($textValue == '__CURRENT_DATE__') {
$textValue = $serialDate;
}
$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
// );
$alignment = strtolower($element['string_align'] ?? '');
$pdf->SetFont($element['font'], '', $element['size']);
$x = (float) $element['x'];
$y = $element['y'] + $currentY;
// $textWidth = $pdf->GetStringWidth((string) $textValue);
if ($alignment == 'center') {
if($stickerId == 'Sewage PumpSet Test Certificate' || $stickerId == 'Submersible Mixer Test Certificate' || $stickerId == 'Pump Test Certificate' || $stickerId == 'Submersible Aerator Pump Test Certificate'){
$leftMargin = 10; // mm from left edge
$rightMargin = 24; // mm from right edge
$usableWidth = $stickerWidth - $leftMargin - $rightMargin;
$textWidth = $pdf->GetStringWidth((string) $textValue);
// start x = left margin + half of the leftover space
$x = $leftMargin + (($usableWidth - $textWidth) / 2);
// if text is wider than the usable area, don't go past the left margin
if ($textWidth > $usableWidth) {
$x = $leftMargin;
}
}
}
$pdf->Text($x, $y, (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'
);
}
}
}
// $currentY += $stickerHeight + $gap;
}
return $pdf->Output('', 'S');
}
// if($stickerId == 'SelfPriming Monoblock Pump Dual'){
// foreach ($serialNumbersArray as $serial) {
// $serial = (string) $serial;
// $pdf->AddPage();
// $serialString = (string) $serial;
// $serialDate = '';
// $firstSerial = $serial;
// $secondSerial = $serial + 1;
// $serialString = (string) $firstSerial;
// $serialDate = '';
// if (strlen($serialString) >= 4) {
// $year = substr($serialString, 0, 2);
// $month = substr($serialString, 2, 2);
// if ((int) $month >= 1 && (int) $month <= 12) {
// $serialDate = \Carbon\Carbon::createFromFormat(
// 'y-m',
// $year . '-' . $month
// )->format('M-y');
// }
// }
// 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 = '';
// }
// }
// if ($textValue == '__CURRENT_DATE__') {
// $textValue = $serialDate;
// }
// $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['type'] == 'qr') {
// $qrValue = $element['value'];
// if ($qrValue == '__DYNAMIC_QR__') {
// $qrValue = $itemCode . '|' . $firstSerial;
// }
// elseif ($qrValue == '__DYNAMIC_QR2__') {
// 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['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'
// );
// }
// }
// }
// }
// return $pdf->Output('', 'S');
// }
}
public function generatePdfBySerial($item, $serNo, $plantId, $refNumber)
{
$recFound = ProductionQuantity::where('plant_id', $plantId)