Browse Source

Fix restore old more INVOICE_ADD_SWISS_QR_CODE and introduce option
'bottom' for new one that is broken due to php compatibility errors

Laurent Destailleur 2 years ago
parent
commit
17609c5375

+ 7 - 7
htdocs/admin/pdf_other.php

@@ -70,7 +70,7 @@ if ($action == 'update') {
 		dolibarr_del_const($db, "INVOICE_ADD_SWISS_QR_CODE", $conf->entity);
 	}
 	if (GETPOSTISSET('INVOICE_ADD_SWISS_QR_CODE')) {
-		dolibarr_set_const($db, "INVOICE_ADD_SWISS_QR_CODE", GETPOST("INVOICE_ADD_SWISS_QR_CODE", 'int'), 'chaine', 0, '', $conf->entity);
+		dolibarr_set_const($db, "INVOICE_ADD_SWISS_QR_CODE", GETPOST("INVOICE_ADD_SWISS_QR_CODE", 'alpha'), 'chaine', 0, '', $conf->entity);
 		dolibarr_del_const($db, "INVOICE_ADD_ZATCA_QR_CODE", $conf->entity);
 	}
 	if (GETPOSTISSET('INVOICE_CATEGORY_OF_OPERATION')) {
@@ -170,12 +170,12 @@ if (isModEnabled('facture')) {
 	print '<tr class="oddeven"><td>';
 	print $form->textwithpicto($langs->trans("INVOICE_ADD_SWISS_QR_CODE"), $langs->trans("INVOICE_ADD_SWISS_QR_CODEMore"));
 	print '</td><td>';
-	if ($conf->use_javascript_ajax) {
-		print ajax_constantonoff('INVOICE_ADD_SWISS_QR_CODE');
-	} else {
-		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
-		print $form->selectarray("INVOICE_ADD_SWISS_QR_CODE", $arrval, $conf->global->INVOICE_ADD_SWISS_QR_CODE);
-	}
+	//if ($conf->use_javascript_ajax) {
+	//	print ajax_constantonoff('INVOICE_ADD_SWISS_QR_CODE');
+	//} else {
+	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"), 'bottom' => $langs->trans("AtBottomOfPage").' ('.$langs->trans("Experimental").')');
+	print $form->selectarray("INVOICE_ADD_SWISS_QR_CODE", $arrval, $conf->global->INVOICE_ADD_SWISS_QR_CODE);
+	//}
 	print '</td></tr>';
 
 	// Mention category of operations

+ 15 - 7
htdocs/core/modules/facture/doc/pdf_crabe.modules.php

@@ -354,10 +354,13 @@ class pdf_crabe extends ModelePDFFactures
 					$heightforfooter += 6;
 				}
 
-				$heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs);
-				if ($heightforqrinvoice_firstpage > 0) {
-					// Shrink infotot to a base 30
-					$heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
+				$heightforqrinvoice_firstpage = 0;
+				if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
+					$heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs);
+					if ($heightforqrinvoice_firstpage > 0) {
+						// Shrink infotot to a base 30
+						$heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
+					}
 				}
 
 				if (class_exists('TCPDF')) {
@@ -493,7 +496,10 @@ class pdf_crabe extends ModelePDFFactures
 				$qrcodestring = '';
 				if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
 					$qrcodestring = $object->buildZATCAQRString();
+				} elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
+					$qrcodestring = $object->buildSwitzerlandQRString();
 				}
+
 				if ($qrcodestring) {
 					$qrcodecolor = array('25', '25', '25');
 					// set style for QR-code
@@ -601,9 +607,9 @@ class pdf_crabe extends ModelePDFFactures
 					}
 
 					$pdf->setTopMargin($tab_top_newpage);
-					$pageposbefore = $pdf->getPage();
-					$page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pageposbefore, $object, $langs);
+					$page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
 					$pdf->setPageOrientation('', 1, $page_bottom_margin);
+					$pageposbefore = $pdf->getPage();
 
 					$showpricebeforepagebreak = 1;
 					$posYAfterImage = 0;
@@ -900,7 +906,9 @@ class pdf_crabe extends ModelePDFFactures
 					$pdf->AliasNbPages();
 				}
 
-				$this->addSwissQRInvoice($pdf, $object, $outputlangs);
+				if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
+					$this->addBottomQRInvoice($pdf, $object, $outputlangs);
+				}
 				$pdf->Close();
 
 				$pdf->Output($file, 'F');

+ 22 - 14
htdocs/core/modules/facture/doc/pdf_sponge.modules.php

@@ -382,10 +382,14 @@ class pdf_sponge extends ModelePDFFactures
 				$this->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
 				$this->heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
 
-				if ($this->getHeightForQRInvoice(1, $object, $langs) > 0) {
-					// Shrink infotot to a base 30
-					$this->heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
+				$heightforqrinvoice = $heightforqrinvoice_firstpage = 0;
+				if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
+					if ($this->getHeightForQRInvoice(1, $object, $langs) > 0) {
+						// Shrink infotot to a base 30
+						$this->heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
+					}
 				}
