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