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