dolibarr  17.0.3
pdf_cornas.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-2011 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  * or see https://www.gnu.org/
23  */
24 
31 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37 
38 
43 {
47  public $db;
48 
52  public $name;
53 
57  public $description;
58 
62  public $update_main_doc_field;
63 
67  public $type;
68 
73  public $phpmin = array(7, 0);
74 
79  public $version = 'dolibarr';
80 
84  public $page_largeur;
85 
89  public $page_hauteur;
90 
94  public $format;
95 
99  public $marge_gauche;
100 
104  public $marge_droite;
105 
109  public $marge_haute;
110 
114  public $marge_basse;
115 
120  public $emetteur;
121 
122 
128  public function __construct($db)
129  {
130  global $conf, $langs, $mysoc;
131 
132  // Load translation files required by the page
133  $langs->loadLangs(array("main", "bills"));
134 
135  $this->db = $db;
136  $this->name = "cornas";
137  $this->description = $langs->trans('SuppliersCommandModel');
138  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
139 
140  // Page size for A4 format
141  $this->type = 'pdf';
142  $formatarray = pdf_getFormat();
143  $this->page_largeur = $formatarray['width'];
144  $this->page_hauteur = $formatarray['height'];
145  $this->format = array($this->page_largeur, $this->page_hauteur);
146  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
147  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
148  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
149  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
150 
151  $this->option_logo = 1; // Display logo
152  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
153  $this->option_modereg = 1; // Display payment mode
154  $this->option_condreg = 1; // Display payment terms
155  $this->option_multilang = 1; //Available in several languages
156  $this->option_escompte = 0; // Displays if there has been a discount
157  $this->option_credit_note = 0; // Support credit notes
158  $this->option_freetext = 1; // Support add of a personalised text
159  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
160 
161  // Get source company
162  $this->emetteur = $mysoc;
163  if (empty($this->emetteur->country_code)) {
164  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
165  }
166 
167  // Define position of columns
168  $this->posxdesc = $this->marge_gauche + 1; // For module retrocompatibility support durring PDF transition: TODO remove this at the end
169 
170  $this->tva = array();
171  $this->tva_array = array();
172  $this->localtax1 = array();
173  $this->localtax2 = array();
174  $this->atleastoneratenotnull = 0;
175  $this->atleastonediscount = 0;
176  }
177 
178 
179  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
191  public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
192  {
193  // phpcs:enable
194  global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
195 
196  if (!is_object($outputlangs)) {
197  $outputlangs = $langs;
198  }
199  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
200  if (!empty($conf->global->MAIN_USE_FPDF)) {
201  $outputlangs->charset_output = 'ISO-8859-1';
202  }
203 
204  // Load translation files required by the page
205  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
206 
207  global $outputlangsbis;
208  $outputlangsbis = null;
209  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
210  $outputlangsbis = new Translate('', $conf);
211  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
212  $outputlangsbis->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
213  }
214 
215  $nblines = count($object->lines);
216 
217  $hidetop = 0;
218  if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
219  $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
220  }
221 
222  // Loop on each lines to detect if there is at least one image to show
223  $realpatharray = array();
224  if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
225  for ($i = 0; $i < $nblines; $i++) {
226  if (empty($object->lines[$i]->fk_product)) {
227  continue;
228  }
229 
230  $objphoto = new Product($this->db);
231  $objphoto->fetch($object->lines[$i]->fk_product);
232 
233  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
234  $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
235  $dir = $conf->product->dir_output.'/'.$pdir;
236  } else {
237  $pdir = get_exdir($objphoto->id, 0, 0, 0, $objphoto, 'product');
238  $dir = $conf->product->dir_output.'/'.$pdir;
239  }
240 
241  $realpath = '';
242  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
243  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
244  if ($obj['photo_vignette']) {
245  $filename = $obj['photo_vignette'];
246  } else {
247  $filename = $obj['photo'];
248  }
249  } else {
250  $filename = $obj['photo'];
251  }
252  $realpath = $dir.$filename;
253  break;
254  }
255 
256  if ($realpath) {
257  $realpatharray[$i] = $realpath;
258  }
259  }
260  }
261  if (count($realpatharray) == 0) {
262  $this->posxpicture = $this->posxtva;
263  }
264 
265  if ($conf->fournisseur->commande->dir_output) {
266  $object->fetch_thirdparty();
267 
268  $deja_regle = 0;
269  $amount_credit_notes_included = 0;
270  $amount_deposits_included = 0;
271  //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
272  //$amount_deposits_included = $object->getSumDepositsUsed();
273 
274  // Definition of $dir and $file
275  if ($object->specimen) {
276  $dir = $conf->fournisseur->commande->dir_output;
277  $file = $dir."/SPECIMEN.pdf";
278  } else {
279  $objectref = dol_sanitizeFileName($object->ref);
280  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
281  $dir = $conf->fournisseur->commande->dir_output.'/'.$objectref;
282  $file = $dir."/".$objectref.".pdf";
283  if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
284  $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
285  }
286  }
287 
288  if (!file_exists($dir)) {
289  if (dol_mkdir($dir) < 0) {
290  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
291  return 0;
292  }
293  }
294 
295  if (file_exists($dir)) {
296  // Add pdfgeneration hook
297  if (!is_object($hookmanager)) {
298  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
299  $hookmanager = new HookManager($this->db);
300  }
301  $hookmanager->initHooks(array('pdfgeneration'));
302  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
303  global $action;
304  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
305 
306  $nblines = count($object->lines);
307 
308  $pdf = pdf_getInstance($this->format);
309  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
310  $heightforinfotot = 50; // Height reserved to output the info and total part
311  $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
312  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
313  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
314  $heightforfooter += 6;
315  }
316  $pdf->SetAutoPageBreak(1, 0);
317 
318  if (class_exists('TCPDF')) {
319  $pdf->setPrintHeader(false);
320  $pdf->setPrintFooter(false);
321  }
322  $pdf->SetFont(pdf_getPDFFont($outputlangs));
323  // Set path to the background PDF File
324  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
325  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
326  $tplidx = $pdf->importPage(1);
327  }
328 
329  $pdf->Open();
330  $pagenb = 0;
331  $pdf->SetDrawColor(128, 128, 128);
332 
333  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
334  $pdf->SetSubject($outputlangs->transnoentities("Order"));
335  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
336  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
337  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
338  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
339  $pdf->SetCompression(false);
340  }
341 
342  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
343 
344  // Does we have at least one line with discount $this->atleastonediscount
345  foreach ($object->lines as $line) {
346  if ($line->remise_percent) {
347  $this->atleastonediscount = true;
348  break;
349  }
350  }
351 
352  // New page
353  $pdf->AddPage();
354  if (!empty($tplidx)) {
355  $pdf->useTemplate($tplidx);
356  }
357  $pagenb++;
358  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
359  $pdf->SetFont('', '', $default_font_size - 1);
360  $pdf->MultiCell(0, 3, ''); // Set interline to 3
361  $pdf->SetTextColor(0, 0, 0);
362 
363  $tab_top = 90 + $top_shift;
364  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
365 
366  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
367 
368  // Incoterm
369  if (isModEnabled('incoterm')) {
370  $desc_incoterms = $object->getIncotermsForPDF();
371  if ($desc_incoterms) {
372  $tab_top -= 2;
373 
374  $pdf->SetFont('', '', $default_font_size - 1);
375  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
376  $nexY = $pdf->GetY();
377  $height_incoterms = $nexY - $tab_top;
378 
379  // Rect takes a length in 3rd parameter
380  $pdf->SetDrawColor(192, 192, 192);
381  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
382 
383  $tab_top = $nexY + 6;
384  }
385  }
386 
387  // Affiche notes
388  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
389 
390  // Extrafields in note
391  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
392  if (!empty($extranote)) {
393  $notetoshow = dol_concatdesc($notetoshow, $extranote);
394  }
395 
396  $pagenb = $pdf->getPage();
397  if ($notetoshow) {
398  $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
399  $pageposbeforenote = $pagenb;
400 
401  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
402  complete_substitutions_array($substitutionarray, $outputlangs, $object);
403  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
404  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
405 
406  $tab_top -= 2;
407 
408  $pdf->startTransaction();
409 
410  $pdf->SetFont('', '', $default_font_size - 1);
411  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
412  // Description
413  $pageposafternote = $pdf->getPage();
414  $posyafter = $pdf->GetY();
415 
416  if ($pageposafternote > $pageposbeforenote) {
417  $pdf->rollbackTransaction(true);
418 
419  // prepar pages to receive notes
420  while ($pagenb < $pageposafternote) {
421  $pdf->AddPage();
422  $pagenb++;
423  if (!empty($tplidx)) {
424  $pdf->useTemplate($tplidx);
425  }
426  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
427  $this->_pagehead($pdf, $object, 0, $outputlangs);
428  }
429  // $this->_pagefoot($pdf,$object,$outputlangs,1);
430  $pdf->setTopMargin($tab_top_newpage);
431  // The only function to edit the bottom margin of current page to set it.
432  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
433  }
434 
435  // back to start
436  $pdf->setPage($pageposbeforenote);
437  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
438  $pdf->SetFont('', '', $default_font_size - 1);
439  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
440  $pageposafternote = $pdf->getPage();
441 
442  $posyafter = $pdf->GetY();
443 
444  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
445  $pdf->AddPage('', '', true);
446  $pagenb++;
447  $pageposafternote++;
448  $pdf->setPage($pageposafternote);
449  $pdf->setTopMargin($tab_top_newpage);
450  // The only function to edit the bottom margin of current page to set it.
451  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
452  //$posyafter = $tab_top_newpage;
453  }
454 
455 
456  // apply note frame to previus pages
457  $i = $pageposbeforenote;
458  while ($i < $pageposafternote) {
459  $pdf->setPage($i);
460 
461 
462  $pdf->SetDrawColor(128, 128, 128);
463  // Draw note frame
464  if ($i > $pageposbeforenote) {
465  $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
466  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
467  } else {
468  $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
469  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
470  }
471 
472  // Add footer
473  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
474  $this->_pagefoot($pdf, $object, $outputlangs, 1);
475 
476  $i++;
477  }
478 
479  // apply note frame to last page
480  $pdf->setPage($pageposafternote);
481  if (!empty($tplidx)) {
482  $pdf->useTemplate($tplidx);
483  }
484  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
485  $this->_pagehead($pdf, $object, 0, $outputlangs);
486  }
487  $height_note = $posyafter - $tab_top_newpage;
488  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
489  } else {
490  // No pagebreak
491  $pdf->commitTransaction();
492  $posyafter = $pdf->GetY();
493  $height_note = $posyafter - $tab_top;
494  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
495 
496 
497  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
498  // not enough space, need to add page
499  $pdf->AddPage('', '', true);
500  $pagenb++;
501  $pageposafternote++;
502  $pdf->setPage($pageposafternote);
503  if (!empty($tplidx)) {
504  $pdf->useTemplate($tplidx);
505  }
506  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
507  $this->_pagehead($pdf, $object, 0, $outputlangs);
508  }
509 
510  $posyafter = $tab_top_newpage;
511  }
512  }
513 
514  $tab_height = $tab_height - $height_note;
515  $tab_top = $posyafter + 6;
516  } else {
517  $height_note = 0;
518  }
519 
520  $nexY = $tab_top + 5;
521 
522  // Use new auto collum system
523  $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
524 
525  // Loop on each lines
526  $pageposbeforeprintlines = $pdf->getPage();
527  $pagenb = $pageposbeforeprintlines;
528  for ($i = 0; $i < $nblines; $i++) {
529  $curY = $nexY;
530  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
531  $pdf->SetTextColor(0, 0, 0);
532 
533  // Define size of image if we need it
534  $imglinesize = array();
535  if (!empty($realpatharray[$i])) {
536  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
537  }
538 
539  $pdf->setTopMargin($tab_top_newpage);
540  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
541  $pageposbefore = $pdf->getPage();
542 
543  $showpricebeforepagebreak = 1;
544  $posYAfterImage = 0;
545  $posYAfterDescription = 0;
546 
547  // We start with Photo of product line
548  if ($this->getColumnStatus('photo')) {
549  // We start with Photo of product line
550  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
551  $pdf->AddPage('', '', true);
552  if (!empty($tplidx)) {
553  $pdf->useTemplate($tplidx);
554  }
555  $pdf->setPage($pageposbefore + 1);
556 
557  $curY = $tab_top_newpage;
558 
559  // Allows data in the first page if description is long enough to break in multiples pages
560  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
561  $showpricebeforepagebreak = 1;
562  } else {
563  $showpricebeforepagebreak = 0;
564  }
565  }
566 
567  if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
568  $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
569  // $pdf->Image does not increase value return by getY, so we save it manually
570  $posYAfterImage = $curY + $imglinesize['height'];
571  }
572  }
573  // Description of product line
574  $curX = $this->posxdesc - 1;
575  $showpricebeforepagebreak = 1;
576 
577  if ($this->getColumnStatus('desc')) {
578  $pdf->startTransaction();
579  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
580 
581  $pageposafter = $pdf->getPage();
582  if ($pageposafter > $pageposbefore) { // There is a pagebreak
583  $pdf->rollbackTransaction(true);
584 
585  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
586 
587  $pageposafter = $pdf->getPage();
588  $posyafter = $pdf->GetY();
589  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
590  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
591  $pdf->AddPage('', '', true);
592  if (!empty($tplidx)) {
593  $pdf->useTemplate($tplidx);
594  }
595  //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
596  $pdf->setPage($pageposafter + 1);
597  }
598  } else {
599  // We found a page break
600  // Allows data in the first page if description is long enough to break in multiples pages
601  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
602  $showpricebeforepagebreak = 1;
603  } else {
604  $showpricebeforepagebreak = 0;
605  }
606  }
607  } else // No pagebreak
608  {
609  $pdf->commitTransaction();
610  }
611  $posYAfterDescription = $pdf->GetY();
612  }
613 
614  $nexY = $pdf->GetY();
615  $pageposafter = $pdf->getPage();
616  $pdf->setPage($pageposbefore);
617  $pdf->setTopMargin($this->marge_haute);
618  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
619 
620  // We suppose that a too long description is moved completely on next page
621  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
622  $pdf->setPage($pageposafter);
623  $curY = $tab_top_newpage;
624  }
625 
626  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
627 
628  // VAT Rate
629  if ($this->getColumnStatus('vat')) {
630  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
631  $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
632  $nexY = max($pdf->GetY(), $nexY);
633  }
634 
635  // Unit price before discount
636  if ($this->getColumnStatus('subprice')) {
637  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
638  $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
639  $nexY = max($pdf->GetY(), $nexY);
640  }
641 
642  // Quantity
643  // Enough for 6 chars
644  if ($this->getColumnStatus('qty')) {
645  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
646  $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
647  $nexY = max($pdf->GetY(), $nexY);
648  }
649 
650 
651  // Unit
652  if ($this->getColumnStatus('unit')) {
653  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
654  $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
655  $nexY = max($pdf->GetY(), $nexY);
656  }
657 
658  // Discount on line
659  if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
660  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
661  $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
662  $nexY = max($pdf->GetY(), $nexY);
663  }
664 
665  // Total HT line
666  if ($this->getColumnStatus('totalexcltax')) {
667  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
668  $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
669  $nexY = max($pdf->GetY(), $nexY);
670  }
671 
672  // Extrafields
673  if (!empty($object->lines[$i]->array_options)) {
674  foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
675  if ($this->getColumnStatus($extrafieldColKey)) {
676  $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
677  $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
678  $nexY = max($pdf->GetY(), $nexY);
679  }
680  }
681  }
682 
683  $parameters = array(
684  'object' => $object,
685  'i' => $i,
686  'pdf' =>& $pdf,
687  'curY' =>& $curY,
688  'nexY' =>& $nexY,
689  'outputlangs' => $outputlangs,
690  'hidedetails' => $hidedetails
691  );
692  $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
693 
694 
695  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
696  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
697  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
698  } else {
699  $tvaligne = $object->lines[$i]->total_tva;
700  }
701 
702  $localtax1ligne = $object->lines[$i]->total_localtax1;
703  $localtax2ligne = $object->lines[$i]->total_localtax2;
704  $localtax1_rate = $object->lines[$i]->localtax1_tx;
705  $localtax2_rate = $object->lines[$i]->localtax2_tx;
706  $localtax1_type = $object->lines[$i]->localtax1_type;
707  $localtax2_type = $object->lines[$i]->localtax2_type;
708 
709  if (!empty($object->remise_percent)) {
710  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
711  }
712  if (!empty($object->remise_percent)) {
713  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
714  }
715  if (!empty($object->remise_percent)) {
716  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
717  }
718 
719  $vatrate = (string) $object->lines[$i]->tva_tx;
720 
721  // Retrieve type from database for backward compatibility with old records
722  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
723  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
724  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty);
725  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
726  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
727  }
728 
729  // retrieve global local tax
730  if ($localtax1_type && $localtax1ligne != 0) {
731  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
732  }
733  if ($localtax2_type && $localtax2ligne != 0) {
734  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
735  }
736 
737  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
738  $vatrate .= '*';
739  }
740 
741  // Fill $this->tva and $this->tva_array
742  if (!isset($this->tva[$vatrate])) {
743  $this->tva[$vatrate] = 0;
744  }
745  $this->tva[$vatrate] += $tvaligne;
746  $vatcode = $object->lines[$i]->vat_src_code;
747  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
748  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
749  }
750  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
751 
752  if ($posYAfterImage > $posYAfterDescription) {
753  $nexY = $posYAfterImage;
754  }
755 
756  // Add line
757  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
758  $pdf->setPage($pageposafter);
759  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
760  //$pdf->SetDrawColor(190,190,200);
761  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
762  $pdf->SetLineStyle(array('dash'=>0));
763  }
764 
765  // Detect if some page were added automatically and output _tableau for past pages
766  while ($pagenb < $pageposafter) {
767  $pdf->setPage($pagenb);
768  if ($pagenb == $pageposbeforeprintlines) {
769  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
770  } else {
771  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
772  }
773  $this->_pagefoot($pdf, $object, $outputlangs, 1);
774  $pagenb++;
775  $pdf->setPage($pagenb);
776  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
777  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
778  $this->_pagehead($pdf, $object, 0, $outputlangs);
779  }
780  if (!empty($tplidx)) {
781  $pdf->useTemplate($tplidx);
782  }
783  }
784  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
785  if ($pagenb == $pageposafter) {
786  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
787  } else {
788  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
789  }
790  $this->_pagefoot($pdf, $object, $outputlangs, 1);
791  // New page
792  $pdf->AddPage();
793  if (!empty($tplidx)) {
794  $pdf->useTemplate($tplidx);
795  }
796  $pagenb++;
797  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
798  $this->_pagehead($pdf, $object, 0, $outputlangs);
799  }
800  }
801  }
802 
803  // Show square
804  if ($pagenb == $pageposbeforeprintlines) {
805  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
806  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
807  } else {
808  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
809  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
810  }
811 
812  // Affiche zone infos
813  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
814 
815  // Affiche zone totaux
816  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
817 
818  // Affiche zone versements
819  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
820  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
821  }
822 
823  // Pied de page
824  $this->_pagefoot($pdf, $object, $outputlangs);
825  if (method_exists($pdf, 'AliasNbPages')) {
826  $pdf->AliasNbPages();
827  }
828 
829  $pdf->Close();
830 
831  $pdf->Output($file, 'F');
832 
833  // Add pdfgeneration hook
834  $hookmanager->initHooks(array('pdfgeneration'));
835  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
836  global $action;
837  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
838  if ($reshook < 0) {
839  $this->error = $hookmanager->error;
840  $this->errors = $hookmanager->errors;
841  }
842 
843  if (!empty($conf->global->MAIN_UMASK)) {
844  @chmod($file, octdec($conf->global->MAIN_UMASK));
845  }
846 
847  $this->result = array('fullpath'=>$file);
848 
849  return 1; // No error
850  } else {
851  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
852  return 0;
853  }
854  } else {
855  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
856  return 0;
857  }
858  }
859 
860  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
861  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
871  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
872  {
873  // phpcs:enable
874  }
875 
876  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
877  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
887  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
888  {
889  // phpcs:enable
890  global $conf, $mysoc;
891  $default_font_size = pdf_getPDFFontSize($outputlangs);
892 
893  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
894 
895  // If France, show VAT mention if not applicable
896  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
897  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
898  $pdf->SetXY($this->marge_gauche, $posy);
899  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
900 
901  $posy = $pdf->GetY() + 4;
902  }
903 
904  $posxval = 52;
905 
906  // Show payments conditions
907  if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
908  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
909  $pdf->SetXY($this->marge_gauche, $posy);
910  $titre = $outputlangs->transnoentities("PaymentConditions").':';
911  $pdf->MultiCell(80, 4, $titre, 0, 'L');
912 
913  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
914  $pdf->SetXY($posxval, $posy);
915  $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);
916  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
917  $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
918 
919  $posy = $pdf->GetY() + 3;
920  }
921 
922  // Show payment mode
923  if (!empty($object->mode_reglement_code)) {
924  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
925  $pdf->SetXY($this->marge_gauche, $posy);
926  $titre = $outputlangs->transnoentities("PaymentMode").':';
927  $pdf->MultiCell(80, 5, $titre, 0, 'L');
928 
929  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
930  $pdf->SetXY($posxval, $posy);
931  $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);
932  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
933 
934  $posy = $pdf->GetY() + 2;
935  }
936 
937 
938  return $posy;
939  }
940 
941  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
942  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
953  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
954  {
955  // phpcs:enable
956  global $conf, $mysoc;
957 
958  $default_font_size = pdf_getPDFFontSize($outputlangs);
959 
960  $tab2_top = $posy;
961  $tab2_hl = 4;
962  $pdf->SetFont('', '', $default_font_size - 1);
963 
964  // Tableau total
965  $col1x = 120;
966  $col2x = 170;
967  if ($this->page_largeur < 210) { // To work with US executive format
968  $col2x -= 20;
969  }
970  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
971 
972  $useborder = 0;
973  $index = 0;
974 
975  // Total HT
976  $pdf->SetFillColor(255, 255, 255);
977  $pdf->SetXY($col1x, $tab2_top + 0);
978  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
979 
980  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
981  $pdf->SetXY($col2x, $tab2_top + 0);
982  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
983 
984  // Show VAT by rates and total
985  $pdf->SetFillColor(248, 248, 248);
986 
987  $this->atleastoneratenotnull = 0;
988  foreach ($this->tva as $tvakey => $tvaval) {
989  if ($tvakey > 0) { // On affiche pas taux 0
990  $this->atleastoneratenotnull++;
991 
992  $index++;
993  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
994 
995  $tvacompl = '';
996 
997  if (preg_match('/\*/', $tvakey)) {
998  $tvakey = str_replace('*', '', $tvakey);
999  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1000  }
1001 
1002  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1003  $totalvat .= vatrate($tvakey, 1).$tvacompl;
1004  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1005 
1006  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1007  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
1008  }
1009  }
1010  if (!$this->atleastoneratenotnull) { // If no vat at all
1011  $index++;
1012  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1013  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
1014 
1015  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1016  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
1017 
1018  // Total LocalTax1
1019  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
1020  $index++;
1021  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1022  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
1023  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1024  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
1025  }
1026 
1027  // Total LocalTax2
1028  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
1029  $index++;
1030  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1031  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
1032  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1033  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
1034  }
1035  } else {
1036  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1037  //{
1038  //Local tax 1
1039  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1040  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1041  continue;
1042  }
1043 
1044  foreach ($localtax_rate as $tvakey => $tvaval) {
1045  if ($tvakey != 0) { // On affiche pas taux 0
1046  //$this->atleastoneratenotnull++;
1047 
1048  $index++;
1049  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1050 
1051  $tvacompl = '';
1052  if (preg_match('/\*/', $tvakey)) {
1053  $tvakey = str_replace('*', '', $tvakey);
1054  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1055  }
1056  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1057  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1058  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1059 
1060  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1061  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1062  }
1063  }
1064  }
1065 
1066  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1067  //{
1068  //Local tax 2
1069  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1070  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1071  continue;
1072  }
1073 
1074  foreach ($localtax_rate as $tvakey => $tvaval) {
1075  if ($tvakey != 0) { // On affiche pas taux 0
1076  //$this->atleastoneratenotnull++;
1077 
1078  $index++;
1079  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1080 
1081  $tvacompl = '';
1082  if (preg_match('/\*/', $tvakey)) {
1083  $tvakey = str_replace('*', '', $tvakey);
1084  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1085  }
1086  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1087  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1088  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1089 
1090  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1091  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
1092  }
1093  }
1094  }
1095  }
1096 
1097  // Total TTC
1098  $index++;
1099  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1100  $pdf->SetTextColor(0, 0, 60);
1101  $pdf->SetFillColor(224, 224, 224);
1102  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1103 
1104  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1105  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1106  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
1107  $pdf->SetFont('', '', $default_font_size - 1);
1108  $pdf->SetTextColor(0, 0, 0);
1109 
1110  $creditnoteamount = 0;
1111  $depositsamount = 0;
1112  //$creditnoteamount=$object->getSumCreditNotesUsed();
1113  //$depositsamount=$object->getSumDepositsUsed();
1114  //print "x".$creditnoteamount."-".$depositsamount;exit;
1115  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1116  if (!empty($object->paye)) {
1117  $resteapayer = 0;
1118  }
1119 
1120  if ($deja_regle > 0) {
1121  // Already paid + Deposits
1122  $index++;
1123 
1124  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1125  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1126  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1127  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
1128 
1129  $index++;
1130  $pdf->SetTextColor(0, 0, 60);
1131  $pdf->SetFillColor(224, 224, 224);
1132  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1133  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1134 
1135  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1136  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
1137 
1138  $pdf->SetFont('', '', $default_font_size - 1);
1139  $pdf->SetTextColor(0, 0, 0);
1140  }
1141 
1142  $index++;
1143  return ($tab2_top + ($tab2_hl * $index));
1144  }
1145 
1146  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1160  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1161  {
1162  global $conf;
1163 
1164  // Force to disable hidetop and hidebottom
1165  $hidebottom = 0;
1166  if ($hidetop) {
1167  $hidetop = -1;
1168  }
1169 
1170  $currency = !empty($currency) ? $currency : $conf->currency;
1171  $default_font_size = pdf_getPDFFontSize($outputlangs);
1172 
1173  // Amount in (at tab_top - 1)
1174  $pdf->SetTextColor(0, 0, 0);
1175  $pdf->SetFont('', '', $default_font_size - 2);
1176 
1177  if (empty($hidetop)) {
1178  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1179  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1180  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1181 
1182  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1183  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1184  $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));
1185  }
1186  }
1187 
1188  $pdf->SetDrawColor(128, 128, 128);
1189  $pdf->SetFont('', '', $default_font_size - 1);
1190 
1191  // Output Rect
1192  $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
1193 
1194  foreach ($this->cols as $colKey => $colDef) {
1195  if (!$this->getColumnStatus($colKey)) {
1196  continue;
1197  }
1198 
1199  // get title label
1200  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1201 
1202  // Add column separator
1203  if (!empty($colDef['border-left'])) {
1204  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1205  }
1206 
1207  if (empty($hidetop)) {
1208  $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
1209 
1210  $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
1211  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1212  }
1213  }
1214 
1215  if (empty($hidetop)) {
1216  $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
1217  }
1218  }
1219 
1220  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1230  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1231  {
1232  global $langs, $conf, $mysoc;
1233 
1234  $ltrdirection = 'L';
1235  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1236 
1237  // Load translation files required by the page
1238  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1239 
1240  $default_font_size = pdf_getPDFFontSize($outputlangs);
1241 
1242  // Do not add the BACKGROUND as this is for suppliers
1243  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1244 
1245  //Affiche le filigrane brouillon - Print Draft Watermark
1246  /*if($object->statut==0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
1247  {
1248  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
1249  }*/
1250  //Print content
1251 
1252  $pdf->SetTextColor(0, 0, 60);
1253  $pdf->SetFont('', 'B', $default_font_size + 3);
1254 
1255  $posx = $this->page_largeur - $this->marge_droite - 100;
1256  $posy = $this->marge_haute;
1257 
1258  $pdf->SetXY($this->marge_gauche, $posy);
1259 
1260  // Logo
1261  if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
1262  if ($this->emetteur->logo) {
1263  $logodir = $conf->mycompany->dir_output;
1264  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1265  $logodir = $conf->mycompany->multidir_output[$object->entity];
1266  }
1267  if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
1268  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1269  } else {
1270  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1271  }
1272  if (is_readable($logo)) {
1273  $height = pdf_getHeightForLogo($logo);
1274  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1275  } else {
1276  $pdf->SetTextColor(200, 0, 0);
1277  $pdf->SetFont('', 'B', $default_font_size - 2);
1278  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1279  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1280  }
1281  } else {
1282  $text = $this->emetteur->name;
1283  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1284  }
1285  }
1286 
1287  $pdf->SetFont('', 'B', $default_font_size + 3);
1288  $pdf->SetXY($posx, $posy);
1289  $pdf->SetTextColor(0, 0, 60);
1290  $title = $outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1291  $pdf->MultiCell(100, 3, $title, '', 'R');
1292  $posy += 1;
1293 
1294  if ($object->ref_supplier) {
1295  $posy += 4;
1296  $pdf->SetFont('', 'B', $default_font_size);
1297  $pdf->SetXY($posx, $posy);
1298  $pdf->SetTextColor(0, 0, 60);
1299  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1300  $posy += 1;
1301  }
1302 
1303  $pdf->SetFont('', '', $default_font_size - 1);
1304 
1305  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1306  $object->fetch_projet();
1307  if (!empty($object->project->ref)) {
1308  $posy += 3;
1309  $pdf->SetXY($posx, $posy);
1310  $pdf->SetTextColor(0, 0, 60);
1311  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1312  }
1313  }
1314 
1315  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1316  $object->fetch_projet();
1317  if (!empty($object->project->ref)) {
1318  $outputlangs->load("projects");
1319  $posy += 4;
1320  $pdf->SetXY($posx, $posy);
1321  $langs->load("projects");
1322  $pdf->SetTextColor(0, 0, 60);
1323  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1324  }
1325  }
1326 
1327  if (!empty($object->date_commande)) {
1328  $posy += 5;
1329  $pdf->SetXY($posx, $posy);
1330  $pdf->SetTextColor(0, 0, 60);
1331  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R');
1332  } else {
1333  $posy += 5;
1334  $pdf->SetXY($posx, $posy);
1335  $pdf->SetTextColor(255, 0, 0);
1336  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1337  }
1338 
1339  $pdf->SetTextColor(0, 0, 60);
1340  $usehourmin = 'day';
1341  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1342  $usehourmin = 'dayhour';
1343  }
1344  if (!empty($object->delivery_date)) {
1345  $posy += 4;
1346  $pdf->SetXY($posx - 90, $posy);
1347  $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1348  }
1349 
1350  if ($object->thirdparty->code_fournisseur) {
1351  $posy += 4;
1352  $pdf->SetXY($posx, $posy);
1353  $pdf->SetTextColor(0, 0, 60);
1354  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1355  }
1356 
1357  // Get contact
1358  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1359  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1360  if (count($arrayidcontact) > 0) {
1361  $usertmp = new User($this->db);
1362  $usertmp->fetch($arrayidcontact[0]);
1363  $posy += 4;
1364  $pdf->SetXY($posx, $posy);
1365  $pdf->SetTextColor(0, 0, 60);
1366  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1367  }
1368  }
1369 
1370  $posy += 1;
1371  $pdf->SetTextColor(0, 0, 60);
1372 
1373  $top_shift = 0;
1374  // Show list of linked objects
1375  $current_y = $pdf->getY();
1376  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1377  if ($current_y < $pdf->getY()) {
1378  $top_shift = $pdf->getY() - $current_y;
1379  }
1380 
1381  if ($showaddress) {
1382  // Sender properties
1383  $carac_emetteur = '';
1384  // Add internal contact of proposal if defined
1385  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1386  if (count($arrayidcontact) > 0) {
1387  $object->fetch_user($arrayidcontact[0]);
1388  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1389  }
1390 
1391  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1392 
1393  // Show sender
1394  $posy = 42 + $top_shift;
1395  $posx = $this->marge_gauche;
1396  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1397  $posx = $this->page_largeur - $this->marge_droite - 80;
1398  }
1399  $hautcadre = 40;
1400 
1401  // Show sender frame
1402  $pdf->SetTextColor(0, 0, 0);
1403  $pdf->SetFont('', '', $default_font_size - 2);
1404  $pdf->SetXY($posx, $posy - 5);
1405  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1406  $pdf->SetXY($posx, $posy);
1407  $pdf->SetFillColor(230, 230, 230);
1408  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1409  $pdf->SetTextColor(0, 0, 60);
1410 
1411  // Show sender name
1412  $pdf->SetXY($posx + 2, $posy + 3);
1413  $pdf->SetFont('', 'B', $default_font_size);
1414  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1415  $posy = $pdf->getY();
1416 
1417  // Show sender information
1418  $pdf->SetXY($posx + 2, $posy);
1419  $pdf->SetFont('', '', $default_font_size - 1);
1420  $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1421 
1422 
1423 
1424  // If CUSTOMER contact defined on order, we use it. Note: Even if this is a supplier object, the code for external contat that follow order is 'CUSTOMER'
1425  $usecontact = false;
1426  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1427  if (count($arrayidcontact) > 0) {
1428  $usecontact = true;
1429  $result = $object->fetch_contact($arrayidcontact[0]);
1430  }
1431 
1432  // Recipient name
1433  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)))) {
1434  $thirdparty = $object->contact;
1435  } else {
1436  $thirdparty = $object->thirdparty;
1437  }
1438 
1439  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1440 
1441  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1442 
1443  // Show recipient
1444  $widthrecbox = 100;
1445  if ($this->page_largeur < 210) {
1446  $widthrecbox = 84; // To work with US executive format
1447  }
1448  $posy = 42 + $top_shift;
1449  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1450  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1451  $posx = $this->marge_gauche;
1452  }
1453 
1454  // Show recipient frame
1455  $pdf->SetTextColor(0, 0, 0);
1456  $pdf->SetFont('', '', $default_font_size - 2);
1457  $pdf->SetXY($posx + 2, $posy - 5);
1458  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1459  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1460 
1461  // Show recipient name
1462  $pdf->SetXY($posx + 2, $posy + 3);
1463  $pdf->SetFont('', 'B', $default_font_size);
1464  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1465 
1466  $posy = $pdf->getY();
1467 
1468  // Show recipient information
1469  $pdf->SetFont('', '', $default_font_size - 1);
1470  $pdf->SetXY($posx + 2, $posy);
1471  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1472  }
1473 
1474  return $top_shift;
1475  }
1476 
1477  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1487  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1488  {
1489  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1490  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1491  }
1492 
1493 
1494 
1505  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1506  {
1507  global $conf, $hookmanager;
1508 
1509  // Default field style for content
1510  $this->defaultContentsFieldsStyle = array(
1511  'align' => 'R', // R,C,L
1512  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1513  );
1514 
1515  // Default field style for content
1516  $this->defaultTitlesFieldsStyle = array(
1517  'align' => 'C', // R,C,L
1518  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1519  );
1520 
1521  /*
1522  * For exemple
1523  $this->cols['theColKey'] = array(
1524  'rank' => $rank, // int : use for ordering columns
1525  'width' => 20, // the column width in mm
1526  'title' => array(
1527  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1528  'label' => ' ', // the final label : used fore final generated text
1529  'align' => 'L', // text alignement : R,C,L
1530  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1531  ),
1532  'content' => array(
1533  'align' => 'L', // text alignement : R,C,L
1534  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1535  ),
1536  );
1537  */
1538 
1539  $rank = 0; // do not use negative rank
1540  $this->cols['desc'] = array(
1541  'rank' => $rank,
1542  'width' => false, // only for desc
1543  'status' => true,
1544  'title' => array(
1545  'textkey' => 'Designation', // use lang key is usefull in somme case with module
1546  'align' => 'L',
1547  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1548  // 'label' => ' ', // the final label
1549  'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1550  ),
1551  'content' => array(
1552  'align' => 'L',
1553  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1554  ),
1555  );
1556 
1557  $rank = $rank + 10;
1558  $this->cols['photo'] = array(
1559  'rank' => $rank,
1560  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1561  'status' => false,
1562  'title' => array(
1563  'textkey' => 'Photo',
1564  'label' => ' '
1565  ),
1566  'content' => array(
1567  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1568  ),
1569  'border-left' => false, // remove left line separator
1570  );
1571 
1572  if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
1573  $this->cols['photo']['status'] = true;
1574  }
1575 
1576 
1577  $rank = $rank + 10;
1578  $this->cols['vat'] = array(
1579  'rank' => $rank,
1580  'status' => false,
1581  'width' => 16, // in mm
1582  'title' => array(
1583  'textkey' => 'VAT'
1584  ),
1585  'border-left' => true, // add left line separator
1586  );
1587 
1588  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1589  $this->cols['vat']['status'] = true;
1590  }
1591 
1592  $rank = $rank + 10;
1593  $this->cols['subprice'] = array(
1594  'rank' => $rank,
1595  'width' => 19, // in mm
1596  'status' => false,
1597  'title' => array(
1598  'textkey' => 'PriceUHT'
1599  ),
1600  'border-left' => true, // add left line separator
1601  );
1602 
1603  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE)) {
1604  $this->cols['subprice']['status'] = true;
1605  }
1606 
1607  $rank = $rank + 10;
1608  $this->cols['qty'] = array(
1609  'rank' => $rank,
1610  'width' => 16, // in mm
1611  'status' => true,
1612  'title' => array(
1613  'textkey' => 'Qty'
1614  ),
1615  'border-left' => true, // add left line separator
1616  );
1617 
1618  $rank = $rank + 10;
1619  $this->cols['unit'] = array(
1620  'rank' => $rank,
1621  'width' => 11, // in mm
1622  'status' => false,
1623  'title' => array(
1624  'textkey' => 'Unit'
1625  ),
1626  'border-left' => true, // add left line separator
1627  );
1628  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1629  $this->cols['unit']['status'] = true;
1630  }
1631 
1632  $rank = $rank + 10;
1633  $this->cols['discount'] = array(
1634  'rank' => $rank,
1635  'width' => 13, // in mm
1636  'status' => false,
1637  'title' => array(
1638  'textkey' => 'ReductionShort'
1639  ),
1640  'border-left' => true, // add left line separator
1641  );
1642  if ($this->atleastonediscount) {
1643  $this->cols['discount']['status'] = true;
1644  }
1645 
1646  $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1647  $this->cols['totalexcltax'] = array(
1648  'rank' => $rank,
1649  'width' => 26, // in mm
1650  'status' => true,
1651  'title' => array(
1652  'textkey' => 'TotalHT'
1653  ),
1654  'border-left' => true, // add left line separator
1655  );
1656 
1657  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN)) {
1658  $this->cols['totalexcltax']['status'] = true;
1659  }
1660 
1661  // Add extrafields cols
1662  if (!empty($object->lines)) {
1663  $line = reset($object->lines);
1664  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1665  }
1666 
1667  $parameters = array(
1668  'object' => $object,
1669  'outputlangs' => $outputlangs,
1670  'hidedetails' => $hidedetails,
1671  'hidedesc' => $hidedesc,
1672  'hideref' => $hideref
1673  );
1674 
1675  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1676  if ($reshook < 0) {
1677  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1678  } elseif (empty($reshook)) {
1679  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1680  } else {
1681  $this->cols = $hookmanager->resArray;
1682  }
1683  }
1684 }
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:8166
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1820
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:6264
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:2510
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1967
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1882
pdf_cornas
Class to generate the supplier orders with the cornas model.
Definition: pdf_cornas.modules.php:42
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
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:2171
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_cornas\defineColumnField
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
Definition: pdf_cornas.modules.php:1505
CommonDocGenerator\getColumnContentXStart
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
Definition: commondocgenerator.class.php:1111
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
CommonDocGenerator\printStdColumnContent
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
Definition: commondocgenerator.class.php:1185
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:2128
pdf_cornas\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_cornas.modules.php:1487
name
$conf db name
Definition: repair.php:122
CommonDocGenerator\getExtrafieldContent
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
Definition: commondocgenerator.class.php:1268
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
CommonDocGenerator\prepareArrayColumnField
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
Definition: commondocgenerator.class.php:1026
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:2550
pdf_cornas\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
Definition: pdf_cornas.modules.php:1160
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:7542
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
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:6735
pdf_cornas\_tableau_info
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Definition: pdf_cornas.modules.php:887
pdf_cornas\_tableau_versements
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
Definition: pdf_cornas.modules.php:871
pdf_cornas\write_file
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_cornas.modules.php:191
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:982
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:1323
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_cornas\__construct
__construct($db)
Constructor.
Definition: pdf_cornas.modules.php:128
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:2721
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
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
pdf_cornas\_tableau_tot
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
Definition: pdf_cornas.modules.php:953
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:7277
CommonDocGenerator\printColDescContent
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
Definition: commondocgenerator.class.php:1231
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:749
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:5697
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
ModelePDFSuppliersOrders
Parent class for supplier orders models.
Definition: modules_commandefournisseur.php:38
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6789
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2265
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
CommonDocGenerator\defineColumnExtrafield
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Definition: commondocgenerator.class.php:1608
CommonDocGenerator\getColumnStatus
getColumnStatus($colKey)
get column status from column key
Definition: commondocgenerator.class.php:1508
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
pdf_cornas\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_cornas.modules.php:1230
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:8289
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:5648
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:1001
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25