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