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