From c8e457c73cc39b0c86a67b81eab585dfc75609d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 May 2024 22:21:02 +0200 Subject: [PATCH] Debug v20 --- .../expedition/doc/pdf_espadon.modules.php | 4 +- .../expedition/doc/pdf_rouget.modules.php | 6 +- .../stocktransfer/doc/pdf_eagle.modules.php | 177 ++++++++++-------- 3 files changed, 106 insertions(+), 81 deletions(-) diff --git a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php index 73ab8a40034..25d455b4b00 100644 --- a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php @@ -181,7 +181,7 @@ class pdf_espadon extends ModelePdfExpedition foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) { if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { - // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo + // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo if ($obj['photo_vignette']) { $filename = $obj['photo_vignette']; } else { @@ -236,7 +236,7 @@ class pdf_espadon extends ModelePdfExpedition $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks // Set nblines with the new facture lines content after hook - $nblines = count($object->lines); + $nblines = is_array($object->lines) ? count($object->lines) : 0; $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index 80bf13eabf7..20a809ea36a 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -187,7 +187,7 @@ class pdf_rouget extends ModelePdfExpedition $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch")); } - $nblines = count($object->lines); + $nblines = is_array($object->lines) ? count($object->lines) : 0; // Loop on each lines to detect if there is at least one image to show $realpatharray = array(); @@ -269,7 +269,7 @@ class pdf_rouget extends ModelePdfExpedition $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks // Set nblines with the new facture lines content after hook - $nblines = count($object->lines); + $nblines = is_array($object->lines) ? count($object->lines) : 0; $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -824,6 +824,7 @@ class pdf_rouget extends ModelePdfExpedition */ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0) { + // phpcs:enable global $conf; // Force to disable hidetop and hidebottom @@ -903,6 +904,7 @@ class pdf_rouget extends ModelePdfExpedition */ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { + // phpcs:enable global $conf, $langs, $mysoc; $langs->load("orders"); diff --git a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php index 957d9d6c12f..c25ac994df5 100644 --- a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php +++ b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php @@ -98,7 +98,7 @@ class pdf_eagle extends ModelePDFStockTransfer * * @param DoliDB $db Database handler */ - public function __construct($db) + public function __construct(DoliDB $db) { global $langs, $mysoc; @@ -122,7 +122,7 @@ class pdf_eagle extends ModelePDFStockTransfer $this->emetteur = $mysoc; if (!$this->emetteur->country_code) { $this->emetteur->country_code = substr($langs->defaultlang, -2); - } // By default if not defined + } // Define position of columns $this->posxdesc = $this->marge_gauche + 1; @@ -178,7 +178,7 @@ class pdf_eagle extends ModelePDFStockTransfer public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) { // phpcs:enable - global $db, $user, $conf, $langs, $hookmanager; + global $user, $conf, $langs, $hookmanager; $object->fetch_thirdparty(); @@ -195,10 +195,19 @@ class pdf_eagle extends ModelePDFStockTransfer // Load traductions files required by page $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch", "stocks", "stocktransfer@stocktransfer")); + global $outputlangsbis; + $outputlangsbis = null; + if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { + $outputlangsbis = new Translate('', $conf); + $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')); + $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch")); + } + $nblines = is_array($object->lines) ? count($object->lines) : 0; // Loop on each lines to detect if there is at least one image to show $realpatharray = array(); + $this->atleastonephoto = false; if (getDolGlobalString('MAIN_GENERATE_STOCKTRANSFER_WITH_PICTURE')) { $objphoto = new Product($this->db); @@ -232,6 +241,7 @@ class pdf_eagle extends ModelePDFStockTransfer } $realpath = $dir.$filename; + $this->atleastonephoto = true; break; } @@ -290,7 +300,7 @@ class pdf_eagle extends ModelePDFStockTransfer $heightforinfotot = 8; // Height reserved to output the info and total part $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) - if (getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') > 0) { + if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) { $heightforfooter += 6; } $pdf->SetAutoPageBreak(1, 0); @@ -301,7 +311,7 @@ class pdf_eagle extends ModelePDFStockTransfer } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Set path to the background PDF File - if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) { + if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')); $tplidx = $pdf->importPage(1); } @@ -332,14 +342,16 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->useTemplate($tplidx); } $pagenb++; - $this->_pagehead($pdf, $object, 1, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); - $tab_top = 90; - $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10); - $tab_height = 130; + $tab_top = 90; // position of top tab + $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift: 10); + + $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext; + $tab_height_newpage = 150; // Incoterm @@ -347,7 +359,7 @@ class pdf_eagle extends ModelePDFStockTransfer if (isModEnabled('incoterm')) { $desc_incoterms = $object->getIncotermsForPDF(); if ($desc_incoterms) { - $tab_top = 88; + $tab_top -= 2; $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1); @@ -363,17 +375,18 @@ class pdf_eagle extends ModelePDFStockTransfer } } + // Public note and Tracking code if (!empty($object->note_public) || !empty($object->tracking_number)) { - $tab_top = 88 + $height_incoterms + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_STOCKTRANSFER_PDF") ? 20 : 0); $tab_top_alt = $tab_top; - $pdf->SetFont('', 'B', $default_font_size - 2); - //$tab_top_alt += 1; // Tracking number if (!empty($object->tracking_number)) { - $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L'); + $height_trackingnumber = 4; + + $pdf->SetFont('', 'B', $default_font_size - 2); + $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L'); $tab_top_alt = $pdf->GetY(); $object->getUrlTrackingStatus($object->tracking_number); @@ -391,12 +404,13 @@ class pdf_eagle extends ModelePDFStockTransfer $label .= " : "; $label .= $object->tracking_url; } - $pdf->SetFont('', 'B', $default_font_size - 2); - $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L'); - $tab_top_alt = $pdf->GetY(); + $height_trackingnumber += 4; + $pdf->SetFont('', 'B', $default_font_size - 2); + $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L'); } } + $tab_top = $pdf->GetY(); } // Notes @@ -418,9 +432,44 @@ class pdf_eagle extends ModelePDFStockTransfer $height_note = 0; } - $iniY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_STOCKTRANSFER_PDF") ? 9 : 7); - $curY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_STOCKTRANSFER_PDF") ? 9 : 7); - $nexY = $tab_top + (isModEnabled("barcode") && getDolGlobalInt("BARCODE_ON_STOCKTRANSFER_PDF") ? 9 : 7); + // Show barcode + $height_barcode = 0; + //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); + if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_STOCKTRANSFER_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) { + $tab_top -= 2; + + $pdf->Image($barcode_path, $this->marge_gauche, $tab_top, 20, 20); + + $nexY = $pdf->GetY(); + $height_barcode = 20; + + $tab_top += 22; + } else { + $this->error = 'Failed to generate barcode'; + } + } + + $iniY = $tab_top + 7; + $curY = $tab_top + 7; + $nexY = $tab_top + 7; $TCacheEntrepots = array(); // Loop on each lines @@ -442,6 +491,7 @@ class pdf_eagle extends ModelePDFStockTransfer $showpricebeforepagebreak = 1; $posYAfterImage = 0; $posYAfterDescription = 0; + $heightforsignature = 0; // We start with Photo of product line if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page @@ -531,7 +581,7 @@ class pdf_eagle extends ModelePDFStockTransfer } $posYAfterDescription = $pdf->GetY(); - $nexY = $pdf->GetY(); + $nexY = max($pdf->GetY(), $posYAfterImage); $pageposafter = $pdf->getPage(); $pdf->setPage($pageposbefore); @@ -550,7 +600,7 @@ class pdf_eagle extends ModelePDFStockTransfer $curY = $tab_top_newpage; } - $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default + $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font // Lot / série if (isModEnabled('productbatch')) { @@ -558,14 +608,15 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 3, $object->lines[$i]->batch, '', 'C'); } - // Weight + // weight + $pdf->SetXY($this->posxweightvol, $curY); $weighttxt = ''; - if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) { + if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->weight) { $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1); } $voltxt = ''; - if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) { + if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->volume) { $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0, 1); } @@ -639,6 +690,9 @@ class pdf_eagle extends ModelePDFStockTransfer if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { $this->_pagehead($pdf, $object, 0, $outputlangs); } + if (!empty($tplidx)) { + $pdf->useTemplate($tplidx); + } } if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { if ($pagenb == 1) { @@ -658,9 +712,7 @@ class pdf_eagle extends ModelePDFStockTransfer } } } - if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_STOCKTRANSFER_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); @@ -670,10 +722,10 @@ class pdf_eagle extends ModelePDFStockTransfer $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } - // Affiche zone totaux + // Display total area $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs); - // Pied de page + // Pagefoot $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); @@ -714,11 +766,11 @@ class pdf_eagle extends ModelePDFStockTransfer * Show total to pay * * @param TCPDF $pdf Object PDF - * @param StockTransfer $object Object invoice - * @param int $deja_regle Montant deja regle - * @param int $posy Position depart + * @param StockTransfer $object Object StockTransfer + * @param int $deja_regle Amount already paid + * @param int $posy Start Position * @param Translate $outputlangs Object langs - * @return int Position pour suite + * @return int Position for suite */ protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) { @@ -729,7 +781,7 @@ class pdf_eagle extends ModelePDFStockTransfer $tab2_hl = 4; $pdf->SetFont('', 'B', $default_font_size - 1); - // Tableau total + // Total table $col1x = $this->posxqty - 50; $col2x = $this->posxqty; /*if ($this->page_largeur < 210) // To work with US executive format @@ -774,10 +826,10 @@ class pdf_eagle extends ModelePDFStockTransfer if ($totalVolume != '') { $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs); } - if ($object->trueWeight) { + if (!empty($object->trueWeight)) { $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs); } - if ($object->trueVolume) { + if (!empty($object->trueVolume)) { $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs); } @@ -858,6 +910,7 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->SetDrawColor(128, 128, 128); $pdf->SetFont('', '', $default_font_size - 1); + // Description if (empty($hidetop)) { $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); @@ -968,7 +1021,7 @@ class pdf_eagle extends ModelePDFStockTransfer pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK); } - //Prepare la suite + //Prepare next $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); @@ -996,38 +1049,6 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); } - // Show barcode - if (isModEnabled('barcode')) { - $posx = 105; - } else { - $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') && getDolGlobalString('BARCODE_ON_STOCKTRANSFER_PDF')) { - require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/doc/tcpdfbarcode.modules.php'; - - $encoding = 'QRCODE'; - $result = 0; - $barcode_path = ''; - $module = new modTcpdfbarcode(); - 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); $posx = $this->page_largeur - $w - $this->marge_droite; @@ -1089,7 +1110,7 @@ class pdf_eagle extends ModelePDFStockTransfer $origin_id = $object->origin_id; // TODO move to external function - if (!empty($conf->$origin->enabled)) { // commonly $origin='commande' + if (isModEnabled($origin)) { // commonly $origin='commande' $outputlangs->load('orders'); $classname = ucfirst($origin); @@ -1100,7 +1121,7 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->SetFont('', '', $default_font_size - 2); $text = $linkedobject->ref; - if ($linkedobject->ref_client) { + if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) { $text .= ' ('.$linkedobject->ref_client.')'; } $Yoff = $Yoff + 8; @@ -1112,6 +1133,8 @@ class pdf_eagle extends ModelePDFStockTransfer } } + $top_shift = 0; + if ($showaddress) { // Sender properties $carac_emetteur = ''; @@ -1157,7 +1180,7 @@ class pdf_eagle extends ModelePDFStockTransfer $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posx, $posy - 5); - $pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L'); + $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender").":", 0, 'L'); $pdf->SetXY($posx, $posy); $pdf->SetFillColor(230, 230, 230); $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1); @@ -1202,8 +1225,8 @@ class pdf_eagle extends ModelePDFStockTransfer // Show recipient $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100; if ($this->page_largeur < 210) { - $widthrecbox = 84; - } // To work with US executive format + $widthrecbox = 84; // To work with US executive format + } $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42; $posx = $this->page_largeur - $this->marge_droite - $widthrecbox; if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) { @@ -1225,14 +1248,14 @@ class pdf_eagle extends ModelePDFStockTransfer $posy = $pdf->getY(); // Show recipient information - $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY($posx + 2, $posy); + $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); } $pdf->SetTextColor(0, 0, 0); - return 0; + return $top_shift; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore