szollosil 5 månader sedan
förälder
incheckning
e1f1d42f8a

+ 129 - 121
core/modules/facture/doc/pdf_crabe_new_printinginvoice.modules.php

@@ -31,11 +31,11 @@
  *	\brief      File of class to generate customers invoices from crabe model
  */
 
-require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
 
 
 /**
@@ -43,9 +43,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  */
 class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 {
-	 /**
-	  * @var DoliDb Database handler
-	  */
+	/**
+	 * @var DoliDb Database handler
+	 */
 	public $db;
 
 	/**
@@ -231,12 +231,12 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 	 *  @param		int			$hideref			Do not show ref
 	 *  @return     int         	    			1=OK, 0=KO
 	 */
-	public function write_file($object, $timestamp,  $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
+	public function write_file($object, $timestamp = '',  $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 	{
 		// phpcs:enable
 		global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
 
-		dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
+		dol_syslog("write_file outputlangs->defaultlang=" . (is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
 
 		if (!is_object($outputlangs)) {
 			$outputlangs = $langs;
@@ -275,14 +275,14 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$objphoto = new Product($this->db);
 				$objphoto->fetch($object->lines[$i]->fk_product);
 
-				$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
-				$dir = $conf->product->dir_output.'/'.$pdir;
+				$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product . "/photos/";
+				$dir = $conf->product->dir_output . '/' . $pdir;
 
 				$realpath = '';
 				foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
 					$filename = $obj['photo'];
 					//if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
-					$realpath = $dir.$filename;
+					$realpath = $dir . $filename;
 					break;
 				}
 
@@ -305,11 +305,11 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			// Definition of $dir and $file
 			if ($object->specimen) {
 				$dir = empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity];
-				$file = $dir."/SPECIMEN.pdf";
+				$file = $dir . "/SPECIMEN.pdf";
 			} else {
 				$objectref = dol_sanitizeFileName($object->ref);
-				$dir = (empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity])."/".$objectref;
-				$file = $dir."/".$objectref."_". $timestamp .".pdf";
+				$dir = (empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity]) . "/" . $objectref;
+				$file = $dir . "/" . $objectref . "_" . $timestamp . ".pdf";
 			}
 			if (!file_exists($dir)) {
 				if (dol_mkdir($dir) < 0) {
@@ -321,11 +321,11 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			if (file_exists($dir)) {
 				// Add pdfgeneration hook
 				if (!is_object($hookmanager)) {
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
+					include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
 					$hookmanager = new HookManager($this->db);
 				}
 				$hookmanager->initHooks(array('pdfgeneration'));
-				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
+				$parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
 				global $action;
 				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
 
@@ -360,7 +360,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					if (!empty($conf->mycompany->multidir_output[$object->entity])) {
 						$logodir = $conf->mycompany->multidir_output[$object->entity];
 					}
-					$pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
+					$pagecount = $pdf->setSourceFile($logodir . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
 					$tplidx = $pdf->importPage(1);
 				}
 
@@ -370,9 +370,9 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
 				$pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
-				$pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
+				$pdf->SetCreator("Dolibarr " . DOL_VERSION);
+				$pdf->SetAuthor($mysoc->name . ($user->id > 0 ? ' - ' . $outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
+				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("PdfInvoiceTitle") . " " . $outputlangs->convToOutputCharset($object->thirdparty->name));
 				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
 					$pdf->SetCompression(false);
 				}
@@ -458,13 +458,13 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				} elseif (! empty($conf->global->INVOICE_ADD_SWISS_QR_CODE)) {
 					$qrcodestring = $object->buildSwitzerlandQRString();
 				}
-				
+
 				$tsForQR = time();
-				$sql = "SELECT * FROM " . $this->db->prefix() . "bbus_bbticket WHERE fk_facture = '".$object->id."'";
+				$sql = "SELECT * FROM " . $this->db->prefix() . "bbus_bbticket WHERE fk_facture = '" . $object->id . "'";
 				$res = $this->db->query($sql);
 				$row = pg_fetch_assoc($res);
 
-				$checkSQL = "SELECT * FROM " . $this->db->prefix() . "bbus_bbticketinvoiceprinting WHERE fk_facture = '".$object->id."'";
+				$checkSQL = "SELECT * FROM " . $this->db->prefix() . "bbus_bbticketinvoiceprinting WHERE fk_facture = '" . $object->id . "'";
 				$resCheck = $this->db->query($checkSQL);
 				$rowCheck = pg_fetch_assoc($resCheck);
 
@@ -473,31 +473,30 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 						$this->db->begin();
 						$ticketPrintSQL = "INSERT INTO " . $this->db->prefix() . "bbus_bbticketinvoiceprinting 
 						(fk_user_creat,status,fk_facture,fk_user_api_key,ticket_id,printing_date,printing_date_timestamp,product_id) VALUES 
-						('".$row['fk_user_creat']."', '0', '".$row['fk_facture']."', 'OajW1ZUiqN7P', '".$row['rowid']."', '".date("Y-m-d H:i:s",$tsForQR)."', '".$tsForQR."', '".$row['ticket_id']."');";
-						if ($this->db->query($ticketPrintSQL))	{
+						('" . $row['fk_user_creat'] . "', '0', '" . $row['fk_facture'] . "', 'OajW1ZUiqN7P', '" . $row['rowid'] . "', '" . date("Y-m-d H:i:s", $tsForQR) . "', '" . $tsForQR . "', '" . $row['ticket_id'] . "');";
+						if ($this->db->query($ticketPrintSQL)) {
 							$this->db->commit();
 						} else {
 							$errorMsg = $this->db->lasterror;
 							$this->db->rollback();
 						}
-					}
-					else {
+					} else {
 						$all = pg_fetch_all($res);
 						foreach ($all as $row) {
 							$this->db->begin();
 							$ticketPrintSQL1 = "INSERT INTO " . $this->db->prefix() . "bbus_bbticketinvoiceprinting 
 							(fk_user_creat,status,fk_facture,fk_user_api_key,ticket_id,printing_date,printing_date_timestamp,product_id) VALUES  
-							('".$row['fk_user_creat']."', '0', '".$row['fk_facture']."', 'OajW1ZUiqN7P', '".$row['rowid']."', '".date("Y-m-d H:i:s",$tsForQR)."', '".$tsForQR."', '".$row['ticket_id']."');";
-							if ($this->db->query($ticketPrintSQL1))	{
+							('" . $row['fk_user_creat'] . "', '0', '" . $row['fk_facture'] . "', 'OajW1ZUiqN7P', '" . $row['rowid'] . "', '" . date("Y-m-d H:i:s", $tsForQR) . "', '" . $tsForQR . "', '" . $row['ticket_id'] . "');";
+							if ($this->db->query($ticketPrintSQL1)) {
 								$this->db->commit();
 							} else {
 								$errorMsg = $this->db->lasterror;
 								$this->db->rollback();
-							}	
+							}
 						}
 					}
 				}
-				$qrcodestring = $object->ref.'_'.$timestamp;
+				$qrcodestring = $object->ref . '_' . $timestamp;
 				if ($qrcodestring) {
 					$qrcodecolor = array('25', '25', '25');
 					// set style for QR-code
@@ -517,7 +516,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$parameters = array(
 					'object' => $object,
 					'i' => $i,
-					'pdf' =>& $pdf,
+					'pdf' => &$pdf,
 					'outputlangs' => $outputlangs,
 					'hidedetails' => $hidedetails
 				);
@@ -781,7 +780,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 
 					// Retrieve type from database for backward compatibility with old records
 					if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
-					&& (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
+						&& (!empty($localtax1_rate) || !empty($localtax2_rate))
+					) { // and there is local tax
 						$localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
 						$localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
 						$localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
@@ -805,10 +805,10 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					}
 					$this->tva[$vatrate] += $tvaligne;	// ->tva is abandonned, we use now ->tva_array that is more complete
 					$vatcode = $object->lines[$i]->vat_src_code;
-					if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
-						$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
+					if (empty($this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'])) {
+						$this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] = 0;
 					}
-					$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
+					$this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] + $tvaligne);
 
 					if ($posYAfterImage > $posYAfterDescription) {
 						$nexY = $posYAfterImage;
@@ -817,10 +817,10 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					// Add line
 					if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
 						$pdf->setPage($pageposafter);
-						$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
+						$pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
 						//$pdf->SetDrawColor(190,190,200);
 						$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
-						$pdf->SetLineStyle(array('dash'=>0));
+						$pdf->SetLineStyle(array('dash' => 0));
 					}
 
 					$nexY += 2; // Add space between lines
@@ -871,7 +871,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
 					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 				}
-				dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
+				dol_syslog("bottomlasttab=" . $bottomlasttab . " this->page_hauteur=" . $this->page_hauteur . " heightforinfotot=" . $heightforinfotot . " heightforfreetext=" . $heightforfreetext . " heightforfooter=" . $heightforfooter);
 
 				// Display info area
 				$posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
@@ -896,7 +896,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 
 				// Add pdfgeneration hook
 				$hookmanager->initHooks(array('pdfgeneration'));
-				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
+				$parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
 				global $action;
 				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 				if ($reshook < 0) {
@@ -908,7 +908,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
 				}
 
-				$this->result = array('fullpath'=>$file);
+				$this->result = array('fullpath' => $file);
 
 				return 1; // No error
 			} else {
@@ -966,8 +966,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		$sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
 		$sql .= " re.description, re.fk_facture_source,";
 		$sql .= " f.type, f.datef";
-		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
-		$sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
+		$sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re, " . MAIN_DB_PREFIX . "facture as f";
+		$sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = " . ((int) $object->id);
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$num = $this->db->num_rows($resql);
@@ -1025,9 +1025,9 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
 		$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
 		$sql .= " cp.code";
-		$sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
-		$sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
+		$sql .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf, " . MAIN_DB_PREFIX . "paiement as p";
+		$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as cp ON p.fk_paiement = cp.id";
+		$sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = " . ((int) $object->id);
 		//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
 		$sql .= " ORDER BY p.datep";
 
@@ -1058,7 +1058,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
 				$pdf->MultiCell(20, 3, price($sign * ((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
 				$pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
-				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
+				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
 
 				$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
 				$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
@@ -1158,12 +1158,12 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
 			$pdf->SetFont('', 'B', $default_font_size - 2);
 			$pdf->SetXY($this->marge_gauche, $posy);
-			$titre = $outputlangs->transnoentities("PaymentConditions").':';
+			$titre = $outputlangs->transnoentities("PaymentConditions") . ':';
 			$pdf->MultiCell(43, 4, $titre, 0, 'L');
 
 			$pdf->SetFont('', '', $default_font_size - 2);
 			$pdf->SetXY($posxval, $posy);
-			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
+			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition" . $object->cond_reglement_code) != ('PaymentCondition' . $object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition" . $object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
 			$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
 			$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
 
@@ -1172,12 +1172,15 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 
 		if ($object->type != 2) {
 			// Check a payment mode is defined
-			if (empty($object->mode_reglement_code)
-			&& empty($conf->global->FACTURE_CHQ_NUMBER)
-			&& empty($conf->global->FACTURE_RIB_NUMBER)) {
+			if (
+				empty($object->mode_reglement_code)
+				&& empty($conf->global->FACTURE_CHQ_NUMBER)
+				&& empty($conf->global->FACTURE_RIB_NUMBER)
+			) {
 				$this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
 			} elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
-				|| ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) {
+				|| ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
+			) {
 				// Avoid having any valid PDF with setup that is not complete
 				$outputlangs->load("errors");
 
@@ -1192,26 +1195,28 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			}
 
 			// Show payment mode
-			if (!empty($object->mode_reglement_code)
-			&& $object->mode_reglement_code != 'CHQ'
-			&& $object->mode_reglement_code != 'VIR') {
+			if (
+				!empty($object->mode_reglement_code)
+				&& $object->mode_reglement_code != 'CHQ'
+				&& $object->mode_reglement_code != 'VIR'
+			) {
 				$pdf->SetFont('', 'B', $default_font_size - 2);
 				$pdf->SetXY($this->marge_gauche, $posy);
-				$titre = $outputlangs->transnoentities("PaymentMode").':';
+				$titre = $outputlangs->transnoentities("PaymentMode") . ':';
 				$pdf->MultiCell(80, 5, $titre, 0, 'L');
 
 				$pdf->SetFont('', '', $default_font_size - 2);
 				$pdf->SetXY($posxval, $posy);
-				$lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
+				$lib_mode_reg = $outputlangs->transnoentities("PaymentType" . $object->mode_reglement_code) != ('PaymentType' . $object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType" . $object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
 				$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
 
 				//szisz
 				//$currency_code = !empty($currency_code) ? $currency_code : $conf->currency;
 				$currency_code = $object->multicurrency_code;
 				$pdf->SetFont('', 'B', $default_font_size - 2);
-				$currency = $outputlangs->transnoentities("Currency").': ';
+				$currency = $outputlangs->transnoentities("Currency") . ': ';
 				$pdf->MultiCell(80, 5, $currency, 0, 'L');
-				$pdf->SetXY($posxval, $posy+5);
+				$pdf->SetXY($posxval, $posy + 5);
 				$pdf->SetFont('', '', $default_font_size - 2);
 				$pdf->MultiCell(80, 5, $currency_code, 0, 'L');
 
@@ -1234,13 +1239,13 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				}
 
 				if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
-					require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
+					require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php';
 					global $langs;
 
 					$langs->loadLangs(array('payment', 'paybox', 'stripe'));
 					$servicename = $langs->transnoentities('Online');
 					$paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
-					$linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
+					$linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename) . ' <a href="' . $paiement_url . '">' . $outputlangs->transnoentities("ClickHere") . '</a>';
 
 					$pdf->SetXY($this->marge_gauche, $posy);
 					$pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
@@ -1363,7 +1368,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		// Total HT
 		$pdf->SetFillColor(255, 255, 255);
 		$pdf->SetXY($col1x, $tab2_top + 0);
-		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") : ''), 0, 'L', 1);
+		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") : ''), 0, 'L', 1);
 
 		$total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
 		$pdf->SetXY($col2x, $tab2_top + 0);
@@ -1400,12 +1405,12 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 							$tvacompl = '';
 							if (preg_match('/\*/', $tvakey)) {
 								$tvakey = str_replace('*', '', $tvakey);
-								$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
+								$tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
 							}
 
-							$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
+							$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code) . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
 							$totalvat .= ' ';
-							$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
+							$totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
 							$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
 							$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@@ -1432,11 +1437,11 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 							$tvacompl = '';
 							if (preg_match('/\*/', $tvakey)) {
 								$tvakey = str_replace('*', '', $tvakey);
-								$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
+								$tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
 							}
-							$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
+							$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code) . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
 							$totalvat .= ' ';
-							$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
+							$totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
 							$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
 							$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@@ -1458,16 +1463,16 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 						$tvacompl = '';
 						if (preg_match('/\*/', $tvakey)) {
 							$tvakey = str_replace('*', '', $tvakey);
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
+							$tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
 						}
-						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
+						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code) . (is_object($outputlangsbis) ? ' / ' . $outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
 						$totalvat .= ' ';
 						if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
-							$totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
+							$totalvat .= vatrate($tvaval['vatrate'], 1) . $tvacompl;
 						} elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
-							$totalvat .= $tvaval['vatcode'].$tvacompl;
+							$totalvat .= $tvaval['vatcode'] . $tvacompl;
 						} else {
-							$totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
+							$totalvat .= vatrate($tvaval['vatrate'], 1) . ($tvaval['vatcode'] ? ' (' . $tvaval['vatcode'] . ')' : '') . $tvacompl;
 						}
 						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
@@ -1494,10 +1499,10 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 							$tvacompl = '';
 							if (preg_match('/\*/', $tvakey)) {
 								$tvakey = str_replace('*', '', $tvakey);
-								$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
+								$tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
 							}
-							$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
-							$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
+							$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code) . ' ';
+							$totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
 
 							$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 							$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@@ -1523,11 +1528,11 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 						$tvacompl = '';
 						if (preg_match('/\*/', $tvakey)) {
 							$tvakey = str_replace('*', '', $tvakey);
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
+							$tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
 						}
-						$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
+						$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code) . ' ';
 
-						$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
+						$totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
 						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
 						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@@ -1576,8 +1581,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					$index++;
 					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
 
-					$retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
-					$retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
+					$retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty") . ' (' . $object->retained_warranty . '%)';
+					$retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' ' . $outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
 
 					$pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
 					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@@ -1674,7 +1679,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		$pdf->SetFont('', '', $default_font_size - 2);
 
 		if (empty($hidetop)) {
-			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
+			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency" . $currency));
 			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
 
@@ -1756,20 +1761,21 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		}
 	}
 
-    protected function getEntityDataById($entity_id)
-    {
-        $entitiArray = [];
-        $sql = "SELECT rowid, label FROM llx_entity WHERE rowid = {$entity_id}";
-        $data = $this->db->query($sql);
-        if (!$data) {
-            return $entitiArray;
-        }
-        while ($row = pg_fetch_all($data)) {
-            return $row;
-        }
-    }
-
-	protected function getEntityVAT($entity_id) {
+	protected function getEntityDataById($entity_id)
+	{
+		$entitiArray = [];
+		$sql = "SELECT rowid, label FROM llx_entity WHERE rowid = {$entity_id}";
+		$data = $this->db->query($sql);
+		if (!$data) {
+			return $entitiArray;
+		}
+		while ($row = pg_fetch_all($data)) {
+			return $row;
+		}
+	}
+
+	protected function getEntityVAT($entity_id)
+	{
 		$sql = "SELECT * FROM llx_const WHERE entity = {$entity_id} AND name = 'MAIN_INFO_TVAINTRA';";
 		$details = $this->db->query($sql);
 		if (!$details) {
@@ -1780,7 +1786,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		}
 	}
 
-	protected function getEntityLogo($entity_id) {
+	protected function getEntityLogo($entity_id)
+	{
 		$sql = "SELECT * FROM llx_const WHERE entity = {$entity_id} AND name = 'MAIN_INFO_SOCIETE_LOGO_SMALL';";
 		$details = $this->db->query($sql);
 		if (!$details) {
@@ -1791,7 +1798,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		}
 	}
 
-	protected function getEntityAddress($entity_id) {
+	protected function getEntityAddress($entity_id)
+	{
 		$sql = "SELECT * FROM llx_const WHERE entity = {$entity_id} AND name = 'MAIN_INFO_SOCIETE_ZIP';";
 		$details = $this->db->query($sql);
 		$row = pg_fetch_all($details);
@@ -1807,7 +1815,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		$row = pg_fetch_all($details);
 		$address = $row[0]['value'];
 
-		return $zip.' '.$city.', '.$address;
+		return $zip . ' ' . $city . ', ' . $address;
 	}
 
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
@@ -1856,9 +1864,9 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 					$logodir = $conf->mycompany->multidir_output[$object->entity];
 				}
 				if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
-					$logo = $logodir.'/logos/thumbs/'.$mycompanyLogo[0]['value'];
+					$logo = $logodir . '/logos/thumbs/' . $mycompanyLogo[0]['value'];
 				} else {
-					$logo = $logodir.'/logos/'.$this->emetteur->logo;
+					$logo = $logodir . '/logos/' . $this->emetteur->logo;
 				}
 				if (is_readable($logo)) {
 					$height = pdf_getHeightForLogo($logo);
@@ -1911,10 +1919,10 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$title .= $outputlangsbis->transnoentities("InvoiceProForma");
 			}
 		}
-		$title .= ' '.$outputlangs->convToOutputCharset($object->ref);
+		$title .= ' ' . $outputlangs->convToOutputCharset($object->ref);
 		if ($object->statut == $object::STATUS_DRAFT) {
 			$pdf->SetTextColor(128, 0, 0);
-			$title .= ' - '.$outputlangs->transnoentities("NotValidated");
+			$title .= ' - ' . $outputlangs->transnoentities("NotValidated");
 		}
 
 		$pdf->MultiCell($w, 3, $title, '', 'R');
@@ -1939,7 +1947,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			$posy += 4;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer") . " : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
 		}
 
 		if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
