dolibarr 19.0.3
pdf_muscadet.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5 * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37
38
43{
47 public $db;
48
52 public $name;
53
57 public $description;
58
62 public $update_main_doc_field;
63
67 public $type;
68
73 public $version = 'dolibarr';
74
75
81 public function __construct($db)
82 {
83 global $conf, $langs, $mysoc;
84
85 // Load translation files required by the page
86 $langs->loadLangs(array("main", "bills"));
87
88 $this->db = $db;
89 $this->name = "muscadet";
90 $this->description = $langs->trans('SuppliersCommandModelMuscadet');
91 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
92
93 // Page size for A4 format
94 $this->type = 'pdf';
95 $formatarray = pdf_getFormat();
96 $this->page_largeur = $formatarray['width'];
97 $this->page_hauteur = $formatarray['height'];
98 $this->format = array($this->page_largeur, $this->page_hauteur);
99 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
100 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
101 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
102 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
103
104 $this->option_logo = 1; // Display logo
105 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
106 $this->option_modereg = 1; // Display payment mode
107 $this->option_condreg = 1; // Display payment terms
108 $this->option_multilang = 1; // Available in several languages
109 $this->option_escompte = 0; // Displays if there has been a discount
110 $this->option_credit_note = 0; // Support credit notes
111 $this->option_freetext = 1; // Support add of a personalised text
112 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
113
114 // Get source company
115 $this->emetteur = $mysoc;
116 if (empty($this->emetteur->country_code)) {
117 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
118 }
119
120 // Define position of columns
121 $this->posxdesc = $this->marge_gauche + 1;
122 $this->posxdiscount = 162;
123 $this->postotalht = 174;
124
125 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
126 $this->posxtva = 95;
127 $this->posxup = 114;
128 $this->posxqty = 132;
129 $this->posxunit = 147;
130 } else {
131 $this->posxtva = 106;
132 $this->posxup = 122;
133 $this->posxqty = 145;
134 $this->posxunit = 162;
135 }
136
137 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
138 $this->posxup = $this->posxtva; // posxtva is picture position reference
139 }
140 $this->posxpicture = $this->posxtva - (!getDolGlobalString('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH') ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
141 if ($this->page_largeur < 210) { // To work with US executive format
142 $this->posxpicture -= 20;
143 $this->posxtva -= 20;
144 $this->posxup -= 20;
145 $this->posxqty -= 20;
146 $this->posxunit -= 20;
147 $this->posxdiscount -= 20;
148 $this->postotalht -= 20;
149 }
150
151 $this->tva = array();
152 $this->tva_array = array();
153 $this->localtax1 = array();
154 $this->localtax2 = array();
155 $this->atleastoneratenotnull = 0;
156 $this->atleastonediscount = 0;
157 }
158
159
160 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
172 public function write_file($object, $outputlangs = null, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
173 {
174 // phpcs:enable
175 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
176
177 if (!is_object($outputlangs)) {
178 $outputlangs = $langs;
179 }
180 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
181 if (getDolGlobalString('MAIN_USE_FPDF')) {
182 $outputlangs->charset_output = 'ISO-8859-1';
183 }
184
185 // Load translation files required by the page
186 $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
187
188 $nblines = count($object->lines);
189
190 // Loop on each lines to detect if there is at least one image to show
191 $realpatharray = array();
192 if (getDolGlobalString('MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE')) {
193 for ($i = 0; $i < $nblines; $i++) {
194 if (empty($object->lines[$i]->fk_product)) {
195 continue;
196 }
197
198 $objphoto = new Product($this->db);
199 $objphoto->fetch($object->lines[$i]->fk_product);
200
201 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
202 $pdir = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
203 $dir = $conf->product->dir_output.'/'.$pdir;
204 } else {
205 $pdir = get_exdir($objphoto->id, 0, 0, 0, $objphoto, 'product');
206 $dir = $conf->product->dir_output.'/'.$pdir;
207 }
208 $realpath = '';
209 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
210 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
211 if ($obj['photo_vignette']) {
212 $filename = $obj['photo_vignette'];
213 } else {
214 $filename = $obj['photo'];
215 }
216 } else {
217 $filename = $obj['photo'];
218 }
219 $realpath = $dir.$filename;
220 break;
221 }
222
223 if ($realpath) {
224 $realpatharray[$i] = $realpath;
225 }
226 }
227 }
228 if (count($realpatharray) == 0) {
229 $this->posxpicture = $this->posxtva;
230 }
231
232 if ($conf->fournisseur->commande->dir_output) {
233 $object->fetch_thirdparty();
234
235 $deja_regle = 0;
236 $amount_credit_notes_included = 0;
237 $amount_deposits_included = 0;
238 //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
239 //$amount_deposits_included = $object->getSumDepositsUsed();
240
241 // Definition of $dir and $file
242 if ($object->specimen) {
243 $dir = $conf->fournisseur->commande->dir_output;
244 $file = $dir."/SPECIMEN.pdf";
245 } else {
246 $objectref = dol_sanitizeFileName($object->ref);
247 $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
248 $dir = $conf->fournisseur->commande->dir_output.'/'.$objectref;
249 $file = $dir."/".$objectref.".pdf";
250 if (getDolGlobalString('SUPPLIER_REF_IN_NAME')) {
251 $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
252 }
253 }
254
255 if (!file_exists($dir)) {
256 if (dol_mkdir($dir) < 0) {
257 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
258 return 0;
259 }
260 }
261
262 if (file_exists($dir)) {
263 // Add pdfgeneration hook
264 if (!is_object($hookmanager)) {
265 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
266 $hookmanager = new HookManager($this->db);
267 }
268 $hookmanager->initHooks(array('pdfgeneration'));
269 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
270 global $action;
271 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
272
273 $nblines = count($object->lines);
274
275 $pdf = pdf_getInstance($this->format);
276 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
277 $heightforinfotot = 50; // Height reserved to output the info and total part
278 $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
279 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
280 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
281 $heightforfooter += 6;
282 }
283 $pdf->SetAutoPageBreak(1, 0);
284
285 if (class_exists('TCPDF')) {
286 $pdf->setPrintHeader(false);
287 $pdf->setPrintFooter(false);
288 }
289 $pdf->SetFont(pdf_getPDFFont($outputlangs));
290 // Set path to the background PDF File
291 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
292 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
293 $tplidx = $pdf->importPage(1);
294 }
295
296 $pdf->Open();
297 $pagenb = 0;
298 $pdf->SetDrawColor(128, 128, 128);
299
300 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
301 $pdf->SetSubject($outputlangs->transnoentities("PurchaseOrder"));
302 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
303 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
304
305 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PurchaseOrder")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
306 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
307 $pdf->SetCompression(false);
308 }
309
310 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
311
312 // Positionne $this->atleastonediscount si on a au moins une remise
313 for ($i = 0; $i < $nblines; $i++) {
314 if ($object->lines[$i]->remise_percent) {
315 $this->atleastonediscount++;
316 }
317 }
318 if (empty($this->atleastonediscount)) {
319 $delta = ($this->postotalht - $this->posxdiscount);
320 $this->posxpicture += $delta;
321 $this->posxtva += $delta;
322 $this->posxup += $delta;
323 $this->posxqty += $delta;
324 $this->posxunit += $delta;
325 $this->posxdiscount += $delta;
326 // post of fields after are not modified, stay at same position
327 }
328
329 // New page
330 $pdf->AddPage();
331 if (!empty($tplidx)) {
332 $pdf->useTemplate($tplidx);
333 }
334 $pagenb++;
335 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
336 $pdf->SetFont('', '', $default_font_size - 1);
337 $pdf->MultiCell(0, 3, ''); // Set interline to 3
338 $pdf->SetTextColor(0, 0, 0);
339
340 $tab_top = 90 + $top_shift;
341 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
342
343 // Incoterm
344 if (isModEnabled('incoterm')) {
345 $desc_incoterms = $object->getIncotermsForPDF();
346 if ($desc_incoterms) {
347 $tab_top -= 2;
348
349 $pdf->SetFont('', '', $default_font_size - 1);
350 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
351 $nexY = $pdf->GetY();
352 $height_incoterms = $nexY - $tab_top;
353
354 // Rect takes a length in 3rd parameter
355 $pdf->SetDrawColor(192, 192, 192);
356 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
357
358 $tab_top = $nexY + 6;
359 }
360 }
361
362 // Affiche notes
363 if (!empty($object->note_public)) {
364 $tab_top -= 2;
365
366 $pdf->SetFont('', '', $default_font_size - 1);
367 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
368 $nexY = $pdf->GetY();
369 $height_note = $nexY - $tab_top;
370
371 // Rect takes a length in 3rd parameter
372 $pdf->SetDrawColor(192, 192, 192);
373 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
374
375 $tab_top = $nexY + 6;
376 }
377
378 $iniY = $tab_top + 7;
379 $curY = $tab_top + 7;
380 $nexY = $tab_top + 7;
381
382 // Loop on each lines
383 for ($i = 0; $i < $nblines; $i++) {
384 $curY = $nexY;
385 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
386 $pdf->SetTextColor(0, 0, 0);
387
388 // Define size of image if we need it
389 $imglinesize = array();
390 if (!empty($realpatharray[$i])) {
391 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
392 }
393
394 $pdf->setTopMargin($tab_top_newpage);
395 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
396 $pageposbefore = $pdf->getPage();
397
398 $showpricebeforepagebreak = 1;
399 $posYAfterImage = 0;
400 $posYAfterDescription = 0;
401
402 // We start with Photo of product line
403 if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
404 $pdf->AddPage('', '', true);
405 if (!empty($tplidx)) {
406 $pdf->useTemplate($tplidx);
407 }
408 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
409 $this->_pagehead($pdf, $object, 0, $outputlangs);
410 }
411 $pdf->setPage($pageposbefore + 1);
412
413 $curY = $tab_top_newpage;
414
415 // Allows data in the first page if description is long enough to break in multiples pages
416 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
417 $showpricebeforepagebreak = 1;
418 } else {
419 $showpricebeforepagebreak = 0;
420 }
421 }
422
423 if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) {
424 $curX = $this->posxpicture - 1;
425 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
426 // $pdf->Image does not increase value return by getY, so we save it manually
427 $posYAfterImage = $curY + $imglinesize['height'];
428 }
429 // Description of product line
430 $curX = $this->posxdesc - 1;
431 $showpricebeforepagebreak = 1;
432
433 $pdf->startTransaction();
434 if ($posYAfterImage > 0) {
435 $descWidth = $this->posxpicture - $curX;
436 } else {
437 $descWidth = $this->posxtva - $curX;
438 }
439 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
440
441 $pageposafter = $pdf->getPage();
442 if ($pageposafter > $pageposbefore) { // There is a pagebreak
443 $pdf->rollbackTransaction(true);
444 $pageposafter = $pageposbefore;
445 //print $pageposafter.'-'.$pageposbefore;exit;
446 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
447 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
448 $posyafter = $pdf->GetY();
449 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
450 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
451 $pdf->AddPage('', '', true);
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
454 }
455 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
456 $this->_pagehead($pdf, $object, 0, $outputlangs);
457 }
458 $pdf->setPage($pageposafter + 1);
459 }
460 } else {
461 // We found a page break
462 // Allows data in the first page if description is long enough to break in multiples pages
463 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
464 $showpricebeforepagebreak = 1;
465 } else {
466 $showpricebeforepagebreak = 0;
467 }
468 }
469 } else { // No pagebreak
470 $pdf->commitTransaction();
471 }
472
473 $nexY = $pdf->GetY();
474 $pageposafter = $pdf->getPage();
475 $pdf->setPage($pageposbefore);
476 $pdf->setTopMargin($this->marge_haute);
477 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
478
479 // We suppose that a too long description is moved completely on next page
480 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
481 $pdf->setPage($pageposafter);
482 $curY = $tab_top_newpage;
483 }
484
485 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
486
487 // VAT Rate
488 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
489 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
490 $pdf->SetXY($this->posxtva, $curY);
491 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
492 }
493
494 // Unit price before discount
495 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE')) {
496 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
497 $pdf->SetXY($this->posxup, $curY);
498 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
499 }
500
501 // Quantity
502 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
503 $pdf->SetXY($this->posxqty, $curY);
504 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
505
506 // Unit
507 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
508 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
509 $pdf->SetXY($this->posxunit, $curY);
510 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
511 }
512
513 // Discount on line
514 $pdf->SetXY($this->posxdiscount, $curY);
515 if ($object->lines[$i]->remise_percent) {
516 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
517 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
518 }
519
520 // Total HT line
521 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN')) {
522 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
523 $pdf->SetXY($this->postotalht, $curY);
524 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
525 }
526
527 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
528 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
529 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
530 } else {
531 $tvaligne = $object->lines[$i]->total_tva;
532 }
533
534 $localtax1ligne = $object->lines[$i]->total_localtax1;
535 $localtax2ligne = $object->lines[$i]->total_localtax2;
536 $localtax1_rate = $object->lines[$i]->localtax1_tx;
537 $localtax2_rate = $object->lines[$i]->localtax2_tx;
538 $localtax1_type = $object->lines[$i]->localtax1_type;
539 $localtax2_type = $object->lines[$i]->localtax2_type;
540
541 // TODO remise_percent is an obsolete field for object parent
542 /*if (!empty($object->remise_percent)) {
543 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
544 }
545 if (!empty($object->remise_percent)) {
546 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
547 }
548 if (!empty($object->remise_percent)) {
549 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
550 }*/
551
552 $vatrate = (string) $object->lines[$i]->tva_tx;
553
554 // Retrieve type from database for backward compatibility with old records
555 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
556 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
557 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty);
558 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
559 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
560 }
561
562 // retrieve global local tax
563 if ($localtax1_type && $localtax1ligne != 0) {
564 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
565 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
566 } else {
567 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
568 }
569 }
570 if ($localtax2_type && $localtax2ligne != 0) {
571 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
572 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
573 } else {
574 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
575 }
576 }
577
578 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
579 $vatrate .= '*';
580 }
581
582 // Fill $this->tva and $this->tva_array
583 if (!isset($this->tva[$vatrate])) {
584 $this->tva[$vatrate] = 0;
585 }
586 $this->tva[$vatrate] += $tvaligne;
587 $vatcode = $object->lines[$i]->vat_src_code;
588 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
589 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
590 }
591 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
592
593 if ($posYAfterImage > $posYAfterDescription) {
594 $nexY = $posYAfterImage;
595 }
596
597 // Add line
598 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
599 $pdf->setPage($pageposafter);
600 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
601 //$pdf->SetDrawColor(190,190,200);
602 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
603 $pdf->SetLineStyle(array('dash'=>0));
604 }
605
606 $nexY += 2; // Add space between lines
607
608 // Detect if some page were added automatically and output _tableau for past pages
609 while ($pagenb < $pageposafter) {
610 $pdf->setPage($pagenb);
611 if ($pagenb == 1) {
612 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
613 } else {
614 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
615 }
616 $this->_pagefoot($pdf, $object, $outputlangs, 1);
617 $pagenb++;
618 $pdf->setPage($pagenb);
619 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
620 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
621 $this->_pagehead($pdf, $object, 0, $outputlangs);
622 }
623 if (!empty($tplidx)) {
624 $pdf->useTemplate($tplidx);
625 }
626 }
627 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
628 if ($pagenb == 1) {
629 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
630 } else {
631 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
632 }
633 $this->_pagefoot($pdf, $object, $outputlangs, 1);
634 // New page
635 $pdf->AddPage();
636 if (!empty($tplidx)) {
637 $pdf->useTemplate($tplidx);
638 }
639 $pagenb++;
640 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
641 $this->_pagehead($pdf, $object, 0, $outputlangs);
642 }
643 }
644 }
645
646 // Show square
647 if ($pagenb == 1) {
648 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
649 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
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 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
653 }
654
655 // Affiche zone infos
656 $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
657
658 // Affiche zone totaux
659 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
660
661 // Affiche zone versements
662 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
663 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
664 }
665
666 // Pied de page
667 $this->_pagefoot($pdf, $object, $outputlangs);
668 if (method_exists($pdf, 'AliasNbPages')) {
669 $pdf->AliasNbPages();
670 }
671
672 $pdf->Close();
673
674 $pdf->Output($file, 'F');
675
676 // Add pdfgeneration hook
677 $hookmanager->initHooks(array('pdfgeneration'));
678 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
679 global $action;
680 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
681 if ($reshook < 0) {
682 $this->error = $hookmanager->error;
683 $this->errors = $hookmanager->errors;
684 }
685
686 dolChmod($file);
687
688 $this->result = array('fullpath'=>$file);
689
690 return 1; // No error
691 } else {
692 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
693 return 0;
694 }
695 } else {
696 $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
697 return 0;
698 }
699 }
700
701 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
702 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
712 protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
713 {
714 // phpcs:enable
715 return 1;
716 }
717
718 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
719 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
729 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
730 {
731 // phpcs:enable
732 global $conf, $mysoc;
733 $default_font_size = pdf_getPDFFontSize($outputlangs);
734
735 $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
736
737 // If France, show VAT mention if not applicable
738 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
739 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
740 $pdf->SetXY($this->marge_gauche, $posy);
741 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
742
743 $posy = $pdf->GetY() + 4;
744 }
745
746 $posxval = 52;
747
748 // Show payments conditions
749 if (!empty($object->cond_reglement_code) || $object->cond_reglement_id) {
750 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
751 $pdf->SetXY($this->marge_gauche, $posy);
752 $titre = $outputlangs->transnoentities("PaymentConditions").':';
753 $pdf->MultiCell(80, 4, $titre, 0, 'L');
754
755 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
756 $pdf->SetXY($posxval, $posy);
757 $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);
758 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
759 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
760
761 $posy = $pdf->GetY() + 3;
762 }
763
764 // Show payment mode
765 if (!empty($object->mode_reglement_code)) {
766 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
767 $pdf->SetXY($this->marge_gauche, $posy);
768 $titre = $outputlangs->transnoentities("PaymentMode").':';
769 $pdf->MultiCell(80, 5, $titre, 0, 'L');
770
771 $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
772 $pdf->SetXY($posxval, $posy);
773 $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);
774 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
775
776 $posy = $pdf->GetY() + 2;
777 }
778
779 return $posy;
780 }
781
782 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
783 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
794 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
795 {
796 // phpcs:enable
797 global $conf, $mysoc;
798
799 $default_font_size = pdf_getPDFFontSize($outputlangs);
800
801 $tab2_top = $posy;
802 $tab2_hl = 4;
803 $pdf->SetFont('', '', $default_font_size - 1);
804
805 // Tableau total
806 $col1x = 120;
807 $col2x = 170;
808 if ($this->page_largeur < 210) { // To work with US executive format
809 $col2x -= 20;
810 }
811 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
812
813 $useborder = 0;
814 $index = 0;
815
816 // Total HT
817 $pdf->SetFillColor(255, 255, 255);
818 $pdf->SetXY($col1x, $tab2_top);
819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
820
821 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
822 $pdf->SetXY($col2x, $tab2_top);
823 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, 'R', 1);
824
825 // Show VAT by rates and total
826 $pdf->SetFillColor(248, 248, 248);
827
828 $this->atleastoneratenotnull = 0;
829 foreach ($this->tva as $tvakey => $tvaval) {
830 if ($tvakey > 0) { // On affiche pas taux 0
831 $this->atleastoneratenotnull++;
832
833 $index++;
834 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
835
836 $tvacompl = '';
837
838 if (preg_match('/\*/', $tvakey)) {
839 $tvakey = str_replace('*', '', $tvakey);
840 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
841 }
842
843 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
844 $totalvat .= vatrate($tvakey, 1).$tvacompl;
845 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
846
847 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
848 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
849 }
850 }
851 if (!$this->atleastoneratenotnull) { // If no vat at all
852 $index++;
853 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
854 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
855
856 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
857 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
858
859 // Total LocalTax1
860 if (getDolGlobalString('FACTURE_LOCAL_TAX1_OPTION') == 'localtax1on' && $object->total_localtax1 > 0) {
861 $index++;
862 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
863 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
864 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
865 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
866 }
867
868 // Total LocalTax2
869 if (getDolGlobalString('FACTURE_LOCAL_TAX2_OPTION') == 'localtax2on' && $object->total_localtax2 > 0) {
870 $index++;
871 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
872 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
873 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
874 $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
875 }
876 } else {
877 //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
878 //{
879 //Local tax 1
880 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
881 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
882 continue;
883 }
884
885 foreach ($localtax_rate as $tvakey => $tvaval) {
886 if ($tvakey != 0) { // On affiche pas taux 0
887 //$this->atleastoneratenotnull++;
888
889 $index++;
890 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
891
892 $tvacompl = '';
893 if (preg_match('/\*/', $tvakey)) {
894 $tvakey = str_replace('*', '', $tvakey);
895 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
896 }
897 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
898 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
899 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
900
901 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
902 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
903 }
904 }
905 }
906
907 //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
908 //{
909 //Local tax 2
910 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
911 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
912 continue;
913 }
914
915 foreach ($localtax_rate as $tvakey => $tvaval) {
916 if ($tvakey != 0) { // On affiche pas taux 0
917 //$this->atleastoneratenotnull++;
918
919 $index++;
920 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
921
922 $tvacompl = '';
923 if (preg_match('/\*/', $tvakey)) {
924 $tvakey = str_replace('*', '', $tvakey);
925 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
926 }
927 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
928 $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
929 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
930
931 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
932 $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
933 }
934 }
935 }
936 }
937
938 // Total TTC
939 $index++;
940 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
941 $pdf->SetTextColor(0, 0, 60);
942 $pdf->SetFillColor(224, 224, 224);
943 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
944
945 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
946 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
947 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
948 $pdf->SetFont('', '', $default_font_size - 1);
949 $pdf->SetTextColor(0, 0, 0);
950
951 $creditnoteamount = 0;
952 $depositsamount = 0;
953 //$creditnoteamount=$object->getSumCreditNotesUsed();
954 //$depositsamount=$object->getSumDepositsUsed();
955 //print "x".$creditnoteamount."-".$depositsamount;exit;
956 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
957 if (!empty($object->paye)) {
958 $resteapayer = 0;
959 }
960
961 if ($deja_regle > 0) {
962 // Already paid + Deposits
963 $index++;
964
965 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
966 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
967 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
968 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
969
970 $index++;
971 $pdf->SetTextColor(0, 0, 60);
972 $pdf->SetFillColor(224, 224, 224);
973 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
974 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
975
976 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
977 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
978
979 $pdf->SetFont('', '', $default_font_size - 1);
980 $pdf->SetTextColor(0, 0, 0);
981 }
982
983 $index++;
984 return ($tab2_top + ($tab2_hl * $index));
985 }
986
987 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1001 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1002 {
1003 global $conf;
1004
1005 // Force to disable hidetop and hidebottom
1006 $hidebottom = 0;
1007 if ($hidetop) {
1008 $hidetop = -1;
1009 }
1010
1011 $currency = !empty($currency) ? $currency : $conf->currency;
1012 $default_font_size = pdf_getPDFFontSize($outputlangs);
1013
1014 // Amount in (at tab_top - 1)
1015 $pdf->SetTextColor(0, 0, 0);
1016 $pdf->SetFont('', '', $default_font_size - 2);
1017
1018 if (empty($hidetop)) {
1019 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1020 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1021 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1022
1023 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1024 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1025 $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')));
1026 }
1027 }
1028
1029 $pdf->SetDrawColor(128, 128, 128);
1030 $pdf->SetFont('', '', $default_font_size - 1);
1031
1032 // Output Rect
1033 $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
1034
1035 if (empty($hidetop)) {
1036 $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
1037
1038 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1039 $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1040 }
1041
1042 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
1043 $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1044 if (empty($hidetop)) {
1045 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1046 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1047 }
1048 }
1049
1050 $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1051 if (empty($hidetop)) {
1052 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1053 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1054 }
1055
1056 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1057 if (empty($hidetop)) {
1058 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1059 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1060 }
1061
1062 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1063 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1064 if (empty($hidetop)) {
1065 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1066 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1067 }
1068 }
1069
1070 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1071 if (empty($hidetop)) {
1072 if ($this->atleastonediscount) {
1073 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1074 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1075 }
1076 }
1077
1078 if ($this->atleastonediscount) {
1079 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1080 }
1081 if (empty($hidetop)) {
1082 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1083 $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1084 }
1085 }
1086
1087 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1097 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1098 {
1099 global $langs, $conf, $mysoc;
1100
1101 $ltrdirection = 'L';
1102 if ($outputlangs->trans("DIRECTION") == 'rtl') {
1103 $ltrdirection = 'R';
1104 }
1105
1106 // Load translation files required by the page
1107 $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1108
1109 $default_font_size = pdf_getPDFFontSize($outputlangs);
1110
1111 // Do not add the BACKGROUND as this is for suppliers
1112 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1113
1114 //Affiche le filigrane brouillon - Print Draft Watermark
1115 /*if($object->statut==0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK'))
1116 {
1117 pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1118 }*/
1119 //Print content
1120
1121 $pdf->SetTextColor(0, 0, 60);
1122 $pdf->SetFont('', 'B', $default_font_size + 3);
1123
1124 $w = 100;
1125
1126 $posx = $this->page_largeur - $this->marge_droite - 100;
1127 $posy = $this->marge_haute;
1128
1129 $pdf->SetXY($this->marge_gauche, $posy);
1130
1131 // Logo
1132 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1133 if ($this->emetteur->logo) {
1134 $logodir = $conf->mycompany->dir_output;
1135 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1136 $logodir = $conf->mycompany->multidir_output[$object->entity];
1137 }
1138 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1139 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1140 } else {
1141 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1142 }
1143 if (is_readable($logo)) {
1144 $height = pdf_getHeightForLogo($logo);
1145 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1146 } else {
1147 $pdf->SetTextColor(200, 0, 0);
1148 $pdf->SetFont('', 'B', $default_font_size - 2);
1149 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1150 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1151 }
1152 } else {
1153 $text = $this->emetteur->name;
1154 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1155 }
1156 }
1157
1158 $pdf->SetFont('', 'B', $default_font_size + 3);
1159 $pdf->SetXY($posx, $posy);
1160 $pdf->SetTextColor(0, 0, 60);
1161 $title = $outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1162 if ($object->status == $object::STATUS_DRAFT) {
1163 $pdf->SetTextColor(128, 0, 0);
1164 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1165 }
1166 $pdf->MultiCell($w, 3, $title, '', 'R');
1167 $posy += 1;
1168
1169 if ($object->ref_supplier) {
1170 $posy += 4;
1171 $pdf->SetFont('', 'B', $default_font_size);
1172 $pdf->SetXY($posx, $posy);
1173 $pdf->SetTextColor(0, 0, 60);
1174 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1175 $posy += 1;
1176 }
1177
1178 $pdf->SetFont('', '', $default_font_size - 1);
1179
1180 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1181 $object->fetch_projet();
1182 if (!empty($object->project->ref)) {
1183 $posy += 3;
1184 $pdf->SetXY($posx, $posy);
1185 $pdf->SetTextColor(0, 0, 60);
1186 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1187 }
1188 }
1189
1190 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1191 $object->fetch_projet();
1192 if (!empty($object->project->ref)) {
1193 $outputlangs->load("projects");
1194 $posy += 4;
1195 $pdf->SetXY($posx, $posy);
1196 $langs->load("projects");
1197 $pdf->SetTextColor(0, 0, 60);
1198 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1199 }
1200 }
1201
1202 if (!empty($object->date_commande)) {
1203 $posy += 5;
1204 $pdf->SetXY($posx, $posy);
1205 $pdf->SetTextColor(0, 0, 60);
1206 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R');
1207 }
1208 // no point in having this here this a document sent to supplier
1209 /*} else {
1210 $posy += 5;
1211 $pdf->SetXY($posx, $posy);
1212 $pdf->SetTextColor(255, 0, 0);
1213 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1214 }*/
1215
1216 $pdf->SetTextColor(0, 0, 60);
1217 $usehourmin = 'day';
1218 if (getDolGlobalString('SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE')) {
1219 $usehourmin = 'dayhour';
1220 }
1221 if (!empty($object->delivery_date)) {
1222 $posy += 4;
1223 $pdf->SetXY($posx - 90, $posy);
1224 $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->delivery_date, $usehourmin, false, $outputlangs, true), '', 'R');
1225 }
1226
1227 if ($object->thirdparty->code_fournisseur) {
1228 $posy += 4;
1229 $pdf->SetXY($posx, $posy);
1230 $pdf->SetTextColor(0, 0, 60);
1231 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1232 }
1233
1234 // Get contact
1235 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1236 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1237 if (count($arrayidcontact) > 0) {
1238 $usertmp = new User($this->db);
1239 $usertmp->fetch($arrayidcontact[0]);
1240 $posy += 4;
1241 $pdf->SetXY($posx, $posy);
1242 $pdf->SetTextColor(0, 0, 60);
1243 $pdf->MultiCell($w, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1244 }
1245 }
1246
1247 $posy += 1;
1248 $pdf->SetTextColor(0, 0, 60);
1249
1250 $top_shift = 0;
1251 // Show list of linked objects
1252 $current_y = $pdf->getY();
1253 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1254 if ($current_y < $pdf->getY()) {
1255 $top_shift = $pdf->getY() - $current_y;
1256 }
1257
1258 if ($showaddress) {
1259 // Sender properties
1260 $carac_emetteur = '';
1261 // Add internal contact of object if defined
1262 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1263 if (count($arrayidcontact) > 0) {
1264 $object->fetch_user($arrayidcontact[0]);
1265 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1266 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1267 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1268 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1269 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1270 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1271 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1272 $carac_emetteur .= "\n";
1273 }
1274
1275 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1276
1277 // Show sender
1278 $posy = 42 + $top_shift;
1279 $posx = $this->marge_gauche;
1280 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1281 $posx = $this->page_largeur - $this->marge_droite - 80;
1282 }
1283 $hautcadre = 40;
1284
1285 // Show sender frame
1286 $pdf->SetTextColor(0, 0, 0);
1287 $pdf->SetFont('', '', $default_font_size - 2);
1288 $pdf->SetXY($posx, $posy - 5);
1289 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1290 $pdf->SetXY($posx, $posy);
1291 $pdf->SetFillColor(230, 230, 230);
1292 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1293 $pdf->SetTextColor(0, 0, 60);
1294
1295 // Show sender name
1296 $pdf->SetXY($posx + 2, $posy + 3);
1297 $pdf->SetFont('', 'B', $default_font_size);
1298 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1299 $posy = $pdf->getY();
1300
1301 // Show sender information
1302 $pdf->SetXY($posx + 2, $posy);
1303 $pdf->SetFont('', '', $default_font_size - 1);
1304 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1305
1306
1307 // If CUSTOMER contact defined on order, we use it. Note: Even if this is a supplier object, the code for external contat that follow order is 'CUSTOMER'
1308 $usecontact = false;
1309 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1310 if (count($arrayidcontact) > 0) {
1311 $usecontact = true;
1312 $result = $object->fetch_contact($arrayidcontact[0]);
1313 }
1314
1315 // Recipient name
1316 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1317 $thirdparty = $object->contact;
1318 } else {
1319 $thirdparty = $object->thirdparty;
1320 }
1321
1322 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1323
1324 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1325
1326 // Show recipient
1327 $widthrecbox = 100;
1328 if ($this->page_largeur < 210) {
1329 $widthrecbox = 84; // To work with US executive format
1330 }
1331 $posy = 42 + $top_shift;
1332 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1333 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1334 $posx = $this->marge_gauche;
1335 }
1336
1337 // Show recipient frame
1338 $pdf->SetTextColor(0, 0, 0);
1339 $pdf->SetFont('', '', $default_font_size - 2);
1340 $pdf->SetXY($posx + 2, $posy - 5);
1341 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1342 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1343
1344 // Show recipient name
1345 $pdf->SetXY($posx + 2, $posy + 3);
1346 $pdf->SetFont('', 'B', $default_font_size);
1347 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1348
1349 $posy = $pdf->getY();
1350
1351 // Show recipient information
1352 $pdf->SetFont('', '', $default_font_size - 1);
1353 $pdf->SetXY($posx + 2, $posy);
1354 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1355 }
1356
1357 return $top_shift;
1358 }
1359
1360 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1370 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1371 {
1372 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1373 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1374 }
1375}
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Parent class for supplier orders models.
Class to manage products or services.
Class to manage Dolibarr users.
Class to generate the supplier orders with the muscadet model.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
write_file($object, $outputlangs=null, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
__construct($db)
Constructor.
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.
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_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.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:2611
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_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1386
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_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