dolibarr  19.0.0-dev
pdf_muscadet.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 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 = "muscadet";
131  $this->description = $langs->trans('SuppliersCommandModelMuscadet');
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;
163  $this->posxdiscount = 162;
164  $this->postotalht = 174;
165 
166  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
167  $this->posxtva = 95;
168  $this->posxup = 114;
169  $this->posxqty = 132;
170  $this->posxunit = 147;
171  } else {
172  $this->posxtva = 106;
173  $this->posxup = 122;
174  $this->posxqty = 145;
175  $this->posxunit = 162;
176  }
177 
178  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
179  $this->posxup = $this->posxtva; // posxtva is picture position reference
180  }
181  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
182  if ($this->page_largeur < 210) { // To work with US executive format
183  $this->posxpicture -= 20;
184  $this->posxtva -= 20;
185  $this->posxup -= 20;
186  $this->posxqty -= 20;
187  $this->posxunit -= 20;
188  $this->posxdiscount -= 20;
189  $this->postotalht -= 20;
190  }
191 
192  $this->tva = array();
193  $this->tva_array = array();
194  $this->localtax1 = array();
195  $this->localtax2 = array();
196  $this->atleastoneratenotnull = 0;
197  $this->atleastonediscount = 0;
198  }
199 
200 
201  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
213  public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
214  {
215  // phpcs:enable
216  global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
217 
218  if (!is_object($outputlangs)) {
219  $outputlangs = $langs;
220  }
221  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
222  if (!empty($conf->global->MAIN_USE_FPDF)) {
223  $outputlangs->charset_output = 'ISO-8859-1';
224  }
225 
226  // Load translation files required by the page
227  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
228 
229  $nblines = count($object->lines);
230 
231  // Loop on each lines to detect if there is at least one image to show
232  $realpatharray = array();
233  if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
234  for ($i = 0; $i < $nblines; $i++) {
235  if (empty($object->lines[$i]->fk_product)) {
236  continue;
237  }
238 
239  $objphoto = new Product($this->db);
240  $objphoto->fetch($object->lines[$i]->fk_product);
241 
242  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
243  $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
244  $dir = $conf->product->dir_output.'/'.$pdir;
245  } else {
246  $pdir = get_exdir($objphoto->id, 0, 0, 0, $objphoto, 'product');
247  $dir = $conf->product->dir_output.'/'.$pdir;
248  }
249  $realpath = '';
250  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
251  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
252  if ($obj['photo_vignette']) {
253  $filename = $obj['photo_vignette'];
254  } else {
255  $filename = $obj['photo'];
256  }
257  } else {
258  $filename = $obj['photo'];
259  }
260  $realpath = $dir.$filename;
261  break;
262  }
263 
264  if ($realpath) {
265  $realpatharray[$i] = $realpath;
266  }
267  }
268  }
269  if (count($realpatharray) == 0) {
270  $this->posxpicture = $this->posxtva;
271  }
272 
273  if ($conf->fournisseur->commande->dir_output) {
274  $object->fetch_thirdparty();
275 
276  $deja_regle = 0;
277  $amount_credit_notes_included = 0;
278  $amount_deposits_included = 0;
279  //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
280  //$amount_deposits_included = $object->getSumDepositsUsed();
281 
282  // Definition of $dir and $file
283  if ($object->specimen) {
284  $dir = $conf->fournisseur->commande->dir_output;
285  $file = $dir."/SPECIMEN.pdf";
286  } else {
287  $objectref = dol_sanitizeFileName($object->ref);
288  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
289  $dir = $conf->fournisseur->commande->dir_output.'/'.$objectref;
290  $file = $dir."/".$objectref.".pdf";
291  if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
292  $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
293  }
294  }
295 
296  if (!file_exists($dir)) {
297  if (dol_mkdir($dir) < 0) {
298  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
299  return 0;
300  }
301  }
302 
303  if (file_exists($dir)) {
304  // Add pdfgeneration hook
305  if (!is_object($hookmanager)) {
306  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
307  $hookmanager = new HookManager($this->db);
308  }
309  $hookmanager->initHooks(array('pdfgeneration'));
310  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
311  global $action;
312  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
313 
314  $nblines = count($object->lines);
315 
316  $pdf = pdf_getInstance($this->format);
317  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
318  $heightforinfotot = 50; // Height reserved to output the info and total part
319  $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
320  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
321  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
322  $heightforfooter += 6;
323  }
324  $pdf->SetAutoPageBreak(1, 0);
325 
326  if (class_exists('TCPDF')) {
327  $pdf->setPrintHeader(false);
328  $pdf->setPrintFooter(false);
329  }
330  $pdf->SetFont(pdf_getPDFFont($outputlangs));
331  // Set path to the background PDF File
332  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
333  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
334  $tplidx = $pdf->importPage(1);
335  }
336 
337  $pdf->Open();
338  $pagenb = 0;
339  $pdf->SetDrawColor(128, 128, 128);
340 
341  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
342  $pdf->SetSubject($outputlangs->transnoentities("PurchaseOrder"));
343  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
344  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
345 
346  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PurchaseOrder")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
347  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
348  $pdf->SetCompression(false);
349  }
350 
351  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
352 
353  // Positionne $this->atleastonediscount si on a au moins une remise
354  for ($i = 0; $i < $nblines; $i++) {
355  if ($object->lines[$i]->remise_percent) {
356  $this->atleastonediscount++;
357  }
358  }
359  if (empty($this->atleastonediscount)) {
360  $delta = ($this->postotalht - $this->posxdiscount);
361  $this->posxpicture += $delta;
362  $this->posxtva += $delta;
363  $this->posxup += $delta;
364  $this->posxqty += $delta;
365  $this->posxunit += $delta;
366  $this->posxdiscount += $delta;
367  // post of fields after are not modified, stay at same position
368  }
369 
370  // New page
371  $pdf->AddPage();
372  if (!empty($tplidx)) {
373  $pdf->useTemplate($tplidx);
374  }
375  $pagenb++;
376  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
377  $pdf->SetFont('', '', $default_font_size - 1);
378  $pdf->MultiCell(0, 3, ''); // Set interline to 3
379  $pdf->SetTextColor(0, 0, 0);
380 
381  $tab_top = 90 + $top_shift;
382  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
383 
384  // Incoterm
385  if (isModEnabled('incoterm')) {
386  $desc_incoterms = $object->getIncotermsForPDF();
387  if ($desc_incoterms) {
388  $tab_top -= 2;
389 
390  $pdf->SetFont('', '', $default_font_size - 1);
391  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
392  $nexY = $pdf->GetY();
393  $height_incoterms = $nexY - $tab_top;
394 
395  // Rect takes a length in 3rd parameter
396  $pdf->SetDrawColor(192, 192, 192);
397  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
398 
399  $tab_top = $nexY + 6;
400  }
401  }
402 
403  // Affiche notes
404  if (!empty($object->note_public)) {
405  $tab_top -= 2;
406 
407  $pdf->SetFont('', '', $default_font_size - 1);
408  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
409  $nexY = $pdf->GetY();
410  $height_note = $nexY - $tab_top;
411 
412  // Rect takes a length in 3rd parameter
413  $pdf->SetDrawColor(192, 192, 192);
414  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
415 
416  $tab_top = $nexY + 6;
417  }
418 
419  $iniY = $tab_top + 7;
420  $curY = $tab_top + 7;
421  $nexY = $tab_top + 7;
422 
423  // Loop on each lines
424  for ($i = 0; $i < $nblines; $i++) {
425  $curY = $nexY;
426  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
427  $pdf->SetTextColor(0, 0, 0);
428 
429  // Define size of image if we need it
430  $imglinesize = array();
431  if (!empty($realpatharray[$i])) {
432  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
433  }
434 
435  $pdf->setTopMargin($tab_top_newpage);
436  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
437  $pageposbefore = $pdf->getPage();
438 
439  $showpricebeforepagebreak = 1;
440  $posYAfterImage = 0;
441  $posYAfterDescription = 0;
442 
443  // We start with Photo of product line
444  if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
445  $pdf->AddPage('', '', true);
446  if (!empty($tplidx)) {
447  $pdf->useTemplate($tplidx);
448  }
449  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
450  $this->_pagehead($pdf, $object, 0, $outputlangs);
451  }
452  $pdf->setPage($pageposbefore + 1);
453 
454  $curY = $tab_top_newpage;
455 
456  // Allows data in the first page if description is long enough to break in multiples pages
457  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
458  $showpricebeforepagebreak = 1;
459  } else {
460  $showpricebeforepagebreak = 0;
461  }
462  }
463 
464  if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) {
465  $curX = $this->posxpicture - 1;
466  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
467  // $pdf->Image does not increase value return by getY, so we save it manually
468  $posYAfterImage = $curY + $imglinesize['height'];
469  }
470  // Description of product line
471  $curX = $this->posxdesc - 1;
472  $showpricebeforepagebreak = 1;
473 
474  $pdf->startTransaction();
475  if ($posYAfterImage > 0) {
476  $descWidth = $this->posxpicture - $curX;
477  } else {
478  $descWidth = $this->posxtva - $curX;
479  }
480  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
481 
482  $pageposafter = $pdf->getPage();
483  if ($pageposafter > $pageposbefore) { // There is a pagebreak
484  $pdf->rollbackTransaction(true);
485  $pageposafter = $pageposbefore;
486  //print $pageposafter.'-'.$pageposbefore;exit;
487  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
488  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
489  $posyafter = $pdf->GetY();
490  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
491  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
492  $pdf->AddPage('', '', true);
493  if (!empty($tplidx)) {
494  $pdf->useTemplate($tplidx);
495  }
496  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
497  $this->_pagehead($pdf, $object, 0, $outputlangs);
498  }
499  $pdf->setPage($pageposafter + 1);
500  }
501  } else {
502  // We found a page break
503  // Allows data in the first page if description is long enough to break in multiples pages
504  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
505  $showpricebeforepagebreak = 1;
506  } else {
507  $showpricebeforepagebreak = 0;
508  }
509  }
510  } else // No pagebreak
511  {
512  $pdf->commitTransaction();
513  }
514 
515  $nexY = $pdf->GetY();
516  $pageposafter = $pdf->getPage();
517  $pdf->setPage($pageposbefore);
518  $pdf->setTopMargin($this->marge_haute);
519  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
520 
521  // We suppose that a too long description is moved completely on next page
522  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
523  $pdf->setPage($pageposafter);
524  $curY = $tab_top_newpage;
525  }
526 
527  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
528 
529  // VAT Rate
530  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
531  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
532  $pdf->SetXY($this->posxtva, $curY);
533  $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
534  }
535 
536  // Unit price before discount
537  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE)) {
538  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
539  $pdf->SetXY($this->posxup, $curY);
540  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
541  }
542 
543  // Quantity
544  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
545  $pdf->SetXY($this->posxqty, $curY);
546  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
547 
548  // Unit
549  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
550  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
551  $pdf->SetXY($this->posxunit, $curY);
552  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
553  }
554 
555  // Discount on line
556  $pdf->SetXY($this->posxdiscount, $curY);
557  if ($object->lines[$i]->remise_percent) {
558  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
559  $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
560  }
561 
562  // Total HT line
563  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN)) {
564  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
565  $pdf->SetXY($this->postotalht, $curY);
566  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
567  }
568 
569  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
570  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
571  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
572  } else {
573  $tvaligne = $object->lines[$i]->total_tva;
574  }
575 
576  $localtax1ligne = $object->lines[$i]->total_localtax1;
577  $localtax2ligne = $object->lines[$i]->total_localtax2;
578  $localtax1_rate = $object->lines[$i]->localtax1_tx;
579  $localtax2_rate = $object->lines[$i]->localtax2_tx;
580  $localtax1_type = $object->lines[$i]->localtax1_type;
581  $localtax2_type = $object->lines[$i]->localtax2_type;
582 
583  // TODO remise_percent is an obsolete field for object parent
584  /*if (!empty($object->remise_percent)) {
585  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
586  }
587  if (!empty($object->remise_percent)) {
588  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
589  }
590  if (!empty($object->remise_percent)) {
591  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
592  }*/
593 
594  $vatrate = (string) $object->lines[$i]->tva_tx;
595 
596  // Retrieve type from database for backward compatibility with old records
597  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
598  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
599  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty);
600  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
601  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
602  }
603 
604  // retrieve global local tax
605  if ($localtax1_type && $localtax1ligne != 0) {
606  if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
607  $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
608  } else {
609  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
610  }
611  }
612  if ($localtax2_type && $localtax2ligne != 0) {
613  if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
614  $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
615  } else {
616  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
617  }
618  }
619 
620  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
621  $vatrate .= '*';
622  }
623 
624  // Fill $this->tva and $this->tva_array
625  if (!isset($this->tva[$vatrate])) {
626  $this->tva[$vatrate] = 0;
627  }
628  $this->tva[$vatrate] += $tvaligne;
629  $vatcode = $object->lines[$i]->vat_src_code;
630  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
631  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
632  }
633  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
634 
635  if ($posYAfterImage > $posYAfterDescription) {
636  $nexY = $posYAfterImage;
637  }
638 
639  // Add line
640  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
641  $pdf->setPage($pageposafter);
642  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
643  //$pdf->SetDrawColor(190,190,200);
644  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
645  $pdf->SetLineStyle(array('dash'=>0));
646  }
647 
648  $nexY += 2; // Add space between lines
649 
650  // Detect if some page were added automatically and output _tableau for past pages
651  while ($pagenb < $pageposafter) {
652  $pdf->setPage($pagenb);
653  if ($pagenb == 1) {
654  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
655  } else {
656  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
657  }
658  $this->_pagefoot($pdf, $object, $outputlangs, 1);
659  $pagenb++;
660  $pdf->setPage($pagenb);
661  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
662  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
663  $this->_pagehead($pdf, $object, 0, $outputlangs);
664  }
665  if (!empty($tplidx)) {
666  $pdf->useTemplate($tplidx);
667  }
668  }
669  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
670  if ($pagenb == 1) {
671  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
672  } else {
673  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
674  }
675  $this->_pagefoot($pdf, $object, $outputlangs, 1);
676  // New page
677  $pdf->AddPage();
678  if (!empty($tplidx)) {
679  $pdf->useTemplate($tplidx);
680  }
681  $pagenb++;
682  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
683  $this->_pagehead($pdf, $object, 0, $outputlangs);
684  }
685  }
686  }
687 
688  // Show square
689  if ($pagenb == 1) {
690  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
691  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
692  } else {
693  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
694  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
695  }
696 
697  // Affiche zone infos
698  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
699 
700  // Affiche zone totaux
701  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
702 
703  // Affiche zone versements
704  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
705  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
706  }
707 
708  // Pied de page
709  $this->_pagefoot($pdf, $object, $outputlangs);
710  if (method_exists($pdf, 'AliasNbPages')) {
711  $pdf->AliasNbPages();
712  }
713 
714  $pdf->Close();
715 
716  $pdf->Output($file, 'F');
717 
718  // Add pdfgeneration hook
719  $hookmanager->initHooks(array('pdfgeneration'));
720  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
721  global $action;
722  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
723  if ($reshook < 0) {
724  $this->error = $hookmanager->error;
725  $this->errors = $hookmanager->errors;
726  }
727 
728  dolChmod($file);
729 
730  $this->result = array('fullpath'=>$file);
731 
732  return 1; // No error
733  } else {
734  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
735  return 0;
736  }
737  } else {
738  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
739  return 0;
740  }
741  }
742 
743  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
744  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
754  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
755  {
756  // phpcs:enable
757  return 1;
758  }
759 
760  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
761  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
771  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
772  {
773  // phpcs:enable
774  global $conf, $mysoc;
775  $default_font_size = pdf_getPDFFontSize($outputlangs);
776 
777  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
778 
779  // If France, show VAT mention if not applicable
780  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
781  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
782  $pdf->SetXY($this->marge_gauche, $posy);
783  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
784 
785  $posy = $pdf->GetY() + 4;
786  }
787 
788  $posxval = 52;
789 
790  // Show payments conditions
791  if (!empty($object->cond_reglement_code) || $object->cond_reglement_id) {
792  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
793  $pdf->SetXY($this->marge_gauche, $posy);
794  $titre = $outputlangs->transnoentities("PaymentConditions").':';
795  $pdf->MultiCell(80, 4, $titre, 0, 'L');
796 
797  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
798  $pdf->SetXY($posxval, $posy);
799  $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);
800  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
801  $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
802 
803  $posy = $pdf->GetY() + 3;
804  }
805 
806  // Show payment mode
807  if (!empty($object->mode_reglement_code)) {
808  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
809  $pdf->SetXY($this->marge_gauche, $posy);
810  $titre = $outputlangs->transnoentities("PaymentMode").':';
811  $pdf->MultiCell(80, 5, $titre, 0, 'L');
812 
813  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
814  $pdf->SetXY($posxval, $posy);
815  $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);
816  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
817 
818  $posy = $pdf->GetY() + 2;
819  }
820 
821  return $posy;
822  }
823 
824  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
825  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
836  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
837  {
838  // phpcs:enable
839  global $conf, $mysoc;
840 
841  $default_font_size = pdf_getPDFFontSize($outputlangs);
842 
843  $tab2_top = $posy;
844  $tab2_hl = 4;
845  $pdf->SetFont('', '', $default_font_size - 1);
846 
847  // Tableau total
848  $col1x = 120;
849  $col2x = 170;
850  if ($this->page_largeur < 210) { // To work with US executive format
851  $col2x -= 20;
852  }
853  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
854 
855  $useborder = 0;
856  $index = 0;
857 
858  // Total HT
859  $pdf->SetFillColor(255, 255, 255);
860  $pdf->SetXY($col1x, $tab2_top);
861  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
862 
863  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
864  $pdf->SetXY($col2x, $tab2_top);
865  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
866 
867  // Show VAT by rates and total
868  $pdf->SetFillColor(248, 248, 248);
869 
870  $this->atleastoneratenotnull = 0;
871  foreach ($this->tva as $tvakey => $tvaval) {
872  if ($tvakey > 0) { // On affiche pas taux 0
873  $this->atleastoneratenotnull++;
874 
875  $index++;
876  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
877 
878  $tvacompl = '';
879 
880  if (preg_match('/\*/', $tvakey)) {
881  $tvakey = str_replace('*', '', $tvakey);
882  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
883  }
884 
885  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
886  $totalvat .= vatrate($tvakey, 1).$tvacompl;
887  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
888 
889  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
890  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
891  }
892  }
893  if (!$this->atleastoneratenotnull) { // If no vat at all
894  $index++;
895  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
896  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
897 
898  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
899  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
900 
901  // Total LocalTax1
902  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
903  $index++;
904  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
905  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
906  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
907  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
908  }
909 
910  // Total LocalTax2
911  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
912  $index++;
913  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
914  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
915  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
916  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
917  }
918  } else {
919  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
920  //{
921  //Local tax 1
922  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
923  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
924  continue;
925  }
926 
927  foreach ($localtax_rate as $tvakey => $tvaval) {
928  if ($tvakey != 0) { // On affiche pas taux 0
929  //$this->atleastoneratenotnull++;
930 
931  $index++;
932  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
933 
934  $tvacompl = '';
935  if (preg_match('/\*/', $tvakey)) {
936  $tvakey = str_replace('*', '', $tvakey);
937  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
938  }
939  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
940  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
941  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
942 
943  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
944  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
945  }
946  }
947  }
948 
949  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
950  //{
951  //Local tax 2
952  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
953  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
954  continue;
955  }
956 
957  foreach ($localtax_rate as $tvakey => $tvaval) {
958  if ($tvakey != 0) { // On affiche pas taux 0
959  //$this->atleastoneratenotnull++;
960 
961  $index++;
962  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
963 
964  $tvacompl = '';
965  if (preg_match('/\*/', $tvakey)) {
966  $tvakey = str_replace('*', '', $tvakey);
967  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
968  }
969  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
970  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
971  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
972 
973  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
974  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
975  }
976  }
977  }
978  }
979 
980  // Total TTC
981  $index++;
982  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
983  $pdf->SetTextColor(0, 0, 60);
984  $pdf->SetFillColor(224, 224, 224);
985  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
986 
987  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
988  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
989  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
990  $pdf->SetFont('', '', $default_font_size - 1);
991  $pdf->SetTextColor(0, 0, 0);
992 
993  $creditnoteamount = 0;
994  $depositsamount = 0;
995  //$creditnoteamount=$object->getSumCreditNotesUsed();
996  //$depositsamount=$object->getSumDepositsUsed();
997  //print "x".$creditnoteamount."-".$depositsamount;exit;
998  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
999  if (!empty($object->paye)) {
1000  $resteapayer = 0;
1001  }
1002 
1003  if ($deja_regle > 0) {
1004  // Already paid + Deposits
1005  $index++;
1006 
1007  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1008  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1009  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1010  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
1011 
1012  $index++;
1013  $pdf->SetTextColor(0, 0, 60);
1014  $pdf->SetFillColor(224, 224, 224);
1015  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1016  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1017 
1018  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1019  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
1020 
1021  $pdf->SetFont('', '', $default_font_size - 1);
1022  $pdf->SetTextColor(0, 0, 0);
1023  }
1024 
1025  $index++;
1026  return ($tab2_top + ($tab2_hl * $index));
1027  }
1028 
1029  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1043  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1044  {
1045  global $conf;
1046 
1047  // Force to disable hidetop and hidebottom
1048  $hidebottom = 0;
1049  if ($hidetop) {
1050  $hidetop = -1;
1051  }
1052 
1053  $currency = !empty($currency) ? $currency : $conf->currency;
1054  $default_font_size = pdf_getPDFFontSize($outputlangs);
1055 
1056  // Amount in (at tab_top - 1)
1057  $pdf->SetTextColor(0, 0, 0);
1058  $pdf->SetFont('', '', $default_font_size - 2);
1059 
1060  if (empty($hidetop)) {
1061  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1062  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1063  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1064 
1065  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1066  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1067  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1068  }
1069  }
1070 
1071  $pdf->SetDrawColor(128, 128, 128);
1072  $pdf->SetFont('', '', $default_font_size - 1);
1073 
1074  // Output Rect
1075  $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
1076 
1077  if (empty($hidetop)) {
1078  $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
1079 
1080  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1081  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1082  }
1083 
1084  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1085  $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1086  if (empty($hidetop)) {
1087  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1088  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1089  }
1090  }
1091 
1092  $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1093  if (empty($hidetop)) {
1094  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1095  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1096  }
1097 
1098  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1099  if (empty($hidetop)) {
1100  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1101  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1102  }
1103 
1104  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1105  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1106  if (empty($hidetop)) {
1107  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1108  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1109  }
1110  }
1111 
1112  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1113  if (empty($hidetop)) {
1114  if ($this->atleastonediscount) {
1115  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1116  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1117  }
1118  }
1119 
1120  if ($this->atleastonediscount) {
1121  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1122  }
1123  if (empty($hidetop)) {
1124  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1125  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1126  }
1127  }
1128 
1129  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1139  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1140  {
1141  global $langs, $conf, $mysoc;
1142 
1143  $ltrdirection = 'L';
1144  if ($outputlangs->trans("DIRECTION") == 'rtl') {
1145  $ltrdirection = 'R';
1146  }
1147 
1148  // Load translation files required by the page
1149  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1150 
1151  $default_font_size = pdf_getPDFFontSize($outputlangs);
1152 
1153  // Do not add the BACKGROUND as this is for suppliers
1154  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1155 
1156  //Affiche le filigrane brouillon - Print Draft Watermark
1157  /*if($object->statut==0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK'))
1158  {
1159  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1160  }*/
1161  //Print content
1162 
1163  $pdf->SetTextColor(0, 0, 60);
1164  $pdf->SetFont('', 'B', $default_font_size + 3);
1165 
1166  $posx = $this->page_largeur - $this->marge_droite - 100;
1167  $posy = $this->marge_haute;
1168 
1169  $pdf->SetXY($this->marge_gauche, $posy);
1170 
1171  // Logo
1172  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1173  if ($this->emetteur->logo) {
1174  $logodir = $conf->mycompany->dir_output;
1175  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1176  $logodir = $conf->mycompany->multidir_output[$object->entity];
1177  }
1178  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1179  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1180  } else {
1181  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1182  }
1183  if (is_readable($logo)) {
1184  $height = pdf_getHeightForLogo($logo);
1185  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1186  } else {
1187  $pdf->SetTextColor(200, 0, 0);
1188  $pdf->SetFont('', 'B', $default_font_size - 2);
1189  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1190  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1191  }
1192  } else {
1193  $text = $this->emetteur->name;
1194  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1195  }
1196  }
1197 
1198  $pdf->SetFont('', 'B', $default_font_size + 3);
1199  $pdf->SetXY($posx, $posy);
1200  $pdf->SetTextColor(0, 0, 60);
1201  $title = $outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1202  $pdf->MultiCell(100, 3, $title, '', 'R');
1203  $posy += 1;
1204 
1205  if ($object->ref_supplier) {
1206  $posy += 4;
1207  $pdf->SetFont('', 'B', $default_font_size);
1208  $pdf->SetXY($posx, $posy);
1209  $pdf->SetTextColor(0, 0, 60);
1210  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1211  $posy += 1;
1212  }
1213 
1214  $pdf->SetFont('', '', $default_font_size - 1);
1215 
1216  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1217  $object->fetch_projet();
1218  if (!empty($object->project->ref)) {
1219  $posy += 3;
1220  $pdf->SetXY($posx, $posy);
1221  $pdf->SetTextColor(0, 0, 60);
1222  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1223  }
1224  }
1225 
1226  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1227  $object->fetch_projet();
1228  if (!empty($object->project->ref)) {
1229  $outputlangs->load("projects");
1230  $posy += 4;
1231  $pdf->SetXY($posx, $posy);
1232  $langs->load("projects");
1233  $pdf->SetTextColor(0, 0, 60);
1234  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1235  }
1236  }
1237 
1238  if (!empty($object->date_commande)) {
1239  $posy += 5;
1240  $pdf->SetXY($posx, $posy);
1241  $pdf->SetTextColor(0, 0, 60);
1242  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R');
1243  } else {
1244  $posy += 5;
1245  $pdf->SetXY($posx, $posy);
1246  $pdf->SetTextColor(255, 0, 0);
1247  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1248  }
1249 
1250  $pdf->SetTextColor(0, 0, 60);
1251  $usehourmin = 'day';
1252  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1253  $usehourmin = 'dayhour';
1254  }
1255  if (!empty($object->delivery_date)) {
1256  $posy += 4;
1257  $pdf->SetXY($posx - 90, $posy);
1258  $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1259  }
1260 
1261  if ($object->thirdparty->code_fournisseur) {
1262  $posy += 4;
1263  $pdf->SetXY($posx, $posy);
1264  $pdf->SetTextColor(0, 0, 60);
1265  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1266  }
1267 
1268  // Get contact
1269  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1270  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1271  if (count($arrayidcontact) > 0) {
1272  $usertmp = new User($this->db);
1273  $usertmp->fetch($arrayidcontact[0]);
1274  $posy += 4;
1275  $pdf->SetXY($posx, $posy);
1276  $pdf->SetTextColor(0, 0, 60);
1277  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1278  }
1279  }
1280 
1281  $posy += 1;
1282  $pdf->SetTextColor(0, 0, 60);
1283 
1284  $top_shift = 0;
1285  // Show list of linked objects
1286  $current_y = $pdf->getY();
1287  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1288  if ($current_y < $pdf->getY()) {
1289  $top_shift = $pdf->getY() - $current_y;
1290  }
1291 
1292  if ($showaddress) {
1293  // Sender properties
1294  $carac_emetteur = '';
1295  // Add internal contact of object if defined
1296  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1297  if (count($arrayidcontact) > 0) {
1298  $object->fetch_user($arrayidcontact[0]);
1299  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1300  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1301  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1302  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1303  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1304  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1305  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1306  $carac_emetteur .= "\n";
1307  }
1308 
1309  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1310 
1311  // Show sender
1312  $posy = 42 + $top_shift;
1313  $posx = $this->marge_gauche;
1314  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1315  $posx = $this->page_largeur - $this->marge_droite - 80;
1316  }
1317  $hautcadre = 40;
1318 
1319  // Show sender frame
1320  $pdf->SetTextColor(0, 0, 0);
1321  $pdf->SetFont('', '', $default_font_size - 2);
1322  $pdf->SetXY($posx, $posy - 5);
1323  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1324  $pdf->SetXY($posx, $posy);
1325  $pdf->SetFillColor(230, 230, 230);
1326  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1327  $pdf->SetTextColor(0, 0, 60);
1328 
1329  // Show sender name
1330  $pdf->SetXY($posx + 2, $posy + 3);
1331  $pdf->SetFont('', 'B', $default_font_size);
1332  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1333  $posy = $pdf->getY();
1334 
1335  // Show sender information
1336  $pdf->SetXY($posx + 2, $posy);
1337  $pdf->SetFont('', '', $default_font_size - 1);
1338  $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1339 
1340 
1341  // 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'
1342  $usecontact = false;
1343  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1344  if (count($arrayidcontact) > 0) {
1345  $usecontact = true;
1346  $result = $object->fetch_contact($arrayidcontact[0]);
1347  }
1348 
1349  // Recipient name
1350  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)))) {
1351  $thirdparty = $object->contact;
1352  } else {
1353  $thirdparty = $object->thirdparty;
1354  }
1355 
1356  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1357 
1358  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1359 
1360  // Show recipient
1361  $widthrecbox = 100;
1362  if ($this->page_largeur < 210) {
1363  $widthrecbox = 84; // To work with US executive format
1364  }
1365  $posy = 42 + $top_shift;
1366  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1367  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1368  $posx = $this->marge_gauche;
1369  }
1370 
1371  // Show recipient frame
1372  $pdf->SetTextColor(0, 0, 0);
1373  $pdf->SetFont('', '', $default_font_size - 2);
1374  $pdf->SetXY($posx + 2, $posy - 5);
1375  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1376  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1377 
1378  // Show recipient name
1379  $pdf->SetXY($posx + 2, $posy + 3);
1380  $pdf->SetFont('', 'B', $default_font_size);
1381  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1382 
1383  $posy = $pdf->getY();
1384 
1385  // Show recipient information
1386  $pdf->SetFont('', '', $default_font_size - 1);
1387  $pdf->SetXY($posx + 2, $posy);
1388  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1389  }
1390 
1391  return $top_shift;
1392  }
1393 
1394  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1404  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1405  {
1406  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1407  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1408  }
1409 }
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Parent class for supplier orders models.
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:48
Class to generate the supplier orders with the muscadet model.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
_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.
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 '.
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).
dolChmod($filepath, $newmask='')
Change mod of a file.
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_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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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:2520
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2275
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:85
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1369
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:314
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
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1892
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1830
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2138
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_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:266
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_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2181
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1977
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:387
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123