dolibarr  13.0.2
pdf_azur.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5  * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
11  * Copyright (C) 2019 Pierre Ardoin <mapiolca@me.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  * or see https://www.gnu.org/
26  */
27 
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38 
39 
44 {
48  public $db;
49 
53  public $name;
54 
58  public $description;
59 
63  public $update_main_doc_field;
64 
68  public $type;
69 
74  public $phpmin = array(5, 6);
75 
80  public $version = 'dolibarr';
81 
85  public $page_largeur;
86 
90  public $page_hauteur;
91 
95  public $format;
96 
100  public $marge_gauche;
101 
105  public $marge_droite;
106 
110  public $marge_haute;
111 
115  public $marge_basse;
116 
121  public $emetteur;
122 
123 
129  public function __construct($db)
130  {
131  global $conf, $langs, $mysoc;
132 
133  // Translations
134  $langs->loadLangs(array("main", "bills"));
135 
136  $this->db = $db;
137  $this->name = "azur";
138  $this->description = $langs->trans('DocModelAzurDescription');
139  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
140 
141  // Dimension page
142  $this->type = 'pdf';
143  $formatarray = pdf_getFormat();
144  $this->page_largeur = $formatarray['width'];
145  $this->page_hauteur = $formatarray['height'];
146  $this->format = array($this->page_largeur, $this->page_hauteur);
147  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
148  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
149  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
150  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
151 
152  $this->option_logo = 1; // Display logo
153  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
154  $this->option_modereg = 1; // Display payment mode
155  $this->option_condreg = 1; // Display payment terms
156  $this->option_codeproduitservice = 1; // Display product-service code
157  $this->option_multilang = 1; // Available in several languages
158  $this->option_escompte = 0; // Displays if there has been a discount
159  $this->option_credit_note = 0; // Support credit notes
160  $this->option_freetext = 1; // Support add of a personalised text
161  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
162 
163  // Get source company
164  $this->emetteur = $mysoc;
165  if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
166 
167  // Define position of columns
168  $this->posxdesc = $this->marge_gauche + 1;
169  if (!empty($conf->global->PRODUCT_USE_UNITS))
170  {
171  $this->posxtva = 101;
172  $this->posxup = 118;
173  $this->posxqty = 135;
174  $this->posxunit = 151;
175  } else {
176  $this->posxtva = 106;
177  $this->posxup = 122;
178  $this->posxqty = 145;
179  $this->posxunit = 162;
180  }
181  $this->posxdiscount = 162;
182  $this->postotalht = 174;
183  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva = $this->posxup;
184  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
185  if ($this->page_largeur < 210) // To work with US executive format
186  {
187  $this->posxpicture -= 20;
188  $this->posxtva -= 20;
189  $this->posxup -= 20;
190  $this->posxqty -= 20;
191  $this->posxunit -= 20;
192  $this->posxdiscount -= 20;
193  $this->postotalht -= 20;
194  }
195 
196  $this->tva = array();
197  $this->localtax1 = array();
198  $this->localtax2 = array();
199  $this->atleastoneratenotnull = 0;
200  $this->atleastonediscount = 0;
201  }
202 
203  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
215  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
216  {
217  // phpcs:enable
218  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
219 
220  if (!is_object($outputlangs)) $outputlangs = $langs;
221  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
222  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
223 
224  // Load traductions files required by page
225  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "propal", "products"));
226 
227  $nblines = count($object->lines);
228 
229  // Loop on each lines to detect if there is at least one image to show
230  $realpatharray = array();
231  if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
232  {
233  $objphoto = new Product($this->db);
234 
235  for ($i = 0; $i < $nblines; $i++)
236  {
237  if (empty($object->lines[$i]->fk_product)) continue;
238 
239  $objphoto->fetch($object->lines[$i]->fk_product);
240  //var_dump($objphoto->ref);exit;
241  if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
242  {
243  $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
244  $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
245  } else {
246  $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
247  $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
248  }
249 
250  $arephoto = false;
251  foreach ($pdir as $midir)
252  {
253  if (!$arephoto)
254  {
255  if ($conf->product->entity != $objphoto->entity) {
256  $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
257  } else {
258  $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
259  }
260 
261  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
262  {
263  if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
264  {
265  if ($obj['photo_vignette'])
266  {
267  $filename = $obj['photo_vignette'];
268  } else {
269  $filename = $obj['photo'];
270  }
271  } else {
272  $filename = $obj['photo'];
273  }
274 
275  $realpath = $dir.$filename;
276  $arephoto = true;
277  }
278  }
279  }
280 
281  if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
282  }
283  }
284 
285  if (count($realpatharray) == 0) $this->posxpicture = $this->posxtva;
286 
287  if ($conf->propal->multidir_output[$conf->entity])
288  {
289  $object->fetch_thirdparty();
290 
291  $deja_regle = 0;
292 
293  // Definition of $dir and $file
294  if ($object->specimen)
295  {
296  $dir = $conf->propal->multidir_output[$conf->entity];
297  $file = $dir."/SPECIMEN.pdf";
298  } else {
299  $objectref = dol_sanitizeFileName($object->ref);
300  $dir = $conf->propal->multidir_output[$object->entity]."/".$objectref;
301  $file = $dir."/".$objectref.".pdf";
302  }
303 
304  if (!file_exists($dir))
305  {
306  if (dol_mkdir($dir) < 0)
307  {
308  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
309  return 0;
310  }
311  }
312 
313  if (file_exists($dir))
314  {
315  // Add pdfgeneration hook
316  if (!is_object($hookmanager))
317  {
318  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
319  $hookmanager = new HookManager($this->db);
320  }
321  $hookmanager->initHooks(array('pdfgeneration'));
322  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
323  global $action;
324  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
325 
326  // Create pdf instance
327  $pdf = pdf_getInstance($this->format);
328  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
329  $pdf->SetAutoPageBreak(1, 0);
330 
331  if (class_exists('TCPDF'))
332  {
333  $pdf->setPrintHeader(false);
334  $pdf->setPrintFooter(false);
335  }
336  $pdf->SetFont(pdf_getPDFFont($outputlangs));
337  // Set path to the background PDF File
338  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
339  {
340  $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
341  $tplidx = $pdf->importPage(1);
342  }
343 
344  $pdf->Open();
345  $pagenb = 0;
346  $pdf->SetDrawColor(128, 128, 128);
347 
348  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
349  $pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
350  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
351  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
352  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
353  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
354 
355  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
356 
357  // Positionne $this->atleastonediscount si on a au moins une remise
358  for ($i = 0; $i < $nblines; $i++)
359  {
360  if ($object->lines[$i]->remise_percent)
361  {
362  $this->atleastonediscount++;
363  }
364  }
365  if (empty($this->atleastonediscount))
366  {
367  $delta = ($this->postotalht - $this->posxdiscount);
368  $this->posxpicture += $delta;
369  $this->posxtva += $delta;
370  $this->posxup += $delta;
371  $this->posxqty += $delta;
372  $this->posxunit += $delta;
373  $this->posxdiscount += $delta;
374  // post of fields after are not modified, stay at same position
375  }
376 
377  // New page
378  $pdf->AddPage();
379  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
380  $pagenb++;
381 
382  $heightforinfotot = 40; // Height reserved to output the info and total part
383  $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE) ? (pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature")) + 10) : 0;
384  $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
385  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
386  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
387  //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
388 
389  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
390  $pdf->SetFont('', '', $default_font_size - 1);
391  $pdf->MultiCell(0, 3, ''); // Set interline to 3
392  $pdf->SetTextColor(0, 0, 0);
393 
394 
395  $tab_top = 90 + $top_shift;
396  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
397 
398  // Incoterm
399  if (!empty($conf->incoterm->enabled))
400  {
401  $desc_incoterms = $object->getIncotermsForPDF();
402  if ($desc_incoterms)
403  {
404  $tab_top -= 2;
405 
406  $pdf->SetFont('', '', $default_font_size - 1);
407  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
408  $nexY = $pdf->GetY();
409  $height_incoterms = $nexY - $tab_top;
410 
411  // Rect takes a length in 3rd parameter
412  $pdf->SetDrawColor(192, 192, 192);
413  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
414 
415  $tab_top = $nexY + 6;
416  }
417  }
418 
419  // Affiche notes
420  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
421  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
422  {
423  // Get first sale rep
424  if (is_object($object->thirdparty))
425  {
426  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
427  $salerepobj = new User($this->db);
428  $salerepobj->fetch($salereparray[0]['id']);
429  if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
430  }
431  }
432  // Extrafields in note
433  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
434  if (!empty($extranote)) {
435  $notetoshow = dol_concatdesc($notetoshow, $extranote);
436  }
437  if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0)
438  {
439  $tmpuser = new User($this->db);
440  $tmpuser->fetch($object->user_author_id);
441  $notetoshow .= $langs->trans("CaseFollowedBy").' '.$tmpuser->getFullName($langs);
442  if ($tmpuser->email) $notetoshow .= ', Mail: '.$tmpuser->email;
443  if ($tmpuser->office_phone) $notetoshow .= ', Tel: '.$tmpuser->office_phone;
444  }
445  if ($notetoshow)
446  {
447  $tab_top -= 2;
448 
449  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
450  complete_substitutions_array($substitutionarray, $outputlangs, $object);
451  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
452  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
453 
454  $pdf->SetFont('', '', $default_font_size - 1);
455  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
456  $nexY = $pdf->GetY();
457  $height_note = $nexY - $tab_top;
458 
459  // Rect takes a length in 3rd parameter
460  $pdf->SetDrawColor(192, 192, 192);
461  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
462 
463  $tab_top = $nexY + 6;
464  }
465 
466  $iniY = $tab_top + 7;
467  $curY = $tab_top + 7;
468  $nexY = $tab_top + 7;
469 
470  // Loop on each lines
471  for ($i = 0; $i < $nblines; $i++)
472  {
473  $curY = $nexY;
474  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
475  $pdf->SetTextColor(0, 0, 0);
476 
477  // Define size of image if we need it
478  $imglinesize = array();
479  if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
480 
481  $pdf->setTopMargin($tab_top_newpage);
482  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
483  $pageposbefore = $pdf->getPage();
484 
485  $showpricebeforepagebreak = 1;
486  $posYAfterImage = 0;
487  $posYAfterDescription = 0;
488 
489  // We start with Photo of product line
490  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) // If photo too high, we moved completely on new page
491  {
492  $pdf->AddPage('', '', true);
493  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
494  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
495  $pdf->setPage($pageposbefore + 1);
496 
497  $curY = $tab_top_newpage;
498 
499  // Allows data in the first page if description is long enough to break in multiples pages
500  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
501  $showpricebeforepagebreak = 1;
502  else $showpricebeforepagebreak = 0;
503  }
504 
505  if (isset($imglinesize['width']) && isset($imglinesize['height']))
506  {
507  $curX = $this->posxpicture - 1;
508  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
509  // $pdf->Image does not increase value return by getY, so we save it manually
510  $posYAfterImage = $curY + $imglinesize['height'];
511  }
512 
513  // Description of product line
514  $curX = $this->posxdesc - 1;
515 
516  $pdf->startTransaction();
517  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
518  $pageposafter = $pdf->getPage();
519  if ($pageposafter > $pageposbefore) // There is a pagebreak
520  {
521  $pdf->rollbackTransaction(true);
522  $pageposafter = $pageposbefore;
523  //print $pageposafter.'-'.$pageposbefore;exit;
524  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
525  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
526 
527  $pageposafter = $pdf->getPage();
528  $posyafter = $pdf->GetY();
529  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
530  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) // There is no space left for total+free text
531  {
532  if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
533  {
534  $pdf->AddPage('', '', true);
535  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
536  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
537  $pdf->setPage($pageposafter + 1);
538  }
539  } else {
540  // We found a page break
541 
542  // Allows data in the first page if description is long enough to break in multiples pages
543  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
544  $showpricebeforepagebreak = 1;
545  else $showpricebeforepagebreak = 0;
546  }
547  } else // No pagebreak
548  {
549  $pdf->commitTransaction();
550  }
551  $posYAfterDescription = $pdf->GetY();
552 
553  $nexY = $pdf->GetY();
554  $pageposafter = $pdf->getPage();
555 
556  $pdf->setPage($pageposbefore);
557  $pdf->setTopMargin($this->marge_haute);
558  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
559 
560  // We suppose that a too long description or photo were moved completely on next page
561  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
562  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
563  }
564 
565  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
566 
567  // VAT Rate
568  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
569  {
570  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
571  $pdf->SetXY($this->posxtva - 5, $curY);
572  $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
573  }
574 
575  // Unit price before discount
576  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
577  $pdf->SetXY($this->posxup, $curY);
578  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
579 
580  // Quantity
581  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
582  $pdf->SetXY($this->posxqty, $curY);
583  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
584 
585  // Unit
586  if (!empty($conf->global->PRODUCT_USE_UNITS))
587  {
588  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
589  $pdf->SetXY($this->posxunit, $curY);
590  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
591  }
592 
593  // Discount on line
594  $pdf->SetXY($this->posxdiscount, $curY);
595  if ($object->lines[$i]->remise_percent)
596  {
597  $pdf->SetXY($this->posxdiscount - 2, $curY);
598  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
599  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
600  }
601 
602  // Total HT line
603  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
604  $pdf->SetXY($this->postotalht, $curY);
605  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
606 
607  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
608  if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva;
609  else $tvaligne = $object->lines[$i]->total_tva;
610 
611  $localtax1ligne = $object->lines[$i]->total_localtax1;
612  $localtax2ligne = $object->lines[$i]->total_localtax2;
613  $localtax1_rate = $object->lines[$i]->localtax1_tx;
614  $localtax2_rate = $object->lines[$i]->localtax2_tx;
615  $localtax1_type = $object->lines[$i]->localtax1_type;
616  $localtax2_type = $object->lines[$i]->localtax2_type;
617 
618  if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
619  if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
620  if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
621 
622  $vatrate = (string) $object->lines[$i]->tva_tx;
623 
624  // Retrieve type from database for backward compatibility with old records
625  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
626  && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
627  {
628  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
629  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
630  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
631  }
632 
633  // retrieve global local tax
634  if ($localtax1_type && $localtax1ligne != 0)
635  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
636  if ($localtax2_type && $localtax2ligne != 0)
637  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
638 
639  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
640  if (!isset($this->tva[$vatrate])) $this->tva[$vatrate] = 0;
641  $this->tva[$vatrate] += $tvaligne;
642 
643  if ($posYAfterImage > $posYAfterDescription) $nexY = $posYAfterImage;
644 
645  // Add line
646  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
647  {
648  $pdf->setPage($pageposafter);
649  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
650  //$pdf->SetDrawColor(190,190,200);
651  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
652  $pdf->SetLineStyle(array('dash'=>0));
653  }
654 
655  $nexY += 2; // Add space between lines
656 
657  // Detect if some page were added automatically and output _tableau for past pages
658  while ($pagenb < $pageposafter)
659  {
660  $pdf->setPage($pagenb);
661  if ($pagenb == 1)
662  {
663  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
664  } else {
665  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
666  }
667  $this->_pagefoot($pdf, $object, $outputlangs, 1);
668  $pagenb++;
669  $pdf->setPage($pagenb);
670  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
671  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
672  }
673  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
674  {
675  if ($pagenb == 1)
676  {
677  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
678  } else {
679  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
680  }
681  $this->_pagefoot($pdf, $object, $outputlangs, 1);
682  // New page
683  $pdf->AddPage();
684  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
685  $pagenb++;
686  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
687  }
688  }
689 
690  // Show square
691  if ($pagenb == 1)
692  {
693  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
694  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
695  } else {
696  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
697  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
698  }
699 
700  // Affiche zone infos
701  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
702 
703  // Affiche zone totaux
704  $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
705 
706  // Affiche zone versements
707  /*
708  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
709  {
710  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
711  }
712  */
713 
714  // Customer signature area
715  if (empty($conf->global->PROPAL_DISABLE_SIGNATURE))
716  {
717  $posy = $this->_signature_area($pdf, $object, $posy, $outputlangs);
718  }
719 
720  // Pied de page
721  $this->_pagefoot($pdf, $object, $outputlangs);
722  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
723 
724  //If propal merge product PDF is active
725  if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL))
726  {
727  require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
728 
729  $already_merged = array();
730  foreach ($object->lines as $line) {
731  if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
732  // Find the desire PDF
733  $filetomerge = new Propalmergepdfproduct($this->db);
734 
735  if ($conf->global->MAIN_MULTILANGS) {
736  $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
737  } else {
738  $filetomerge->fetch_by_product($line->fk_product);
739  }
740 
741  $already_merged[] = $line->fk_product;
742 
743  $product = new Product($this->db);
744  $product->fetch($line->fk_product);
745 
746  if ($product->entity != $conf->entity) {
747  $entity_product_file = $product->entity;
748  } else {
749  $entity_product_file = $conf->entity;
750  }
751 
752  // If PDF is selected and file is not empty
753  if (count($filetomerge->lines) > 0) {
754  foreach ($filetomerge->lines as $linefile) {
755  if (!empty($linefile->id) && !empty($linefile->file_name)) {
756  if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
757  {
758  if (!empty($conf->product->enabled)) {
759  $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
760  } elseif (!empty($conf->service->enabled)) {
761  $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
762  }
763  } else {
764  if (!empty($conf->product->enabled)) {
765  $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
766  } elseif (!empty($conf->service->enabled)) {
767  $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product').dol_sanitizeFileName($product->ref);
768  }
769  }
770 
771  dol_syslog(get_class($this).':: upload_dir='.$filetomerge_dir, LOG_DEBUG);
772 
773  $infile = $filetomerge_dir.'/'.$linefile->file_name;
774  if (file_exists($infile) && is_readable($infile)) {
775  $pagecount = $pdf->setSourceFile($infile);
776  for ($i = 1; $i <= $pagecount; $i++) {
777  $tplIdx = $pdf->importPage($i);
778  if ($tplIdx !== false) {
779  $s = $pdf->getTemplatesize($tplIdx);
780  $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
781  $pdf->useTemplate($tplIdx);
782  } else {
783  setEventMessages(null, array($infile.' cannot be added, probably protected PDF'), 'warnings');
784  }
785  }
786  }
787  }
788  }
789  }
790  }
791  }
792  }
793 
794  $pdf->Close();
795 
796  $pdf->Output($file, 'F');
797 
798  //Add pdfgeneration hook
799  $hookmanager->initHooks(array('pdfgeneration'));
800  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
801  global $action;
802  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
803  if ($reshook < 0)
804  {
805  $this->error = $hookmanager->error;
806  $this->errors = $hookmanager->errors;
807  }
808 
809  if (!empty($conf->global->MAIN_UMASK))
810  @chmod($file, octdec($conf->global->MAIN_UMASK));
811 
812  $this->result = array('fullpath'=>$file);
813 
814  return 1; // No error
815  } else {
816  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
817  return 0;
818  }
819  } else {
820  $this->error = $langs->trans("ErrorConstantNotDefined", "PROP_OUTPUTDIR");
821  return 0;
822  }
823  }
824 
825  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
826  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
836  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
837  {
838  // phpcs:enable
839  }
840 
841  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
842  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
852  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
853  {
854  // phpcs:enable
855  global $conf, $mysoc;
856  $default_font_size = pdf_getPDFFontSize($outputlangs);
857 
858  $pdf->SetFont('', '', $default_font_size - 1);
859 
860  // If France, show VAT mention if not applicable
861  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj))
862  {
863  $pdf->SetFont('', 'B', $default_font_size - 2);
864  $pdf->SetXY($this->marge_gauche, $posy);
865  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
866 
867  $posy = $pdf->GetY() + 4;
868  }
869 
870  $posxval = 52;
871 
872  // Show shipping date
873  if (!empty($object->delivery_date))
874  {
875  $outputlangs->load("sendings");
876  $pdf->SetFont('', 'B', $default_font_size - 2);
877  $pdf->SetXY($this->marge_gauche, $posy);
878  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
879  $pdf->MultiCell(80, 4, $titre, 0, 'L');
880  $pdf->SetFont('', '', $default_font_size - 2);
881  $pdf->SetXY($posxval, $posy);
882  $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
883  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
884 
885  $posy = $pdf->GetY() + 1;
886  } elseif ($object->availability_code || $object->availability) // Show availability conditions
887  {
888  $pdf->SetFont('', 'B', $default_font_size - 2);
889  $pdf->SetXY($this->marge_gauche, $posy);
890  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
891  $pdf->MultiCell(80, 4, $titre, 0, 'L');
892  $pdf->SetTextColor(0, 0, 0);
893  $pdf->SetFont('', '', $default_font_size - 2);
894  $pdf->SetXY($posxval, $posy);
895  $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
896  $lib_availability = str_replace('\n', "\n", $lib_availability);
897  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
898 
899  $posy = $pdf->GetY() + 1;
900  }
901 
902  // Show payments conditions
903  if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTTERM) && ($object->cond_reglement_code || $object->cond_reglement))
904  {
905  $pdf->SetFont('', 'B', $default_font_size - 2);
906  $pdf->SetXY($this->marge_gauche, $posy);
907  $titre = $outputlangs->transnoentities("PaymentConditions").':';
908  $pdf->MultiCell(43, 4, $titre, 0, 'L');
909 
910  $pdf->SetFont('', '', $default_font_size - 2);
911  $pdf->SetXY($posxval, $posy);
912  $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);
913  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
914  $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
915 
916  $posy = $pdf->GetY() + 3;
917  }
918 
919  if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTMODE))
920  {
921  // Check a payment mode is defined
922  /* Not required on a proposal
923  if (empty($object->mode_reglement_code)
924  && ! $conf->global->FACTURE_CHQ_NUMBER
925  && ! $conf->global->FACTURE_RIB_NUMBER)
926  {
927  $pdf->SetXY($this->marge_gauche, $posy);
928  $pdf->SetTextColor(200,0,0);
929  $pdf->SetFont('','B', $default_font_size - 2);
930  $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
931  $pdf->SetTextColor(0,0,0);
932 
933  $posy=$pdf->GetY()+1;
934  }
935  */
936 
937  // Show payment mode
938  if ($object->mode_reglement_code
939  && $object->mode_reglement_code != 'CHQ'
940  && $object->mode_reglement_code != 'VIR')
941  {
942  $pdf->SetFont('', 'B', $default_font_size - 2);
943  $pdf->SetXY($this->marge_gauche, $posy);
944  $titre = $outputlangs->transnoentities("PaymentMode").':';
945  $pdf->MultiCell(80, 5, $titre, 0, 'L');
946  $pdf->SetFont('', '', $default_font_size - 2);
947  $pdf->SetXY($posxval, $posy);
948  $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);
949  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
950 
951  $posy = $pdf->GetY() + 2;
952  }
953 
954  // Show payment mode CHQ
955  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
956  {
957  // Si mode reglement non force ou si force a CHQ
958  if (!empty($conf->global->FACTURE_CHQ_NUMBER))
959  {
960  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
961 
962  if ($conf->global->FACTURE_CHQ_NUMBER > 0)
963  {
964  $account = new Account($this->db);
965  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
966 
967  $pdf->SetXY($this->marge_gauche, $posy);
968  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
969  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
970  $posy = $pdf->GetY() + 1;
971 
972  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
973  {
974  $pdf->SetXY($this->marge_gauche, $posy);
975  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
976  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
977  $posy = $pdf->GetY() + 2;
978  }
979  }
980  if ($conf->global->FACTURE_CHQ_NUMBER == -1)
981  {
982  $pdf->SetXY($this->marge_gauche, $posy);
983  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
984  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
985  $posy = $pdf->GetY() + 1;
986 
987  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
988  {
989  $pdf->SetXY($this->marge_gauche, $posy);
990  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
991  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
992  $posy = $pdf->GetY() + 2;
993  }
994  }
995  }
996  }
997 
998  // If payment mode not forced or forced to VIR, show payment with BAN
999  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1000  {
1001  if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER))
1002  {
1003  $bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1004  if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1005  $account = new Account($this->db);
1006  $account->fetch($bankid);
1007 
1008  $curx = $this->marge_gauche;
1009  $cury = $posy;
1010 
1011  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1012 
1013  $posy += 2;
1014  }
1015  }
1016  }
1017 
1018  return $posy;
1019  }
1020 
1021  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1022  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1033  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1034  {
1035  // phpcs:enable
1036  global $conf, $mysoc;
1037  $default_font_size = pdf_getPDFFontSize($outputlangs);
1038 
1039  $tab2_top = $posy;
1040  $tab2_hl = 4;
1041  $pdf->SetFont('', '', $default_font_size - 1);
1042 
1043  // Total table
1044  $col1x = 120; $col2x = 170;
1045  if ($this->page_largeur < 210) // To work with US executive format
1046  {
1047  $col2x -= 20;
1048  }
1049  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1050 
1051  $useborder = 0;
1052  $index = 0;
1053 
1054  // Total HT
1055  $pdf->SetFillColor(255, 255, 255);
1056  $pdf->SetXY($col1x, $tab2_top + 0);
1057  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1058 
1059  $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1060  $pdf->SetXY($col2x, $tab2_top + 0);
1061  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
1062 
1063  // Show VAT by rates and total
1064  $pdf->SetFillColor(248, 248, 248);
1065 
1066  $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1067 
1068  $this->atleastoneratenotnull = 0;
1069  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1070  {
1071  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1072  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1073  {
1074  // Nothing to do
1075  } else {
1076  //Local tax 1 before VAT
1077  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1078  //{
1079  foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1080  {
1081  if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1082 
1083  foreach ($localtax_rate as $tvakey => $tvaval)
1084  {
1085  if ($tvakey != 0) // On affiche pas taux 0
1086  {
1087  //$this->atleastoneratenotnull++;
1088 
1089  $index++;
1090  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1091 
1092  $tvacompl = '';
1093  if (preg_match('/\*/', $tvakey))
1094  {
1095  $tvakey = str_replace('*', '', $tvakey);
1096  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1097  }
1098  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1099  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1100  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1101 
1102  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1103  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1104  }
1105  }
1106  }
1107  //}
1108  //Local tax 2 before VAT
1109  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1110  //{
1111  foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1112  {
1113  if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1114 
1115  foreach ($localtax_rate as $tvakey => $tvaval)
1116  {
1117  if ($tvakey != 0) // On affiche pas taux 0
1118  {
1119  //$this->atleastoneratenotnull++;
1120 
1121 
1122 
1123  $index++;
1124  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1125 
1126  $tvacompl = '';
1127  if (preg_match('/\*/', $tvakey))
1128  {
1129  $tvakey = str_replace('*', '', $tvakey);
1130  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1131  }
1132  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1133  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1134  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1135 
1136  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1137  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1138  }
1139  }
1140  }
1141  //}
1142  // VAT
1143  foreach ($this->tva as $tvakey => $tvaval)
1144  {
1145  if ($tvakey != 0) // On affiche pas taux 0
1146  {
1147  $this->atleastoneratenotnull++;
1148 
1149  $index++;
1150  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1151 
1152  $tvacompl = '';
1153  if (preg_match('/\*/', $tvakey))
1154  {
1155  $tvakey = str_replace('*', '', $tvakey);
1156  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1157  }
1158  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1159  $totalvat .= vatrate($tvakey, 1).$tvacompl;
1160  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1161 
1162  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1163  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1164  }
1165  }
1166 
1167  //Local tax 1 after VAT
1168  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1169  //{
1170  foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1171  {
1172  if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1173 
1174  foreach ($localtax_rate as $tvakey => $tvaval)
1175  {
1176  if ($tvakey != 0) // On affiche pas taux 0
1177  {
1178  //$this->atleastoneratenotnull++;
1179 
1180  $index++;
1181  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1182 
1183  $tvacompl = '';
1184  if (preg_match('/\*/', $tvakey))
1185  {
1186  $tvakey = str_replace('*', '', $tvakey);
1187  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1188  }
1189  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1190 
1191  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1192  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1193  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1194  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1195  }
1196  }
1197  }
1198  //}
1199  //Local tax 2 after VAT
1200  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1201  //{
1202  foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1203  {
1204  if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1205 
1206  foreach ($localtax_rate as $tvakey => $tvaval)
1207  {
1208  // retrieve global local tax
1209  if ($tvakey != 0) // On affiche pas taux 0
1210  {
1211  //$this->atleastoneratenotnull++;
1212 
1213  $index++;
1214  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1215 
1216  $tvacompl = '';
1217  if (preg_match('/\*/', $tvakey))
1218  {
1219  $tvakey = str_replace('*', '', $tvakey);
1220  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1221  }
1222  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1223 
1224  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1225  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1226 
1227  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1228  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1229  }
1230  }
1231  }
1232  //}
1233 
1234  // Total TTC
1235  $index++;
1236  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1237  $pdf->SetTextColor(0, 0, 60);
1238  $pdf->SetFillColor(224, 224, 224);
1239  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1240 
1241  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1242  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1243  }
1244  }
1245 
1246  $pdf->SetTextColor(0, 0, 0);
1247 
1248  /*
1249  $resteapayer = $object->total_ttc - $deja_regle;
1250  if (! empty($object->paye)) $resteapayer=0;
1251  */
1252 
1253  if ($deja_regle > 0)
1254  {
1255  $index++;
1256 
1257  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1258  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1259 
1260  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1261  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1262 
1263  /*
1264  if ($object->close_code == 'discount_vat')
1265  {
1266  $index++;
1267  $pdf->SetFillColor(255,255,255);
1268 
1269  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1270  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1271 
1272  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1273  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1274 
1275  $resteapayer=0;
1276  }
1277  */
1278 
1279  $index++;
1280  $pdf->SetTextColor(0, 0, 60);
1281  $pdf->SetFillColor(224, 224, 224);
1282  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1283  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1284 
1285  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1286  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1287 
1288  $pdf->SetFont('', '', $default_font_size - 1);
1289  $pdf->SetTextColor(0, 0, 0);
1290  }
1291 
1292  $index++;
1293  return ($tab2_top + ($tab2_hl * $index));
1294  }
1295 
1296  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1310  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1311  {
1312  global $conf;
1313 
1314  // Force to disable hidetop and hidebottom
1315  $hidebottom = 0;
1316  if ($hidetop) $hidetop = -1;
1317 
1318  $currency = !empty($currency) ? $currency : $conf->currency;
1319  $default_font_size = pdf_getPDFFontSize($outputlangs);
1320 
1321  // Amount in (at tab_top - 1)
1322  $pdf->SetTextColor(0, 0, 0);
1323  $pdf->SetFont('', '', $default_font_size - 2);
1324 
1325  if (empty($hidetop))
1326  {
1327  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1328  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1329  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1330 
1331  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1332  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1333  }
1334 
1335  $pdf->SetDrawColor(128, 128, 128);
1336  $pdf->SetFont('', '', $default_font_size - 1);
1337 
1338  // Output Rect
1339  $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
1340 
1341  if (empty($hidetop))
1342  {
1343  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
1344 
1345  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1346  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1347  }
1348 
1349  if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1350  {
1351  $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1352  if (empty($hidetop))
1353  {
1354  //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1355  //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1356  }
1357  }
1358 
1359  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1360  {
1361  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1362  if (empty($hidetop))
1363  {
1364  // Not do -3 and +3 instead of -1 -1 to have more space for text 'Sales tax'
1365  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1366  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1367  }
1368  }
1369 
1370  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1371  if (empty($hidetop))
1372  {
1373  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1374  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1375  }
1376 
1377  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1378  if (empty($hidetop))
1379  {
1380  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1381  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1382  }
1383 
1384  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1385  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1386  if (empty($hidetop)) {
1387  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1388  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1389  'C');
1390  }
1391  }
1392 
1393  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1394  if (empty($hidetop))
1395  {
1396  if ($this->atleastonediscount)
1397  {
1398  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1399  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1400  }
1401  }
1402  if ($this->atleastonediscount)
1403  {
1404  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1405  }
1406  if (empty($hidetop))
1407  {
1408  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1409  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
1410  }
1411  }
1412 
1413  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1423  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1424  {
1425  global $conf, $langs;
1426 
1427  // Load traductions files required by page
1428  $outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
1429 
1430  $default_font_size = pdf_getPDFFontSize($outputlangs);
1431 
1432  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1433 
1434  // Show Draft Watermark
1435  if ($object->statut == 0 && (!empty($conf->global->PROPALE_DRAFT_WATERMARK)))
1436  {
1437  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->PROPALE_DRAFT_WATERMARK);
1438  }
1439 
1440  $pdf->SetTextColor(0, 0, 60);
1441  $pdf->SetFont('', 'B', $default_font_size + 3);
1442 
1443  $posy = $this->marge_haute;
1444  $posx = $this->page_largeur - $this->marge_droite - 100;
1445 
1446  $pdf->SetXY($this->marge_gauche, $posy);
1447 
1448  // Logo
1449  if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1450  {
1451  if ($this->emetteur->logo)
1452  {
1453  $logodir = $conf->mycompany->dir_output;
1454  if (!empty($conf->mycompany->multidir_output[$object->entity])) $logodir = $conf->mycompany->multidir_output[$object->entity];
1455  if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO))
1456  {
1457  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1458  } else {
1459  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1460  }
1461  if (is_readable($logo))
1462  {
1463  $height = pdf_getHeightForLogo($logo);
1464  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1465  } else {
1466  $pdf->SetTextColor(200, 0, 0);
1467  $pdf->SetFont('', 'B', $default_font_size - 2);
1468  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1469  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1470  }
1471  } else {
1472  $text = $this->emetteur->name;
1473  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1474  }
1475  }
1476 
1477  $pdf->SetFont('', 'B', $default_font_size + 3);
1478  $pdf->SetXY($posx, $posy);
1479  $pdf->SetTextColor(0, 0, 60);
1480  $title = $outputlangs->transnoentities("PdfCommercialProposalTitle");
1481  $pdf->MultiCell(100, 4, $title, '', 'R');
1482 
1483  $pdf->SetFont('', 'B', $default_font_size);
1484 
1485  $posy += 5;
1486  $pdf->SetXY($posx, $posy);
1487  $pdf->SetTextColor(0, 0, 60);
1488  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1489 
1490  $posy += 1;
1491  $pdf->SetFont('', '', $default_font_size - 2);
1492 
1493  if ($object->ref_client)
1494  {
1495  $posy += 4;
1496  $pdf->SetXY($posx, $posy);
1497  $pdf->SetTextColor(0, 0, 60);
1498  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1499  }
1500 
1501  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE))
1502  {
1503  $object->fetch_projet();
1504  if (!empty($object->project->ref))
1505  {
1506  $posy += 3;
1507  $pdf->SetXY($posx, $posy);
1508  $pdf->SetTextColor(0, 0, 60);
1509  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1510  }
1511  }
1512 
1513  if (!empty($conf->global->PDF_SHOW_PROJECT))
1514  {
1515  $object->fetch_projet();
1516  if (!empty($object->project->ref))
1517  {
1518  $posy += 3;
1519  $pdf->SetXY($posx, $posy);
1520  $pdf->SetTextColor(0, 0, 60);
1521  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->projet->ref), '', 'R');
1522  }
1523  }
1524 
1525  $posy += 4;
1526  $pdf->SetXY($posx, $posy);
1527  $pdf->SetTextColor(0, 0, 60);
1528  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1529 
1530  $posy += 4;
1531  $pdf->SetXY($posx, $posy);
1532  $pdf->SetTextColor(0, 0, 60);
1533  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : ".dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R');
1534 
1535  if ($object->thirdparty->code_client)
1536  {
1537  $posy += 4;
1538  $pdf->SetXY($posx, $posy);
1539  $pdf->SetTextColor(0, 0, 60);
1540  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1541  }
1542 
1543  // Get contact
1544  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1545  {
1546  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1547  if (count($arrayidcontact) > 0)
1548  {
1549  $usertmp = new User($this->db);
1550  $usertmp->fetch($arrayidcontact[0]);
1551  $posy += 4;
1552  $pdf->SetXY($posx, $posy);
1553  $pdf->SetTextColor(0, 0, 60);
1554  $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1555  }
1556  }
1557 
1558  $posy += 2;
1559 
1560  $top_shift = 0;
1561  // Show list of linked objects
1562  $current_y = $pdf->getY();
1563  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1564  if ($current_y < $pdf->getY())
1565  {
1566  $top_shift = $pdf->getY() - $current_y;
1567  }
1568 
1569  if ($showaddress)
1570  {
1571  // Sender properties
1572  $carac_emetteur = '';
1573  // Add internal contact of proposal if defined
1574  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1575  if (count($arrayidcontact) > 0)
1576  {
1577  $object->fetch_user($arrayidcontact[0]);
1578  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1579  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1580  }
1581 
1582  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1583 
1584  // Show sender
1585  $posy = 42 + $top_shift;
1586  $posx = $this->marge_gauche;
1587  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1588  $hautcadre = 40;
1589 
1590  // Show sender frame
1591  $pdf->SetTextColor(0, 0, 0);
1592  $pdf->SetFont('', '', $default_font_size - 2);
1593  $pdf->SetXY($posx, $posy - 5);
1594  $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1595  $pdf->SetXY($posx, $posy);
1596  $pdf->SetFillColor(230, 230, 230);
1597  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1598  $pdf->SetTextColor(0, 0, 60);
1599 
1600  // Show sender name
1601  $pdf->SetXY($posx + 2, $posy + 3);
1602  $pdf->SetFont('', 'B', $default_font_size);
1603  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1604  $posy = $pdf->getY();
1605 
1606  // Show sender information
1607  $pdf->SetXY($posx + 2, $posy);
1608  $pdf->SetFont('', '', $default_font_size - 1);
1609  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1610 
1611 
1612  // If CUSTOMER contact defined, we use it
1613  $usecontact = false;
1614  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1615  if (count($arrayidcontact) > 0)
1616  {
1617  $usecontact = true;
1618  $result = $object->fetch_contact($arrayidcontact[0]);
1619  }
1620 
1621  // Recipient name
1622  if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1623  $thirdparty = $object->contact;
1624  } else {
1625  $thirdparty = $object->thirdparty;
1626  }
1627 
1628  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1629 
1630  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1631 
1632  // Show recipient
1633  $widthrecbox = 100;
1634  if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1635  $posy = 42 + $top_shift;
1636  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1637  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1638 
1639  // Show recipient frame
1640  $pdf->SetTextColor(0, 0, 0);
1641  $pdf->SetFont('', '', $default_font_size - 2);
1642  $pdf->SetXY($posx + 2, $posy - 5);
1643  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1644  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1645 
1646  // Show recipient name
1647  $pdf->SetXY($posx + 2, $posy + 3);
1648  $pdf->SetFont('', 'B', $default_font_size);
1649  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1650 
1651  $posy = $pdf->getY();
1652 
1653  // Show recipient information
1654  $pdf->SetFont('', '', $default_font_size - 1);
1655  $pdf->SetXY($posx + 2, $posy);
1656  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1657  }
1658 
1659  $pdf->SetTextColor(0, 0, 0);
1660  return $top_shift;
1661  }
1662 
1663  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1673  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1674  {
1675  global $conf;
1676  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1677  return pdf_pagefoot($pdf, $outputlangs, 'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1678  }
1679 
1680  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1681  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1691  protected function _signature_area(&$pdf, $object, $posy, $outputlangs)
1692  {
1693  // phpcs:enable
1694  global $conf;
1695  $default_font_size = pdf_getPDFFontSize($outputlangs);
1696  $tab_top = $posy + 4;
1697  $tab_hl = 4;
1698 
1699  $posx = 120;
1700  $largcol = ($this->page_largeur - $this->marge_droite - $posx);
1701  $useborder = 0;
1702  $index = 0;
1703  // Total HT
1704  $pdf->SetFillColor(255, 255, 255);
1705  $pdf->SetXY($posx, $tab_top + 0);
1706  $pdf->SetFont('', '', $default_font_size - 2);
1707  $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
1708 
1709  $pdf->SetXY($posx, $tab_top + $tab_hl);
1710  $pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
1711  if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
1712  $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
1713  }
1714 
1715  return ($tab_hl * 7);
1716  }
1717 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency= '')
Show table for lines.
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:712
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:342
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:620
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:663
write_file($object, $outputlangs, $srctemplatepath= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Put here description of your class.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
Class to generate PDF proposal Azur.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
Class to manage products or services.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
Class to manage Dolibarr users.
Definition: user.class.php:44
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:222
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1828
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
Classe mere des modeles de propale.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
$conf db
API class for accounts.
Definition: inc.php:54
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Class to manage bank accounts.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:1952
Class to manage hooks.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1556
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1691
_signature_area(&$pdf, $object, $posy, $outputlangs)
Show area for the customer to sign.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:887
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1615
pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition: pdf.lib.php:294
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2221
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:1869
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:270
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1135
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:643
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
Definition: pdf.lib.php:88
pdf_build_address($outputlangs, $sourcecompany, $targetcompany= '', $targetcontact= '', $usecontact=0, $mode= 'source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:376
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1174
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the &quot;subst...
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.