+
 				if (class_exists('TCPDF')) {
 					$pdf->setPrintHeader(false);
 					$pdf->setPrintFooter(false);
@@ -502,6 +506,8 @@ class pdf_sponge extends ModelePDFFactures
 				$qrcodestring = '';
 				if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
 					$qrcodestring = $object->buildZATCAQRString();
+				} elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
+					$qrcodestring = $object->buildSwitzerlandQRString();
 				}
 				if ($qrcodestring) {
 					$qrcodecolor = array('25', '25', '25');
@@ -614,7 +620,6 @@ class pdf_sponge extends ModelePDFFactures
 							if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
 								$this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
 							}
-							// $this->_pagefoot($pdf,$object,$outputlangs,1);
 							$pdf->setTopMargin($this->tab_top_newpage);
 							// The only function to edit the bottom margin of current page to set it.
 							$pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
@@ -659,7 +664,7 @@ class pdf_sponge extends ModelePDFFactures
 
 							// Add footer
 							$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
-							$this->_pagefoot($pdf, $object, $outputlangs, 1);
+							$this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
 
 							$i++;
 						}
@@ -730,9 +735,9 @@ class pdf_sponge extends ModelePDFFactures
 					}
 
 					$pdf->setTopMargin($this->tab_top_newpage);
-					$pageposbefore = $pdf->getPage();
-					$page_bottom_margin =  $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pageposbefore, $object, $langs);
+					$page_bottom_margin =  $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
 					$pdf->setPageOrientation('', 1, $page_bottom_margin);
+					$pageposbefore = $pdf->getPage();
 
 					$showpricebeforepagebreak = 1;
 					$posYAfterImage = 0;
@@ -992,7 +997,7 @@ class pdf_sponge extends ModelePDFFactures
 						} else {
 							$this->_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
 						}
-						$this->_pagefoot($pdf, $object, $outputlangs, 1);
+						$this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
 						$pagenb++;
 						$pdf->setPage($pagenb);
 						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
@@ -1011,7 +1016,7 @@ class pdf_sponge extends ModelePDFFactures
 						} else {
 							$this->_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
 						}
-						$this->_pagefoot($pdf, $object, $outputlangs, 1);
+						$this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
 						// New page
 						$pdf->AddPage();
 						if (!empty($tplidx)) {
@@ -1046,12 +1051,14 @@ class pdf_sponge extends ModelePDFFactures
 				}
 
 				// Pagefoot
-				$this->_pagefoot($pdf, $object, $outputlangs);
+				$this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pageposbefore, $object, $langs));
 				if (method_exists($pdf, 'AliasNbPages')) {
 					$pdf->AliasNbPages();
 				}
 
-				$this->addSwissQRInvoice($pdf, $object, $outputlangs);
+				if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
+					$this->addBottomQRInvoice($pdf, $object, $outputlangs);
+				}
 				$pdf->Close();
 
 				$pdf->Output($file, 'F');
@@ -1537,7 +1544,7 @@ class pdf_sponge extends ModelePDFFactures
 
 			foreach ($TPreviousIncoice as &$fac) {
 				if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
-					$this->_pagefoot($pdf, $object, $outputlangs, 1);
+					$this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
 					$pdf->addPage();
 					if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
 						$this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
@@ -2449,12 +2456,13 @@ class pdf_sponge extends ModelePDFFactures
 	 * 		@param	Facture		$object				Object to show
 	 *      @param	Translate	$outputlangs		Object lang for output
 	 *      @param	int			$hidefreetext		1=Hide free text
+	 *      @param	int			$heightforqrinvoice	Height for QR invoices
 	 *      @return	int								Return height of bottom margin including footer text
 	 */
-	protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
+	protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
 	{
 		$showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
-		return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs) + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
+		return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
 	}
 
 	/**

+ 9 - 8
htdocs/core/modules/facture/modules_facture.php

@@ -185,20 +185,21 @@ abstract class ModelePDFFactures extends CommonDocGenerator
 	 */
 	protected function getHeightForQRInvoice(int $pagenbr, \Facture $object, \Translate $langs) : int
 	{
-		global $conf;
-
-		// Keep it, reset it after QRinvoice getter
-		$error = $this->error;
+		if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
+			// Keep it, to reset it after QRinvoice getter
+			$error = $this->error;
 
-		if (!empty($conf->global->INVOICE_ADD_SWISS_QR_CODE)) {
 			if (!$this->getSwissQrBill($object, $langs)) {
 				// Reset error to previous one if exists
-				$this->error = $error;
+				if (!empty($error)) {
+					$this->error = $error;
+				}
 				return 0;
 			}
-			// SWIFT's requirementis 105, but we get more room with 100 and the page nuber is in a nice place.
+			// SWIFT's requirementis 105, but we get more room with 100 and the page number is in a nice place.
 			return $pagenbr == 1 ? 100 : 0;
 		}
+
 		return 0;
 	}
 
@@ -210,7 +211,7 @@ abstract class ModelePDFFactures extends CommonDocGenerator
 	 * @param Translate $langs   Translation object
 	 * @return bool for success
 	 */
-	public function addSwissQRInvoice(\TCPDF $pdf, \Facture $object, \Translate $langs) : bool
+	public function addBottomQRInvoice(\TCPDF $pdf, \Facture $object, \Translate $langs) : bool
 	{
 		if (!($qrBill = $this->getSwissQrBill($object, $langs))) {
 			return false;