@@ -1948,7 +1956,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$posy += 3;
 				$pdf->SetXY($posx, $posy);
 				$pdf->SetTextColor(0, 0, 60);
-				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
+				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project") . " : " . (empty($object->project->title) ? '' : $object->project->title), '', 'R');
 			}
 		}
 
@@ -1959,7 +1967,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$posy += 3;
 				$pdf->SetXY($posx, $posy);
 				$pdf->SetTextColor(0, 0, 60);
-				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
+				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject") . " : " . (empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
 			}
 		}
 
@@ -1971,7 +1979,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			$posy += 3;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
 		}
 		if ($object->type == 1) {
 			$objectreplaced = new Facture($this->db);
@@ -1980,7 +1988,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			$posy += 4;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
 		}
 		if ($object->type == 2 && !empty($object->fk_facture_source)) {
 			$objectreplaced = new Facture($this->db);
@@ -1989,7 +1997,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			$posy += 3;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
 		}
 
 		$posy += 4;
@@ -1997,15 +2005,15 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 		$pdf->SetTextColor(0, 0, 60);
 		$title = $outputlangs->transnoentities("DateInvoice");
 		if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
-			$title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
+			$title .= ' - ' . $outputlangsbis->transnoentities("DateInvoice");
 		}
-		$pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
+		$pdf->MultiCell($w, 3, $title . " : " . dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
 
 		if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
 			$posy += 4;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax") . " : " . dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
 		}
 
 		if ($object->type != 2) {
@@ -2014,16 +2022,16 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			$pdf->SetTextColor(0, 0, 60);
 			$title = $outputlangs->transnoentities("DateDue");
 			if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
-				$title .= ' - '.$outputlangsbis->transnoentities("DateDue");
+				$title .= ' - ' . $outputlangsbis->transnoentities("DateDue");
 			}
