dolibarr  18.0.0-alpha
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  dolChmod($file);
844 
845  $this->result = array('fullpath'=>$file);
846 
847  return 1; // No error
848  } else {
849  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
850  return 0;
851  }
852  } else {
853  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
854  return 0;
855  }
856  }
857 
858  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
859  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
869  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
870  {
871  // phpcs:enable
872  }
873 
874  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
875  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
885  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
886  {
887  // phpcs:enable
888  global $conf, $mysoc;
889  $default_font_size = pdf_getPDFFontSize($outputlangs);
890 
891  // If France, show VAT mention if not applicable
892  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
893  $pdf->SetFont('', 'B', $default_font_size - 2);
894  $pdf->SetXY($this->marge_gauche, $posy);
895  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
896 
897  $posy = $pdf->GetY() + 4;
898  }
899 
900  $posxval = 52;
901 
902  // Show payments conditions
903  if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
904  $pdf->SetFont('', 'B', $default_font_size - 2);
905  $pdf->SetXY($this->marge_gauche, $posy);
906  $titre = $outputlangs->transnoentities("PaymentConditions").':';
907  $pdf->MultiCell(80, 4, $titre, 0, 'L');
908 
909  $pdf->SetFont('', '', $default_font_size - 2);
910  $pdf->SetXY($posxval, $posy);
911  $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);
912  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
913  $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
914 
915  $posy = $pdf->GetY() + 3;
916  }
917 
918  // Show payment mode
919  if (!empty($object->mode_reglement_code)) {
920  $pdf->SetFont('', 'B', $default_font_size - 2);
921  $pdf->SetXY($this->marge_gauche, $posy);
922  $titre = $outputlangs->transnoentities("PaymentMode").':';
923  $pdf->MultiCell(80, 5, $titre, 0, 'L');
924 
925  $pdf->SetFont('', '', $default_font_size - 2);
926  $pdf->SetXY($posxval, $posy);
927  $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);
928  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
929 
930  $posy = $pdf->GetY() + 2;
931  }
932 
933 
934  return $posy;
935  }
936 
937  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
938  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
949  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
950  {
951  // phpcs:enable
952  global $conf, $mysoc;
953 
954  $default_font_size = pdf_getPDFFontSize($outputlangs);
955 
956  $tab2_top = $posy;
957  $tab2_hl = 4;
958  $pdf->SetFont('', '', $default_font_size - 1);
959 
960  // Tableau total
961  $col1x = 120;
962  $col2x = 170;
963  if ($this->page_largeur < 210) { // To work with US executive format
964  $col2x -= 20;
965  }
966  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
967 
968  $useborder = 0;
969  $index = 0;
970 
971  // Total HT
972  $pdf->SetFillColor(255, 255, 255);
973  $pdf->SetXY($col1x, $tab2_top);
974  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
975 
976  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
977  $pdf->SetXY($col2x, $tab2_top);
978  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
979 
980  // Show VAT by rates and total
981  $pdf->SetFillColor(248, 248, 248);
982 
983  $this->atleastoneratenotnull = 0;
984  foreach ($this->tva as $tvakey => $tvaval) {
985  if ($tvakey > 0) { // On affiche pas taux 0
986  $this->atleastoneratenotnull++;
987 
988  $index++;
989  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
990 
991  $tvacompl = '';
992 
993  if (preg_match('/\*/', $tvakey)) {
994  $tvakey = str_replace('*', '', $tvakey);
995  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
996  }
997 
998  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
999  $totalvat .= vatrate($tvakey, 1).$tvacompl;
1000  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1001 
1002  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1003  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
1004  }
1005  }
1006  if (!$this->atleastoneratenotnull) { // If no vat at all
1007  $index++;
1008  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1009  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
1010 
1011  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1012  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
1013 
1014  // Total LocalTax1
1015  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
1016  $index++;
1017  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1018  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
1019  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1020  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
1021  }
1022 
1023  // Total LocalTax2
1024  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
1025  $index++;
1026  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1027  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
1028  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1029  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
1030  }
1031  } else {
1032  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1033  //{
1034  //Local tax 1
1035  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1036  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1037  continue;
1038  }
1039 
1040  foreach ($localtax_rate as $tvakey => $tvaval) {
1041  if ($tvakey != 0) { // On affiche pas taux 0
1042  //$this->atleastoneratenotnull++;
1043 
1044  $index++;
1045  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1046 
1047  $tvacompl = '';
1048  if (preg_match('/\*/', $tvakey)) {
1049  $tvakey = str_replace('*', '', $tvakey);
1050  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1051  }
1052  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1053  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1054  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1055 
1056  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1057  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1058  }
1059  }
1060  }
1061 
1062  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1063  //{
1064  //Local tax 2
1065  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1066  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1067  continue;
1068  }
1069 
1070  foreach ($localtax_rate as $tvakey => $tvaval) {
1071  if ($tvakey != 0) { // On affiche pas taux 0
1072  //$this->atleastoneratenotnull++;
1073 
1074  $index++;
1075  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1076 
1077  $tvacompl = '';
1078  if (preg_match('/\*/', $tvakey)) {
1079  $tvakey = str_replace('*', '', $tvakey);
1080  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1081  }
1082  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1083  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1084  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1085 
1086  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1087  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
1088  }
1089  }
1090  }
1091  }
1092 
1093  // Total TTC
1094  $index++;
1095  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1096  $pdf->SetTextColor(0, 0, 60);
1097  $pdf->SetFillColor(224, 224, 224);
1098  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1099 
1100  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1101  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1102  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
1103  $pdf->SetFont('', '', $default_font_size - 1);
1104  $pdf->SetTextColor(0, 0, 0);
1105 
1106  $creditnoteamount = 0;
1107  $depositsamount = 0;
1108  //$creditnoteamount=$object->getSumCreditNotesUsed();
1109  //$depositsamount=$object->getSumDepositsUsed();
1110  //print "x".$creditnoteamount."-".$depositsamount;exit;
1111  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1112  if (!empty($object->paye)) {
1113  $resteapayer = 0;
1114  }
1115 
1116  if ($deja_regle > 0) {
1117  // Already paid + Deposits
1118  $index++;
1119 
1120  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1121  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1122  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1123  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
1124 
1125  $index++;
1126  $pdf->SetTextColor(0, 0, 60);
1127  $pdf->SetFillColor(224, 224, 224);
1128  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1129  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1130 
1131  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1132  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
1133 
1134  $pdf->SetFont('', '', $default_font_size - 1);
1135  $pdf->SetTextColor(0, 0, 0);
1136  }
1137 
1138  $index++;
1139  return ($tab2_top + ($tab2_hl * $index));
1140  }
1141 
1142  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1156  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1157  {
1158  global $conf;
1159 
1160  // Force to disable hidetop and hidebottom
1161  $hidebottom = 0;
1162  if ($hidetop) {
1163  $hidetop = -1;
1164  }
1165 
1166  $currency = !empty($currency) ? $currency : $conf->currency;
1167  $default_font_size = pdf_getPDFFontSize($outputlangs);
1168 
1169  // Amount in (at tab_top - 1)
1170  $pdf->SetTextColor(0, 0, 0);
1171  $pdf->SetFont('', '', $default_font_size - 2);
1172 
1173  if (empty($hidetop)) {
1174  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1175  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1176  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1177 
1178  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1179  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1180  $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));
1181  }
1182  }
1183 
1184  $pdf->SetDrawColor(128, 128, 128);
1185  $pdf->SetFont('', '', $default_font_size - 1);
1186 
1187  // Output Rect
1188  $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
1189 
1190  foreach ($this->cols as $colKey => $colDef) {
1191  if (!$this->getColumnStatus($colKey)) {
1192  continue;
1193  }
1194 
1195  // get title label
1196  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1197 
1198  // Add column separator
1199  if (!empty($colDef['border-left'])) {
1200  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1201  }
1202 
1203  if (empty($hidetop)) {
1204  $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
1205 
1206  $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
1207  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1208  }
1209  }
1210 
1211  if (empty($hidetop)) {
1212  $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
1213  }
1214  }
1215 
1216  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1226  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1227  {
1228  global $langs, $conf, $mysoc;
1229 
1230  $ltrdirection = 'L';
1231  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1232 
1233  // Load translation files required by the page
1234  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1235 
1236  $default_font_size = pdf_getPDFFontSize($outputlangs);
1237 
1238  // Do not add the BACKGROUND as this is for suppliers
1239  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1240 
1241  //Affiche le filigrane brouillon - Print Draft Watermark
1242  /*if($object->statut==0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK'))
1243  {
1244  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1245  }*/
1246  //Print content
1247 
1248  $pdf->SetTextColor(0, 0, 60);
1249  $pdf->SetFont('', 'B', $default_font_size + 3);
1250 
1251  $posx = $this->page_largeur - $this->marge_droite - 100;
1252  $posy = $this->marge_haute;
1253 
1254  $pdf->SetXY($this->marge_gauche, $posy);
1255 
1256  // Logo
1257  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1258  if ($this->emetteur->logo) {
1259  $logodir = $conf->mycompany->dir_output;
1260  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1261  $logodir = $conf->mycompany->multidir_output[$object->entity];
1262  }
1263  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1264  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1265  } else {
1266  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1267  }
1268  if (is_readable($logo)) {
1269  $height = pdf_getHeightForLogo($logo);
1270  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1271  } else {
1272  $pdf->SetTextColor(200, 0, 0);
1273  $pdf->SetFont('', 'B', $default_font_size - 2);
1274  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1275  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1276  }
1277  } else {
1278  $text = $this->emetteur->name;
1279  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1280  }
1281  }
1282 
1283  $pdf->SetFont('', 'B', $default_font_size + 3);
1284  $pdf->SetXY($posx, $posy);
1285  $pdf->SetTextColor(0, 0, 60);
1286  $title = $outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1287  $pdf->MultiCell(100, 3, $title, '', 'R');
1288  $posy += 1;
1289 
1290  if ($object->ref_supplier) {
1291  $posy += 4;
1292  $pdf->SetFont('', 'B', $default_font_size);
1293  $pdf->SetXY($posx, $posy);
1294  $pdf->SetTextColor(0, 0, 60);
1295  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1296  $posy += 1;
1297  }
1298 
1299  $pdf->SetFont('', '', $default_font_size - 1);
1300 
1301  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1302  $object->fetch_projet();
1303  if (!empty($object->project->ref)) {
1304  $posy += 3;
1305  $pdf->SetXY($posx, $posy);
1306  $pdf->SetTextColor(0, 0, 60);
1307  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1308  }
1309  }
1310 
1311  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1312  $object->fetch_projet();
1313  if (!empty($object->project->ref)) {
1314  $outputlangs->load("projects");
1315  $posy += 4;
1316  $pdf->SetXY($posx, $posy);
1317  $langs->load("projects");
1318  $pdf->SetTextColor(0, 0, 60);
1319  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1320  }
1321  }
1322 
1323  if (!empty($object->date_commande)) {
1324  $posy += 5;
1325  $pdf->SetXY($posx, $posy);
1326  $pdf->SetTextColor(0, 0, 60);
1327  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R');
1328  } else {
1329  $posy += 5;
1330  $pdf->SetXY($posx, $posy);
1331  $pdf->SetTextColor(255, 0, 0);
1332  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1333  }
1334 
1335  $pdf->SetTextColor(0, 0, 60);
1336  $usehourmin = 'day';
1337  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1338  $usehourmin = 'dayhour';
1339  }
1340  if (!empty($object->delivery_date)) {
1341  $posy += 4;
1342  $pdf->SetXY($posx - 90, $posy);
1343  $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1344  }
1345 
1346  if ($object->thirdparty->code_fournisseur) {
1347  $posy += 4;
1348  $pdf->SetXY($posx, $posy);
1349  $pdf->SetTextColor(0, 0, 60);
1350  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1351  }
1352 
1353  // Get contact
1354  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1355  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1356  if (count($arrayidcontact) > 0) {
1357  $usertmp = new User($this->db);
1358  $usertmp->fetch($arrayidcontact[0]);
1359  $posy += 4;
1360  $pdf->SetXY($posx, $posy);
1361  $pdf->SetTextColor(0, 0, 60);
1362  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1363  }
1364  }
1365 
1366  $posy += 1;
1367  $pdf->SetTextColor(0, 0, 60);
1368 
1369  $top_shift = 0;
1370  // Show list of linked objects
1371  $current_y = $pdf->getY();
1372  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1373  if ($current_y < $pdf->getY()) {
1374  $top_shift = $pdf->getY() - $current_y;
1375  }
1376 
1377  if ($showaddress) {
1378  // Sender properties
1379  $carac_emetteur = '';
1380  // Add internal contact of proposal if defined
1381  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1382  if (count($arrayidcontact) > 0) {
1383  $object->fetch_user($arrayidcontact[0]);
1384  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1385  }
1386 
1387  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1388 
1389  // Show sender
1390  $posy = 42 + $top_shift;
1391  $posx = $this->marge_gauche;
1392  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1393  $posx = $this->page_largeur - $this->marge_droite - 80;
1394  }
1395  $hautcadre = 40;
1396 
1397  // Show sender frame
1398  $pdf->SetTextColor(0, 0, 0);
1399  $pdf->SetFont('', '', $default_font_size - 2);
1400  $pdf->SetXY($posx, $posy - 5);
1401  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1402  $pdf->SetXY($posx, $posy);
1403  $pdf->SetFillColor(230, 230, 230);
1404  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1405  $pdf->SetTextColor(0, 0, 60);
1406 
1407  // Show sender name
1408  $pdf->SetXY($posx + 2, $posy + 3);
1409  $pdf->SetFont('', 'B', $default_font_size);
1410  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1411  $posy = $pdf->getY();
1412 
1413  // Show sender information
1414  $pdf->SetXY($posx + 2, $posy);
1415  $pdf->SetFont('', '', $default_font_size - 1);
1416  $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1417 
1418 
1419 
1420  // 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'
1421  $usecontact = false;
1422  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1423  if (count($arrayidcontact) > 0) {
1424  $usecontact = true;
1425  $result = $object->fetch_contact($arrayidcontact[0]);
1426  }
1427 
1428  // Recipient name
1429  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)))) {
1430  $thirdparty = $object->contact;
1431  } else {
1432  $thirdparty = $object->thirdparty;
1433  }
1434 
1435  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1436 
1437  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1438 
1439  // Show recipient
1440  $widthrecbox = 100;
1441  if ($this->page_largeur < 210) {
1442  $widthrecbox = 84; // To work with US executive format
1443  }
1444  $posy = 42 + $top_shift;
1445  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1446  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1447  $posx = $this->marge_gauche;
1448  }
1449 
1450  // Show recipient frame
1451  $pdf->SetTextColor(0, 0, 0);
1452  $pdf->SetFont('', '', $default_font_size - 2);
1453  $pdf->SetXY($posx + 2, $posy - 5);
1454  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1455  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1456 
1457  // Show recipient name
1458  $pdf->SetXY($posx + 2, $posy + 3);
1459  $pdf->SetFont('', 'B', $default_font_size);
1460  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1461 
1462  $posy = $pdf->getY();
1463 
1464  // Show recipient information
1465  $pdf->SetFont('', '', $default_font_size - 1);
1466  $pdf->SetXY($posx + 2, $posy);
1467  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1468  }
1469 
1470  return $top_shift;
1471  }
1472 
1473  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1483  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1484  {
1485  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1486  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1487  }
1488 
1489 
1490 
1501  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1502  {
1503  global $conf, $hookmanager;
1504 
1505  // Default field style for content
1506  $this->defaultContentsFieldsStyle = array(
1507  'align' => 'R', // R,C,L
1508  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1509  );
1510 
1511  // Default field style for content
1512  $this->defaultTitlesFieldsStyle = array(
1513  'align' => 'C', // R,C,L
1514  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1515  );
1516 
1517  /*
1518  * For exemple
1519  $this->cols['theColKey'] = array(
1520  'rank' => $rank, // int : use for ordering columns
1521  'width' => 20, // the column width in mm
1522  'title' => array(
1523  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1524  'label' => ' ', // the final label : used fore final generated text
1525  'align' => 'L', // text alignement : R,C,L
1526  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1527  ),
1528  'content' => array(
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  );
1533  */
1534 
1535  $rank = 0; // do not use negative rank
1536  $this->cols['desc'] = array(
1537  'rank' => $rank,
1538  'width' => false, // only for desc
1539  'status' => true,
1540  'title' => array(
1541  'textkey' => 'Designation', // use lang key is usefull in somme case with module
1542  'align' => 'L',
1543  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1544  // 'label' => ' ', // the final label
1545  'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1546  ),
1547  'content' => array(
1548  'align' => 'L',
1549  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1550  ),
1551  );
1552 
1553  $rank = $rank + 10;
1554  $this->cols['photo'] = array(
1555  'rank' => $rank,
1556  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1557  'status' => false,
1558  'title' => array(
1559  'textkey' => 'Photo',
1560  'label' => ' '
1561  ),
1562  'content' => array(
1563  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1564  ),
1565  'border-left' => false, // remove left line separator
1566  );
1567 
1568  if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
1569  $this->cols['photo']['status'] = true;
1570  }
1571 
1572 
1573  $rank = $rank + 10;
1574  $this->cols['vat'] = array(
1575  'rank' => $rank,
1576  'status' => false,
1577  'width' => 16, // in mm
1578  'title' => array(
1579  'textkey' => 'VAT'
1580  ),
1581  'border-left' => true, // add left line separator
1582  );
1583 
1584  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1585  $this->cols['vat']['status'] = true;
1586  }
1587 
1588  $rank = $rank + 10;
1589  $this->cols['subprice'] = array(
1590  'rank' => $rank,
1591  'width' => 19, // in mm
1592  'status' => false,
1593  'title' => array(
1594  'textkey' => 'PriceUHT'
1595  ),
1596  'border-left' => true, // add left line separator
1597  );
1598 
1599  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE)) {
1600  $this->cols['subprice']['status'] = true;
1601  }
1602 
1603  $rank = $rank + 10;
1604  $this->cols['qty'] = array(
1605  'rank' => $rank,
1606  'width' => 16, // in mm
1607  'status' => true,
1608  'title' => array(
1609  'textkey' => 'Qty'
1610  ),
1611  'border-left' => true, // add left line separator
1612  );
1613 
1614  $rank = $rank + 10;
1615  $this->cols['unit'] = array(
1616  'rank' => $rank,
1617  'width' => 11, // in mm
1618  'status' => false,
1619  'title' => array(
1620  'textkey' => 'Unit'
1621  ),
1622  'border-left' => true, // add left line separator
1623  );
1624  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1625  $this->cols['unit']['status'] = true;
1626  }
1627 
1628  $rank = $rank + 10;
1629  $this->cols['discount'] = array(
1630  'rank' => $rank,
1631  'width' => 13, // in mm
1632  'status' => false,
1633  'title' => array(
1634  'textkey' => 'ReductionShort'
1635  ),
1636  'border-left' => true, // add left line separator
1637  );
1638  if ($this->atleastonediscount) {
1639  $this->cols['discount']['status'] = true;
1640  }
1641 
1642  $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1643  $this->cols['totalexcltax'] = array(
1644  'rank' => $rank,
1645  'width' => 26, // in mm
1646  'status' => true,
1647  'title' => array(
1648  'textkey' => 'TotalHT'
1649  ),
1650  'border-left' => true, // add left line separator
1651  );
1652 
1653  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN)) {
1654  $this->cols['totalexcltax']['status'] = true;
1655  }
1656 
1657  // Add extrafields cols
1658  if (!empty($object->lines)) {
1659  $line = reset($object->lines);
1660  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1661  }
1662 
1663  $parameters = array(
1664  'object' => $object,
1665  'outputlangs' => $outputlangs,
1666  'hidedetails' => $hidedetails,
1667  'hidedesc' => $hidedesc,
1668  'hideref' => $hideref
1669  );
1670 
1671  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1672  if ($reshook < 0) {
1673  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1674  } elseif (empty($reshook)) {
1675  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1676  } else {
1677  $this->cols = $hookmanager->resArray;
1678  }
1679  }
1680 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:8210
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1815
getLocalTaxesFromRate
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
Definition: functions.lib.php:6275
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_getSizeForImage
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2505
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1962
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1877
pdf_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:1236
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getlineremisepercent
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2166
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_cornas\defineColumnField
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
Definition: pdf_cornas.modules.php:1501
CommonDocGenerator\getColumnContentXStart
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
Definition: commondocgenerator.class.php:1137
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:1211
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
Translate
Class to manage translations.
Definition: translate.class.php:30
pdf_getlineunit
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2123
pdf_cornas\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_cornas.modules.php:1483
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:1296
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
CommonDocGenerator\prepareArrayColumnField
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
Definition: commondocgenerator.class.php:1054
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
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:1156
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7590
dolChmod
dolChmod($filepath, $newmask='')
Change mod of a file.
Definition: functions.lib.php:6882
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6757
pdf_cornas\_tableau_info
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Definition: pdf_cornas.modules.php:885
pdf_cornas\_tableau_versements
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
Definition: pdf_cornas.modules.php:869
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:1010
pdf_writeLinkedObjects
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1318
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:2723
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
User
Class to manage Dolibarr users.
Definition: user.class.php:44
pdf_cornas\_tableau_tot
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
Definition: pdf_cornas.modules.php:949
Product
Class to manage products or services.
Definition: product.class.php:46
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:7325
CommonDocGenerator\printColDescContent
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
Definition: commondocgenerator.class.php:1259
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:744
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5708
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509
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:6811
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2260
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
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:1631
CommonDocGenerator\getColumnStatus
getColumnStatus($colKey)
get column status from column key
Definition: commondocgenerator.class.php:1535
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:1226
complete_substitutions_array
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
Definition: functions.lib.php:8333
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5659
pdf_pagefoot
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:996
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25