diff --git a/app/Services/StickerPdfService.php b/app/Services/StickerPdfService.php index 8c974ae..504e158 100644 --- a/app/Services/StickerPdfService.php +++ b/app/Services/StickerPdfService.php @@ -16,22 +16,6 @@ class StickerPdfService public function generate1(string $stickerId, Collection $dynamicElements, ?ItemCharacteristic $itemCharacteristic) { - // $dynamicValueMap = []; - - // foreach ($dynamicElements as $element) { - - // $column = $element->characteristics_type; - - // if ( - // $itemCharacteristic && - // $column && - // Schema::hasColumn('item_characteristics', $column) - // ) { - // $dynamicValueMap[$element->id] = $itemCharacteristic->{$column}; - // } else { - // $dynamicValueMap[$element->id] = ''; - // } - // } $dynamicValueMap = []; foreach ($dynamicElements as $element) { @@ -81,17 +65,17 @@ class StickerPdfService $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // $pdf->setCellPaddings(0, 0, 0, 0); - $pdf->setCellMargins(5, 5, 5, 5); + // $pdf->setCellMargins(5, 5, 5, 5); // Set margins - $pdf->SetMargins(5, 5, 5); // left, top, right + //$pdf->SetMargins(5, 5, 5); // left, top, right $pdf->SetMargins( (float) $structure->sticker_lmargin, (float) $structure->sticker_tmargin, (float) $structure->sticker_rmargin, - (float) $structure->sticker_bmargin, ); + $pdf->SetAutoPageBreak(false, 0); $pdf->AddPage(); @@ -154,19 +138,10 @@ class StickerPdfService { $imageName = strtolower($dynamicValueMap[$row->id]['value']) . '.png'; - $imagePath = storage_path('app/public/' . ltrim($imageName, '/')); - - // $imagePath = storage_path( - // 'app/public/' . $imageName - // ); - - // $imagePath = storage_path( - // 'app/public/images/' . ltrim(strtolower($dynamicValueMap[$row->id]['value'])) . '.png' - // ); - - //dd($imagePath); + $imagePath = public_path('images/' . ltrim($imageName, '/')); } + $pdf->Image( $imagePath, (float) ($row->image_x ?? 0), @@ -174,15 +149,7 @@ class StickerPdfService (float) ($row->image_width ?? 0), (float) ($row->image_height ?? 0) ); - - // $pdf->Image( - // '/home/iot-dev/projects/qds/storage/app/public/images/cri.png', - // 10, 10, 50, 50 - // ); - - break; - case 'Shape': if ($row->shape_name == 'Line') { $pdf->SetLineWidth((float) ($row->shape_pen_size ?? 0.3)); @@ -222,6 +189,41 @@ class StickerPdfService $pdf->Rect($x, $y, $width, $height, 'D'); } + elseif ($row->shape_name == 'CurvedRectangle') { + $pdf->SetLineWidth((float) ($row->shape_pen_size ?? 0.3)); + + if (isset($row->element_colour)) { + $rgb = $this->hexToRgb($row->element_colour); + $pdf->SetDrawColor($rgb[0], $rgb[1], $rgb[2]); + } else { + $pdf->SetDrawColor(0, 0, 0); + } + + $x1 = (float) $row->shape_x1_value; + $y1 = (float) $row->shape_y1_value; + $x2 = (float) $row->shape_x2_value; + $y2 = (float) $row->shape_y2_value; + + $x = min($x1, $x2); + $y = min($y1, $y2); + $width = abs($x2 - $x1); + $height = abs($y2 - $y1); + + // radius in mm + // $radius = 3; + $radius = (float) $row->curve_radius; + + $pdf->RoundedRect( + $x, + $y, + $width, + $height, + $radius, + '1111', // ← round all 4 corners (default) + 'D' + ); + } + break; } } @@ -399,13 +401,32 @@ class StickerPdfService ->header('Content-Disposition', 'inline; filename="sticker.pdf"'); } + // private function hexToRgb($hex) + // { + // $hex = ltrim($hex, '#'); + // return [ + // hexdec(substr($hex, 0, 2)), + // hexdec(substr($hex, 2, 2)), + // hexdec(substr($hex, 4, 2)), + // ]; + // } private function hexToRgb($hex) { + if (!is_string($hex) || ($hex = trim($hex)) === '') { + return [0, 0, 0]; + } $hex = ltrim($hex, '#'); + if (strlen($hex) == 3) { + $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; + } + if (strlen($hex) !== 6 || !ctype_xdigit($hex)) { + return [0, 0, 0]; + } return [ - hexdec(substr($hex, 0, 2)), - hexdec(substr($hex, 2, 2)), - hexdec(substr($hex, 4, 2)), + hexdec(substr($hex, 0, 2)), // integer + hexdec(substr($hex, 2, 2)), // integer + hexdec(substr($hex, 4, 2)) // integer ]; } + }