-			$pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
+			$pdf->MultiCell($w, 3, $title . " : " . dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
 		}
 
 		if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
 			$posy += 3;
 			$pdf->SetXY($posx, $posy);
 			$pdf->SetTextColor(0, 0, 60);
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode") . " : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
 		}
 
 		// Get contact
@@ -2035,7 +2043,7 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 				$posy += 4;
 				$pdf->SetXY($posx, $posy);
 				$pdf->SetTextColor(0, 0, 60);
-				$pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
+				$pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative") . " : " . $usertmp->getFullName($langs), '', 'R');
 			}
 		}
 
@@ -2058,8 +2066,8 @@ class pdf_crabe_new_printinginvoice extends ModelePDFFactures
 			//print_r($entityDetails);
 			//die();
 			$entityName = $entityInfo[0]['label'];
-			$carac_emetteur = "\n".$entityAddress;
-			$carac_emetteur .= "\n\nVAT number: ".$entityDetails[0]['value'];
+			$carac_emetteur = "\n" . $entityAddress;
+			$carac_emetteur .= "\n\nVAT number: " . $entityDetails[0]['value'];
 
 			// Show sender
 			$posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;

+ 7 - 3
core/modules/facture/doc/pdf_crabe_receipt.modules.php

@@ -237,7 +237,7 @@ class pdf_crabe_receipt extends ModelePDFFactures
 	 *  @param		int			$hideref			Do not show ref
 	 *  @return     int         	    			1=OK, 0=KO
 	 */
