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