dolibarr  13.0.2
pdf_eratosthene.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-2013 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 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  * or see https://www.gnu.org/
25  */
26 
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.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 
126  public $cols;
127 
128 
134  public function __construct($db)
135  {
136  global $conf, $langs, $mysoc;
137 
138  // Translations
139  $langs->loadLangs(array("main", "bills", "products"));
140 
141  $this->db = $db;
142  $this->name = "eratosthene";
143  $this->description = $langs->trans('PDFEratostheneDescription');
144  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
145 
146  // Dimension page
147  $this->type = 'pdf';
148  $formatarray = pdf_getFormat();
149  $this->page_largeur = $formatarray['width'];
150  $this->page_hauteur = $formatarray['height'];
151  $this->format = array($this->page_largeur, $this->page_hauteur);
152  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
153  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
154  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
155  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
156 
157  $this->option_logo = 1; // Display logo
158  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
159  $this->option_modereg = 1; // Display payment mode
160  $this->option_condreg = 1; // Display payment terms
161  $this->option_codeproduitservice = 1; // Display product-service code
162  $this->option_multilang = 1; // Available in several languages
163  $this->option_escompte = 0; // Displays if there has been a discount
164  $this->option_credit_note = 0; // Support credit notes
165  $this->option_freetext = 1; // Support add of a personalised text
166  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
167 
168  // Get source company
169  $this->emetteur = $mysoc;
170  if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
171 
172  // Define position of columns
173  $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
174 
175 
176  $this->tabTitleHeight = 5; // default height
177 
178  // Use new system for position of columns, view $this->defineColumnField()
179 
180  $this->tva = array();
181  $this->localtax1 = array();
182  $this->localtax2 = array();
183  $this->atleastoneratenotnull = 0;
184  $this->atleastonediscount = 0;
185  }
186 
187  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
199  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
200  {
201  // phpcs:enable
202  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
203 
204  if (!is_object($outputlangs)) $outputlangs = $langs;
205  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
206  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
207 
208  // Load translation files required by the page
209  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
210 
211  global $outputlangsbis;
212  $outputlangsbis = null;
213  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
214  $outputlangsbis = new Translate('', $conf);
215  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
216  $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
217  }
218 
219  $nblines = count($object->lines);
220 
221  $hidetop = 0;
222  if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
223  $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
224  }
225 
226  // Loop on each lines to detect if there is at least one image to show
227  $realpatharray = array();
228  $this->atleastonephoto = false;
229  if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE))
230  {
231  $objphoto = new Product($this->db);
232 
233  for ($i = 0; $i < $nblines; $i++)
234  {
235  if (empty($object->lines[$i]->fk_product)) continue;
236 
237  $objphoto->fetch($object->lines[$i]->fk_product);
238  //var_dump($objphoto->ref);exit;
239  if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
240  {
241  $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
242  $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
243  } else {
244  $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; // default
245  $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
246  }
247 
248  $arephoto = false;
249  foreach ($pdir as $midir)
250  {
251  if (!$arephoto)
252  {
253  if ($conf->product->entity != $objphoto->entity) {
254  $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
255  } else {
256  $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
257  }
258 
259  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
260  {
261  if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
262  {
263  if ($obj['photo_vignette'])
264  {
265  $filename = $obj['photo_vignette'];
266  } else {
267  $filename = $obj['photo'];
268  }
269  } else {
270  $filename = $obj['photo'];
271  }
272 
273  $realpath = $dir.$filename;
274  $arephoto = true;
275  $this->atleastonephoto = true;
276  }
277  }
278  }
279 
280  if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
281  }
282  }
283 
284 
285 
286  if ($conf->commande->multidir_output[$conf->entity])
287  {
288  $object->fetch_thirdparty();
289 
290  $deja_regle = 0;
291 
292  // Definition of $dir and $file
293  if ($object->specimen)
294  {
295  $dir = $conf->commande->multidir_output[$conf->entity];
296  $file = $dir."/SPECIMEN.pdf";
297  } else {
298  $objectref = dol_sanitizeFileName($object->ref);
299  $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref;
300  $file = $dir."/".$objectref.".pdf";
301  }
302 
303  if (!file_exists($dir))
304  {
305  if (dol_mkdir($dir) < 0)
306  {
307  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
308  return 0;
309  }
310  }
311 
312  if (file_exists($dir))
313  {
314  // Add pdfgeneration hook
315  if (!is_object($hookmanager))
316  {
317  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
318  $hookmanager = new HookManager($this->db);
319  }
320  $hookmanager->initHooks(array('pdfgeneration'));
321  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
322  global $action;
323  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
324 
325  // Create pdf instance
326  $pdf = pdf_getInstance($this->format);
327  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
328  $pdf->SetAutoPageBreak(1, 0);
329 
330  $heightforinfotot = 40; // Height reserved to output the info and total part
331  $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
332  $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
333 
334  if (class_exists('TCPDF'))
335  {
336  $pdf->setPrintHeader(false);
337  $pdf->setPrintFooter(false);
338  }
339  $pdf->SetFont(pdf_getPDFFont($outputlangs));
340  // Set path to the background PDF File
341  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
342  {
343  $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
344  $tplidx = $pdf->importPage(1);
345  }
346 
347  $pdf->Open();
348  $pagenb = 0;
349  $pdf->SetDrawColor(128, 128, 128);
350 
351  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
352  $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
353  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
354  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
355  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
356  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
357 
358  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
359 
360  // Set $this->atleastonediscount if you have at least one discount
361  for ($i = 0; $i < $nblines; $i++)
362  {
363  if ($object->lines[$i]->remise_percent)
364  {
365  $this->atleastonediscount++;
366  }
367  }
368 
369 
370  // New page
371  $pdf->AddPage();
372  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
373  $pagenb++;
374  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
375  $pdf->SetFont('', '', $default_font_size - 1);
376  $pdf->MultiCell(0, 3, ''); // Set interline to 3
377  $pdf->SetTextColor(0, 0, 0);
378 
379 
380  $tab_top = 90 + $top_shift;
381  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
382 
383  // Incoterm
384  $height_incoterms = 0;
385  if (!empty($conf->incoterm->enabled))
386  {
387  $desc_incoterms = $object->getIncotermsForPDF();
388  if ($desc_incoterms)
389  {
390  $tab_top -= 2;
391 
392  $pdf->SetFont('', '', $default_font_size - 1);
393  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
394  $nexY = max($pdf->GetY(), $nexY);
395  $height_incoterms = $nexY - $tab_top;
396 
397  // Rect takes a length in 3rd parameter
398  $pdf->SetDrawColor(192, 192, 192);
399  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
400 
401  $tab_top = $nexY + 6;
402  }
403  }
404 
405  // Displays notes
406  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
407  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
408  {
409  // Get first sale rep
410  if (is_object($object->thirdparty))
411  {
412  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
413  $salerepobj = new User($this->db);
414  $salerepobj->fetch($salereparray[0]['id']);
415  if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
416  }
417  }
418 
419  // Extrafields in note
420  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
421  if (!empty($extranote)) {
422  $notetoshow = dol_concatdesc($notetoshow, $extranote);
423  }
424 
425  $pagenb = $pdf->getPage();
426  if ($notetoshow)
427  {
428  $tab_top -= 2;
429 
430  $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
431  $pageposbeforenote = $pagenb;
432 
433  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
434  complete_substitutions_array($substitutionarray, $outputlangs, $object);
435  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
436  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
437 
438  $pdf->startTransaction();
439 
440  $pdf->SetFont('', '', $default_font_size - 1);
441  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
442  // Description
443  $pageposafternote = $pdf->getPage();
444  $posyafter = $pdf->GetY();
445 
446  if ($pageposafternote > $pageposbeforenote)
447  {
448  $pdf->rollbackTransaction(true);
449 
450  // prepare pages to receive notes
451  while ($pagenb < $pageposafternote) {
452  $pdf->AddPage();
453  $pagenb++;
454  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
455  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
456  // $this->_pagefoot($pdf,$object,$outputlangs,1);
457  $pdf->setTopMargin($tab_top_newpage);
458  // The only function to edit the bottom margin of current page to set it.
459  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
460  }
461 
462  // back to start
463  $pdf->setPage($pageposbeforenote);
464  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
465  $pdf->SetFont('', '', $default_font_size - 1);
466  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
467  $pageposafternote = $pdf->getPage();
468 
469  $posyafter = $pdf->GetY();
470 
471  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) // There is no space left for total+free text
472  {
473  $pdf->AddPage('', '', true);
474  $pagenb++;
475  $pageposafternote++;
476  $pdf->setPage($pageposafternote);
477  $pdf->setTopMargin($tab_top_newpage);
478  // The only function to edit the bottom margin of current page to set it.
479  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
480  //$posyafter = $tab_top_newpage;
481  }
482 
483 
484  // apply note frame to previous pages
485  $i = $pageposbeforenote;
486  while ($i < $pageposafternote) {
487  $pdf->setPage($i);
488 
489 
490  $pdf->SetDrawColor(128, 128, 128);
491  // Draw note frame
492  if ($i > $pageposbeforenote) {
493  $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
494  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
495  } else {
496  $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
497  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
498  }
499 
500  // Add footer
501  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
502  $this->_pagefoot($pdf, $object, $outputlangs, 1);
503 
504  $i++;
505  }
506 
507  // apply note frame to last page
508  $pdf->setPage($pageposafternote);
509  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
510  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
511  $height_note = $posyafter - $tab_top_newpage;
512  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
513  } else // No pagebreak
514  {
515  $pdf->commitTransaction();
516  $posyafter = $pdf->GetY();
517  $height_note = $posyafter - $tab_top;
518  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
519 
520 
521  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
522  {
523  // not enough space, need to add page
524  $pdf->AddPage('', '', true);
525  $pagenb++;
526  $pageposafternote++;
527  $pdf->setPage($pageposafternote);
528  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
529  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
530 
531  $posyafter = $tab_top_newpage;
532  }
533  }
534 
535  $tab_height = $tab_height - $height_note;
536  $tab_top = $posyafter + 6;
537  } else {
538  $height_note = 0;
539  }
540 
541 
542  // Use new auto column system
543  $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
544 
545  // Table simulation to know the height of the title line
546  $pdf->startTransaction();
547  $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
548  $pdf->rollbackTransaction(true);
549 
550  $nexY = $tab_top + $this->tabTitleHeight;
551 
552  // Loop on each lines
553  $pageposbeforeprintlines = $pdf->getPage();
554  $pagenb = $pageposbeforeprintlines;
555  for ($i = 0; $i < $nblines; $i++)
556  {
557  $curY = $nexY;
558  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
559  $pdf->SetTextColor(0, 0, 0);
560 
561  // Define size of image if we need it
562  $imglinesize = array();
563  if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
564 
565  $pdf->setTopMargin($tab_top_newpage);
566  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
567  $pageposbefore = $pdf->getPage();
568 
569 
570  $showpricebeforepagebreak = 1;
571  $posYAfterImage = 0;
572  $posYAfterDescription = 0;
573 
574  if ($this->getColumnStatus('photo'))
575  {
576  // We start with Photo of product line
577  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // If photo too high, we moved completely on new page
578  {
579  $pdf->AddPage('', '', true);
580  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
581  $pdf->setPage($pageposbefore + 1);
582 
583  $curY = $tab_top_newpage;
584 
585  // Allows data in the first page if description is long enough to break in multiples pages
586  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
587  $showpricebeforepagebreak = 1;
588  else $showpricebeforepagebreak = 0;
589  }
590 
591  if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
592  {
593  $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
594  // $pdf->Image does not increase value return by getY, so we save it manually
595  $posYAfterImage = $curY + $imglinesize['height'];
596  }
597  }
598 
599  // Description of product line
600  if ($this->getColumnStatus('desc'))
601  {
602  $pdf->startTransaction();
603 
604  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
605  $pageposafter = $pdf->getPage();
606 
607  if ($pageposafter > $pageposbefore) // There is a pagebreak
608  {
609  $pdf->rollbackTransaction(true);
610  $pageposafter = $pageposbefore;
611  //print $pageposafter.'-'.$pageposbefore;exit;
612  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
613 
614  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
615  $pageposafter = $pdf->getPage();
616  $posyafter = $pdf->GetY();
617  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text
618  {
619  if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
620  {
621  $pdf->AddPage('', '', true);
622  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
623  //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
624  $pdf->setPage($pageposafter + 1);
625  }
626  } else {
627  // We found a page break
628  // Allows data in the first page if description is long enough to break in multiples pages
629  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
630  $showpricebeforepagebreak = 1;
631  else $showpricebeforepagebreak = 0;
632  }
633  } else // No pagebreak
634  {
635  $pdf->commitTransaction();
636  }
637  $posYAfterDescription = $pdf->GetY();
638  }
639 
640 
641  $nexY = max($pdf->GetY(), $posYAfterImage);
642 
643 
644  $pageposafter = $pdf->getPage();
645 
646  $pdf->setPage($pageposbefore);
647  $pdf->setTopMargin($this->marge_haute);
648  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
649 
650  // We suppose that a too long description or photo were moved completely on next page
651  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
652  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
653  }
654 
655  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
656 
657  // VAT Rate
658  if ($this->getColumnStatus('vat'))
659  {
660  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
661  $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
662  $nexY = max($pdf->GetY(), $nexY);
663  }
664 
665  // Unit price before discount
666  if ($this->getColumnStatus('subprice'))
667  {
668  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
669  $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
670  $nexY = max($pdf->GetY(), $nexY);
671  }
672 
673  // Quantity
674  // Enough for 6 chars
675  if ($this->getColumnStatus('qty'))
676  {
677  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
678  $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
679  $nexY = max($pdf->GetY(), $nexY);
680  }
681 
682 
683  // Unit
684  if ($this->getColumnStatus('unit'))
685  {
686  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
687  $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
688  $nexY = max($pdf->GetY(), $nexY);
689  }
690 
691  // Discount on line
692  if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent)
693  {
694  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
695  $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
696  $nexY = max($pdf->GetY(), $nexY);
697  }
698 
699  // Total excl tax line (HT)
700  if ($this->getColumnStatus('totalexcltax'))
701  {
702  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
703  $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
704  $nexY = max($pdf->GetY(), $nexY);
705  }
706 
707  // Total with tax line (TTC)
708  if ($this->getColumnStatus('totalincltax'))
709  {
710  $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
711  $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
712  $nexY = max($pdf->GetY(), $nexY);
713  }
714 
715  // Extrafields
716  if (!empty($object->lines[$i]->array_options)) {
717  foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
718  if ($this->getColumnStatus($extrafieldColKey))
719  {
720  $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
721  $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
722  $nexY = max($pdf->GetY(), $nexY);
723  }
724  }
725  }
726 
727  $parameters = array(
728  'object' => $object,
729  'i' => $i,
730  'pdf' =>& $pdf,
731  'curY' =>& $curY,
732  'nexY' =>& $nexY,
733  'outputlangs' => $outputlangs,
734  'hidedetails' => $hidedetails
735  );
736  $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
737 
738 
739  // Collection of totals by value of vat in $this->tva["rate"] = total_tva
740  if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva;
741  else $tvaligne = $object->lines[$i]->total_tva;
742 
743  $localtax1ligne = $object->lines[$i]->total_localtax1;
744  $localtax2ligne = $object->lines[$i]->total_localtax2;
745  $localtax1_rate = $object->lines[$i]->localtax1_tx;
746  $localtax2_rate = $object->lines[$i]->localtax2_tx;
747  $localtax1_type = $object->lines[$i]->localtax1_type;
748  $localtax2_type = $object->lines[$i]->localtax2_type;
749 
750  if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
751  if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
752  if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
753 
754  $vatrate = (string) $object->lines[$i]->tva_tx;
755 
756  // Retrieve type from database for backward compatibility with old records
757  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
758  && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
759  {
760  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
761  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
762  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
763  }
764 
765  // retrieve global local tax
766  if ($localtax1_type && $localtax1ligne != 0)
767  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
768  if ($localtax2_type && $localtax2ligne != 0)
769  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
770 
771  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
772  if (!isset($this->tva[$vatrate])) $this->tva[$vatrate] = 0;
773  $this->tva[$vatrate] += $tvaligne;
774 
775  // Add line
776  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
777  {
778  $pdf->setPage($pageposafter);
779  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
780  //$pdf->SetDrawColor(190,190,200);
781  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
782  $pdf->SetLineStyle(array('dash'=>0));
783  }
784 
785 
786  // Detect if some page were added automatically and output _tableau for past pages
787  while ($pagenb < $pageposafter)
788  {
789  $pdf->setPage($pagenb);
790  if ($pagenb == $pageposbeforeprintlines)
791  {
792  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
793  } else {
794  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
795  }
796  $this->_pagefoot($pdf, $object, $outputlangs, 1);
797  $pagenb++;
798  $pdf->setPage($pagenb);
799  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
800  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
801  }
802  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
803  {
804  if ($pagenb == $pageposafter)
805  {
806  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
807  } else {
808  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
809  }
810  $this->_pagefoot($pdf, $object, $outputlangs, 1);
811  // New page
812  $pdf->AddPage();
813  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
814  $pagenb++;
815  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
816  }
817  }
818 
819  // Show square
820  if ($pagenb == $pageposbeforeprintlines)
821  {
822  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
823  } else {
824  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
825  }
826  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
827 
828  // Display infos area
829  $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
830 
831  // Display total zone
832  $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
833 
834  // Affiche zone versements
835  /*
836  if ($deja_regle)
837  {
838  $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
839  }
840  */
841 
842  // Pied de page
843  $this->_pagefoot($pdf, $object, $outputlangs);
844  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
845 
846  $pdf->Close();
847 
848  $pdf->Output($file, 'F');
849 
850  // Add pdfgeneration hook
851  $hookmanager->initHooks(array('pdfgeneration'));
852  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
853  global $action;
854  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
855  if ($reshook < 0)
856  {
857  $this->error = $hookmanager->error;
858  $this->errors = $hookmanager->errors;
859  }
860 
861  if (!empty($conf->global->MAIN_UMASK))
862  @chmod($file, octdec($conf->global->MAIN_UMASK));
863 
864  $this->result = array('fullpath'=>$file);
865 
866  return 1; // No error
867  } else {
868  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
869  return 0;
870  }
871  } else {
872  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
873  return 0;
874  }
875  }
876 
886  protected function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
887  {
888  }
889 
899  protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
900  {
901  global $conf, $mysoc;
902  $default_font_size = pdf_getPDFFontSize($outputlangs);
903 
904  $pdf->SetFont('', '', $default_font_size - 1);
905 
906  // If France, show VAT mention if not applicable
907  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj))
908  {
909  $pdf->SetFont('', 'B', $default_font_size - 2);
910  $pdf->SetXY($this->marge_gauche, $posy);
911  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
912 
913  $posy = $pdf->GetY() + 4;
914  }
915 
916  $posxval = 52;
917 
918  // Show payments conditions
919  if ($object->cond_reglement_code || $object->cond_reglement)
920  {
921  $pdf->SetFont('', 'B', $default_font_size - 2);
922  $pdf->SetXY($this->marge_gauche, $posy);
923  $titre = $outputlangs->transnoentities("PaymentConditions").':';
924  $pdf->MultiCell(43, 4, $titre, 0, 'L');
925 
926  $pdf->SetFont('', '', $default_font_size - 2);
927  $pdf->SetXY($posxval, $posy);
928  $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);
929  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
930  $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
931 
932  $posy = $pdf->GetY() + 3;
933  }
934 
935  // Check a payment mode is defined
936  /* Not used with orders
937  if (empty($object->mode_reglement_code)
938  && ! $conf->global->FACTURE_CHQ_NUMBER
939  && ! $conf->global->FACTURE_RIB_NUMBER)
940  {
941  $pdf->SetXY($this->marge_gauche, $posy);
942  $pdf->SetTextColor(200,0,0);
943  $pdf->SetFont('','B', $default_font_size - 2);
944  $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
945  $pdf->SetTextColor(0,0,0);
946 
947  $posy=$pdf->GetY()+1;
948  }
949  */
950  /* TODO
951  else if (! empty($object->availability_code))
952  {
953  $pdf->SetXY($this->marge_gauche, $posy);
954  $pdf->SetTextColor(200,0,0);
955  $pdf->SetFont('','B', $default_font_size - 2);
956  $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
957  $pdf->SetTextColor(0,0,0);
958 
959  $posy=$pdf->GetY()+1;
960  }*/
961 
962  // Show planed date of delivery
963  if (!empty($object->delivery_date))
964  {
965  $outputlangs->load("sendings");
966  $pdf->SetFont('', 'B', $default_font_size - 2);
967  $pdf->SetXY($this->marge_gauche, $posy);
968  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
969  $pdf->MultiCell(80, 4, $titre, 0, 'L');
970  $pdf->SetFont('', '', $default_font_size - 2);
971  $pdf->SetXY($posxval, $posy);
972  $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
973  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
974 
975  $posy = $pdf->GetY() + 1;
976  } elseif ($object->availability_code || $object->availability) // Show availability conditions
977  {
978  $pdf->SetFont('', 'B', $default_font_size - 2);
979  $pdf->SetXY($this->marge_gauche, $posy);
980  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
981  $pdf->MultiCell(80, 4, $titre, 0, 'L');
982  $pdf->SetTextColor(0, 0, 0);
983  $pdf->SetFont('', '', $default_font_size - 2);
984  $pdf->SetXY($posxval, $posy);
985  $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
986  $lib_availability = str_replace('\n', "\n", $lib_availability);
987  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
988 
989  $posy = $pdf->GetY() + 1;
990  }
991 
992  // Show payment mode
993  if ($object->mode_reglement_code
994  && $object->mode_reglement_code != 'CHQ'
995  && $object->mode_reglement_code != 'VIR') {
996  $pdf->SetFont('', 'B', $default_font_size - 2);
997  $pdf->SetXY($this->marge_gauche, $posy);
998  $titre = $outputlangs->transnoentities("PaymentMode").':';
999  $pdf->MultiCell(80, 5, $titre, 0, 'L');
1000 
1001  $pdf->SetFont('', '', $default_font_size - 2);
1002  $pdf->SetXY($posxval, $posy);
1003  $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);
1004  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1005 
1006  $posy = $pdf->GetY() + 2;
1007  }
1008 
1009  // Show payment mode CHQ
1010  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1011  {
1012  // Si mode reglement non force ou si force a CHQ
1013  if (!empty($conf->global->FACTURE_CHQ_NUMBER))
1014  {
1015  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1016 
1017  if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1018  {
1019  $account = new Account($this->db);
1020  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1021 
1022  $pdf->SetXY($this->marge_gauche, $posy);
1023  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1024  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1025  $posy = $pdf->GetY() + 1;
1026 
1027  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1028  {
1029  $pdf->SetXY($this->marge_gauche, $posy);
1030  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1031  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1032  $posy = $pdf->GetY() + 2;
1033  }
1034  }
1035  if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1036  {
1037  $pdf->SetXY($this->marge_gauche, $posy);
1038  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1039  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1040  $posy = $pdf->GetY() + 1;
1041 
1042  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1043  {
1044  $pdf->SetXY($this->marge_gauche, $posy);
1045  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1046  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1047  $posy = $pdf->GetY() + 2;
1048  }
1049  }
1050  }
1051  }
1052 
1053  // If payment mode not forced or forced to VIR, show payment with BAN
1054  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1055  {
1056  if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER))
1057  {
1058  $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1059  if ($object->fk_bank > 0) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1060  $account = new Account($this->db);
1061  $account->fetch($bankid);
1062 
1063  $curx = $this->marge_gauche;
1064  $cury = $posy;
1065 
1066  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1067 
1068  $posy += 2;
1069  }
1070  }
1071 
1072  return $posy;
1073  }
1074 
1075 
1086  protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1087  {
1088  global $conf, $mysoc, $hookmanager;
1089 
1090  $default_font_size = pdf_getPDFFontSize($outputlangs);
1091 
1092  $outputlangsbis = null;
1093  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1094  $outputlangsbis = new Translate('', $conf);
1095  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1096  $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1097  $default_font_size--;
1098  }
1099 
1100  $tab2_top = $posy;
1101  $tab2_hl = 4;
1102  $pdf->SetFont('', '', $default_font_size - 1);
1103 
1104  // Total table
1105  $col1x = 120; $col2x = 170;
1106  if ($this->page_largeur < 210) // To work with US executive format
1107  {
1108  $col2x -= 20;
1109  }
1110  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1111 
1112  $useborder = 0;
1113  $index = 0;
1114 
1115  // Total HT
1116  $pdf->SetFillColor(255, 255, 255);
1117  $pdf->SetXY($col1x, $tab2_top + 0);
1118  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
1119  $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1120  $pdf->SetXY($col2x, $tab2_top + 0);
1121  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
1122 
1123  // Show VAT by rates and total
1124  $pdf->SetFillColor(248, 248, 248);
1125 
1126  $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1127 
1128  $this->atleastoneratenotnull = 0;
1129  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1130  {
1131  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1132  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1133  {
1134  // Nothing to do
1135  } else {
1136  //Local tax 1 before VAT
1137  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1138  //{
1139  foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1140  {
1141  if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1142  foreach ($localtax_rate as $tvakey => $tvaval)
1143  {
1144  if ($tvakey != 0) // On affiche pas taux 0
1145  {
1146  //$this->atleastoneratenotnull++;
1147  $index++;
1148  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1149 
1150  $tvacompl = '';
1151  if (preg_match('/\*/', $tvakey))
1152  {
1153  $tvakey = str_replace('*', '', $tvakey);
1154  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1155  }
1156  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1157  $totalvat .= ' ';
1158  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1159  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1160 
1161  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1162  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1163  }
1164  }
1165  }
1166  //}
1167  //Local tax 2 before VAT
1168  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1169  //{
1170  foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1171  {
1172  if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1173  foreach ($localtax_rate as $tvakey => $tvaval)
1174  {
1175  if ($tvakey != 0) // On affiche pas taux 0
1176  {
1177  //$this->atleastoneratenotnull++;
1178 
1179  $index++;
1180  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1181 
1182  $tvacompl = '';
1183  if (preg_match('/\*/', $tvakey))
1184  {
1185  $tvakey = str_replace('*', '', $tvakey);
1186  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1187  }
1188  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1189  $totalvat .= ' ';
1190  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1191  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1192 
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  // VAT
1200  foreach ($this->tva as $tvakey => $tvaval)
1201  {
1202  if ($tvakey != 0) // On affiche pas taux 0
1203  {
1204  $this->atleastoneratenotnull++;
1205 
1206  $index++;
1207  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1208 
1209  $tvacompl = '';
1210  if (preg_match('/\*/', $tvakey))
1211  {
1212  $tvakey = str_replace('*', '', $tvakey);
1213  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1214  }
1215  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1216  $totalvat .= ' ';
1217  $totalvat .= vatrate($tvakey, 1).$tvacompl;
1218  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1219 
1220  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1221  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1222  }
1223  }
1224 
1225  //Local tax 1 after VAT
1226  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1227  //{
1228  foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1229  {
1230  if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1231 
1232  foreach ($localtax_rate as $tvakey => $tvaval)
1233  {
1234  if ($tvakey != 0) // On affiche pas taux 0
1235  {
1236  //$this->atleastoneratenotnull++;
1237 
1238  $index++;
1239  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1240 
1241  $tvacompl = '';
1242  if (preg_match('/\*/', $tvakey))
1243  {
1244  $tvakey = str_replace('*', '', $tvakey);
1245  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1246  }
1247  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1248  $totalvat .= ' ';
1249  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1250 
1251  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1252  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1253  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1254  }
1255  }
1256  }
1257  //}
1258  //Local tax 2 after VAT
1259  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1260  //{
1261  foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1262  {
1263  if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1264 
1265  foreach ($localtax_rate as $tvakey => $tvaval)
1266  {
1267  // retrieve global local tax
1268  if ($tvakey != 0) // On affiche pas taux 0
1269  {
1270  //$this->atleastoneratenotnull++;
1271 
1272  $index++;
1273  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1274 
1275  $tvacompl = '';
1276  if (preg_match('/\*/', $tvakey))
1277  {
1278  $tvakey = str_replace('*', '', $tvakey);
1279  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1280  }
1281  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1282  $totalvat .= ' ';
1283 
1284  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1285  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1286 
1287  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1288  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1289  }
1290  }
1291  }
1292  //}
1293 
1294  // Total TTC
1295  $index++;
1296  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1297  $pdf->SetTextColor(0, 0, 60);
1298  $pdf->SetFillColor(224, 224, 224);
1299  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
1300 
1301  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1302  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1303  }
1304  }
1305 
1306  $pdf->SetTextColor(0, 0, 0);
1307 
1308  $creditnoteamount = 0;
1309  $depositsamount = 0;
1310  //$creditnoteamount=$object->getSumCreditNotesUsed();
1311  //$depositsamount=$object->getSumDepositsUsed();
1312  //print "x".$creditnoteamount."-".$depositsamount;exit;
1313  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1314  if (!empty($object->paye)) $resteapayer = 0;
1315 
1316  if ($deja_regle > 0)
1317  {
1318  // Already paid + Deposits
1319  $index++;
1320 
1321  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1322  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1323  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1324  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1325 
1326  $index++;
1327  $pdf->SetTextColor(0, 0, 60);
1328  $pdf->SetFillColor(224, 224, 224);
1329  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1330  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
1331 
1332  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1333  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1334 
1335  $pdf->SetFont('', '', $default_font_size - 1);
1336  $pdf->SetTextColor(0, 0, 0);
1337  }
1338 
1339  $index++;
1340  return ($tab2_top + ($tab2_hl * $index));
1341  }
1342 
1343  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1358  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1359  {
1360  global $conf;
1361 
1362  // Force to disable hidetop and hidebottom
1363  $hidebottom = 0;
1364  if ($hidetop) $hidetop = -1;
1365 
1366  $currency = !empty($currency) ? $currency : $conf->currency;
1367  $default_font_size = pdf_getPDFFontSize($outputlangs);
1368 
1369  // Amount in (at tab_top - 1)
1370  $pdf->SetTextColor(0, 0, 0);
1371  $pdf->SetFont('', '', $default_font_size - 2);
1372 
1373  if (empty($hidetop))
1374  {
1375  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1376  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1377  $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
1378  }
1379 
1380  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1381  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1382 
1383  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1384  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1385  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1386  }
1387  }
1388 
1389  $pdf->SetDrawColor(128, 128, 128);
1390  $pdf->SetFont('', '', $default_font_size - 1);
1391 
1392  // Output Rect
1393  $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
1394 
1395 
1396  $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1397 
1398  if (empty($hidetop)) {
1399  $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
1400  }
1401  }
1402 
1403  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1404  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1416  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
1417  {
1418  // phpcs:enable
1419  global $conf, $langs, $hookmanager;
1420 
1421  // Load traductions files required by page
1422  $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1423 
1424  $default_font_size = pdf_getPDFFontSize($outputlangs);
1425 
1426  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1427 
1428  // Show Draft Watermark
1429  if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
1430  {
1431  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
1432  }
1433 
1434  $pdf->SetTextColor(0, 0, 60);
1435  $pdf->SetFont('', 'B', $default_font_size + 3);
1436 
1437  $w = 100;
1438 
1439  $posy = $this->marge_haute;
1440  $posx = $this->page_largeur - $this->marge_droite - $w;
1441 
1442  $pdf->SetXY($this->marge_gauche, $posy);
1443 
1444  // Logo
1445  if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1446  {
1447  if ($this->emetteur->logo)
1448  {
1449  $logodir = $conf->mycompany->dir_output;
1450  if (!empty($conf->mycompany->multidir_output[$object->entity])) $logodir = $conf->mycompany->multidir_output[$object->entity];
1451  if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO))
1452  {
1453  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1454  } else {
1455  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1456  }
1457  if (is_readable($logo)) {
1458  $height = pdf_getHeightForLogo($logo);
1459  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1460  } else {
1461  $pdf->SetTextColor(200, 0, 0);
1462  $pdf->SetFont('', 'B', $default_font_size - 2);
1463  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1464  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1465  }
1466  } else {
1467  $text = $this->emetteur->name;
1468  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1469  }
1470  }
1471 
1472  $pdf->SetFont('', 'B', $default_font_size + 3);
1473  $pdf->SetXY($posx, $posy);
1474  $pdf->SetTextColor(0, 0, 60);
1475  $title = $outputlangs->transnoentities($titlekey);
1476  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1477  $title .= ' - ';
1478  $title .= $outputlangsbis->transnoentities($titlekey);
1479  }
1480 
1481  $pdf->MultiCell($w, 3, $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  $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1489  if ($object->statut == $object::STATUS_DRAFT)
1490  {
1491  $pdf->SetTextColor(128, 0, 0);
1492  $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1493  }
1494  $pdf->MultiCell($w, 4, $textref, '', 'R');
1495 
1496  $posy += 1;
1497  $pdf->SetFont('', '', $default_font_size - 2);
1498 
1499  if ($object->ref_client)
1500  {
1501  $posy += 4;
1502  $pdf->SetXY($posx, $posy);
1503  $pdf->SetTextColor(0, 0, 60);
1504  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1505  }
1506 
1507  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE))
1508  {
1509  $object->fetch_projet();
1510  if (!empty($object->project->ref))
1511  {
1512  $posy += 3;
1513  $pdf->SetXY($posx, $posy);
1514  $pdf->SetTextColor(0, 0, 60);
1515  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1516  }
1517  }
1518 
1519  if (!empty($conf->global->PDF_SHOW_PROJECT))
1520  {
1521  $object->fetch_projet();
1522  if (!empty($object->project->ref))
1523  {
1524  $posy += 3;
1525  $pdf->SetXY($posx, $posy);
1526  $pdf->SetTextColor(0, 0, 60);
1527  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->projet->ref), '', 'R');
1528  }
1529  }
1530 
1531  $posy += 4;
1532 
1533  $pdf->SetXY($posx, $posy);
1534  $pdf->SetTextColor(0, 0, 60);
1535  $title = $outputlangs->transnoentities("OrderDate");
1536  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1537  $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
1538  }
1539  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1540 
1541  if (!empty($conf->global->DOC_SHOW_CUSTOMER_CODE) && !empty($object->thirdparty->code_client))
1542  {
1543  $posy += 4;
1544  $pdf->SetXY($posx, $posy);
1545  $pdf->SetTextColor(0, 0, 60);
1546  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1547  }
1548 
1549  // Get contact
1550  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1551  {
1552  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1553  if (count($arrayidcontact) > 0)
1554  {
1555  $usertmp = new User($this->db);
1556  $usertmp->fetch($arrayidcontact[0]);
1557  $posy += 4;
1558  $pdf->SetXY($posx, $posy);
1559  $pdf->SetTextColor(0, 0, 60);
1560  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1561  }
1562  }
1563 
1564  $posy += 2;
1565 
1566  $top_shift = 0;
1567  // Show list of linked objects
1568  $current_y = $pdf->getY();
1569  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1570  if ($current_y < $pdf->getY())
1571  {
1572  $top_shift = $pdf->getY() - $current_y;
1573  }
1574 
1575  if ($showaddress)
1576  {
1577  // Sender properties
1578  $carac_emetteur = '';
1579  // Add internal contact of proposal if defined
1580  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1581  if (count($arrayidcontact) > 0)
1582  {
1583  $object->fetch_user($arrayidcontact[0]);
1584  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1585  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1586  }
1587 
1588  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1589 
1590  // Show sender
1591  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1592  $posy += $top_shift;
1593  $posx = $this->marge_gauche;
1594  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1595 
1596  $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1597  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1598 
1599 
1600  // Show sender frame
1601  $pdf->SetTextColor(0, 0, 0);
1602  $pdf->SetFont('', '', $default_font_size - 2);
1603  $pdf->SetXY($posx, $posy - 5);
1604  $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1605  $pdf->SetXY($posx, $posy);
1606  $pdf->SetFillColor(230, 230, 230);
1607  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1608  $pdf->SetTextColor(0, 0, 60);
1609 
1610  // Show sender name
1611  $pdf->SetXY($posx + 2, $posy + 3);
1612  $pdf->SetFont('', 'B', $default_font_size);
1613  $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1614  $posy = $pdf->getY();
1615 
1616  // Show sender information
1617  $pdf->SetXY($posx + 2, $posy);
1618  $pdf->SetFont('', '', $default_font_size - 1);
1619  $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1620 
1621  // If CUSTOMER contact defined, we use it
1622  $usecontact = false;
1623  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1624  if (count($arrayidcontact) > 0)
1625  {
1626  $usecontact = true;
1627  $result = $object->fetch_contact($arrayidcontact[0]);
1628  }
1629 
1630  //Recipient name
1631  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)))) {
1632  $thirdparty = $object->contact;
1633  } else {
1634  $thirdparty = $object->thirdparty;
1635  }
1636 
1637  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1638 
1639  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1640 
1641  // Show recipient
1642  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1643  if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1644  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1645  $posy += $top_shift;
1646  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1647  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1648 
1649  // Show recipient frame
1650  $pdf->SetTextColor(0, 0, 0);
1651  $pdf->SetFont('', '', $default_font_size - 2);
1652  $pdf->SetXY($posx + 2, $posy - 5);
1653  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1654  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1655 
1656  // Show recipient name
1657  $pdf->SetXY($posx + 2, $posy + 3);
1658  $pdf->SetFont('', 'B', $default_font_size);
1659  $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1660 
1661  $posy = $pdf->getY();
1662 
1663  // Show recipient information
1664  $pdf->SetFont('', '', $default_font_size - 1);
1665  $pdf->SetXY($posx + 2, $posy);
1666  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1667  }
1668 
1669  $pdf->SetTextColor(0, 0, 0);
1670  return $top_shift;
1671  }
1672 
1673  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1674  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1684  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1685  {
1686  // phpcs:enable
1687  global $conf;
1688  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1689  return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1690  }
1691 
1692 
1693 
1704  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1705  {
1706  global $conf, $hookmanager;
1707 
1708  // Default field style for content
1709  $this->defaultContentsFieldsStyle = array(
1710  'align' => 'R', // R,C,L
1711  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1712  );
1713 
1714  // Default field style for content
1715  $this->defaultTitlesFieldsStyle = array(
1716  'align' => 'C', // R,C,L
1717  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1718  );
1719 
1720  /*
1721  * For exemple
1722  $this->cols['theColKey'] = array(
1723  'rank' => $rank, // int : use for ordering columns
1724  'width' => 20, // the column width in mm
1725  'title' => array(
1726  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1727  'label' => ' ', // the final label : used fore final generated text
1728  'align' => 'L', // text alignement : R,C,L
1729  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1730  ),
1731  'content' => array(
1732  'align' => 'L', // text alignement : R,C,L
1733  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1734  ),
1735  );
1736  */
1737 
1738  $rank = 0; // do not use negative rank
1739  $this->cols['desc'] = array(
1740  'rank' => $rank,
1741  'width' => false, // only for desc
1742  'status' => true,
1743  'title' => array(
1744  'textkey' => 'Designation', // use lang key is usefull in somme case with module
1745  'align' => 'L',
1746  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1747  // 'label' => ' ', // the final label
1748  'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1749  ),
1750  'content' => array(
1751  'align' => 'L',
1752  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1753  ),
1754  );
1755 
1756  // Image of product
1757  $rank = $rank + 10;
1758  $this->cols['photo'] = array(
1759  'rank' => $rank,
1760  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1761  'status' => false,
1762  'title' => array(
1763  'textkey' => 'Photo',
1764  'label' => ' '
1765  ),
1766  'content' => array(
1767  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1768  ),
1769  'border-left' => false, // remove left line separator
1770  );
1771 
1772  if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto))
1773  {
1774  $this->cols['photo']['status'] = true;
1775  }
1776 
1777  $rank = $rank + 10;
1778  $this->cols['vat'] = array(
1779  'rank' => $rank,
1780  'status' => false,
1781  'width' => 16, // in mm
1782  'title' => array(
1783  'textkey' => 'VAT'
1784  ),
1785  'border-left' => true, // add left line separator
1786  );
1787 
1788  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1789  {
1790  $this->cols['vat']['status'] = true;
1791  }
1792 
1793  $rank = $rank + 10;
1794  $this->cols['subprice'] = array(
1795  'rank' => $rank,
1796  'width' => 19, // in mm
1797  'status' => true,
1798  'title' => array(
1799  'textkey' => 'PriceUHT'
1800  ),
1801  'border-left' => true, // add left line separator
1802  );
1803 
1804  // Adapt dynamically the width of subprice, if text is too long.
1805  $tmpwidth = 0;
1806  $nblines = count($object->lines);
1807  for ($i = 0; $i < $nblines; $i++) {
1808  $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
1809  $tmpwidth = max($tmpwidth, $tmpwidth2);
1810  }
1811  if ($tmpwidth > 10) {
1812  $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
1813  }
1814 
1815  $rank = $rank + 10;
1816  $this->cols['qty'] = array(
1817  'rank' => $rank,
1818  'width' => 16, // in mm
1819  'status' => true,
1820  'title' => array(
1821  'textkey' => 'Qty'
1822  ),
1823  'border-left' => true, // add left line separator
1824  );
1825 
1826  $rank = $rank + 10;
1827  $this->cols['unit'] = array(
1828  'rank' => $rank,
1829  'width' => 11, // in mm
1830  'status' => false,
1831  'title' => array(
1832  'textkey' => 'Unit'
1833  ),
1834  'border-left' => true, // add left line separator
1835  );
1836  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1837  $this->cols['unit']['status'] = true;
1838  }
1839 
1840  $rank = $rank + 10;
1841  $this->cols['discount'] = array(
1842  'rank' => $rank,
1843  'width' => 13, // in mm
1844  'status' => false,
1845  'title' => array(
1846  'textkey' => 'ReductionShort'
1847  ),
1848  'border-left' => true, // add left line separator
1849  );
1850  if ($this->atleastonediscount) {
1851  $this->cols['discount']['status'] = true;
1852  }
1853 
1854  $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1855  $this->cols['totalexcltax'] = array(
1856  'rank' => $rank,
1857  'width' => 26, // in mm
1858  'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
1859  'title' => array(
1860  'textkey' => 'TotalHT'
1861  ),
1862  'border-left' => true, // add left line separator
1863  );
1864 
1865  $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
1866  $this->cols['totalincltax'] = array(
1867  'rank' => $rank,
1868  'width' => 26, // in mm
1869  'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
1870  'title' => array(
1871  'textkey' => 'TotalTTC'
1872  ),
1873  'border-left' => true, // add left line separator
1874  );
1875 
1876  // Add extrafields cols
1877  if (!empty($object->lines)) {
1878  $line = reset($object->lines);
1879  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1880  }
1881 
1882  $parameters = array(
1883  'object' => $object,
1884  'outputlangs' => $outputlangs,
1885  'hidedetails' => $hidedetails,
1886  'hidedesc' => $hidedesc,
1887  'hideref' => $hideref
1888  );
1889 
1890  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1891  if ($reshook < 0)
1892  {
1893  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1894  } elseif (empty($reshook))
1895  {
1896  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1897  } else {
1898  $this->cols = $hookmanager->resArray;
1899  }
1900  }
1901 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:712
getExtrafieldContent($object, $extrafieldKey)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency= '', $outputlangsbis=null)
Show table for lines.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:663
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
__construct($db)
Constructor.
</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
write_file($object, $outputlangs, $srctemplatepath= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
Class to manage products or services.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
Class to manage Dolibarr users.
Definition: user.class.php:44
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
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...
printStdColumnContent($pdf, &$curY, $colKey, $columnText= '')
print standard column content
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
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...
drawInfoTable(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
$conf db
API class for accounts.
Definition: inc.php:54
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...
getColumnStatus($colKey)
get column status from column key
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.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1691
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
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
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1615
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
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
Class to manage translations.
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.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="PdfOrderTitle")
Show top header of page.
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...
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
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).
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.
Class to generate PDF orders with template Eratosthene.
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
Parent class for orders models.
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...
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition: pdf.lib.php:2009