dolibarr 21.0.0-alpha
pdf_einstein.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-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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/commande/modules_commande.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 $entity;
55
59 public $name;
60
64 public $description;
65
69 public $update_main_doc_field;
70
74 public $type;
75
80 public $version = 'dolibarr';
81
82
88 public function __construct(DoliDB $db)
89 {
90 global $conf, $langs, $mysoc;
91
92 // Translations
93 $langs->loadLangs(array("main", "bills", "products"));
94
95 $this->db = $db;
96 $this->name = "einstein";
97 $this->description = $langs->trans('PDFEinsteinDescription');
98 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
99
100 // Dimension page
101 $this->type = 'pdf';
102 $formatarray = pdf_getFormat();
103 $this->page_largeur = $formatarray['width'];
104 $this->page_hauteur = $formatarray['height'];
105 $this->format = array($this->page_largeur, $this->page_hauteur);
106 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
107 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
108 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
109 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
110
111 $this->option_logo = 1; // Display logo
112 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
113 $this->option_modereg = 1; // Display payment mode
114 $this->option_condreg = 1; // Display payment terms
115 $this->option_multilang = 1; // Available in several languages
116 $this->option_escompte = 0; // Displays if there has been a discount
117 $this->option_credit_note = 0; // Support credit notes
118 $this->option_freetext = 1; // Support add of a personalised text
119 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
120 $this->watermark = '';
121
122 // Get source company
123 $this->emetteur = $mysoc;
124 if (empty($this->emetteur->country_code)) {
125 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
126 }
127
128 // Define position of columns
129 $this->posxdesc = $this->marge_gauche + 1;
130 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
131 $this->posxtva = 101;
132 $this->posxup = 118;
133 $this->posxqty = 135;
134 $this->posxunit = 151;
135 } else {
136 $this->posxtva = 106;
137 $this->posxup = 122;
138 $this->posxqty = 145;
139 $this->posxunit = 162;
140 }
141 $this->posxdiscount = 162;
142 $this->postotalht = 174;
143 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') || getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
144 $this->posxtva = $this->posxup;
145 }
146 $this->posxpicture = $this->posxtva - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images
147 if ($this->page_largeur < 210) { // To work with US executive format
148 $this->posxpicture -= 20;
149 $this->posxtva -= 20;
150 $this->posxup -= 20;
151 $this->posxqty -= 20;
152 $this->posxunit -= 20;
153 $this->posxdiscount -= 20;
154 $this->postotalht -= 20;
155 }
156
157 $this->tva = array();
158 $this->tva_array = array();
159 $this->localtax1 = array();
160 $this->localtax2 = array();
161 $this->atleastoneratenotnull = 0;
162 $this->atleastonediscount = 0;
163 }
164
165 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
177 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
178 {
179 // phpcs:enable
180 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
181
182 if (!is_object($outputlangs)) {
183 $outputlangs = $langs;
184 }
185 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
186 if (getDolGlobalString('MAIN_USE_FPDF')) {
187 $outputlangs->charset_output = 'ISO-8859-1';
188 }
189
190 // Load translation files required by the page
191 $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
192
193 // Show Draft Watermark
194 if ($object->statut == $object::STATUS_DRAFT && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')) {
195 $this->watermark = getDolGlobalString('COMMANDE_DRAFT_WATERMARK');
196 }
197
198 global $outputlangsbis;
199 $outputlangsbis = null;
200 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
201 $outputlangsbis = new Translate('', $conf);
202 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
203 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
204 }
205
206 $nblines = count($object->lines);
207
208 if ($conf->commande->multidir_output[$conf->entity]) {
209 $object->fetch_thirdparty();
210
211 $deja_regle = 0;
212
213 // Definition of $dir and $file
214 if ($object->specimen) {
215 $dir = $conf->commande->multidir_output[$conf->entity];
216 $file = $dir."/SPECIMEN.pdf";
217 } else {
218 // Possibility to use suffix for proforma
219 $suffix = '';
220 if (getDolGlobalString('PROFORMA_PDF_WITH_SUFFIX')) {
221 $suffix = (GETPOST('model') == 'proforma') ? getDolGlobalString('PROFORMA_PDF_WITH_SUFFIX') : '';
222 $suffix = dol_sanitizeFileName($suffix);
223 }
224
225 $objectref = dol_sanitizeFileName($object->ref);
226 $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref;
227 $file = $dir."/".$objectref.$suffix.".pdf";
228 }
229
230 if (!file_exists($dir)) {
231 if (dol_mkdir($dir) < 0) {
232 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
233 return 0;
234 }
235 }
236
237 if (file_exists($dir)) {
238 // Add pdfgeneration hook
239 if (!is_object($hookmanager)) {
240 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
241 $hookmanager = new HookManager($this->db);
242 }
243 $hookmanager->initHooks(array('pdfgeneration'));
244 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
245 global $action;
246 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
247
248 // Set nblines with the new command lines content after hook
249 $nblines = count($object->lines);
250
251 // Create pdf instance
252 $pdf = pdf_getInstance($this->format);
253 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
254 $pdf->SetAutoPageBreak(1, 0);
255
256 $heightforinfotot = 40; // Height reserved to output the info and total part
257 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
258 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
259 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
260 $heightforfooter += 6;
261 }
262
263 if (class_exists('TCPDF')) {
264 $pdf->setPrintHeader(false);
265 $pdf->setPrintFooter(false);
266 }
267 $pdf->SetFont(pdf_getPDFFont($outputlangs));
268 // Set path to the background PDF File
269 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
270 $logodir = $conf->mycompany->dir_output;
271 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
272 $logodir = $conf->mycompany->multidir_output[$object->entity];
273 }
274 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
275 $tplidx = $pdf->importPage(1);
276 }
277
278 $pdf->Open();
279 $pagenb = 0;
280 $pdf->SetDrawColor(128, 128, 128);
281
282 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
283 $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
284 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
285 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
287 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
288 $pdf->SetCompression(false);
289 }
290
291 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
292 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
293
294 // Set $this->atleastonediscount if you have at least one discount
295 for ($i = 0; $i < $nblines; $i++) {
296 if ($object->lines[$i]->remise_percent) {
297 $this->atleastonediscount++;
298 }
299 }
300 if (empty($this->atleastonediscount)) {
301 $delta = ($this->postotalht - $this->posxdiscount);
302 $this->posxpicture += $delta;
303 $this->posxtva += $delta;
304 $this->posxup += $delta;
305 $this->posxqty += $delta;
306 $this->posxunit += $delta;
307 $this->posxdiscount += $delta;
308 // post of fields after are not modified, stay at same position
309 }
310
311 // New page
312 $pdf->AddPage();
313 if (!empty($tplidx)) {
314 $pdf->useTemplate($tplidx);
315 }
316 $pagenb++;
317 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
318 $pdf->SetFont('', '', $default_font_size - 1);
319 $pdf->MultiCell(0, 3, ''); // Set interline to 3
320 $pdf->SetTextColor(0, 0, 0);
321
322
323 $tab_top = 90 + $top_shift;
324 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
325
326 // Incoterm
327 $height_incoterms = 0;
328 if (isModEnabled('incoterm')) {
329 $desc_incoterms = $object->getIncotermsForPDF();
330 if ($desc_incoterms) {
331 $tab_top -= 2;
332
333 $pdf->SetFont('', '', $default_font_size - 1);
334 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
335 $nexY = $pdf->GetY();
336 $height_incoterms = $nexY - $tab_top;
337
338 // Rect takes a length in 3rd parameter
339 $pdf->SetDrawColor(192, 192, 192);
340 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
341
342 $tab_top = $nexY + 6;
343 }
344 }
345
346 // Displays notes
347 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
348 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
349 // Get first sale rep
350 if (is_object($object->thirdparty)) {
351 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
352 $salerepobj = new User($this->db);
353 $salerepobj->fetch($salereparray[0]['id']);
354 if (!empty($salerepobj->signature)) {
355 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
356 }
357 }
358 }
359 // Extrafields in note
360 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
361 if (!empty($extranote)) {
362 $notetoshow = dol_concatdesc($notetoshow, $extranote);
363 }
364
365 if ($notetoshow) {
366 $tab_top -= 2;
367
368 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
369 complete_substitutions_array($substitutionarray, $outputlangs, $object);
370 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
371 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
372
373 $pdf->SetFont('', '', $default_font_size - 1);
374 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
375 $nexY = $pdf->GetY();
376 $height_note = $nexY - $tab_top;
377
378 // Rect takes a length in 3rd parameter
379 $pdf->SetDrawColor(192, 192, 192);
380 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
381
382 $tab_top = $nexY + 6;
383 }
384
385 $iniY = $tab_top + 7;
386 $curY = $tab_top + 7;
387 $nexY = $tab_top + 7;
388
389 // Loop on each lines
390 for ($i = 0; $i < $nblines; $i++) {
391 $curY = $nexY;
392 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
393 $pdf->SetTextColor(0, 0, 0);
394
395 $pdf->setTopMargin($tab_top_newpage);
396 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
397 $pageposbefore = $pdf->getPage();
398
399 // Description of product line
400 $curX = $this->posxdesc - 1;
401
402 $showpricebeforepagebreak = 1;
403
404 $pdf->startTransaction();
405 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
406 $pageposafter = $pdf->getPage();
407 if ($pageposafter > $pageposbefore) { // There is a pagebreak
408 $pdf->rollbackTransaction(true);
409 $pageposafter = $pageposbefore;
410 //print $pageposafter.'-'.$pageposbefore;exit;
411 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
412 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc);
413 $pageposafter = $pdf->getPage();
414 $posyafter = $pdf->GetY();
415 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
416 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
417 $pdf->AddPage('', '', true);
418 if (!empty($tplidx)) {
419 $pdf->useTemplate($tplidx);
420 }
421 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
422 $this->_pagehead($pdf, $object, 0, $outputlangs);
423 }
424 $pdf->setPage($pageposafter + 1);
425 }
426 } else {
427 // We found a page break
428 // Allows data in the first page if description is long enough to break in multiples pages
429 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
430 $showpricebeforepagebreak = 1;
431 } else {
432 $showpricebeforepagebreak = 0;
433 }
434 }
435 } else { // No pagebreak
436 $pdf->commitTransaction();
437 }
438 $posYAfterDescription = $pdf->GetY();
439
440 $nexY = $pdf->GetY();
441 $pageposafter = $pdf->getPage();
442
443 $pdf->setPage($pageposbefore);
444 $pdf->setTopMargin($this->marge_haute);
445 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
446
447 // We suppose that a too long description is moved completely on next page
448 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
449 $pdf->setPage($pageposafter);
450 $curY = $tab_top_newpage;
451 }
452
453 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
454
455 // VAT Rate
456 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
457 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
458 $pdf->SetXY($this->posxtva - 5, $curY);
459 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
460 }
461
462 // Unit price before discount
463 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
464 $pdf->SetXY($this->posxup, $curY);
465 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
466
467 // Quantity
468 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
469 $pdf->SetXY($this->posxqty, $curY);
470 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
471
472 // Unit
473 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
474 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
475 $pdf->SetXY($this->posxunit, $curY);
476 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
477 }
478
479 // Discount on line
480 $pdf->SetXY($this->posxdiscount, $curY);
481 if ($object->lines[$i]->remise_percent) {
482 $pdf->SetXY($this->posxdiscount - 2, $curY);
483 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
484 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
485 }
486
487 // Total HT line
488 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
489 $pdf->SetXY($this->postotalht, $curY);
490 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
491
492 // Collection of totals by value of vat in $this->vat["rate"] = total_tva
493 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
494 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
495 } else {
496 $tvaligne = $object->lines[$i]->total_tva;
497 }
498
499 $localtax1ligne = $object->lines[$i]->total_localtax1;
500 $localtax2ligne = $object->lines[$i]->total_localtax2;
501 $localtax1_rate = $object->lines[$i]->localtax1_tx;
502 $localtax2_rate = $object->lines[$i]->localtax2_tx;
503 $localtax1_type = $object->lines[$i]->localtax1_type;
504 $localtax2_type = $object->lines[$i]->localtax2_type;
505
506 // TODO remise_percent is an obsolete field for object parent
507 /*if ($object->remise_percent) {
508 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
509 }
510 if ($object->remise_percent) {
511 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
512 }
513 if ($object->remise_percent) {
514 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
515 }*/
516
517 $vatrate = (string) $object->lines[$i]->tva_tx;
518
519 // Retrieve type from database for backward compatibility with old records
520 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
521 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
522 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
523 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
524 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
525 }
526
527 // retrieve global local tax
528 if ($localtax1_type && $localtax1ligne != 0) {
529 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
530 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
531 } else {
532 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
533 }
534 }
535 if ($localtax2_type && $localtax2ligne != 0) {
536 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
537 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
538 } else {
539 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
540 }
541 }
542
543 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
544 $vatrate .= '*';
545 }
546
547 // Fill $this->tva and $this->tva_array
548 if (!isset($this->tva[$vatrate])) {
549 $this->tva[$vatrate] = 0;
550 }
551 $this->tva[$vatrate] += $tvaligne;
552 $vatcode = $object->lines[$i]->vat_src_code;
553 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
554 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
555 }
556 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
557
558 // Add line
559 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
560 $pdf->setPage($pageposafter);
561 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
562 //$pdf->SetDrawColor(190,190,200);
563 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
564 $pdf->SetLineStyle(array('dash' => 0));
565 }
566
567 $nexY += 2; // Add space between lines
568
569 // Detect if some page were added automatically and output _tableau for past pages
570 while ($pagenb < $pageposafter) {
571 $pdf->setPage($pagenb);
572 if ($pagenb == 1) {
573 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
574 } else {
575 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
576 }
577 $this->_pagefoot($pdf, $object, $outputlangs, 1);
578 $pagenb++;
579 $pdf->setPage($pagenb);
580 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
581 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
582 $this->_pagehead($pdf, $object, 0, $outputlangs);
583 }
584 if (!empty($tplidx)) {
585 $pdf->useTemplate($tplidx);
586 }
587 }
588 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
589 if ($pagenb == 1) {
590 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
591 } else {
592 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
593 }
594 $this->_pagefoot($pdf, $object, $outputlangs, 1);
595 // New page
596 $pdf->AddPage();
597 if (!empty($tplidx)) {
598 $pdf->useTemplate($tplidx);
599 }
600 $pagenb++;
601 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
602 $this->_pagehead($pdf, $object, 0, $outputlangs);
603 }
604 }
605 }
606
607 // Show square
608 if ($pagenb == 1) {
609 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
610 } else {
611 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
612 }
613 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
614
615 // Display infos area
616 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
617
618 // Display total zone
619 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
620
621 // Affiche zone versements
622 /*
623 if ($deja_regle)
624 {
625 $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
626 }
627 */
628
629 // Pied de page
630 $this->_pagefoot($pdf, $object, $outputlangs);
631 if (method_exists($pdf, 'AliasNbPages')) {
632 $pdf->AliasNbPages();
633 }
634
635 $pdf->Close();
636
637 $pdf->Output($file, 'F');
638
639 // Add pdfgeneration hook
640 $hookmanager->initHooks(array('pdfgeneration'));
641 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
642 global $action;
643 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
644 if ($reshook < 0) {
645 $this->error = $hookmanager->error;
646 $this->errors = $hookmanager->errors;
647 }
648
649 dolChmod($file);
650
651 $this->result = array('fullpath' => $file);
652
653 return 1; // No error
654 } else {
655 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
656 return 0;
657 }
658 } else {
659 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
660 return 0;
661 }
662 }
663
664 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
665 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
675 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
676 {
677 // phpcs:enable
678 return 1;
679 }
680
681 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
682 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
692 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
693 {
694 // phpcs:enable
695 global $conf, $mysoc;
696 $default_font_size = pdf_getPDFFontSize($outputlangs);
697
698 $pdf->SetFont('', '', $default_font_size - 1);
699
700 $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
701
702 // If France, show VAT mention if not applicable
703 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
704 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
705 $pdf->SetXY($this->marge_gauche, $posy);
706 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
707
708 $posy = $pdf->GetY() + 4;
709 }
710
711 $posxval = 52;
712
713 $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
714
715 // Show payments conditions
716 if ($object->cond_reglement_code || $object->cond_reglement) {
717 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
718 $pdf->SetXY($this->marge_gauche, $posy);
719 $titre = $outputlangs->transnoentities("PaymentConditions").':';
720 $pdf->MultiCell(43, 4, $titre, 0, 'L');
721
722 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
723 $pdf->SetXY($posxval, $posy);
724 $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);
725 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
726 if ($object->deposit_percent > 0) {
727 $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', (string) $object->deposit_percent, $lib_condition_paiement);
728 }
729 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
730
731 $posy = $pdf->GetY() + 3;
732 }
733
734 // Check a payment mode is defined
735 /* Not used with orders
736 if (empty($object->mode_reglement_code)
737 && ! $conf->global->FACTURE_CHQ_NUMBER
738 && ! $conf->global->FACTURE_RIB_NUMBER)
739 {
740 $pdf->SetXY($this->marge_gauche, $posy);
741 $pdf->SetTextColor(200,0,0);
742 $pdf->SetFont('','B', $default_font_size - 2);
743 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
744 $pdf->SetTextColor(0,0,0);
745
746 $posy=$pdf->GetY()+1;
747 }
748 */
749 /* TODO
750 else if (!empty($object->availability_code))
751 {
752 $pdf->SetXY($this->marge_gauche, $posy);
753 $pdf->SetTextColor(200,0,0);
754 $pdf->SetFont('','B', $default_font_size - 2);
755 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
756 $pdf->SetTextColor(0,0,0);
757
758 $posy=$pdf->GetY()+1;
759 }*/
760
761 // Show planned date of delivery
762 if (!empty($object->delivery_date)) {
763 $outputlangs->load("sendings");
764 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
765 $pdf->SetXY($this->marge_gauche, $posy);
766 $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
767 $pdf->MultiCell(80, 4, $titre, 0, 'L');
768 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
769 $pdf->SetXY($posxval, $posy);
770 $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
771 $pdf->MultiCell(80, 4, $dlp, 0, 'L');
772
773 $posy = $pdf->GetY() + 1;
774 } elseif ($object->availability_code || $object->availability) {
775 // Show availability conditions
776 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
777 $pdf->SetXY($this->marge_gauche, $posy);
778 $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
779 $pdf->MultiCell(80, 4, $titre, 0, 'L');
780 $pdf->SetTextColor(0, 0, 0);
781 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
782 $pdf->SetXY($posxval, $posy);
783 $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != 'AvailabilityType'.$object->availability_code ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
784 $lib_availability = str_replace('\n', "\n", $lib_availability);
785 $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
786
787 $posy = $pdf->GetY() + 1;
788 }
789
790 // Show payment mode
791 if ($object->mode_reglement_code
792 && $object->mode_reglement_code != 'CHQ'
793 && $object->mode_reglement_code != 'VIR') {
794 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
795 $pdf->SetXY($this->marge_gauche, $posy);
796 $titre = $outputlangs->transnoentities("PaymentMode").':';
797 $pdf->MultiCell(80, 5, $titre, 0, 'L');
798
799 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
800 $pdf->SetXY($posxval, $posy);
801 $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);
802 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
803
804 $posy = $pdf->GetY() + 2;
805 }
806
807 // Show payment mode CHQ
808 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
809 // Si mode reglement non force ou si force a CHQ
810 if (getDolGlobalString('FACTURE_CHQ_NUMBER')) {
811 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
812 $account = new Account($this->db);
813 $account->fetch(getDolGlobalString('FACTURE_CHQ_NUMBER'));
814
815 $pdf->SetXY($this->marge_gauche, $posy);
816 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
817 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
818 $posy = $pdf->GetY() + 1;
819
820 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
821 $pdf->SetXY($this->marge_gauche, $posy);
822 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
823 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
824 $posy = $pdf->GetY() + 2;
825 }
826 }
827 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
828 $pdf->SetXY($this->marge_gauche, $posy);
829 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
830 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
831 $posy = $pdf->GetY() + 1;
832
833 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
834 $pdf->SetXY($this->marge_gauche, $posy);
835 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
836 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
837 $posy = $pdf->GetY() + 2;
838 }
839 }
840 }
841 }
842
843 // If payment mode not forced or forced to VIR, show payment with BAN
844 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
845 if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
846 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
847 if ($object->fk_bank > 0) {
848 $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
849 }
850 $account = new Account($this->db);
851 $account->fetch($bankid);
852
853 $curx = $this->marge_gauche;
854 $cury = $posy;
855
856 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
857
858 $posy += 2;
859 }
860 }
861
862 return $posy;
863 }
864
865 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
866 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
878 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
879 {
880 // phpcs:enable
881 global $conf, $mysoc, $hookmanager;
882
883 $default_font_size = pdf_getPDFFontSize($outputlangs);
884
885 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
886 $outputlangsbis = new Translate('', $conf);
887 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
888 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
889 $default_font_size--;
890 }
891
892 $tab2_top = $posy;
893 $tab2_hl = 4;
894 $pdf->SetFont('', '', $default_font_size - 1);
895
896 // Total table
897 $col1x = 120;
898 $col2x = 170;
899 if ($this->page_largeur < 210) { // To work with US executive format
900 $col2x -= 20;
901 }
902 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
903
904 $useborder = 0;
905 $index = 0;
906
907 // Total HT
908 $pdf->SetFillColor(255, 255, 255);
909 $pdf->SetXY($col1x, $tab2_top);
910 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
911
912 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
913 $pdf->SetXY($col2x, $tab2_top);
914 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
915
916 // Show VAT by rates and total
917 $pdf->SetFillColor(248, 248, 248);
918
919 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
920
921 $this->atleastoneratenotnull = 0;
922 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
923 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
924 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
925 // Nothing to do
926 } else {
927 //Local tax 1 before VAT
928 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
929 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
930 continue;
931 }
932 foreach ($localtax_rate as $tvakey => $tvaval) {
933 if ($tvakey != 0) { // On affiche pas taux 0
934 //$this->atleastoneratenotnull++;
935
936 $index++;
937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
938
939 $tvacompl = '';
940 if (preg_match('/\*/', (string) $tvakey)) {
941 $tvakey = str_replace('*', '', (string) $tvakey);
942 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
943 }
944 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
945 $totalvat .= ' ';
946
947 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
948 $totalvat .= $tvacompl;
949 } else {
950 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
951 }
952
953 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
954
955 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
956
957 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
958 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
959 }
960 }
961 }
962
963 //Local tax 2 before VAT
964 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
965 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
966 continue;
967 }
968 foreach ($localtax_rate as $tvakey => $tvaval) {
969 if ($tvakey != 0) { // On affiche pas taux 0
970 //$this->atleastoneratenotnull++;
971
972 $index++;
973 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
974
975 $tvacompl = '';
976 if (preg_match('/\*/', (string) $tvakey)) {
977 $tvakey = str_replace('*', '', (string) $tvakey);
978 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
979 }
980 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
981 $totalvat .= ' ';
982
983 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
984 $totalvat .= $tvacompl;
985 } else {
986 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
987 }
988
989 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
990
991 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
992
993 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
994 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
995 }
996 }
997 }
998
999 // VAT
1000 foreach ($this->tva_array as $tvakey => $tvaval) {
1001 if ($tvakey != 0) { // On affiche pas taux 0
1002 $this->atleastoneratenotnull++;
1003
1004 $index++;
1005 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1006
1007 $tvacompl = '';
1008 if (preg_match('/\*/', $tvakey)) {
1009 $tvakey = str_replace('*', '', $tvakey);
1010 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1011 }
1012 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1013 $totalvat .= ' ';
1014 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1015 $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1016 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1017 $totalvat .= $tvaval['vatcode'].$tvacompl;
1018 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1019 $totalvat .= $tvacompl;
1020 } else {
1021 $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1022 }
1023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1024
1025 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1026 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1027 }
1028 }
1029
1030 //Local tax 1 after VAT
1031 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1032 //{
1033 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1034 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1035 continue;
1036 }
1037
1038 foreach ($localtax_rate as $tvakey => $tvaval) {
1039 if ($tvakey != 0) { // On affiche pas taux 0
1040 //$this->atleastoneratenotnull++;
1041
1042 $index++;
1043 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1044
1045 $tvacompl = '';
1046 if (preg_match('/\*/', (string) $tvakey)) {
1047 $tvakey = str_replace('*', '', (string) $tvakey);
1048 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1049 }
1050 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1051 $totalvat .= ' ';
1052
1053 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1054 $totalvat .= $tvacompl;
1055 } else {
1056 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1057 }
1058
1059 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1060
1061 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1062
1063 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1064 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1065 }
1066 }
1067 }
1068 //}
1069 //Local tax 2 after VAT
1070 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1071 //{
1072 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1073 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1074 continue;
1075 }
1076
1077 foreach ($localtax_rate as $tvakey => $tvaval) {
1078 // retrieve global local tax
1079 if ($tvakey != 0) { // On affiche pas taux 0
1080 //$this->atleastoneratenotnull++;
1081
1082 $index++;
1083 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1084
1085 $tvacompl = '';
1086 if (preg_match('/\*/', (string) $tvakey)) {
1087 $tvakey = str_replace('*', '', (string) $tvakey);
1088 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1089 }
1090 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1091 $totalvat .= ' ';
1092
1093 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1094 $totalvat .= $tvacompl;
1095 } else {
1096 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1097 }
1098
1099 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1100
1101 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1102
1103 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1104 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', 1);
1105 }
1106 }
1107 }
1108 //}
1109
1110 // Total TTC
1111 $index++;
1112 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1113 $pdf->SetTextColor(0, 0, 60);
1114 $pdf->SetFillColor(224, 224, 224);
1115 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
1116
1117 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1118 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1119 }
1120 }
1121
1122 $pdf->SetTextColor(0, 0, 0);
1123
1124 $creditnoteamount = 0;
1125 $depositsamount = 0;
1126 //$creditnoteamount=$object->getSumCreditNotesUsed();
1127 //$depositsamount=$object->getSumDepositsUsed();
1128 //print "x".$creditnoteamount."-".$depositsamount;exit;
1129 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1130 if (!empty($object->paye)) {
1131 $resteapayer = 0;
1132 }
1133
1134 if ($deja_regle > 0) {
1135 // Already paid + Deposits
1136 $index++;
1137
1138 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1139 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1140 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1141 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1142
1143 $index++;
1144 $pdf->SetTextColor(0, 0, 60);
1145 $pdf->SetFillColor(224, 224, 224);
1146 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1147 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), $useborder, 'L', 1);
1148
1149 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1150 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1151
1152 $pdf->SetFont('', '', $default_font_size - 1);
1153 $pdf->SetTextColor(0, 0, 0);
1154 }
1155
1156 $index++;
1157 return ($tab2_top + ($tab2_hl * $index));
1158 }
1159
1160 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1175 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1176 {
1177 global $conf;
1178
1179 // Force to disable hidetop and hidebottom
1180 $hidebottom = 0;
1181 if ($hidetop) {
1182 $hidetop = -1;
1183 }
1184
1185 $currency = !empty($currency) ? $currency : $conf->currency;
1186 $default_font_size = pdf_getPDFFontSize($outputlangs);
1187
1188 // Amount in (at tab_top - 1)
1189 $pdf->SetTextColor(0, 0, 0);
1190 $pdf->SetFont('', '', $default_font_size - 2);
1191
1192 if (empty($hidetop)) {
1193 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1194 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1195 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
1196 }
1197
1198 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1199 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1200
1201 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1202 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1203 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1204 }
1205 }
1206
1207 $pdf->SetDrawColor(128, 128, 128);
1208 $pdf->SetFont('', '', $default_font_size - 1);
1209
1210 // Output Rect
1211 $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
1212
1213 if (empty($hidetop)) {
1214 $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
1215
1216 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1217 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1218 }
1219
1220 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1221 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1222 if (empty($hidetop)) {
1223 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1224 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1225 }
1226 }
1227
1228 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1229 if (empty($hidetop)) {
1230 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1231 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1232 }
1233
1234 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1235 if (empty($hidetop)) {
1236 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1237 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1238 }
1239
1240 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1241 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1242 if (empty($hidetop)) {
1243 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1244 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1245 }
1246 }
1247
1248 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1249 if (empty($hidetop)) {
1250 if ($this->atleastonediscount) {
1251 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1252 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1253 }
1254 }
1255
1256 if ($this->atleastonediscount) {
1257 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1258 }
1259 if (empty($hidetop)) {
1260 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1261 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1262 }
1263 }
1264
1265 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1266 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1278 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
1279 {
1280 // phpcs:enable
1281 global $conf, $langs, $hookmanager;
1282
1283 $ltrdirection = 'L';
1284 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1285 $ltrdirection = 'R';
1286 }
1287
1288 // Load traductions files required by page
1289 $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1290
1291 $default_font_size = pdf_getPDFFontSize($outputlangs);
1292
1293 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1294
1295 $pdf->SetTextColor(0, 0, 60);
1296 $pdf->SetFont('', 'B', $default_font_size + 3);
1297
1298 $w = 100;
1299
1300 $posy = $this->marge_haute;
1301 $posx = $this->page_largeur - $this->marge_droite - $w;
1302
1303 $pdf->SetXY($this->marge_gauche, $posy);
1304
1305 // Logo
1306 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1307 if ($this->emetteur->logo) {
1308 $logodir = $conf->mycompany->dir_output;
1309 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1310 $logodir = $conf->mycompany->multidir_output[$object->entity];
1311 }
1312 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1313 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1314 } else {
1315 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1316 }
1317 if (is_readable($logo)) {
1318 $height = pdf_getHeightForLogo($logo);
1319 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1320 } else {
1321 $pdf->SetTextColor(200, 0, 0);
1322 $pdf->SetFont('', 'B', $default_font_size - 2);
1323 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1324 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1325 }
1326 } else {
1327 $text = $this->emetteur->name;
1328 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1329 }
1330 }
1331
1332 $pdf->SetFont('', 'B', $default_font_size + 3);
1333 $pdf->SetXY($posx, $posy);
1334 $pdf->SetTextColor(0, 0, 60);
1335 $title = $outputlangs->transnoentities($titlekey);
1336 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1337 if ($object->statut == $object::STATUS_DRAFT) {
1338 $pdf->SetTextColor(128, 0, 0);
1339 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1340 }
1341 $pdf->MultiCell($w, 3, $title, '', 'R');
1342
1343 $pdf->SetFont('', 'B', $default_font_size);
1344
1345 /*
1346 $posy += 5;
1347 $pdf->SetXY($posx, $posy);
1348 $pdf->SetTextColor(0, 0, 60);
1349 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1350 */
1351
1352 $posy += 3;
1353 $pdf->SetFont('', '', $default_font_size - 1);
1354
1355 if ($object->ref_client) {
1356 $posy += 5;
1357 $pdf->SetXY($posx, $posy);
1358 $pdf->SetTextColor(0, 0, 60);
1359 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1360 }
1361
1362 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1363 $object->fetch_projet();
1364 if (!empty($object->project->ref)) {
1365 $posy += 3;
1366 $pdf->SetXY($posx, $posy);
1367 $pdf->SetTextColor(0, 0, 60);
1368 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1369 }
1370 }
1371
1372 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1373 $object->fetch_projet();
1374 if (!empty($object->project->ref)) {
1375 $outputlangs->load("projects");
1376 $posy += 3;
1377 $pdf->SetXY($posx, $posy);
1378 $pdf->SetTextColor(0, 0, 60);
1379 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1380 }
1381 }
1382
1383 $posy += 4;
1384 $pdf->SetXY($posx, $posy);
1385 $pdf->SetTextColor(0, 0, 60);
1386 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1387
1388 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
1389 $posy += 4;
1390 $pdf->SetXY($posx, $posy);
1391 $pdf->SetTextColor(0, 0, 60);
1392 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1393 }
1394
1395 // Get contact
1396 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1397 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1398 if (count($arrayidcontact) > 0) {
1399 $usertmp = new User($this->db);
1400 $usertmp->fetch($arrayidcontact[0]);
1401 $posy += 4;
1402 $pdf->SetXY($posx, $posy);
1403 $pdf->SetTextColor(0, 0, 60);
1404 $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1405 }
1406 }
1407
1408 $posy += 2;
1409
1410 $top_shift = 0;
1411 // Show list of linked objects
1412 $current_y = $pdf->getY();
1413 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1414 if ($current_y < $pdf->getY()) {
1415 $top_shift = $pdf->getY() - $current_y;
1416 }
1417
1418 if ($showaddress) {
1419 // Sender properties
1420 $carac_emetteur = '';
1421 // Add internal contact of object if defined
1422 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1423 if (count($arrayidcontact) > 0) {
1424 $object->fetch_user($arrayidcontact[0]);
1425 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1426 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1427 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1428 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1429 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1430 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1431 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1432 $carac_emetteur .= "\n";
1433 }
1434
1435 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1436
1437 // Show sender
1438 $posy = 42 + $top_shift;
1439 $posx = $this->marge_gauche;
1440 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1441 $posx = $this->page_largeur - $this->marge_droite - 80;
1442 }
1443 $hautcadre = 40;
1444
1445 // Show sender frame
1446 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1447 $pdf->SetTextColor(0, 0, 0);
1448 $pdf->SetFont('', '', $default_font_size - 2);
1449 $pdf->SetXY($posx, $posy - 5);
1450 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1451 $pdf->SetXY($posx, $posy);
1452 $pdf->SetFillColor(230, 230, 230);
1453 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1454 $pdf->SetTextColor(0, 0, 60);
1455 }
1456
1457 // Show sender name
1458 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1459 $pdf->SetXY($posx + 2, $posy + 3);
1460 $pdf->SetFont('', 'B', $default_font_size);
1461 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1462 $posy = $pdf->getY();
1463 }
1464
1465 // Show sender information
1466 $pdf->SetXY($posx + 2, $posy);
1467 $pdf->SetFont('', '', $default_font_size - 1);
1468 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1469
1470
1471 // If CUSTOMER contact defined, we use it
1472 $usecontact = false;
1473 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1474 if (count($arrayidcontact) > 0) {
1475 $usecontact = true;
1476 $result = $object->fetch_contact($arrayidcontact[0]);
1477 }
1478
1479 // Recipient name
1480 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1481 $thirdparty = $object->contact;
1482 } else {
1483 $thirdparty = $object->thirdparty;
1484 }
1485
1486 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1487
1488 $mode = 'target';
1489 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
1490
1491 // Show recipient
1492 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1493 if ($this->page_largeur < 210) {
1494 $widthrecbox = 84; // To work with US executive format
1495 }
1496 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1497 $posy += $top_shift;
1498 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1499 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1500 $posx = $this->marge_gauche;
1501 }
1502
1503 // Show recipient frame
1504 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1505 $pdf->SetTextColor(0, 0, 0);
1506 $pdf->SetFont('', '', $default_font_size - 2);
1507 $pdf->SetXY($posx + 2, $posy - 5);
1508 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1509 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1510 }
1511
1512 // Show recipient name
1513 $pdf->SetXY($posx + 2, $posy + 3);
1514 $pdf->SetFont('', 'B', $default_font_size);
1515 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1516 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1517
1518 $posy = $pdf->getY();
1519
1520 // Show recipient information
1521 $pdf->SetFont('', '', $default_font_size - 1);
1522 $pdf->SetXY($posx + 2, $posy);
1523 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1524 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1525 }
1526
1527 $pdf->SetTextColor(0, 0, 0);
1528
1529 return $top_shift;
1530 }
1531
1532 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1533 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1543 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1544 {
1545 // phpcs:enable
1546 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1547 return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1548 }
1549}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage Dolibarr database access.
Class to manage hooks.
Parent class for orders models.
Class to manage translations.
Class to manage Dolibarr users.
Class to generate PDF orders with template Einstein.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="PdfOrderTitle")
Show top header of page.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis=null)
Show total to pay.
__construct(DoliDB $db)
Constructor.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1431
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2369
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:290
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:315
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1020
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:1987
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1925
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1394
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:843
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:267
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:436
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2232
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2275
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2072
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:769
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:388
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:139
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142