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