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