-	public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
+	public function write_file($object, $timestamp = '', $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 	{
 		// phpcs:enable
 		global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
@@ -315,7 +315,7 @@ class pdf_crabe_receipt extends ModelePDFFactures
 			} else {
 				$objectref = dol_sanitizeFileName($object->ref);
 				$dir = (empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity]) . "/" . $objectref;
-				$file = $dir . "/" . $objectref . ".pdf";
+				$file = $dir . "/" . $objectref . "_" . $timestamp . ".pdf";
 			}
 			if (!file_exists($dir)) {
 				if (dol_mkdir($dir) < 0) {
@@ -532,7 +532,11 @@ class pdf_crabe_receipt extends ModelePDFFactures
 						}
 					}
 				}
-				$qrcodestring = $object->ref . '_' . $tsForQR;
+				if($timestamp !== ''){
+					$qrcodestring = $object->ref . '_' . $timestamp;
+				} else {
+					$qrcodestring = $object->ref . '_' . $tsForQR;
+				}
 
 
 				if ($qrcodestring) {

+ 29 - 17
custom/bbus/class/api_bbus.class.php

@@ -115,18 +115,30 @@ class BBus extends DolibarrApi
 		$this->checkUserReadPermission();
 		global $user;
 		$this->code = $code;
-		$this->facture_id = $this->getFactureRowIdByFactureId();
-
-		$sql = "SELECT bt.*, pr.ref as product_ref, pr.label as product_label, btp.printing_date, btp.printing_date_timestamp
-		FROM llx_bbus_bbticketinvoiceprinting as btp
-		INNER JOIN llx_bbus_bbticket AS bt ON bt.rowid = btp.ticket_id
-		INNER JOIN llx_product AS pr ON pr.rowid = bt.ticket_id
-		WHERE btp.fk_facture = {$this->facture_id}
-		  AND btp.printing_date = (
-			SELECT MIN(printing_date)
-			FROM llx_bbus_bbticketinvoiceprinting AS btp2
-			WHERE btp2.fk_facture = {$this->facture_id}
-		)";
+		$facturesList = $this->getFactureRowIdByFactureId();
+		$sql = "SELECT *
+		FROM (
+			SELECT 
+				bt.rowid, bt.entity, bt.fk_facture, bt.invoice_number, bt.available_at, 
+				bt.validated_at, bt.expire_at, bt.bundle_id, bt.ticket_id, bt.booking_history_id, bh.date_start, bh.date_end,evloc_dep.label as departure, evloc_arr.label as arrival,
+				pr_b.ref as bundle_ref, 
+				pr_b.label as bundle_label, 
+				pr.ref as product_ref, 
+				pr.label as product_label, 
+				btp.printing_date,
+				RANK() OVER (PARTITION BY btp.fk_facture ORDER BY btp.printing_date DESC) as rank_date
+			FROM llx_bbus_bbticketinvoiceprinting as btp
+			INNER JOIN llx_bbus_bbticket AS bt ON bt.rowid = btp.ticket_id
+			INNER JOIN llx_product AS pr_b ON pr_b.rowid = bt.bundle_id
+			INNER JOIN llx_product AS pr ON pr.rowid = bt.ticket_id
+			LEFT JOIN llx_booking_bookinghistory as bh ON bh.rowid = bt.booking_history_id
+			LEFT JOIN llx_eventwizard_eventdetails as edt ON edt.rowid = bh.fk_event_detail
+			LEFT JOIN llx_eventwizard_eventlocation as evloc_dep ON evloc_dep.rowid = edt.fk_elventlocation_departure
+			LEFT JOIN llx_eventwizard_eventlocation as evloc_arr ON evloc_arr.rowid = edt.fk_elventlocation_arrival
+			WHERE btp.fk_facture IN ($facturesList)
+		) AS ranked
+		WHERE ranked.rank_date = 1;";
+		//print $sql;exit;
 		$ticketsData = $this->db->query($sql);
 		while ($row = pg_fetch_assoc($ticketsData)) {
 			$now = date("Y-m-d H:i:s");
@@ -137,7 +149,6 @@ class BBus extends DolibarrApi
 				$this->isValid = false;
 			}
 
-			$row['facture_ref'] = $code;
 			$row['isValid'] = $this->isValid;
 			$sub = [];
 			foreach ($row as $key => $value) {
@@ -1008,25 +1019,26 @@ class BBus extends DolibarrApi
 		}
 	}
 
