From 5945fd8c7f0161da612e1c8bb2fbbbeddf81ea0d Mon Sep 17 00:00:00 2001 From: lamrani abdelwadoud Date: Wed, 22 May 2024 20:31:11 +0200 Subject: [PATCH] Fix display Qrcode on reception pdf (#29742) * Fix display Qrcode on reception pdf * Fix run phan --- htdocs/core/class/commonobject.class.php | 2 +- .../reception/doc/pdf_squille.modules.php | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 087668ae982..fe58017f57a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4949,7 +4949,7 @@ abstract class CommonObject * Return into unit=0, the calculated total of weight and volume of all lines * qty * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. * - * @return array{weight:int|float,volume:int|float,ordered:int|float,toship:int|float} array('weight'=>...,'volume'=>...) + * @return array{weight:int|float,volume:int|float,ordered:int|float,toship:int|float}|array{} array('weight'=>...,'volume'=>...) */ public function getTotalWeightVolume() { diff --git a/htdocs/core/modules/reception/doc/pdf_squille.modules.php b/htdocs/core/modules/reception/doc/pdf_squille.modules.php index 275ccce6b4f..712602aac8c 100644 --- a/htdocs/core/modules/reception/doc/pdf_squille.modules.php +++ b/htdocs/core/modules/reception/doc/pdf_squille.modules.php @@ -317,7 +317,7 @@ class pdf_squille extends ModelePdfReception } if (!empty($object->note_public) || !empty($object->tracking_number)) { - $tab_top = 88 + $height_incoterms; + $tab_top = 88 + $height_incoterms + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_RECEPTION_PDF") ? 20 : 0); $tab_top_alt = $tab_top; $pdf->SetFont('', 'B', $default_font_size - 2); @@ -370,9 +370,9 @@ class pdf_squille extends ModelePdfReception $height_note = 0; } - $iniY = $tab_top + 7; - $curY = $tab_top + 7; - $nexY = $tab_top + 7; + $iniY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_SHIPPING_PDF") ? 9 : 7); + $curY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_SHIPPING_PDF") ? 9 : 7); + $nexY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_SHIPPING_PDF") ? 9 : 7); $fk_commandefourndet = 0; $totalOrdered = 0; $totalAmount = 0; @@ -587,7 +587,9 @@ class pdf_squille extends ModelePdfReception $pagenb++; } } - + if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_RECEPTION_PDF')) { + $heightforfooter = $heightforfooter - 5; + } // Show square if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object); @@ -901,10 +903,29 @@ class pdf_squille extends ModelePdfReception $posx = $this->marge_gauche + 3; } //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); - if (isModEnabled('barcode')) { - // TODO Build code bar with function writeBarCode of barcode module for reception ref $object->ref - //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); - //$pdf->Image($logo,10, 5, 0, 24); + if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_RECEPTION_PDF')) { + require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/doc/tcpdfbarcode.modules.php'; + + $encoding = 'QRCODE'; + $module = new modTcpdfbarcode(); + $barcode_path = ''; + $result = 0; + if ($module->encodingIsSupported($encoding)) { + $result = $module->writeBarCode($object->ref, $encoding); + + // get path of qrcode image + $newcode = $object->ref; + if (!preg_match('/^\w+$/', $newcode) || dol_strlen($newcode) > 32) { + $newcode = dol_hash($newcode, 'md5'); + } + $barcode_path = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png'; + } + + if ($result > 0) { + $pdf->Image($barcode_path, $this->marge_gauche, $this->marge_haute +80 -5, 20, 20); + } else { + $this->error = 'Failed to generate barcode'; + } } $pdf->SetDrawColor(128, 128, 128);