dolibarr 25.0.0-alpha
pdf_zenith.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-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Nick Fragoulis
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
34require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
39
40
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 $conf, $langs, $mysoc;
86
87 // Load translation files required by the page
88 $langs->loadLangs(array("main", "bills"));
89
90 $this->db = $db;
91 $this->name = "zenith";
92 $this->description = $langs->trans('DocModelZenithDescription');
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 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
106 $this->option_logo = 1; // Display logo
107 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
108 $this->option_modereg = 1; // Display payment mode
109 $this->option_condreg = 1; // Display payment terms
110 $this->option_multilang = 1; //Available in several languages
111 $this->option_escompte = 0; // Displays if there has been a discount
112 $this->option_credit_note = 0; // Support credit notes
113 $this->option_freetext = 1; // Support add of a personalised text
114 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
115
116 // Define position of columns
117 $this->posxdesc = $this->marge_gauche + 1; // For module retrocompatibility support during PDF transition: TODO remove this at the end
118
119 $this->tabTitleHeight = 5; // default height
120
121 $this->tva = array();
122 $this->tva_array = array();
123 $this->localtax1 = array();
124 $this->localtax2 = array();
125 $this->atleastoneratenotnull = 0;
126 $this->atleastonediscount = 0;
127
128 if ($mysoc === null) {
129 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
130 return;
131 }
132
133 // Get source company
134 $this->emetteur = $mysoc;
135 if (empty($this->emetteur->country_code)) {
136 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
137 }
138 }
139
140
141 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
153 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
154 {
155 // phpcs:enable
156 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
157
158 if (!is_object($outputlangs)) {
159 $outputlangs = $langs;
160 }
161 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
162 if (getDolGlobalString('MAIN_USE_FPDF')) {
163 $outputlangs->charset_output = 'ISO-8859-1';
164 }
165
166 // Load translation files required by the page
167 $outputlangs->loadLangs(array("main", "supplier_proposal", "companies", "bills", "dict", "products"));
168
169 global $outputlangsbis;
170 $outputlangsbis = null;
171 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
172 $outputlangsbis = new Translate('', $conf);
173 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
174 $outputlangsbis->loadLangs(array("main", "supplier_proposal", "companies", "bills", "dict", "products"));
175 }
176
177 $nblines = count($object->lines);
178
179 $hidetop = 0;
180 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
181 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
182 }
183
184 // Loop on each lines to detect if there is at least one image to show
185 $realpatharray = array();
186 if (getDolGlobalString('MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE')) {
187 for ($i = 0; $i < $nblines; $i++) {
188 if (empty($object->lines[$i]->fk_product)) {
189 continue;
190 }
191
192 $objphoto = new Product($this->db);
193 $objphoto->fetch($object->lines[$i]->fk_product);
194
195 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
196 $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
197 $dir = $conf->product->dir_output.'/'.$pdir;
198 } else {
199 $pdir = get_exdir($objphoto->id, 0, 0, 0, $objphoto, 'product');
200 $dir = $conf->product->dir_output.'/'.$pdir;
201 }
202
203 $realpath = '';
204 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
205 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
206 if ($obj['photo_vignette']) {
207 $filename = $obj['photo_vignette'];
208 } else {
209 $filename = $obj['photo'];
210 }
211 } else {
212 $filename = $obj['photo'];
213 }
214 $realpath = $dir.$filename;
215 break;
216 }
217
218 if ($realpath) {
219 $realpatharray[$i] = $realpath;
220 }
221 }
222 }
223 if (count($realpatharray) == 0) {
224 $this->posxpicture = $this->posxtva;
225 }
226
227 if ($conf->supplier_proposal->dir_output) {
228 $object->fetch_thirdparty();
229
230 $deja_regle = 0;
231 $amount_credit_notes_included = 0;
232 $amount_deposits_included = 0;
233 //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
234 //$amount_deposits_included = $object->getSumDepositsUsed();
235
236 // Definition of $dir and $file
237 if ($object->specimen) {
238 $dir = $conf->supplier_proposal->dir_output;
239 $file = $dir."/SPECIMEN.pdf";
240 } else {
241 $objectref = dol_sanitizeFileName($object->ref);
242 $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
243 $dir = $conf->supplier_proposal->dir_output.'/'.$objectref;
244 $file = $dir."/".$objectref.".pdf";
245 if (getDolGlobalString('SUPPLIER_REF_IN_NAME')) {
246 $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
247 }
248 }
249
250 if (!file_exists($dir)) {
251 if (dol_mkdir($dir) < 0) {
252 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
253 return 0;
254 }
255 }
256
257 if (file_exists($dir)) {
258 // Add pdfgeneration hook
259 if (!is_object($hookmanager)) {
260 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
261 $hookmanager = new HookManager($this->db);
262 }
263 $hookmanager->initHooks(array('pdfgeneration'));
264 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
265 global $action;
266 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
267
268 $nblines = count($object->lines);
269
270 $pdf = pdf_getInstance($this->format);
271 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
272 $heightforinfotot = 50; // Height reserved to output the info and total part
273 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
274 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
275 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
276 $heightforfooter += 6;
277 }
278 $pdf->setAutoPageBreak(true, 0);
279
280 if (class_exists('TCPDF')) {
281 $pdf->setPrintHeader(false);
282 $pdf->setPrintFooter(false);
283 }
284 $pdf->SetFont(pdf_getPDFFont($outputlangs));
285 // Set path to the background PDF File
286 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
287 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
288 $tplidx = $pdf->importPage(1);
289 }
290
291 $pdf->Open();
292 $pagenb = 0;
293 $pdf->SetDrawColor(128, 128, 128);
294
295 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
296 $pdf->SetSubject($outputlangs->transnoentities("SupplierProposal"));
297 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
298 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
299 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("SupplierProposal")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
300 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
301 $pdf->SetCompression(false);
302 }
303
304 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
305 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
306
307 // Does we have at least one line with discount $this->atleastonediscount
308 foreach ($object->lines as $line) {
309 if ($line->remise_percent) {
310 $this->atleastonediscount = true;
311 break;
312 }
313 }
314
315 // New page
316 $pdf->AddPage();
317 if (!empty($tplidx)) {
318 $pdf->useTemplate($tplidx);
319 }
320 $pagenb++;
321 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
322 $pdf->SetFont('', '', $default_font_size - 1);
323 $pdf->MultiCell(0, 3, ''); // Set interline to 3
324 $pdf->SetTextColor(0, 0, 0);
325
326 $tab_top = 80 + $this->marge_haute + $top_shift;
327 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute + $top_shift : $this->marge_haute);
328
329 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
330
331 // Incoterm
332 if (isModEnabled('incoterm')) {
333 $desc_incoterms = $object->getIncotermsForPDF();
334 if ($desc_incoterms) {
335 $tab_top -= 2;
336
337 $pdf->SetFont('', '', $default_font_size - 1);
338 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
339 $nexY = $pdf->GetY();
340 $height_incoterms = $nexY - $tab_top;
341
342 // Rect takes a length in 3rd parameter
343 $pdf->SetDrawColor(192, 192, 192);
344 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
345
346 $tab_top = $nexY + 6;
347 }
348 }
349
350 // Affiche notes
351 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
352
353 // Extrafields in note
354 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
355 if (!empty($extranote)) {
356 $notetoshow = dol_concatdesc($notetoshow, $extranote);
357 }
358
359 $pagenb = $pdf->getPage();
360 if ($notetoshow) {
361 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
362 $pageposbeforenote = $pagenb;
363
364 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
365 complete_substitutions_array($substitutionarray, $outputlangs, $object);
366 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
367 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
368
369 $tab_top -= 2;
370
371 $pdf->startTransaction();
372
373 $pdf->SetFont('', '', $default_font_size - 1);
374 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
375 // Description
376 $pageposafternote = $pdf->getPage();
377 $posyafter = $pdf->GetY();
378
379 if ($pageposafternote > $pageposbeforenote) {
380 $pdf->rollbackTransaction(true);
381
382 // prepar pages to receive notes
383 while ($pagenb < $pageposafternote) {
384 $pdf->AddPage();
385 $pagenb++;
386 if (!empty($tplidx)) {
387 $pdf->useTemplate($tplidx);
388 }
389 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
390 $this->_pagehead($pdf, $object, 0, $outputlangs);
391 }
392 // $this->_pagefoot($pdf,$object,$outputlangs,1);
393 $pdf->setTopMargin($tab_top_newpage);
394 // The only function to edit the bottom margin of current page to set it.
395 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
396 }
397
398 // back to start
399 $pdf->setPage($pageposbeforenote);
400 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
401 $pdf->SetFont('', '', $default_font_size - 1);
402 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
403 $pageposafternote = $pdf->getPage();
404
405 $posyafter = $pdf->GetY();
406
407 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
408 $pdf->AddPage('', '', true);
409 $pagenb++;
410 $pageposafternote++;
411 $pdf->setPage($pageposafternote);
412 $pdf->setTopMargin($tab_top_newpage);
413 // The only function to edit the bottom margin of current page to set it.
414 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
415 //$posyafter = $tab_top_newpage;
416 }
417
418
419 // apply note frame to previous pages
420 $i = $pageposbeforenote;
421 while ($i < $pageposafternote) {
422 $pdf->setPage($i);
423
424
425 $pdf->SetDrawColor(128, 128, 128);
426 // Draw note frame
427 if ($i > $pageposbeforenote) {
428 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
429 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
430 } else {
431 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
432 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
433 }
434
435 // Add footer
436 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
437 $this->_pagefoot($pdf, $object, $outputlangs, 1);
438
439 $i++;
440 }
441
442 // apply note frame to last page
443 $pdf->setPage($pageposafternote);
444 if (!empty($tplidx)) {
445 $pdf->useTemplate($tplidx);
446 }
447 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
448 $this->_pagehead($pdf, $object, 0, $outputlangs);
449 }
450 $height_note = $posyafter - $tab_top_newpage;
451 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
452 } else {
453 // No pagebreak
454 $pdf->commitTransaction();
455 $posyafter = $pdf->GetY();
456 $height_note = $posyafter - $tab_top;
457 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
458
459
460 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
461 // not enough space, need to add page
462 $pdf->AddPage('', '', true);
463 $pagenb++;
464 $pageposafternote++;
465 $pdf->setPage($pageposafternote);
466 if (!empty($tplidx)) {
467 $pdf->useTemplate($tplidx);
468 }
469 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
470 $this->_pagehead($pdf, $object, 0, $outputlangs);
471 }
472
473 $posyafter = $tab_top_newpage;
474 }
475 }
476
477 $tab_height -= $height_note;
478 $tab_top = $posyafter + 6;
479 } else {
480 $height_note = 0;
481 }
482
483 // Use new auto column system
484 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
485
486 $nexY = $tab_top + $this->tabTitleHeight;
487
488 $pageposbeforeprintlines = $pdf->getPage();
489 $pagenb = $pageposbeforeprintlines;
490 $pdf_sub_options = [
491 'titleshowuponpdf' => 1,
492 'titleshowtotalexludingvatonpdf' => 1,
493 ];
494
495 // Loop on each lines
496 for ($i = 0; $i < $nblines; $i++) {
497 $sub_options = $object->lines[$i]->extraparams["subtotal"] ?? array();
498
499 if ($object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
500 $level = $object->lines[$i]->qty;
501 if ($sub_options) {
502 if (isset($sub_options['titleshowuponpdf'])) {
503 $pdf_sub_options['titleshowuponpdf'] = isset($pdf_sub_options['titleshowuponpdf']) && $pdf_sub_options['titleshowuponpdf'] < $level ? $pdf_sub_options['titleshowuponpdf'] : $level;
504 } elseif (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
505 unset($pdf_sub_options['titleshowuponpdf']);
506 }
507 if (isset($sub_options['titleshowtotalexludingvatonpdf'])) {
508 $pdf_sub_options['titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && $pdf_sub_options['titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options['titleshowtotalexludingvatonpdf'] : $level;
509 } elseif (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
510 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
511 }
512 } else {
513 if (isset($pdf_sub_options['titleshowuponpdf']) && abs($level) <= $pdf_sub_options['titleshowuponpdf']) {
514 unset($pdf_sub_options['titleshowuponpdf']);
515 }
516 if (isset($pdf_sub_options['titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options['titleshowtotalexludingvatonpdf']) {
517 unset($pdf_sub_options['titleshowtotalexludingvatonpdf']);
518 }
519 }
520 }
521 $curY = $nexY;
522 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
523 $pdf->SetTextColor(0, 0, 0);
524
525 // Define size of image if we need it
526 $imglinesize = array();
527 if (!empty($realpatharray[$i])) {
528 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
529 }
530
531 $pdf->setTopMargin($tab_top_newpage);
532 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
533 $pageposbefore = $pdf->getPage();
534 $this->resetAfterColsLinePositionsData($curY, $pageposbefore);
535
536 $showpricebeforepagebreak = 1;
537 $posYAfterImage = 0;
538
539 // We start with Photo of product line
540 if ($this->getColumnStatus('photo')) {
541 // We start with Photo of product line
542 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
543 $pdf->AddPage('', '', true);
544 if (!empty($tplidx)) {
545 $pdf->useTemplate($tplidx);
546 }
547 $pdf->setPage($pageposbefore + 1);
548
549 $curY = $tab_top_newpage;
550
551 // Allows data in the first page if description is long enough to break in multiples pages
552 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
553 $showpricebeforepagebreak = 1;
554 } else {
555 $showpricebeforepagebreak = 0;
556 }
557 }
558
559 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
560 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
561 // $pdf->Image does not increase value return by getY, so we save it manually
562 $posYAfterImage = $curY + $imglinesize['height'];
563 $this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
564 }
565 }
566 // Description of product line
567 $curX = $this->posxdesc - 1;
568 $showpricebeforepagebreak = 1;
569
570 if ($this->getColumnStatus('desc') && $object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
571 // Title or subtotal line: colored banner, like on other documents (pdf_render_subtotals() manages its own transaction)
572 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs($object->lines[$i]->qty), 'ffffff'));
573 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
574 $posYAfterDescription = $pdf->GetY();
575 } elseif ($this->getColumnStatus('desc')) {
576 $pdf->startTransaction();
577 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
578
579 $pageposafter = $pdf->getPage();
580 if ($pageposafter > $pageposbefore) { // There is a pagebreak
581 $pdf->rollbackTransaction(true);
582
583 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc, 1);
584
585 $pageposafter = $pdf->getPage();
586 $posyafter = $pdf->GetY();
587 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
588 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
589 $pdf->AddPage('', '', true);
590 if (!empty($tplidx)) {
591 $pdf->useTemplate($tplidx);
592 }
593 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
594 $pdf->setPage($pageposafter + 1);
595 }
596 } else {
597 // We found a page break
598 // Allows data in the first page if description is long enough to break in multiples pages
599 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
600 $showpricebeforepagebreak = 1;
601 } else {
602 $showpricebeforepagebreak = 0;
603 }
604 }
605 } else { // No pagebreak
606 $pdf->commitTransaction();
607 }
608 $this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
609 }
610
611 $afterPosData = $this->getMaxAfterColsLinePositionsData();
612 $pageposafter = $afterPosData['page'];
613 $pdf->setPage($pageposbefore);
614 $pdf->setTopMargin($this->marge_haute);
615 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
616
617 // We suppose that a too long description is moved completely on next page
618 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
619 $pdf->setPage($pageposafter);
620 $curY = $tab_top_newpage;
621 }
622
623 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
624
625 // VAT Rate
626 if ($this->getColumnStatus('vat') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
627 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
628 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
629 $this->setAfterColsLinePositionsData('vat', $pdf->GetY(), $pdf->getPage());
630 }
631
632 // Unit price before discount
633 if ($this->getColumnStatus('subprice') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowuponpdf'])) {
634 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
635 $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
636 $this->setAfterColsLinePositionsData('subprice', $pdf->GetY(), $pdf->getPage());
637 }
638
639 // Quantity
640 // Enough for 6 chars
641 if ($this->getColumnStatus('qty') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
642 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
643 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
644 $this->setAfterColsLinePositionsData('qty', $pdf->GetY(), $pdf->getPage());
645 }
646
647
648 // Unit
649 if ($this->getColumnStatus('unit') && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
650 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
651 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
652 $this->setAfterColsLinePositionsData('unit', $pdf->GetY(), $pdf->getPage());
653 }
654
655 // Discount on line
656 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent && $object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
657 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
658 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
659 $this->setAfterColsLinePositionsData('discount', $pdf->GetY(), $pdf->getPage());
660 }
661
662 // Total HT line
663 if ($this->getColumnStatus('totalexcltax')) {
664 if ($object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options['titleshowtotalexludingvatonpdf'])) {
665 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
666 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
667 } elseif ($object->lines[$i]->qty < 0 && isset($sub_options['subtotalshowtotalexludingvatonpdf'])) {
668 if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
669 $total_excl_tax = $object->getSubtotalLineMulticurrencyAmount($object->lines[$i]);
670 } else {
671 $total_excl_tax = $object->getSubtotalLineAmount($object->lines[$i]);
672 }
673 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
674 }
675 $this->setAfterColsLinePositionsData('totalexcltax', $pdf->GetY(), $pdf->getPage());
676 }
677
678 // Extrafields
679 if (!empty($object->lines[$i]->array_options)) {
680 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
681 if ($this->getColumnStatus($extrafieldColKey)) {
682 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
683 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
684 $this->setAfterColsLinePositionsData('options_'.$extrafieldColKey, $pdf->GetY(), $pdf->getPage());
685 }
686 }
687 }
688
689 $afterPosData = $this->getMaxAfterColsLinePositionsData();
690 $nexY = $afterPosData['y'];
691 $pageposafter = $afterPosData['page'];
692
693 $parameters = array(
694 'object' => $object,
695 'i' => $i,
696 'pdf' => & $pdf,
697 'curY' => & $curY,
698 'nexY' => & $nexY,
699 'outputlangs' => $outputlangs,
700 'hidedetails' => $hidedetails
701 );
702 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
703
704
705 // // Collect total by value of vat rate into $this->tva["taux"]=total_tva
706 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
707 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
708 } else {
709 $tvaligne = $object->lines[$i]->total_tva;
710 }
711
712 $localtax1ligne = $object->lines[$i]->total_localtax1;
713 $localtax2ligne = $object->lines[$i]->total_localtax2;
714 $localtax1_rate = $object->lines[$i]->localtax1_tx;
715 $localtax2_rate = $object->lines[$i]->localtax2_tx;
716 $localtax1_type = $object->lines[$i]->localtax1_type;
717 $localtax2_type = $object->lines[$i]->localtax2_type;
718
719 $vatrate = (string) $object->lines[$i]->tva_tx;
720
721 // Retrieve type from database for backward compatibility with old records
722 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
723 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
724 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty);
725 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
726 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
727 }
728
729 // retrieve global local tax
730 if ($localtax1_type && $localtax1ligne != 0) {
731 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
732 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
733 } else {
734 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
735 }
736 }
737 if ($localtax2_type && $localtax2ligne != 0) {
738 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
739 $this->localtax2[$localtax2_type][$localtax2_rate] = (float) $localtax2ligne;
740 } else {
741 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
742 }
743 }
744
745 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
746 $vatrate .= '*';
747 }
748
749 // Fill $this->tva and $this->tva_array
750 if (!isset($this->tva[$vatrate])) {
751 $this->tva[$vatrate] = 0;
752 }
753 $this->tva[$vatrate] += $tvaligne;
754 $vatcode = $object->lines[$i]->vat_src_code;
755 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
756 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
757 }
758 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
759
760 // Add line
761 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
762 $pdf->setPage($pageposafter);
763 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
764 //$pdf->SetDrawColor(190,190,200);
765 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
766 $pdf->SetLineStyle(array('dash' => 0));
767 }
768
769 // Detect if some page were added automatically and output _tableau for past pages
770 while ($pagenb < $pageposafter) {
771 $pdf->setPage($pagenb);
772 if ($pagenb == $pageposbeforeprintlines) {
773 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
774 } else {
775 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
776 }
777 $this->_pagefoot($pdf, $object, $outputlangs, 1);
778 $pagenb++;
779 $pdf->setPage($pagenb);
780 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
781 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
782 $this->_pagehead($pdf, $object, 0, $outputlangs);
783 }
784 if (!empty($tplidx)) {
785 $pdf->useTemplate($tplidx);
786 }
787 }
788 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
789 if ($pagenb == $pageposafter) {
790 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
791 } else {
792 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
793 }
794 $this->_pagefoot($pdf, $object, $outputlangs, 1);
795 // New page
796 $pdf->AddPage();
797 if (!empty($tplidx)) {
798 $pdf->useTemplate($tplidx);
799 }
800 $pagenb++;
801 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
802 $this->_pagehead($pdf, $object, 0, $outputlangs);
803 }
804 }
805 }
806
807 // Show square
808 if ($pagenb == $pageposbeforeprintlines) {
809 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
810 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
811 } else {
812 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
813 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
814 }
815
816 // Affiche zone infos
817 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
818
819 // Affiche zone totaux
820 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
821
822 // Affiche zone versements
823 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
824 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
825 }
826
827 // Pied de page
828 $this->_pagefoot($pdf, $object, $outputlangs);
829 if (method_exists($pdf, 'AliasNbPages')) {
830 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
831 }
832
833 $pdf->Close();
834
835 $pdf->Output($file, 'F');
836
837 // Add pdfgeneration hook
838 $hookmanager->initHooks(array('pdfgeneration'));
839 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
840 global $action;
841 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
842 $this->warnings = $hookmanager->warnings;
843 if ($reshook < 0) {
844 $this->error = $hookmanager->error;
845 $this->errors = $hookmanager->errors;
846 dolChmod($file);
847 return -1;
848 }
849
850 dolChmod($file);
851
852 $this->result = array('fullpath' => $file);
853
854 return 1; // No error
855 } else {
856 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
857 return 0;
858 }
859 } else {
860 $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
861 return 0;
862 }
863 }
864
865 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
866 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
876 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
877 {
878 // phpcs:enable
879 return 1;
880 }
881
882 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
883 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
893 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
894 {
895 // phpcs:enable
896 global $conf, $mysoc;
897 $default_font_size = pdf_getPDFFontSize($outputlangs);
898
899 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
900
901 // If France, show VAT mention if not applicable
902 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
903 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
904 $pdf->SetXY($this->marge_gauche, $posy);
905 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', false);
906
907 $posy = $pdf->GetY() + 4;
908 }
909
910 $posxval = 52;
911
912 // Show payments conditions
913 if (!empty($object->cond_reglement_code) || $object->cond_reglement) {
914 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
915 $pdf->SetXY($this->marge_gauche, $posy);
916 $titre = $outputlangs->transnoentities("PaymentConditions").':';
917 $pdf->MultiCell(80, 4, $titre, 0, 'L');
918
919 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
920 $pdf->SetXY($posxval, $posy);
921 $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);
922 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
923 if ($object->deposit_percent > 0) {
924 $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
925 }
926 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
927
928 $posy = $pdf->GetY() + 3;
929 }
930
931 // Show payment mode
932 if (!empty($object->mode_reglement_code)) {
933 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
934 $pdf->SetXY($this->marge_gauche, $posy);
935 $titre = $outputlangs->transnoentities("PaymentMode").':';
936 $pdf->MultiCell(80, 5, $titre, 0, 'L');
937
938 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
939 $pdf->SetXY($posxval, $posy);
940 $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);
941 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
942
943 $posy = $pdf->GetY() + 2;
944 }
945
946
947 return $posy;
948 }
949
950 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
951 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
962 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
963 {
964 // phpcs:enable
965 global $conf, $mysoc;
966
967 $default_font_size = pdf_getPDFFontSize($outputlangs);
968
969 $tab2_top = $posy;
970 $tab2_hl = 4;
971 $pdf->SetFont('', '', $default_font_size - 1);
972
973 // Tableau total
974 $col1x = 120;
975 $col2x = 170;
976 if ($this->page_largeur < 210) { // To work with US executive format
977 $col2x -= 20;
978 }
979 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
980
981 $useborder = 0;
982 $index = 0;
983
984 // Total HT
985 $pdf->SetFillColor(255, 255, 255);
986 $pdf->SetXY($col1x, $tab2_top);
987 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', true);
988
989 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
990 $pdf->SetXY($col2x, $tab2_top);
991 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht), 0, 'R', true);
992
993 // Show VAT by rates and total
994 $pdf->SetFillColor(248, 248, 248);
995
996 $this->atleastoneratenotnull = 0;
997 foreach ($this->tva as $tvakey => $tvaval) {
998 if ($tvakey > 0) { // On affiche pas taux 0
999 $this->atleastoneratenotnull++;
1000
1001 $index++;
1002 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1003
1004 $tvacompl = '';
1005
1006 if (preg_match('/\*/', $tvakey)) {
1007 $tvakey = str_replace('*', '', $tvakey);
1008 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1009 }
1010
1011 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1012 $totalvat .= vatrate($tvakey, true).$tvacompl;
1013 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1014
1015 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1016 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', true);
1017 }
1018 }
1019 if (!$this->atleastoneratenotnull) { // If no vat at all
1020 $index++;
1021 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1022 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', true);
1023
1024 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1025 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', true);
1026
1027 // Total LocalTax1
1028 if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on' && $object->total_localtax1 > 0) {
1029 $index++;
1030 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1031 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', true);
1032 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1033 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', true);
1034 }
1035
1036 // Total LocalTax2
1037 if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on' && $object->total_localtax2 > 0) {
1038 $index++;
1039 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1040 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', true);
1041 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1042 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', true);
1043 }
1044 } else {
1045 //if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on')
1046 //{
1047 //Local tax 1
1048 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1049 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1050 continue;
1051 }
1052
1053 foreach ($localtax_rate as $tvakey => $tvaval) {
1054 if ($tvakey != 0) { // On affiche pas taux 0
1055 //$this->atleastoneratenotnull++;
1056
1057 $index++;
1058 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1059
1060 $tvacompl = '';
1061 if (preg_match('/\*/', $tvakey)) {
1062 $tvakey = str_replace('*', '', $tvakey);
1063 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1064 }
1065 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1066 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1067 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1068
1069 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1070 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', true);
1071 }
1072 }
1073 }
1074
1075 //if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') && getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on')
1076 //{
1077 //Local tax 2
1078 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1079 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1080 continue;
1081 }
1082
1083 foreach ($localtax_rate as $tvakey => $tvaval) {
1084 if ($tvakey != 0) { // On affiche pas taux 0
1085 //$this->atleastoneratenotnull++;
1086
1087 $index++;
1088 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1089
1090 $tvacompl = '';
1091 if (preg_match('/\*/', $tvakey)) {
1092 $tvakey = str_replace('*', '', $tvakey);
1093 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1094 }
1095 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1096 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1097 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1098
1099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1100 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', true);
1101 }
1102 }
1103 }
1104 }
1105
1106 // Total TTC
1107 $index++;
1108 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1109 $pdf->SetTextColor(0, 0, 60);
1110 $pdf->SetFillColor(224, 224, 224);
1111 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', true);
1112
1113 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1114 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1115 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', true);
1116 $pdf->SetFont('', '', $default_font_size - 1);
1117 $pdf->SetTextColor(0, 0, 0);
1118
1119 $creditnoteamount = 0;
1120 $depositsamount = 0;
1121 //$creditnoteamount=$object->getSumCreditNotesUsed();
1122 //$depositsamount=$object->getSumDepositsUsed();
1123 //print "x".$creditnoteamount."-".$depositsamount;exit;
1124 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1125 if (!empty($object->paye)) {
1126 $resteapayer = 0;
1127 }
1128
1129 if ($deja_regle > 0) {
1130 // Already paid + Deposits
1131 $index++;
1132
1133 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1134 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', false);
1135 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1136 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', false);
1137
1138 $index++;
1139 $pdf->SetTextColor(0, 0, 60);
1140 $pdf->SetFillColor(224, 224, 224);
1141 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1142 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', true);
1143
1144 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1145 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', true);
1146
1147 $pdf->SetFont('', '', $default_font_size - 1);
1148 $pdf->SetTextColor(0, 0, 0);
1149 }
1150
1151 $index++;
1152 return ($tab2_top + ($tab2_hl * $index));
1153 }
1154
1155 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1169 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1170 {
1171 global $conf;
1172
1173 // Force to disable hidetop and hidebottom
1174 $hidebottom = 0;
1175 if ($hidetop) {
1176 $hidetop = -1;
1177 }
1178
1179 $currency = !empty($currency) ? $currency : $conf->currency;
1180 $default_font_size = pdf_getPDFFontSize($outputlangs);
1181
1182 // Amount in (at tab_top - 1)
1183 $pdf->SetTextColor(0, 0, 0);
1184 $pdf->SetFont('', '', $default_font_size - 2);
1185
1186 if (empty($hidetop)) {
1187 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1188 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1189 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1190
1191 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1192 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1193 $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')));
1194 }
1195 }
1196
1197 $pdf->SetDrawColor(128, 128, 128);
1198 $pdf->SetFont('', '', $default_font_size - 1);
1199
1200 // Output Rect
1201 $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
1202
1203 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1204
1205 if (empty($hidetop)) {
1206 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
1207 }
1208 }
1209
1210 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1220 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1221 {
1222 global $langs, $conf, $mysoc;
1223
1224 $ltrdirection = 'L';
1225 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1226 $ltrdirection = 'R';
1227 }
1228
1229 // Load translation files required by the page
1230 $outputlangs->loadLangs(array("main", "supplier_proposal", "companies", "bills", "sendings"));
1231
1232 $default_font_size = pdf_getPDFFontSize($outputlangs);
1233
1234 // Do not add the BACKGROUND as this is for suppliers
1235 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1236
1237 // Print Draft Watermark
1238 /*if($object->statut==0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK'))
1239 {
1240 pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1241 }*/
1242 //Print content
1243
1244 $pdf->SetTextColor(0, 0, 60);
1245 $pdf->SetFont('', 'B', $default_font_size + 3);
1246
1247 $w = 110;
1248
1249 $posx = $this->page_largeur - $this->marge_droite - $w;
1250 $posy = $this->marge_haute;
1251
1252 $pdf->SetXY($this->marge_gauche, $posy);
1253
1254 // Logo
1255 $logodir = $conf->mycompany->dir_output;
1256 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
1257 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
1258 }
1259 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, 100, $default_font_size, $ltrdirection);
1260
1261 $pdf->SetFont('', 'B', $default_font_size + 3);
1262 $pdf->SetXY($posx, $posy);
1263 $pdf->SetTextColor(0, 0, 60);
1264 $title = $outputlangs->transnoentities("SupplierProposal")." ".$outputlangs->convToOutputCharset($object->ref);
1265 $pdf->MultiCell($w, 3, $title, '', 'R');
1266 $posy += 1;
1267
1268 if ($object->ref_supplier) {
1269 $posy += 4;
1270 $pdf->SetFont('', 'B', $default_font_size);
1271 $pdf->SetXY($posx, $posy);
1272 $pdf->SetTextColor(0, 0, 60);
1273 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1274 $posy += 1;
1275 }
1276
1277 $pdf->SetFont('', '', $default_font_size - 1);
1278
1279 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1280 $object->fetchProject();
1281 if (!empty($object->project->ref)) {
1282 $posy += 3;
1283 $pdf->SetXY($posx, $posy);
1284 $pdf->SetTextColor(0, 0, 60);
1285 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : pdf_truncate_text($pdf, $object->project->title, 50)), '', 'R');
1286 }
1287 }
1288
1289 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1290 $object->fetchProject();
1291 if (!empty($object->project->ref)) {
1292 $outputlangs->load("projects");
1293 $posy += 4;
1294 $pdf->SetXY($posx, $posy);
1295 $langs->load("projects");
1296 $pdf->SetTextColor(0, 0, 60);
1297 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1298 }
1299 }
1300
1301 if (!empty($object->date)) {
1302 $posy += 5;
1303 $pdf->SetXY($posx, $posy);
1304 $pdf->SetTextColor(0, 0, 60);
1305 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1306 } else {
1307 $posy += 5;
1308 $pdf->SetXY($posx, $posy);
1309 $pdf->SetTextColor(255, 0, 0);
1310 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Draft"), '', 'R');
1311 }
1312
1313 $pdf->SetTextColor(0, 0, 60);
1314 $usehourmin = 'day';
1315 if (getDolGlobalString('SUPPLIER_PROPOSAL_USE_HOUR_FOR_DELIVERY_DATE')) {
1316 $usehourmin = 'dayhour';
1317 }
1318 if (!empty($object->delivery_date)) {
1319 $posy += 4;
1320 $pdf->SetXY($posx - 90, $posy);
1321 $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1322 }
1323
1324 if ($object->thirdparty->code_fournisseur) {
1325 $posy += 4;
1326 $pdf->SetXY($posx, $posy);
1327 $pdf->SetTextColor(0, 0, 60);
1328 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_fournisseur), '', 'R');
1329 }
1330
1331 // Get contact
1332 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1333 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1334
1335 if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
1336 $usertmp = new User($this->db);
1337 $usertmp->fetch($arrayidcontact[0]);
1338 $posy += 4;
1339 $pdf->SetXY($posx, $posy);
1340 $pdf->SetTextColor(0, 0, 60);
1341 $pdf->MultiCell($w, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1342 }
1343 }
1344
1345 $posy += 1;
1346 $pdf->SetTextColor(0, 0, 60);
1347
1348 $top_shift = 0;
1349 // Show list of linked objects
1350 $current_y = $pdf->getY();
1351 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1352 if ($current_y < $pdf->getY()) {
1353 $top_shift = $pdf->getY() - $current_y;
1354 }
1355
1356 if ($showaddress) {
1357 // Sender properties
1358 $carac_emetteur = '';
1359 // Add internal contact of object if defined
1360 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1361 if (count($arrayidcontact) > 0) {
1362 $object->fetch_user($arrayidcontact[0]);
1363 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1364 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1365 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1366 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1367 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1368 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1369 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1370 $carac_emetteur .= "\n";
1371 }
1372
1373 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1374
1375 // Show sender
1376 $posy = 32 + $this->marge_haute + $top_shift;
1377 $posx = $this->marge_gauche;
1378 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1379 $posx = $this->page_largeur - $this->marge_droite - 80;
1380 }
1381 $hautcadre = 40;
1382
1383 // Show sender frame
1384 $pdf->SetTextColor(0, 0, 0);
1385 $pdf->SetFont('', '', $default_font_size - 2);
1386 $pdf->SetXY($posx, $posy - 5);
1387 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1388 $pdf->SetXY($posx, $posy);
1389 $pdf->SetFillColor(230, 230, 230);
1390 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
1391 $pdf->SetTextColor(0, 0, 60);
1392
1393 // Show sender name
1394 $pdf->SetXY($posx + 2, $posy + 3);
1395 $pdf->SetFont('', 'B', $default_font_size);
1396 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1397 $posy = $pdf->getY();
1398
1399 // Show sender information
1400 $pdf->SetXY($posx + 2, $posy);
1401 $pdf->SetFont('', '', $default_font_size - 1);
1402 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1403
1404
1405
1406 // If CUSTOMER contact defined on proposal, we use it. Note: Even if this is a supplier object, the code for external contact that follow-up a supplier proposal is 'CUSTOMER'
1407 $usecontact = false;
1408 if (!getDolGlobalInt('SUPPLIER_PROPOSAL_ADD_BILLING_CONTACT')) {
1409 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1410 } else {
1411 $arrayidcontact = array_merge($object->getIdContact('external', 'CUSTOMER'), $object->getIdContact('external', 'BILLING'));
1412 }
1413 if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
1414 $usecontact = true;
1415 $result = $object->fetch_contact($arrayidcontact[0]);
1416 }
1417
1418 // Recipient name
1419 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1420 $thirdparty = $object->contact;
1421 } else {
1422 $thirdparty = $object->thirdparty;
1423 }
1424
1425 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1426
1427 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
1428
1429 // Show recipient
1430 $widthrecbox = 100;
1431 if ($this->page_largeur < 210) {
1432 $widthrecbox = 84; // To work with US executive format
1433 }
1434 $posy = 32 + $this->marge_haute + $top_shift;
1435 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1436 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1437 $posx = $this->marge_gauche;
1438 }
1439
1440 // Show recipient frame
1441 $pdf->SetTextColor(0, 0, 0);
1442 $pdf->SetFont('', '', $default_font_size - 2);
1443 $pdf->SetXY($posx + 2, $posy - 5);
1444 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1445 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1446
1447 // Show recipient name
1448 $pdf->SetXY($posx + 2, $posy + 3);
1449 $pdf->SetFont('', 'B', $default_font_size);
1450 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1451 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1452
1453 $posy = $pdf->getY();
1454
1455 // Show recipient information
1456 $pdf->SetFont('', '', $default_font_size - 1);
1457 $pdf->SetXY($posx + 2, $posy);
1458 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1459 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1460 }
1461
1462 return $top_shift;
1463 }
1464
1465 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1475 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1476 {
1477 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1478 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1479 }
1480
1481
1482
1493 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1494 {
1495 global $hookmanager;
1496
1497 // Default field style for content
1498 $this->defaultContentsFieldsStyle = array(
1499 'align' => 'R', // R,C,L
1500 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1501 );
1502
1503 // Default field style for content
1504 $this->defaultTitlesFieldsStyle = array(
1505 'align' => 'C', // R,C,L
1506 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1507 );
1508
1509 $rank = 0; // do not use negative rank
1510 $this->cols['desc'] = array(
1511 'rank' => $rank,
1512 'width' => false, // only for desc
1513 'status' => true,
1514 'title' => array(
1515 'textkey' => 'Designation', // use lang key is useful in some case with module
1516 'align' => 'L',
1517 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1518 // 'label' => ' ', // the final label
1519 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1520 ),
1521 'content' => array(
1522 'align' => 'L',
1523 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1524 ),
1525 );
1526
1527 $rank += 10;
1528 $this->cols['photo'] = array(
1529 'rank' => $rank,
1530 'width' => (float) getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
1531 'status' => false,
1532 'title' => array(
1533 'textkey' => 'Photo',
1534 'label' => ' '
1535 ),
1536 'content' => array(
1537 'padding' => array(0.0, 0.0, 0.0, 0.0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1538 ),
1539 'border-left' => false, // remove left line separator
1540 );
1541
1542 if (getDolGlobalString('MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE')) {
1543 $this->cols['photo']['status'] = true;
1544 }
1545
1546
1547 $rank += 10;
1548 $this->cols['vat'] = array(
1549 'rank' => $rank,
1550 'status' => false,
1551 'width' => 16.0, // in mm
1552 'title' => array(
1553 'textkey' => 'VAT'
1554 ),
1555 'border-left' => true, // add left line separator
1556 );
1557
1558 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1559 $this->cols['vat']['status'] = true;
1560 }
1561
1562 $rank += 10;
1563 $this->cols['subprice'] = array(
1564 'rank' => $rank,
1565 'width' => 19.0, // in mm
1566 'status' => false,
1567 'title' => array(
1568 'textkey' => 'PriceUHT'
1569 ),
1570 'border-left' => true, // add left line separator
1571 );
1572
1573 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SUPPLIER_PROPOSAL_WITHOUT_UNIT_PRICE')) {
1574 $this->cols['subprice']['status'] = true;
1575 }
1576
1577 $rank += 10;
1578 $this->cols['qty'] = array(
1579 'rank' => $rank,
1580 'width' => 16.0, // in mm
1581 'status' => true,
1582 'title' => array(
1583 'textkey' => 'Qty'
1584 ),
1585 'border-left' => true, // add left line separator
1586 );
1587
1588 $rank += 10;
1589 $this->cols['unit'] = array(
1590 'rank' => $rank,
1591 'width' => 11.0, // in mm
1592 'status' => false,
1593 'title' => array(
1594 'textkey' => 'Unit'
1595 ),
1596 'border-left' => true, // add left line separator
1597 );
1598 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1599 $this->cols['unit']['status'] = true;
1600 }
1601
1602 $rank += 10;
1603 $this->cols['discount'] = array(
1604 'rank' => $rank,
1605 'width' => 13.0, // in mm
1606 'status' => false,
1607 'title' => array(
1608 'textkey' => 'ReductionShort'
1609 ),
1610 'border-left' => true, // add left line separator
1611 );
1612 if ($this->atleastonediscount) {
1613 $this->cols['discount']['status'] = true;
1614 }
1615
1616 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1617 $this->cols['totalexcltax'] = array(
1618 'rank' => $rank,
1619 'width' => 26.0, // in mm
1620 'status' => false,
1621 'title' => array(
1622 'textkey' => 'TotalHT'
1623 ),
1624 'border-left' => true, // add left line separator
1625 );
1626
1627 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SUPPLIER_PROPOSAL_WITHOUT_TOTAL_COLUMN')) {
1628 $this->cols['totalexcltax']['status'] = true;
1629 }
1630
1631 // Add extrafields cols
1632 if (!empty($object->lines)) {
1633 $line = reset($object->lines);
1634 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1635 }
1636
1637 $parameters = array(
1638 'object' => $object,
1639 'outputlangs' => $outputlangs,
1640 'hidedetails' => $hidedetails,
1641 'hidedesc' => $hidedesc,
1642 'hideref' => $hideref
1643 );
1644
1645 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1646 if ($reshook < 0) {
1647 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1648 } elseif (empty($reshook)) {
1649 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1650 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1651 } else {
1652 $this->cols = $hookmanager->resArray;
1653 }
1654 }
1655}
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:
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
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getMaxAfterColsLinePositionsData()
Get position in PDF after col display.
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
resetAfterColsLinePositionsData(float $y, int $pageNumb)
Used for reset afterColsLinePositions var in start of a new pdf draw line loop.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Perent class of the Proposal models.
Class to manage products or services.
Class to manage translations.
Class to manage Dolibarr users.
Class to generate the supplier proposals with the zenith model.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct($db)
Constructor.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
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...
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
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.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
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.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:3263
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2964
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_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2553
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2491
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_render_subtotals(TCPDF $pdf, CommonDocGenerator $generator, float $curY, CommonObject $object, int $i, Translate $outputlangs, int $hideref, int $hidedesc, array $bgColor, bool $isSubtotal=false, bool $applySubtotalLogic=true)
Render subtotals line with a colored background and adapted text color .
Definition pdf.lib.php:3395
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_writeLogoOrCompanyName($pdf, $outputlangs, $emetteur, $logodir, $posx, $posy, $w, $default_font_size, $align)
Output company logo on top-left of a PDF page header, or the company name as fallback text if no logo...
Definition pdf.lib.php:351
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2798
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2841
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2638
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
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:436
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165