-	private function getFactureRowIdByFactureId()
+	private function getFactureRowIdByFactureId(): string
 	{
 		$facture = new Facture($this->db);
 		$sqlFacture = "SELECT rowid FROM public.llx_facture WHERE ref ILIKE '%{$this->code}%'";
 		$result = $this->db->query($sqlFacture);
 		if (pg_num_rows($result) > 0) {
 			while ($adatok = pg_fetch_assoc($result)) {
-				$factureRowid = $adatok['rowid'];
+				$array[] = $adatok['rowid'];
 			}
 		} else {
 			throw new RestException(404, 'Invoice not found.');
 		}
-		$sql = "SELECT rowid FROM llx_facture WHERE fk_facture_source = {$factureRowid} AND type = 2";
+		$string = implode(',', $array);
+		$sql = "SELECT rowid FROM llx_facture WHERE fk_facture_source IN ({$string}) AND type = 2";
 		$res = $this->db->query($sql);
 		if (pg_num_rows($res) > 0) {
 			throw new RestException(404, 'Invoice has a Credit account.');
 		}
 
-		return $factureRowid;
+		return $string;
 	}
 
 	private function checkResult($result, $tableName)

+ 7 - 3
custom/bbus/views/printview.php

@@ -9,6 +9,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
 require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketinvoiceprinting.class.php';
 require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketnaplo.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/doc/pdf_crabe_new_printinginvoice.modules.php';
