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