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