+require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/doc/pdf_crabe_receipt.modules.php';
 require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketcounter.class.php';
 
 
@@ -66,6 +67,7 @@ $formcompany = new FormCompany($db);
 $contactstatic = new Contact($db);
 $userstatic = new User($db);
 $PDF_Crabe = new pdf_crabe_new_printinginvoice($db);
+$PDF_Crabe_receipt = new pdf_crabe_receipt($db);
 
 function getBbticketinvoiceprinting($id)
 {
@@ -129,17 +131,19 @@ function createPDFButton($id, $ticket_id)
         $string = '<a href="/custom/bbus/views/printview.php?id=' . $id . '&timestamp=' . $QRCode . '" name="timestamp">' . $langs->trans('GenerateInvoice') . '</a>';
     }
     return $string;
-
 }
 
 if ($timestamp !== '') {
-    $result = $PDF_Crabe->write_file($object, $timestamp, $langs);
+    if ($object->type == 7) {
+        $result = $PDF_Crabe_receipt->write_file($object, $timestamp, $langs);
+    } else {
+        $result = $PDF_Crabe->write_file($object, $timestamp, $langs);
+    }
     if ($result == 1) {
         setEventMessage($langs->trans('InvoiceReady'));
     } else {
         setEventMessage($langs->trans('InvoiceFailed'), 'error');
     }
-
 }
 
 function setColor($status)

