Added logic in for plant name in sticker pdf service #887
@@ -67,7 +67,7 @@ class StickerPdfService
|
|||||||
|
|
||||||
$pdf->AddPage();
|
$pdf->AddPage();
|
||||||
|
|
||||||
$pdf->SetFont('dejavusans', 'B', 10);
|
$pdf->SetFont('helvetica', 'B', 10);
|
||||||
|
|
||||||
foreach ($elements as $row) {
|
foreach ($elements as $row) {
|
||||||
|
|
||||||
@@ -794,40 +794,35 @@ class StickerPdfService
|
|||||||
// ->header('Content-Disposition', 'inline; filename="sticker.pdf"');
|
// ->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 = [];
|
$dynamicValueMap = [];
|
||||||
$itemCode = $itemCharacteristic?->item?->code ?? '';
|
$itemCode = $itemCharacteristic?->item?->code ?? '';
|
||||||
|
|
||||||
|
$plantName = $itemCharacteristic?->plant?->name ?? '';
|
||||||
|
$plantAddress = $itemCharacteristic?->plant?->address ?? '';
|
||||||
|
|
||||||
foreach ($dynamicElements as $element) {
|
foreach ($dynamicElements as $element) {
|
||||||
|
|
||||||
$column = $element->characteristics_type;
|
$column = $element->characteristics_type;
|
||||||
|
|
||||||
$value = '';
|
$value = '';
|
||||||
|
if ($itemCharacteristic && $column && Schema::hasColumn('item_characteristics', $column))
|
||||||
if (
|
{
|
||||||
$itemCharacteristic &&
|
|
||||||
$column &&
|
|
||||||
Schema::hasColumn('item_characteristics', $column)
|
|
||||||
) {
|
|
||||||
$value = $itemCharacteristic->{$column};
|
$value = $itemCharacteristic->{$column};
|
||||||
}
|
}
|
||||||
|
|
||||||
$dynamicValueMap[$element->id] = [
|
$dynamicValueMap[$element->id] = [
|
||||||
'design_type' => $element->design_element_type, // Text / Image
|
'design_type' => $element->design_element_type,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$structure = StickerStructureDetail::where('sticker_id', $stickerId)
|
$structure = StickerStructureDetail::where('sticker_id', $stickerId)->first();
|
||||||
->first();
|
|
||||||
|
|
||||||
$structureId = $structure->id;
|
$structureId = $structure->id;
|
||||||
$elements = StickerDetail::where(
|
$elements = StickerDetail::where('sticker_structure_detail_id',$structureId)->get();
|
||||||
'sticker_structure_detail_id',
|
|
||||||
$structureId
|
|
||||||
)->get();
|
|
||||||
|
|
||||||
$width = (float) $structure->sticker_width;
|
$width = (float) $structure->sticker_width;
|
||||||
$height = (float) $structure->sticker_height;
|
$height = (float) $structure->sticker_height;
|
||||||
@@ -847,17 +842,6 @@ class StickerPdfService
|
|||||||
|
|
||||||
$pdf->AddPage();
|
$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);
|
$pdf->SetFont('helvetica', 'B', 10);
|
||||||
|
|
||||||
foreach ($elements as $row) {
|
foreach ($elements as $row) {
|
||||||
@@ -866,11 +850,20 @@ class StickerPdfService
|
|||||||
|
|
||||||
case 'Text':
|
case 'Text':
|
||||||
|
|
||||||
$pdf->SetFont(
|
if (str_contains($row->string_value, '₹')) {
|
||||||
$row->string_font ?? 'helvetica',
|
$pdf->SetFont(
|
||||||
'',
|
'dejavusans',
|
||||||
(int) ($row->string_size ?? 10)
|
'',
|
||||||
);
|
(int) ($row->string_size ?? 10)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$pdf->SetFont(
|
||||||
|
$row->string_font ?? 'helvetica',
|
||||||
|
'',
|
||||||
|
(int) ($row->string_size ?? 10)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$pdf->SetTextColor(
|
$pdf->SetTextColor(
|
||||||
...$this->hexToRgb($row->element_colour ?? '#000000')
|
...$this->hexToRgb($row->element_colour ?? '#000000')
|
||||||
@@ -880,10 +873,22 @@ class StickerPdfService
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
$row->element_type == 'Dynamic' &&
|
$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'];
|
$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(
|
$pdf->Text(
|
||||||
(float) ($row->string_x_value ?? 0),
|
(float) ($row->string_x_value ?? 0),
|
||||||
@@ -897,7 +902,8 @@ class StickerPdfService
|
|||||||
if (
|
if (
|
||||||
($row->element_type) == 'Dynamic'
|
($row->element_type) == 'Dynamic'
|
||||||
) {
|
) {
|
||||||
$qrContent = $serNo ?? '';
|
// $qrContent = $serNo ?? '';
|
||||||
|
$qrContent = $itemCode . '|' . $serNo;
|
||||||
$pdf->write2DBarcode(
|
$pdf->write2DBarcode(
|
||||||
$qrContent,
|
$qrContent,
|
||||||
'QRCODE,H',
|
'QRCODE,H',
|
||||||
@@ -920,7 +926,6 @@ class StickerPdfService
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case 'Image':
|
case 'Image':
|
||||||
|
|
||||||
$imagePath = null;
|
$imagePath = null;
|
||||||
@@ -928,7 +933,7 @@ class StickerPdfService
|
|||||||
if (
|
if (
|
||||||
$row->element_type == 'Dynamic' &&
|
$row->element_type == 'Dynamic' &&
|
||||||
isset($dynamicValueMap[$row->id]) &&
|
isset($dynamicValueMap[$row->id]) &&
|
||||||
! empty($dynamicValueMap[$row->id]['value'])
|
!empty($dynamicValueMap[$row->id]['value'])
|
||||||
) {
|
) {
|
||||||
$imageName = strtolower($dynamicValueMap[$row->id]['value']).'.png';
|
$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 the PDF as a response
|
||||||
// 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
|
|
||||||
try {
|
try {
|
||||||
$pdfContent = $pdf->Output('', 'S'); // 'S' returns the PDF as a string
|
$pdfContent = $pdf->Output('', 'S'); // 'S' returns the PDF as a string
|
||||||
return response($pdfContent)
|
return response($pdfContent)
|
||||||
|
|||||||
Reference in New Issue
Block a user