dolibarr  17.0.4
pdf_vinci.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-2021 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/mrp/modules_mo.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.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/files.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38 
39 
43 class pdf_vinci extends ModelePDFMo
44 {
48  public $db;
49 
53  public $name;
54 
58  public $description;
59 
63  public $update_main_doc_field;
64 
68  public $type;
69 
74  public $phpmin = array(7, 0);
75 
80  public $version = 'dolibarr';
81 
85  public $page_largeur;
86 
90  public $page_hauteur;
91 
95  public $format;
96 
100  public $marge_gauche;
101 
105  public $marge_droite;
106 
110  public $marge_haute;
111 
115  public $marge_basse;
116 
121  public $emetteur;
122 
123 
129  public function __construct($db)
130  {
131  global $conf, $langs, $mysoc;
132 
133  // Load translation files required by the page
134  $langs->loadLangs(array("main", "bills"));
135 
136  $this->db = $db;
137  $this->name = "vinci";
138  $this->description = $langs->trans('DocumentModelStandardPDF');
139  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
140 
141  // Page size for A4 format
142  $this->type = 'pdf';
143  $formatarray = pdf_getFormat();
144  $this->page_largeur = $formatarray['width'];
145  $this->page_hauteur = $formatarray['height'];
146  $this->format = array($this->page_largeur, $this->page_hauteur);
147  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
148  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
149  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
150  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
151 
152  $this->option_logo = 1; // Display logo
153  $this->option_multilang = 1; //Available in several languages
154  $this->option_escompte = 0; // Displays if there has been a discount
155  $this->option_credit_note = 0; // Support credit notes
156  $this->option_freetext = 1; // Support add of a personalised text
157  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
158 
159  // Get source company
160  $this->emetteur = $mysoc;
161  if (empty($this->emetteur->country_code)) {
162  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
163  }
164 
165  // Define position of columns
166  $this->posxdesc = $this->marge_gauche + 1; // For module retrocompatibility support durring PDF transition: TODO remove this at the end
167  }
168 
169 
170  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
182  public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
183  {
184  // phpcs:enable
185  global $user, $langs, $conf, $hookmanager, $mysoc;
186 
187  if (!is_object($outputlangs)) {
188  $outputlangs = $langs;
189  }
190  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
191  if (!empty($conf->global->MAIN_USE_FPDF)) {
192  $outputlangs->charset_output = 'ISO-8859-1';
193  }
194 
195  // Load translation files required by the page
196  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
197 
198  global $outputlangsbis;
199  $outputlangsbis = null;
200  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
201  $outputlangsbis = new Translate('', $conf);
202  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
203  $outputlangsbis->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
204  }
205 
206  if (!isset($object->lines) || !is_array($object->lines)) {
207  $object->lines = array();
208  }
209 
210  $nblines = count($object->lines);
211 
212  $hidetop = 0;
213  if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
214  $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
215  }
216 
217  // Loop on each lines to detect if there is at least one image to show
218  $realpatharray = array();
219 
220  if ($conf->mrp->dir_output) {
221  $object->fetch_thirdparty();
222 
223  $deja_regle = 0;
224  $amount_credit_notes_included = 0;
225  $amount_deposits_included = 0;
226  //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
227  //$amount_deposits_included = $object->getSumDepositsUsed();
228 
229  // Definition of $dir and $file
230  if ($object->specimen) {
231  $dir = $conf->mrp->dir_output;
232  $file = $dir."/SPECIMEN.pdf";
233  } else {
234  $objectref = dol_sanitizeFileName($object->ref);
235  $dir = $conf->mrp->dir_output.'/'.$objectref;
236  $file = $dir."/".$objectref.".pdf";
237  }
238 
239  if (!file_exists($dir)) {
240  if (dol_mkdir($dir) < 0) {
241  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
242  return 0;
243  }
244  }
245 
246  if (file_exists($dir)) {
247  // Add pdfgeneration hook
248  if (!is_object($hookmanager)) {
249  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
250  $hookmanager = new HookManager($this->db);
251  }
252  $hookmanager->initHooks(array('pdfgeneration'));
253  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
254  global $action;
255  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
256 
257  $nblines = count($object->lines);
258 
259  $pdf = pdf_getInstance($this->format);
260  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
261  $heightforinfotot = 50; // Height reserved to output the info and total part
262  $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
263  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
264  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
265  $heightforfooter += 6;
266  }
267  $pdf->SetAutoPageBreak(1, 0);
268 
269  if (class_exists('TCPDF')) {
270  $pdf->setPrintHeader(false);
271  $pdf->setPrintFooter(false);
272  }
273  $pdf->SetFont(pdf_getPDFFont($outputlangs));
274  // Set path to the background PDF File
275  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
276  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
277  $tplidx = $pdf->importPage(1);
278  }
279 
280  $pdf->Open();
281  $pagenb = 0;
282  $pdf->SetDrawColor(128, 128, 128);
283 
284  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
285  $pdf->SetSubject($outputlangs->transnoentities("Mo"));
286  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
287  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
288  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Mo")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
289  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
290  $pdf->SetCompression(false);
291  }
292 
293  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
294 
295  // Does we have at least one line with discount $this->atleastonediscount
296 
297  // New page
298  $pdf->AddPage();
299  if (!empty($tplidx)) {
300  $pdf->useTemplate($tplidx);
301  }
302  $pagenb++;
303  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
304  $pdf->SetFont('', '', $default_font_size - 1);
305  $pdf->MultiCell(0, 3, ''); // Set interline to 3
306  $pdf->SetTextColor(0, 0, 0);
307 
308  $tab_top = 90 + $top_shift;
309  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
310 
311  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
312 
313 
314  // Affiche notes
315  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
316 
317  // Extrafields in note
318  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
319  if (!empty($extranote)) {
320  $notetoshow = dol_concatdesc($notetoshow, $extranote);
321  }
322 
323  $pagenb = $pdf->getPage();
324  if ($notetoshow) {
325  $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
326  $pageposbeforenote = $pagenb;
327 
328  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
329  complete_substitutions_array($substitutionarray, $outputlangs, $object);
330  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
331  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
332 
333  $tab_top -= 2;
334 
335  $pdf->startTransaction();
336 
337  $pdf->SetFont('', '', $default_font_size - 1);
338  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
339  // Description
340  $pageposafternote = $pdf->getPage();
341  $posyafter = $pdf->GetY();
342 
343  if ($pageposafternote > $pageposbeforenote) {
344  $pdf->rollbackTransaction(true);
345 
346  // prepar pages to receive notes
347  while ($pagenb < $pageposafternote) {
348  $pdf->AddPage();
349  $pagenb++;
350  if (!empty($tplidx)) {
351  $pdf->useTemplate($tplidx);
352  }
353  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
354  $this->_pagehead($pdf, $object, 0, $outputlangs);
355  }
356  // $this->_pagefoot($pdf,$object,$outputlangs,1);
357  $pdf->setTopMargin($tab_top_newpage);
358  // The only function to edit the bottom margin of current page to set it.
359  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
360  }
361 
362  // back to start
363  $pdf->setPage($pageposbeforenote);
364  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
365  $pdf->SetFont('', '', $default_font_size - 1);
366  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
367  $pageposafternote = $pdf->getPage();
368 
369  $posyafter = $pdf->GetY();
370 
371  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
372  $pdf->AddPage('', '', true);
373  $pagenb++;
374  $pageposafternote++;
375  $pdf->setPage($pageposafternote);
376  $pdf->setTopMargin($tab_top_newpage);
377  // The only function to edit the bottom margin of current page to set it.
378  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
379  //$posyafter = $tab_top_newpage;
380  }
381 
382 
383  // apply note frame to previus pages
384  $i = $pageposbeforenote;
385  while ($i < $pageposafternote) {
386  $pdf->setPage($i);
387 
388 
389  $pdf->SetDrawColor(128, 128, 128);
390  // Draw note frame
391  if ($i > $pageposbeforenote) {
392  $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
393  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
394  } else {
395  $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
396  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
397  }
398 
399  // Add footer
400  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
401  $this->_pagefoot($pdf, $object, $outputlangs, 1);
402 
403  $i++;
404  }
405 
406  // apply note frame to last page
407  $pdf->setPage($pageposafternote);
408  if (!empty($tplidx)) {
409  $pdf->useTemplate($tplidx);
410  }
411  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
412  $this->_pagehead($pdf, $object, 0, $outputlangs);
413  }
414  $height_note = $posyafter - $tab_top_newpage;
415  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
416  } else {
417  // No pagebreak
418  $pdf->commitTransaction();
419  $posyafter = $pdf->GetY();
420  $height_note = $posyafter - $tab_top;
421  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
422 
423 
424  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
425  // not enough space, need to add page
426  $pdf->AddPage('', '', true);
427  $pagenb++;
428  $pageposafternote++;
429  $pdf->setPage($pageposafternote);
430  if (!empty($tplidx)) {
431  $pdf->useTemplate($tplidx);
432  }
433  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
434  $this->_pagehead($pdf, $object, 0, $outputlangs);
435  }
436 
437  $posyafter = $tab_top_newpage;
438  }
439  }
440 
441  $tab_height = $tab_height - $height_note;
442  $tab_top = $posyafter + 6;
443  } else {
444  $height_note = 0;
445  }
446 
447  $nexY = $tab_top + 5;
448 
449  // Use new auto collum system
450  $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
451 
452  // Loop on each lines
453  $pageposbeforeprintlines = $pdf->getPage();
454  $pagenb = $pageposbeforeprintlines;
455 
456  $bom = new BOM($this->db);
457  $bom -> fetch($object->fk_bom);
458 
459  $nblines = count($bom->lines);
460 
461  for ($i = 0; $i < $nblines; $i++) {
462  $curY = $nexY;
463  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
464  $pdf->SetTextColor(0, 0, 0);
465 
466  $prod = new Product($this->db);
467  $prod->fetch($bom->lines[$i]->fk_product);
468 
469  // Define size of image if we need it
470  $imglinesize = array();
471  if (!empty($realpatharray[$i])) {
472  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
473  }
474 
475  $pdf->setTopMargin($tab_top_newpage);
476  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
477  $pageposbefore = $pdf->getPage();
478 
479  $showpricebeforepagebreak = 1;
480  $posYAfterImage = 0;
481  $posYAfterDescription = 0;
482 
483  // We start with Photo of product line
484  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
485  $pdf->AddPage('', '', true);
486  if (!empty($tplidx)) {
487  $pdf->useTemplate($tplidx);
488  }
489  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
490  $this->_pagehead($pdf, $object, 0, $outputlangs);
491  }
492  $pdf->setPage($pageposbefore + 1);
493 
494  $curY = $tab_top_newpage;
495 
496  // Allows data in the first page if description is long enough to break in multiples pages
497  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
498  $showpricebeforepagebreak = 1;
499  } else {
500  $showpricebeforepagebreak = 0;
501  }
502  }
503 
504  if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) {
505  $curX = $this->posxpicture - 1;
506  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
507  // $pdf->Image does not increase value return by getY, so we save it manually
508  $posYAfterImage = $curY + $imglinesize['height'];
509  }
510  // Description of product line
511  $curX = $this->posxdesc - 1;
512  $showpricebeforepagebreak = 1;
513 
514  if ($this->getColumnStatus('code')) {
515  $pdf->startTransaction(); //description
516  //$this->printColDescContent($pdf, $curY, 'code', $object, $i, $outputlangs, $hideref, $hidedesc, $showsupplierSKU);
517  $this->printStdColumnContent($pdf, $curY, 'code', $prod->ref);
518 
519  $pageposafter = $pdf->getPage();
520  $posyafter = $pdf->GetY();
521  if ($pageposafter > $pageposbefore) { // There is a pagebreak
522  $pdf->rollbackTransaction(true);
523 
524  //$this->printColDescContent($pdf, $curY, 'code', $object, $i, $outputlangs, $hideref, $hidedesc, $showsupplierSKU);
525  $this->printStdColumnContent($pdf, $curY, 'code', $prod->ref);
526 
527  $pageposafter = $pdf->getPage();
528  $posyafter = $pdf->GetY();
529  } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
530  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
531  $pdf->AddPage('', '', true);
532  if (!empty($tplidx)) {
533  $pdf->useTemplate($tplidx);
534  }
535  //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
536  $pdf->setPage($pageposafter + 1);
537  } else {
538  // We found a page break
539  // Allows data in the first page if description is long enough to break in multiples pages
540  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
541  $showpricebeforepagebreak = 1;
542  } else {
543  $showpricebeforepagebreak = 0;
544  }
545  }
546  } else // No pagebreak
547  {
548  $pdf->commitTransaction();
549  }
550  $posYAfterDescription = $pdf->GetY();
551  }
552 
553  $nexY = $pdf->GetY();
554  $pageposafter = $pdf->getPage();
555  $pdf->setPage($pageposbefore);
556  $pdf->setTopMargin($this->marge_haute);
557  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
558 
559  // We suppose that a too long description is moved completely on next page
560  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
561  $pdf->setPage($pageposafter);
562  $curY = $tab_top_newpage;
563  }
564 
565  if ($this->getColumnStatus('desc')) {
566  $pdf->startTransaction(); //description
567  $des = $prod -> description;
568  $descr = $des;//implode("<br>", $des);
569 
570  $this->printStdColumnContent($pdf, $curY, 'desc', $descr);
571 
572  $pageposafter = $pdf->getPage();
573  $posyafter = $pdf->GetY();
574  if ($pageposafter > $pageposbefore) { // There is a pagebreak
575  $pdf->rollbackTransaction(true);
576 
577  $this->printStdColumnContent($pdf, $curY, 'desc', $descr);
578 
579  $pageposafter = $pdf->getPage();
580  $posyafter = $pdf->GetY();
581  } elseif ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
582  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
583  $pdf->AddPage('', '', true);
584  if (!empty($tplidx)) {
585  $pdf->useTemplate($tplidx);
586  }
587  //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
588  $pdf->setPage($pageposafter + 1);
589  } else {
590  // We found a page break
591  // Allows data in the first page if description is long enough to break in multiples pages
592  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
593  $showpricebeforepagebreak = 1;
594  } else {
595  $showpricebeforepagebreak = 0;
596  }
597  }
598  } else // No pagebreak
599  {
600  $pdf->commitTransaction();
601  }
602  $posYAfterDescription = max($posYAfterDescription, $pdf->GetY());
603  }
604 
605  $nexY = max($nexY, $pdf->GetY());
606  $pageposafter = $pdf->getPage();
607  $pdf->setPage($pageposbefore);
608  $pdf->setTopMargin($this->marge_haute);
609  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
610 
611  // We suppose that a too long description is moved completely on next page
612  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
613  $pdf->setPage($pageposafter);
614  $curY = $tab_top_newpage;
615  }
616 
617  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
618 
619  // Quantity
620  // Enough for 6 chars
621  if ($this->getColumnStatus('qty')) {
622  $qty = $bom->lines[$i]->qty;
623  $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
624  $nexY = max($pdf->GetY(), $nexY);
625  }
626 
627  // Quantity
628  // Enough for 6 chars
629  if ($this->getColumnStatus('qtytot')) {
630  $qtytot = $object->qty * $bom->lines[$i]->qty;
631  $this->printStdColumnContent($pdf, $curY, 'qtytot', $qtytot);
632  $nexY = max($pdf->GetY(), $nexY);
633  }
634 
635  // Dimensions
636  if ($this->getColumnStatus('dim')) {
637  $array = array_filter(array($prod->length, $prod->width, $prod->height));
638  $dim = implode("x", $array);
639  $this->printStdColumnContent($pdf, $curY, 'dim', $dim);
640  $nexY = max($pdf->GetY(), $nexY);
641  }
642  }
643 
644 
645 
646 
647  // Show square
648  if ($pagenb == $pageposbeforeprintlines) {
649  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
650  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
651  } else {
652  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
653  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
654  }
655 
656  // Affiche zone infos
657  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
658 
659  // Affiche zone totaux
660  //$posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
661 
662  // Affiche zone versements
663  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
664  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
665  }
666 
667  // Pied de page
668  $this->_pagefoot($pdf, $object, $outputlangs);
669  if (method_exists($pdf, 'AliasNbPages')) {
670  $pdf->AliasNbPages();
671  }
672 
673  $pdf->Close();
674 
675  $pdf->Output($file, 'F');
676 
677  // Add pdfgeneration hook
678  $hookmanager->initHooks(array('pdfgeneration'));
679  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
680  global $action;
681  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
682  if ($reshook < 0) {
683  $this->error = $hookmanager->error;
684  $this->errors = $hookmanager->errors;
685  }
686 
687  if (!empty($conf->global->MAIN_UMASK)) {
688  @chmod($file, octdec($conf->global->MAIN_UMASK));
689  }
690 
691  $this->result = array('fullpath'=>$file);
692 
693  return 1; // No error
694  } else {
695  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
696  return 0;
697  }
698  } else {
699  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
700  return 0;
701  }
702  }
703 
704  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
705  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
715  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
716  {
717  // phpcs:enable
718  }
719 
720  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
721  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
731  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
732  {
733  // phpcs:enable
734  global $conf, $mysoc;
735  $default_font_size = pdf_getPDFFontSize($outputlangs);
736 
737  // If France, show VAT mention if not applicable
738  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
739  $pdf->SetFont('', 'B', $default_font_size - 2);
740  $pdf->SetXY($this->marge_gauche, $posy);
741  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
742 
743  $posy = $pdf->GetY() + 4;
744  }
745 
746  $posxval = 52;
747 
748  // Show payments conditions
749  if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
750  $pdf->SetFont('', 'B', $default_font_size - 2);
751  $pdf->SetXY($this->marge_gauche, $posy);
752  $titre = $outputlangs->transnoentities("PaymentConditions").':';
753  $pdf->MultiCell(80, 4, $titre, 0, 'L');
754 
755  $pdf->SetFont('', '', $default_font_size - 2);
756  $pdf->SetXY($posxval, $posy);
757  $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);
758  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
759  $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
760 
761  $posy = $pdf->GetY() + 3;
762  }
763 
764  // Show payment mode
765  if (!empty($object->mode_reglement_code)) {
766  $pdf->SetFont('', 'B', $default_font_size - 2);
767  $pdf->SetXY($this->marge_gauche, $posy);
768  $titre = $outputlangs->transnoentities("PaymentMode").':';
769  $pdf->MultiCell(80, 5, $titre, 0, 'L');
770 
771  $pdf->SetFont('', '', $default_font_size - 2);
772  $pdf->SetXY($posxval, $posy);
773  $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);
774  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
775 
776  $posy = $pdf->GetY() + 2;
777  }
778 
779 
780  return $posy;
781  }
782 
783  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
784  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
795  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
796  {
797  // phpcs:enable
798  global $conf, $mysoc;
799 
800  $default_font_size = pdf_getPDFFontSize($outputlangs);
801 
802  $tab2_top = $posy;
803  $tab2_hl = 4;
804  $pdf->SetFont('', '', $default_font_size - 1);
805 
806  // Tableau total
807  $col1x = 120;
808  $col2x = 170;
809  if ($this->page_largeur < 210) { // To work with US executive format
810  $col2x -= 20;
811  }
812  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
813 
814  $useborder = 0;
815  $index = 0;
816 
817  // Total HT
818  $pdf->SetFillColor(255, 255, 255);
819  $pdf->SetXY($col1x, $tab2_top + 0);
820  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
821 
822  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
823  $pdf->SetXY($col2x, $tab2_top + 0);
824  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
825 
826  // Show VAT by rates and total
827  $pdf->SetFillColor(248, 248, 248);
828 
829  $this->atleastoneratenotnull = 0;
830  foreach ($this->tva as $tvakey => $tvaval) {
831  if ($tvakey > 0) { // On affiche pas taux 0
832  $this->atleastoneratenotnull++;
833 
834  $index++;
835  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
836 
837  $tvacompl = '';
838 
839  if (preg_match('/\*/', $tvakey)) {
840  $tvakey = str_replace('*', '', $tvakey);
841  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
842  }
843 
844  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
845  $totalvat .= vatrate($tvakey, 1).$tvacompl;
846  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
847 
848  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
849  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
850  }
851  }
852  if (!$this->atleastoneratenotnull) { // If no vat at all
853  $index++;
854  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
855  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
856 
857  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
858  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
859 
860  // Total LocalTax1
861  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
862  $index++;
863  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
864  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
865  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
866  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
867  }
868 
869  // Total LocalTax2
870  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
871  $index++;
872  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
873  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
874  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
875  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
876  }
877  } else {
878  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
879  //{
880  //Local tax 1
881  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
882  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
883  continue;
884  }
885 
886  foreach ($localtax_rate as $tvakey => $tvaval) {
887  if ($tvakey != 0) { // On affiche pas taux 0
888  //$this->atleastoneratenotnull++;
889 
890  $index++;
891  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
892 
893  $tvacompl = '';
894  if (preg_match('/\*/', $tvakey)) {
895  $tvakey = str_replace('*', '', $tvakey);
896  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
897  }
898  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
899  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
900  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
901 
902  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
903  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
904  }
905  }
906  }
907 
908  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
909  //{
910  //Local tax 2
911  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
912  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
913  continue;
914  }
915 
916  foreach ($localtax_rate as $tvakey => $tvaval) {
917  if ($tvakey != 0) { // On affiche pas taux 0
918  //$this->atleastoneratenotnull++;
919 
920  $index++;
921  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
922 
923  $tvacompl = '';
924  if (preg_match('/\*/', $tvakey)) {
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 = (isModEnabled("multicurrency") && $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)) {
959  $resteapayer = 0;
960  }
961 
962  if ($deja_regle > 0) {
963  // Already paid + Deposits
964  $index++;
965 
966  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
967  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
968  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
969  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
970 
971  $index++;
972  $pdf->SetTextColor(0, 0, 60);
973  $pdf->SetFillColor(224, 224, 224);
974  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
975  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
976 
977  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
978  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
979 
980  $pdf->SetFont('', '', $default_font_size - 1);
981  $pdf->SetTextColor(0, 0, 0);
982  }
983 
984  $index++;
985  return ($tab2_top + ($tab2_hl * $index));
986  }
987 
988  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1002  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1003  {
1004  global $conf;
1005 
1006  // Force to disable hidetop and hidebottom
1007  $hidebottom = 0;
1008  if ($hidetop) {
1009  $hidetop = -1;
1010  }
1011 
1012  $currency = !empty($currency) ? $currency : $conf->currency;
1013  $default_font_size = pdf_getPDFFontSize($outputlangs);
1014 
1015  // Amount in (at tab_top - 1)
1016  $pdf->SetTextColor(0, 0, 0);
1017  $pdf->SetFont('', '', $default_font_size - 2);
1018 
1019  if (empty($hidetop)) {
1020  //$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1021  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1022  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1023 
1024  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1025  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1026  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1027  }
1028  }
1029 
1030  $pdf->SetDrawColor(128, 128, 128);
1031  $pdf->SetFont('', '', $default_font_size - 1);
1032 
1033  // Output Rect
1034  $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
1035 
1036  foreach ($this->cols as $colKey => $colDef) {
1037  if (!$this->getColumnStatus($colKey)) {
1038  continue;
1039  }
1040 
1041  // get title label
1042  $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1043 
1044  // Add column separator
1045  if (!empty($colDef['border-left'])) {
1046  $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1047  }
1048 
1049  if (empty($hidetop)) {
1050  $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
1051 
1052  $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
1053  $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1054  }
1055  }
1056 
1057  if (empty($hidetop)) {
1058  $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
1059  }
1060  }
1061 
1062  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1072  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1073  {
1074  global $langs, $conf, $mysoc;
1075 
1076  $ltrdirection = 'L';
1077  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1078 
1079  // Load translation files required by the page
1080  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1081 
1082  $default_font_size = pdf_getPDFFontSize($outputlangs);
1083 
1084  // Do not add the BACKGROUND as this is for suppliers
1085  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1086 
1087  //Affiche le filigrane brouillon - Print Draft Watermark
1088  /*if($object->statut==0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
1089  {
1090  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
1091  }*/
1092  //Print content
1093 
1094  $pdf->SetTextColor(0, 0, 60);
1095  $pdf->SetFont('', 'B', $default_font_size + 3);
1096 
1097  $posx = $this->page_largeur - $this->marge_droite - 100;
1098  $posy = $this->marge_haute;
1099 
1100  $pdf->SetXY($this->marge_gauche, $posy);
1101 
1102  // Logo
1103  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1104  if ($this->emetteur->logo) {
1105  if (is_readable($logo)) {
1106  $height = pdf_getHeightForLogo($logo);
1107  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1108  } else {
1109  $pdf->SetTextColor(200, 0, 0);
1110  $pdf->SetFont('', 'B', $default_font_size - 2);
1111  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1112  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1113  }
1114  } else {
1115  $text = $this->emetteur->name;
1116  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1117  }
1118 
1119  $pdf->SetFont('', 'B', $default_font_size + 3);
1120  $pdf->SetXY($posx, $posy);
1121  $pdf->SetTextColor(0, 0, 60);
1122  $title = $outputlangs->transnoentities("Mo")." ".$outputlangs->convToOutputCharset($object->ref);
1123  $pdf->MultiCell(100, 3, $title, '', 'R');
1124  $posy += 1;
1125 
1126  if ($object->ref_supplier) {
1127  $posy += 4;
1128  $pdf->SetFont('', 'B', $default_font_size);
1129  $pdf->SetXY($posx, $posy);
1130  $pdf->SetTextColor(0, 0, 60);
1131  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1132  $posy += 1;
1133  }
1134 
1135  $pdf->SetFont('', '', $default_font_size - 1);
1136  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1137  $object->fetch_projet();
1138  if (!empty($object->project->ref)) {
1139  $posy += 3;
1140  $pdf->SetXY($posx, $posy);
1141  $pdf->SetTextColor(0, 0, 60);
1142  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1143  }
1144  }
1145 
1146  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1147  $object->fetch_projet();
1148  if (!empty($object->project->ref)) {
1149  $outputlangs->load("projects");
1150  $posy += 4;
1151  $pdf->SetXY($posx, $posy);
1152  $langs->load("projects");
1153  $pdf->SetTextColor(0, 0, 60);
1154  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1155  }
1156  }
1157 
1158  if (!empty($object->date_approve)) {
1159  $posy += 5;
1160  $pdf->SetXY($posx, $posy);
1161  $pdf->SetTextColor(0, 0, 60);
1162  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("MoDate")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs, true), '', 'R');
1163  } else {
1164  $posy += 5;
1165  $pdf->SetXY($posx, $posy);
1166  $pdf->SetTextColor(255, 0, 0);
1167  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToApprove"), '', 'R');
1168  }
1169 
1170  // product info
1171  $prodToMake = new Product($this->db);
1172  $resProdToMake = $prodToMake->fetch($object->fk_product);
1173 
1174  if ($resProdToMake > 0) {
1175  // ref
1176  $posy += 7;
1177  $pdf->SetFont('', 'B', $default_font_size + 1);
1178  $pdf->SetXY($posx, $posy);
1179  $pdf->SetTextColor(0, 0, 60);
1180  $pdf->MultiCell($w, 3, $prodToMake->ref, '', 'R');
1181 
1182  // description
1183  $posy += 5;
1184  $pdf->SetFont('', 'B', $default_font_size + 3);
1185  $pdf->SetXY($posx, $posy);
1186  $pdf->SetTextColor(0, 0, 60);
1187  $pdf->MultiCell($w, 3, html_entity_decode($prodToMake->description), '', 'R');
1188  $posy = $pdf->GetY() - 5;
1189 
1190  // dimensions
1191  $array = array_filter(array($prodToMake->length, $prodToMake->width, $prodToMake->height));
1192  $dim = implode("x", $array);
1193  if (!empty($dim)) {
1194  $posy += 5;
1195  $pdf->SetFont('', 'B', $default_font_size + 3);
1196  $pdf->SetXY($posx, $posy);
1197  $pdf->SetTextColor(0, 0, 60);
1198  $pdf->MultiCell($w, 3, $dim, '', 'R');
1199  }
1200  }
1201 
1202  $posy += 5;
1203  $pdf->SetFont('', 'B', $default_font_size + 3);
1204  $pdf->SetXY($posx, $posy);
1205  $pdf->SetTextColor(0, 0, 60);
1206  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("QtyToProduce").": " .$object->qty, '', 'R');
1207 
1208 
1209  $pdf->SetTextColor(0, 0, 60);
1210  $usehourmin = 'day';
1211  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1212  $usehourmin = 'dayhour';
1213  }
1214  if (!empty($object->delivery_date)) {
1215  $posy += 4;
1216  $pdf->SetXY($posx - 90, $posy);
1217  $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1218  }
1219 
1220  if ($object->thirdparty->code_fournisseur) {
1221  $posy += 4;
1222  $pdf->SetXY($posx, $posy);
1223  $pdf->SetTextColor(0, 0, 60);
1224  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1225  }
1226 
1227  // Get contact
1228  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1229  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1230  if (count($arrayidcontact) > 0) {
1231  $usertmp = new User($this->db);
1232  $usertmp->fetch($arrayidcontact[0]);
1233  $posy += 4;
1234  $pdf->SetXY($posx, $posy);
1235  $pdf->SetTextColor(0, 0, 60);
1236  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1237  }
1238  }
1239 
1240  $posy += 1;
1241  $pdf->SetTextColor(0, 0, 60);
1242 
1243  $top_shift = 0;
1244  // Show list of linked objects
1245  $current_y = $pdf->getY();
1246  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1247  if ($current_y < $pdf->getY()) {
1248  $top_shift = $pdf->getY() - $current_y;
1249  }
1250 
1251  if ($showaddress) {
1252  // Sender properties
1253  $carac_emetteur = '';
1254  // Add internal contact of proposal if defined
1255  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1256  if (count($arrayidcontact) > 0) {
1257  $object->fetch_user($arrayidcontact[0]);
1258  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1259  }
1260 
1261  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1262 
1263  // Show sender
1264  $posy = 42 + $top_shift;
1265  $posx = $this->marge_gauche;
1266  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1267  $posx = $this->page_largeur - $this->marge_droite - 80;
1268  }
1269  $hautcadre = 40;
1270 
1271  // Show sender frame
1272  $pdf->SetTextColor(0, 0, 0);
1273  $pdf->SetFont('', '', $default_font_size - 2);
1274  $pdf->SetXY($posx, $posy - 5);
1275  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1276  $pdf->SetXY($posx, $posy);
1277  $pdf->SetFillColor(230, 230, 230);
1278  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1279  $pdf->SetTextColor(0, 0, 60);
1280 
1281  // Show sender name
1282  $pdf->SetXY($posx + 2, $posy + 3);
1283  $pdf->SetFont('', 'B', $default_font_size);
1284  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1285  $posy = $pdf->getY();
1286 
1287  // Show sender information
1288  $pdf->SetXY($posx + 2, $posy);
1289  $pdf->SetFont('', '', $default_font_size - 1);
1290  $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1291 
1292 
1293 
1294  // 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'
1295  $usecontact = false;
1296  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1297  if (count($arrayidcontact) > 0) {
1298  $usecontact = true;
1299  $result = $object->fetch_contact($arrayidcontact[0]);
1300  }
1301 
1302  // Recipient name
1303  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)))) {
1304  $thirdparty = $object->contact;
1305  } else {
1306  $thirdparty = $object->thirdparty;
1307  }
1308 
1309  //$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1310 
1311  //$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1312 
1313  // Show recipient
1314  //$widthrecbox = 100;
1315  //if ($this->page_largeur < 210) {
1316  // $widthrecbox = 84; // To work with US executive format
1317  //}
1318  //$posy = 42 + $top_shift;
1319  //$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1320  //if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1321  // $posx = $this->marge_gauche;
1322  //}
1323  //
1325  //$pdf->SetTextColor(0, 0, 0);
1326  //$pdf->SetFont('', '', $default_font_size - 2);
1327  //$pdf->SetXY($posx + 2, $posy - 5);
1328  //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1329  //$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1330  //
1332  //$pdf->SetXY($posx + 2, $posy + 3);
1333  //$pdf->SetFont('', 'B', $default_font_size);
1334  //$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1335  //
1336  //$posy = $pdf->getY();
1337  //
1339  //$pdf->SetFont('', '', $default_font_size - 1);
1340  //$pdf->SetXY($posx + 2, $posy);
1341  //$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1342  }
1343 
1344  return $top_shift;
1345  }
1346 
1347  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1357  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1358  {
1359  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1360  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1361  }
1362 
1363 
1364 
1375  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1376  {
1377  global $conf, $hookmanager;
1378 
1379  // Default field style for content
1380  $this->defaultContentsFieldsStyle = array(
1381  'align' => 'R', // R,C,L
1382  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1383  );
1384 
1385  // Default field style for content
1386  $this->defaultTitlesFieldsStyle = array(
1387  'align' => 'C', // R,C,L
1388  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1389  );
1390 
1391  /*
1392  * For exemple
1393  $this->cols['theColKey'] = array(
1394  'rank' => $rank, // int : use for ordering columns
1395  'width' => 20, // the column width in mm
1396  'title' => array(
1397  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1398  'label' => ' ', // the final label : used fore final generated text
1399  'align' => 'L', // text alignement : R,C,L
1400  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1401  ),
1402  'content' => array(
1403  'align' => 'L', // text alignement : R,C,L
1404  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1405  ),
1406  );
1407  */
1408  $rank = 0;
1409  $this->cols['code'] = array(
1410  'rank' => $rank,
1411  'status' => false,
1412  'width' => 35, // in mm
1413  'title' => array(
1414  'textkey' => 'Ref'
1415  ),
1416  'border-left' => true, // add left line separator
1417  );
1418  $this->cols['code']['status'] = true;
1419 
1420  $rank = 1; // do not use negative rank
1421  $this->cols['desc'] = array(
1422  'rank' => $rank,
1423  'width' => false, // only for desc
1424  'status' => true,
1425  'title' => array(
1426  'textkey' => 'Designation', // use lang key is usefull in somme case with module
1427  'align' => 'L',
1428  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1429  // 'label' => ' ', // the final label
1430  'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1431  ),
1432  'border-left' => true,
1433  'content' => array(
1434  'align' => 'L',
1435  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1436  ),
1437  );
1438 
1439  $rank = $rank + 10;
1440  $this->cols['photo'] = array(
1441  'rank' => $rank,
1442  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1443  'status' => false,
1444  'title' => array(
1445  'textkey' => 'Photo',
1446  'label' => ' '
1447  ),
1448  'content' => array(
1449  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1450  ),
1451  'border-left' => false, // remove left line separator
1452  );
1453 
1454  if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) {
1455  $this->cols['photo']['status'] = true;
1456  }
1457 
1458  $rank = $rank + 10;
1459  $this->cols['dim'] = array(
1460  'rank' => $rank,
1461  'status' => false,
1462  'width' => 25, // in mm
1463  'title' => array(
1464  'textkey' => 'Size'
1465  ),
1466  'border-left' => true, // add left line separator
1467  );
1468  $this->cols['dim']['status'] = true;
1469 
1470  $rank = $rank + 10;
1471  $this->cols['qty'] = array(
1472  'rank' => $rank,
1473  'width' => 16, // in mm
1474  'status' => true,
1475  'title' => array(
1476  'textkey' => 'Qty'
1477  ),
1478  'border-left' => true, // add left line separator
1479  );
1480  $this->cols['qty']['status'] = true;
1481 
1482  $rank = $rank + 10;
1483  $this->cols['qtytot'] = array(
1484  'rank' => $rank,
1485  'width' => 25, // in mm
1486  'status' => true,
1487  'title' => array(
1488  'textkey' => 'QtyTot'
1489  ),
1490  'border-left' => true, // add left line separator
1491  );
1492  $this->cols['qtytot']['status'] = true;
1493 
1494  // Add extrafields cols
1495  if (!empty($object->lines)) {
1496  $line = reset($object->lines);
1497  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1498  }
1499 
1500  $parameters = array(
1501  'object' => $object,
1502  'outputlangs' => $outputlangs,
1503  'hidedetails' => $hidedetails,
1504  'hidedesc' => $hidedesc,
1505  'hideref' => $hideref
1506  );
1507 
1508  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1509  if ($reshook < 0) {
1510  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1511  } elseif (empty($reshook)) {
1512  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1513  } else {
1514  $this->cols = $hookmanager->resArray;
1515  }
1516  }
1517 }
Class for BOM.
Definition: bom.class.php:37
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Parent class for mos models.
Definition: modules_mo.php:40
Class to manage products or services.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class to generate the manufacturing orders with the vinci model.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1001
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:749
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_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:434
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41