+ 3 - 2
custom/booking/class/api_booking.class.php

@@ -1264,6 +1264,7 @@ class BookingApi extends DolibarrApi
 	 */
 	public function localCheckAvailablePlaces($product_id)
 	{
+		ApiBbusLog::appLog("localCheckAvailablePlaces");
 		$date_from = $this->getCutOffTimeDate($product_id);
 		$sql = "SELECT 
 		ac.id, 
@@ -1286,7 +1287,7 @@ class BookingApi extends DolibarrApi
 	private function getCutOffTimeDate($product_id)
 	{
 		$date = date("Y-m-d H:i:s");
-		ApiBbusLog::appLog("{$date}");
+		//ApiBbusLog::appLog("{$date}");
 		$sql = "SELECT cut_off_time_app FROM llx_product_extrafields WHERE fk_object = {$product_id}";
 		if ($result = $this->db->query($sql)) {
 			if ($this->db->num_rows($result) > 0) {
@@ -1297,7 +1298,7 @@ class BookingApi extends DolibarrApi
 				$date = date("Y-m-d H:i:s", $dateTimestamp + $cutOffTime * 60);
 			}
 		}
-		ApiBbusLog::appLog("{$date}");
+		//ApiBbusLog::appLog("{$date}");
 		return $date;
 	}