dolibarr  x.y.z
pdf_aurore.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-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 
35 
40 {
44  public $db;
45 
49  public $name;
50 
54  public $description;
55 
59  public $update_main_doc_field;
60 
64  public $type;
65 
70  public $phpmin = array(7, 0);
71 
76  public $version = 'dolibarr';
77 
81  public $page_largeur;
82 
86  public $page_hauteur;
87 
91  public $format;
92 
96  public $marge_gauche;
97 
101  public $marge_droite;
102 
106  public $marge_haute;
107 
111  public $marge_basse;
112 
117  public $emetteur;
118 
119 
125  public function __construct($db)
126  {
127  global $conf, $langs, $mysoc;
128 
129  // Translations
130  $langs->loadLangs(array("main", "bills"));
131 
132  $this->db = $db;
133  $this->name = "aurore";
134  $this->description = $langs->trans('DocModelAuroreDescription');
135  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
136 
137  // Page size for A4 format
138  $this->type = 'pdf';
139  $formatarray = pdf_getFormat();
140  $this->page_largeur = $formatarray['width'];
141  $this->page_hauteur = $formatarray['height'];
142  $this->format = array($this->page_largeur, $this->page_hauteur);
143  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
144  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
145  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
146  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
147 
148  $this->option_logo = 1; // Display logo
149  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
150  $this->option_modereg = 1; // Display payment mode
151  $this->option_condreg = 1; // Display payment terms
152  $this->option_multilang = 1; // Available in several languages
153  $this->option_escompte = 1; // Displays if there has been a discount
154  $this->option_credit_note = 1; // Support credit notes
155  $this->option_freetext = 1; // Support add of a personalised text
156  $this->option_draft_watermark = 1; //Support add of a watermark on drafts
157  $this->watermark = '';
158 
159  // Get source company
160  $this->emetteur = $mysoc;
161  if (empty($this->emetteur->country_code)) {
162  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
163  }
164 
165  // Define position of columns
166  $this->posxdesc = $this->marge_gauche + 1;
167  $this->posxdiscount = 162;
168  $this->postotalht = 174;
169 
170  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
171  $this->posxup = 112;
172  $this->posxqty = 135;
173  $this->posxunit = 151;
174  } else {
175  $this->posxup = 120;
176  $this->posxqty = 145;
177  $this->posxunit = 162;
178  }
179 
180  $this->posxpicture = $this->posxup - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
181  if ($this->page_largeur < 210) { // To work with US executive format
182  $this->posxpicture -= 20;
183  $this->posxup -= 20;
184  $this->posxqty -= 20;
185  $this->posxunit -= 20;
186  $this->posxdiscount -= 20;
187  $this->postotalht -= 20;
188  }
189 
190  $this->tva = array();
191  $this->tva_array = array();
192  $this->localtax1 = array();
193  $this->localtax2 = array();
194  $this->atleastoneratenotnull = 0;
195  $this->atleastonediscount = 0;
196  }
197 
198  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
210  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
211  {
212  // phpcs:enable
213  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
214 
215  if (!is_object($outputlangs)) {
216  $outputlangs = $langs;
217  }
218  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
219  if (!empty($conf->global->MAIN_USE_FPDF)) {
220  $outputlangs->charset_output = 'ISO-8859-1';
221  }
222 
223  // Load traductions files required by page
224  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "supplier_proposal"));
225 
226  // Show Draft Watermark
227  if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK))) {
228  $this->watermark = $conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK;
229  }
230 
231  $nblines = count($object->lines);
232 
233  // Loop on each lines to detect if there is at least one image to show
234  $realpatharray = array();
235  if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE)) {
236  for ($i = 0; $i < $nblines; $i++) {
237  if (empty($object->lines[$i]->fk_product)) {
238  continue;
239  }
240 
241  $objphoto = new Product($this->db);
242  $objphoto->fetch($object->lines[$i]->fk_product);
243 
244  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
245  $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
246  $dir = $conf->product->dir_output.'/'.$pdir;
247  } else {
248  $pdir = get_exdir(0, 0, 0, 0, $objphoto, 'product');
249  $dir = $conf->product->dir_output.'/'.$pdir;
250  }
251 
252  $realpath = '';
253  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
254  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
255  if ($obj['photo_vignette']) {
256  $filename = $obj['photo_vignette'];
257  } else {
258  $filename = $obj['photo'];
259  }
260  } else {
261  $filename = $obj['photo'];
262  }
263  $realpath = $dir.$filename;
264  break;
265  }
266 
267  if ($realpath) {
268  $realpatharray[$i] = $realpath;
269  }
270  }
271  }
272  if (count($realpatharray) == 0) {
273  $this->posxpicture = $this->posxup;
274  }
275 
276  if ($conf->supplier_proposal->dir_output) {
277  $object->fetch_thirdparty();
278 
279  // $deja_regle = 0;
280 
281  // Definition of $dir and $file
282  if ($object->specimen) {
283  $dir = $conf->supplier_proposal->dir_output;
284  $file = $dir."/SPECIMEN.pdf";
285  } else {
286  $objectref = dol_sanitizeFileName($object->ref);
287  $dir = $conf->supplier_proposal->dir_output."/".$objectref;
288  $file = $dir."/".$objectref.".pdf";
289  }
290 
291  if (!file_exists($dir)) {
292  if (dol_mkdir($dir) < 0) {
293  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
294  return 0;
295  }
296  }
297 
298  if (file_exists($dir)) {
299  // Add pdfgeneration hook
300  if (!is_object($hookmanager)) {
301  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
302  $hookmanager = new HookManager($this->db);
303  }
304  $hookmanager->initHooks(array('pdfgeneration'));
305  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
306  global $action;
307  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
308 
309  // Create pdf instance
310  $pdf = pdf_getInstance($this->format);
311  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
312  $heightforinfotot = 50; // Height reserved to output the info and total part
313  $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
314  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
315  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
316  $heightforfooter += 6;
317  }
318  $pdf->SetAutoPageBreak(1, 0);
319 
320  if (class_exists('TCPDF')) {
321  $pdf->setPrintHeader(false);
322  $pdf->setPrintFooter(false);
323  }
324  $pdf->SetFont(pdf_getPDFFont($outputlangs));
325  // Set path to the background PDF File
326  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
327  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
328  $tplidx = $pdf->importPage(1);
329  }
330 
331  $pdf->Open();
332  $pagenb = 0;
333  $pdf->SetDrawColor(128, 128, 128);
334 
335  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
336  $pdf->SetSubject($outputlangs->transnoentities("CommercialAsk"));
337  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
338  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
339  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialAsk")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
340  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
341  $pdf->SetCompression(false);
342  }
343 
344  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
345 
346  // Positionne $this->atleastonediscount si on a au moins une remise
347  for ($i = 0; $i < $nblines; $i++) {
348  if ($object->lines[$i]->remise_percent) {
349  $this->atleastonediscount++;
350  }
351  }
352  if (empty($this->atleastonediscount)) {
353  $delta = ($this->postotalht - $this->posxdiscount);
354  $this->posxpicture += $delta;
355  $this->posxup += $delta;
356  $this->posxqty += $delta;
357  $this->posxunit += $delta;
358  $this->posxdiscount += $delta;
359  // post of fields after are not modified, stay at same position
360  }
361 
362  // New page
363  $pdf->AddPage();
364  if (!empty($tplidx)) {
365  $pdf->useTemplate($tplidx);
366  }
367  $pagenb++;
368  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
369  $pdf->SetFont('', '', $default_font_size - 1);
370  $pdf->MultiCell(0, 3, ''); // Set interline to 3
371  $pdf->SetTextColor(0, 0, 0);
372 
373  $tab_top = 90 + $top_shift;
374  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
375 
376  // Affiche notes
377  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
378  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
379  // Get first sale rep
380  if (is_object($object->thirdparty)) {
381  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
382  $salerepobj = new User($this->db);
383  $salerepobj->fetch($salereparray[0]['id']);
384  if (!empty($salerepobj->signature)) {
385  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
386  }
387  }
388  }
389  if ($notetoshow) {
390  $tab_top -= 2;
391 
392  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
393  complete_substitutions_array($substitutionarray, $outputlangs, $object);
394  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
395  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
396 
397  $pdf->SetFont('', '', $default_font_size - 1);
398  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
399  $nexY = $pdf->GetY();
400  $height_note = $nexY - $tab_top;
401 
402  // Rect takes a length in 3rd parameter
403  $pdf->SetDrawColor(192, 192, 192);
404  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
405 
406  $tab_top = $nexY + 6;
407  }
408 
409  $iniY = $tab_top + 7;
410  $curY = $tab_top + 7;
411  $nexY = $tab_top + 7;
412 
413  // Loop on each lines
414  for ($i = 0; $i < $nblines; $i++) {
415  $curY = $nexY;
416  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
417  $pdf->SetTextColor(0, 0, 0);
418 
419  // Define size of image if we need it
420  $imglinesize = array();
421  if (!empty($realpatharray[$i])) {
422  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
423  }
424 
425  $pdf->setTopMargin($tab_top_newpage);
426  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
427  $pageposbefore = $pdf->getPage();
428 
429  $showpricebeforepagebreak = 1;
430  $posYAfterImage = 0;
431  $posYAfterDescription = 0;
432 
433  // We start with Photo of product line
434  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
435  $pdf->AddPage('', '', true);
436  if (!empty($tplidx)) {
437  $pdf->useTemplate($tplidx);
438  }
439  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
440  $this->_pagehead($pdf, $object, 0, $outputlangs);
441  }
442  $pdf->setPage($pageposbefore + 1);
443 
444  $curY = $tab_top_newpage;
445 
446  // Allows data in the first page if description is long enough to break in multiples pages
447  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
448  $showpricebeforepagebreak = 1;
449  } else {
450  $showpricebeforepagebreak = 0;
451  }
452  }
453 
454  if (!empty($imglinesize['width']) && !empty($imglinesize['height'])) {
455  $curX = $this->posxpicture - 1;
456  $pdf->Image($realpatharray[$i], $curX + (($this->posxup - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
457  // $pdf->Image does not increase value return by getY, so we save it manually
458  $posYAfterImage = $curY + $imglinesize['height'];
459  }
460 
461  // Description of product line
462  $curX = $this->posxdesc - 1;
463 
464  $pdf->startTransaction();
465  if ($posYAfterImage > 0) {
466  $descWidth = $this->posxpicture - $curX;
467  } else {
468  $descWidth = $this->posxup - $curX;
469  }
470  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
471 
472  $pageposafter = $pdf->getPage();
473  if ($pageposafter > $pageposbefore) { // There is a pagebreak
474  $pdf->rollbackTransaction(true);
475  $pageposafter = $pageposbefore;
476  //print $pageposafter.'-'.$pageposbefore;exit;
477  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
478  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
479 
480  $pageposafter = $pdf->getPage();
481  $posyafter = $pdf->GetY();
482  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
483  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
484  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
485  $pdf->AddPage('', '', true);
486  if (!empty($tplidx)) {
487  $pdf->useTemplate($tplidx);
488  }
489  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
490  $this->_pagehead($pdf, $object, 0, $outputlangs);
491  }
492  $pdf->setPage($pageposafter + 1);
493  }
494  } else {
495  // We found a page break
496  // Allows data in the first page if description is long enough to break in multiples pages
497  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
498  $showpricebeforepagebreak = 1;
499  } else {
500  $showpricebeforepagebreak = 0;
501  }
502  }
503  } else // No pagebreak
504  {
505  $pdf->commitTransaction();
506  }
507  $posYAfterDescription = $pdf->GetY();
508 
509  $nexY = $pdf->GetY();
510  $pageposafter = $pdf->getPage();
511 
512  $pdf->setPage($pageposbefore);
513  $pdf->setTopMargin($this->marge_haute);
514  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
515 
516  // We suppose that a too long description or photo were moved completely on next page
517  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
518  $pdf->setPage($pageposafter);
519  $curY = $tab_top_newpage;
520  }
521 
522  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
523 
524  // Quantity
525  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
526  $pdf->SetXY($this->posxqty, $curY);
527  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
528 
529  // Unit
530  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
531  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
532  $pdf->SetXY($this->posxunit, $curY);
533  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
534  }
535 
536  // Discount on line
537  /*
538  if ($object->lines[$i]->remise_percent)
539  {
540  $pdf->SetXY($this->posxdiscount-2, $curY);
541  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
542  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
543  }
544 
545  // Total HT line
546  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
547  $pdf->SetXY($this->postotalht, $curY);
548  if ($total_excl_tax > 0)
549  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
550  */
551 
552  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
553  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
554  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
555  } else {
556  $tvaligne = $object->lines[$i]->total_tva;
557  }
558 
559  $localtax1ligne = $object->lines[$i]->total_localtax1;
560  $localtax2ligne = $object->lines[$i]->total_localtax2;
561  $localtax1_rate = $object->lines[$i]->localtax1_tx;
562  $localtax2_rate = $object->lines[$i]->localtax2_tx;
563  $localtax1_type = $object->lines[$i]->localtax1_type;
564  $localtax2_type = $object->lines[$i]->localtax2_type;
565 
566  if ($object->remise_percent) {
567  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
568  }
569  if ($object->remise_percent) {
570  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
571  }
572  if ($object->remise_percent) {
573  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
574  }
575 
576  $vatrate = (string) $object->lines[$i]->tva_tx;
577 
578  // Retrieve type from database for backward compatibility with old records
579  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
580  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
581  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
582  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
583  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
584  }
585 
586  // retrieve global local tax
587  if ($localtax1_type && $localtax1ligne != 0) {
588  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
589  }
590  if ($localtax2_type && $localtax2ligne != 0) {
591  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
592  }
593 
594  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
595  $vatrate .= '*';
596  }
597 
598  // Fill $this->tva and $this->tva_array
599  if (!isset($this->tva[$vatrate])) {
600  $this->tva[$vatrate] = 0;
601  }
602  $this->tva[$vatrate] += $tvaligne;
603  $vatcode = $object->lines[$i]->vat_src_code;
604  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
605  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
606  }
607  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
608 
609  if ($posYAfterImage > $posYAfterDescription) {
610  $nexY = $posYAfterImage;
611  }
612 
613  // Add line
614  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
615  $pdf->setPage($pageposafter);
616  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
617  //$pdf->SetDrawColor(190,190,200);
618  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
619  $pdf->SetLineStyle(array('dash'=>0));
620  }
621 
622  $nexY += 2; // Add space between lines
623 
624  // Detect if some page were added automatically and output _tableau for past pages
625  while ($pagenb < $pageposafter) {
626  $pdf->setPage($pagenb);
627  if ($pagenb == 1) {
628  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
629  } else {
630  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
631  }
632  $this->_pagefoot($pdf, $object, $outputlangs, 1);
633  $pagenb++;
634  $pdf->setPage($pagenb);
635  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
636  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
637  $this->_pagehead($pdf, $object, 0, $outputlangs);
638  }
639  if (!empty($tplidx)) {
640  $pdf->useTemplate($tplidx);
641  }
642  }
643  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
644  if ($pagenb == 1) {
645  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
646  } else {
647  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
648  }
649  $this->_pagefoot($pdf, $object, $outputlangs, 1);
650  // New page
651  $pdf->AddPage();
652  if (!empty($tplidx)) {
653  $pdf->useTemplate($tplidx);
654  }
655  $pagenb++;
656  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
657  $this->_pagehead($pdf, $object, 0, $outputlangs);
658  }
659  }
660  }
661 
662  // Show square
663  if ($pagenb == 1) {
664  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
665  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
666  } else {
667  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
668  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
669  }
670 
671  // Affiche zone infos
672  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
673 
674  // Affiche zone totaux
675  //$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
676 
677  // Affiche zone versements
678  /*
679  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
680  {
681  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
682  }
683  */
684 
685  // Pied de page
686  $this->_pagefoot($pdf, $object, $outputlangs);
687  if (method_exists($pdf, 'AliasNbPages')) {
688  $pdf->AliasNbPages();
689  }
690 
691  $pdf->Close();
692 
693  $pdf->Output($file, 'F');
694 
695  //Add pdfgeneration hook
696  $hookmanager->initHooks(array('pdfgeneration'));
697  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
698  global $action;
699  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
700  if ($reshook < 0) {
701  $this->error = $hookmanager->error;
702  $this->errors = $hookmanager->errors;
703  }
704 
705  if (!empty($conf->global->MAIN_UMASK)) {
706  @chmod($file, octdec($conf->global->MAIN_UMASK));
707  }
708 
709  $this->result = array('fullpath'=>$file);
710 
711  return 1; // No error
712  } else {
713  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
714  return 0;
715  }
716  } else {
717  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_PROPOSAL_OUTPUTDIR");
718  return 0;
719  }
720  }
721 
722  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
723  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
733  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
734  {
735  // phpcs:enable
736  }
737 
738  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
739  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
749  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
750  {
751  // phpcs:enable
752  global $conf;
753  $default_font_size = pdf_getPDFFontSize($outputlangs);
754 
755  $pdf->SetFont('', '', $default_font_size - 1);
756 
757  $posxval = 52;
758 
759  // Show shipping date
760  if (!empty($object->delivery_date)) {
761  $outputlangs->load("sendings");
762  $pdf->SetFont('', 'B', $default_font_size - 2);
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 - 2);
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  } else {
773  $outputlangs->load("sendings");
774  $pdf->SetFont('', 'B', $default_font_size - 2);
775  $pdf->SetXY($this->marge_gauche, $posy);
776  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
777  $pdf->MultiCell(80, 4, $titre, 0, 'L');
778  $pdf->SetFont('', '', $default_font_size - 2);
779  $pdf->SetXY($posxval, $posy);
780  //$dlp=dol_print_date($object->delivery_date,"daytext",false,$outputlangs,true);
781  $pdf->MultiCell(80, 4, '', 0, 'L');
782 
783  $posy = $pdf->GetY() + 1;
784  }
785  /*
786  elseif ($object->availability_code || $object->availability) // Show availability conditions
787  {
788  $pdf->SetFont('','B', $default_font_size - 2);
789  $pdf->SetXY($this->marge_gauche, $posy);
790  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
791  $pdf->MultiCell(80, 4, $titre, 0, 'L');
792  $pdf->SetTextColor(0,0,0);
793  $pdf->SetFont('','', $default_font_size - 2);
794  $pdf->SetXY($posxval, $posy);
795  $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
796  $lib_availability=str_replace('\n',"\n",$lib_availability);
797  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
798 
799  $posy=$pdf->GetY()+1;
800  }*/
801 
802  // Show payments conditions
803  if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) {
804  $pdf->SetFont('', 'B', $default_font_size - 2);
805  $pdf->SetXY($this->marge_gauche, $posy);
806  $titre = $outputlangs->transnoentities("PaymentConditions").':';
807  $pdf->MultiCell(80, 4, $titre, 0, 'L');
808 
809  $pdf->SetFont('', '', $default_font_size - 2);
810  $pdf->SetXY($posxval, $posy);
811  $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);
812  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
813  $pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
814 
815  $posy = $pdf->GetY() + 3;
816  }
817 
818  if (!empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE)) {
819  // Show payment mode
820  if ($object->mode_reglement_code
821  && $object->mode_reglement_code != 'CHQ'
822  && $object->mode_reglement_code != 'VIR') {
823  $pdf->SetFont('', 'B', $default_font_size - 2);
824  $pdf->SetXY($this->marge_gauche, $posy - 2);
825  $titre = $outputlangs->transnoentities("PaymentMode").':';
826  $pdf->MultiCell(80, 5, $titre, 0, 'L');
827  $pdf->SetFont('', '', $default_font_size - 2);
828  $pdf->SetXY($posxval, $posy - 2);
829  $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);
830  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
831 
832  $posy = $pdf->GetY() + 2;
833  }
834 
835  // Show payment mode CHQ
836  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
837  // Si mode reglement non force ou si force a CHQ
838  if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
839  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
840 
841  if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
842  $account = new Account($this->db);
843  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
844 
845  $pdf->SetXY($this->marge_gauche, $posy);
846  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
847  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
848  $posy = $pdf->GetY() + 1;
849 
850  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
851  $pdf->SetXY($this->marge_gauche, $posy);
852  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
853  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
854  $posy = $pdf->GetY() + 2;
855  }
856  }
857  if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
858  $pdf->SetXY($this->marge_gauche, $posy);
859  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
860  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
861  $posy = $pdf->GetY() + 1;
862 
863  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
864  $pdf->SetXY($this->marge_gauche, $posy);
865  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
866  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
867  $posy = $pdf->GetY() + 2;
868  }
869  }
870  }
871  }
872 
873  // If payment mode not forced or forced to VIR, show payment with BAN
874  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
875  if (!empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
876  $bankid = (empty($object->fk_bank) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_bank);
877  $account = new Account($this->db);
878  $account->fetch($bankid);
879 
880  $curx = $this->marge_gauche;
881  $cury = $posy;
882 
883  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
884 
885  $posy += 2;
886  }
887  }
888  }
889 
890  return $posy;
891  }
892 
893  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
894  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
905  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
906  {
907  // phpcs:enable
908  global $conf, $mysoc;
909  $default_font_size = pdf_getPDFFontSize($outputlangs);
910 
911  $tab2_top = $posy;
912  $tab2_hl = 4;
913  $pdf->SetFont('', '', $default_font_size - 1);
914 
915  // Tableau total
916  $col1x = 120;
917  $col2x = 170;
918  if ($this->page_largeur < 210) { // To work with US executive format
919  $col2x -= 20;
920  }
921  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
922 
923  $useborder = 0;
924  $index = 0;
925 
926  // Total HT
927  $pdf->SetFillColor(255, 255, 255);
928  $pdf->SetXY($col1x, $tab2_top);
929  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
930 
931  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
932  $pdf->SetXY($col2x, $tab2_top);
933  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
934 
935  // Show VAT by rates and total
936  $pdf->SetFillColor(248, 248, 248);
937 
938  $this->atleastoneratenotnull = 0;
939  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
940  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
941  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
942  // Nothing to do
943  } else {
944  //Local tax 1 before VAT
945  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
946  //{
947  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
948  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
949  continue;
950  }
951 
952  foreach ($localtax_rate as $tvakey => $tvaval) {
953  if ($tvakey != 0) { // On affiche pas taux 0
954  //$this->atleastoneratenotnull++;
955 
956  $index++;
957  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
958 
959  $tvacompl = '';
960  if (preg_match('/\*/', $tvakey)) {
961  $tvakey = str_replace('*', '', $tvakey);
962  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
963  }
964  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
965  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
966  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
967 
968  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
969  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
970  }
971  }
972  }
973  //}
974  //Local tax 2 before VAT
975  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
976  //{
977  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
978  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
979  continue;
980  }
981 
982  foreach ($localtax_rate as $tvakey => $tvaval) {
983  if ($tvakey != 0) { // On affiche pas taux 0
984  //$this->atleastoneratenotnull++;
985 
986 
987 
988  $index++;
989  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
990 
991  $tvacompl = '';
992  if (preg_match('/\*/', $tvakey)) {
993  $tvakey = str_replace('*', '', $tvakey);
994  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
995  }
996  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
997  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
998  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
999 
1000  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1001  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1002  }
1003  }
1004  }
1005  //}
1006  // VAT
1007  foreach ($this->tva as $tvakey => $tvaval) {
1008  if ($tvakey > 0) { // On affiche pas taux 0
1009  $this->atleastoneratenotnull++;
1010 
1011  $index++;
1012  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1013 
1014  $tvacompl = '';
1015  if (preg_match('/\*/', $tvakey)) {
1016  $tvakey = str_replace('*', '', $tvakey);
1017  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1018  }
1019  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1020  $totalvat .= vatrate($tvakey, 1).$tvacompl;
1021  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1022 
1023  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1024  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1025  }
1026  }
1027 
1028  //Local tax 1 after VAT
1029  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1030  //{
1031  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1032  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1033  continue;
1034  }
1035 
1036  foreach ($localtax_rate as $tvakey => $tvaval) {
1037  if ($tvakey != 0) { // On affiche pas taux 0
1038  //$this->atleastoneratenotnull++;
1039 
1040  $index++;
1041  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1042 
1043  $tvacompl = '';
1044  if (preg_match('/\*/', $tvakey)) {
1045  $tvakey = str_replace('*', '', $tvakey);
1046  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1047  }
1048  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1049 
1050  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1051  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1052  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1053  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1054  }
1055  }
1056  }
1057  //}
1058  //Local tax 2 after VAT
1059  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1060  //{
1061  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1062  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1063  continue;
1064  }
1065 
1066  foreach ($localtax_rate as $tvakey => $tvaval) {
1067  // retrieve global local tax
1068  if ($tvakey != 0) { // On affiche pas taux 0
1069  //$this->atleastoneratenotnull++;
1070 
1071  $index++;
1072  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1073 
1074  $tvacompl = '';
1075  if (preg_match('/\*/', $tvakey)) {
1076  $tvakey = str_replace('*', '', $tvakey);
1077  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1078  }
1079  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1080 
1081  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1082  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1083 
1084  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1085  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1086  }
1087  }
1088  }
1089  //}
1090 
1091  // Total TTC
1092  $index++;
1093  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1094  $pdf->SetTextColor(0, 0, 60);
1095  $pdf->SetFillColor(224, 224, 224);
1096  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1097 
1098  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1099  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1100  }
1101  }
1102 
1103  $pdf->SetTextColor(0, 0, 0);
1104 
1105  $resteapayer = $object->total_ttc - $deja_regle;
1106  if (!empty($object->paye)) {
1107  $resteapayer = 0;
1108  }
1109 
1110  if ($deja_regle > 0) {
1111  $index++;
1112 
1113  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1114  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1115 
1116  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1117  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1118 
1119  $index++;
1120  $pdf->SetTextColor(0, 0, 60);
1121  $pdf->SetFillColor(224, 224, 224);
1122  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1123  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1124 
1125  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1126  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1127 
1128  $pdf->SetFont('', '', $default_font_size - 1);
1129  $pdf->SetTextColor(0, 0, 0);
1130  }
1131 
1132  $index++;
1133  return ($tab2_top + ($tab2_hl * $index));
1134  }
1135 
1136  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1150  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1151  {
1152  global $conf;
1153 
1154  // Force to disable hidetop and hidebottom
1155  $hidebottom = 0;
1156  if ($hidetop) {
1157  $hidetop = -1;
1158  }
1159 
1160  $currency = !empty($currency) ? $currency : $conf->currency;
1161  $default_font_size = pdf_getPDFFontSize($outputlangs);
1162 
1163  // Amount in (at tab_top - 1)
1164  $pdf->SetTextColor(0, 0, 0);
1165  $pdf->SetFont('', '', $default_font_size - 2);
1166 
1167  if (empty($hidetop)) {
1168  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1169  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1170  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1171 
1172  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1173  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1174  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1175  }
1176  }
1177 
1178  $pdf->SetDrawColor(128, 128, 128);
1179  $pdf->SetFont('', '', $default_font_size - 1);
1180 
1181  // Output Rect
1182  $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
1183 
1184  if (empty($hidetop)) {
1185  $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
1186 
1187  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1188  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1189  }
1190 
1191  $pdf->line($this->posxup + 1, $tab_top, $this->posxup + 1, $tab_top + $tab_height);
1192  if (empty($hidetop)) {
1193  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1194  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1195  }
1196 
1197  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1198  if (empty($hidetop)) {
1199  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1200  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1201  }
1202 
1203  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1204  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1205  if (empty($hidetop)) {
1206  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1207  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1208  }
1209  }
1210 
1211  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1212  if (empty($hidetop)) {
1213  if ($this->atleastonediscount) {
1214  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1215  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1216  }
1217  }
1218  if ($this->atleastonediscount) {
1219  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1220  }
1221  if (empty($hidetop)) {
1222  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1223  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
1224  }
1225  }
1226 
1227  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1237  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1238  {
1239  global $conf, $langs;
1240 
1241  // Load traductions files required by page
1242  $outputlangs->loadLangs(array("main", "bills", "supplier_proposal", "companies"));
1243 
1244  $default_font_size = pdf_getPDFFontSize($outputlangs);
1245 
1246  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1247 
1248  $pdf->SetTextColor(0, 0, 60);
1249  $pdf->SetFont('', 'B', $default_font_size + 3);
1250 
1251  $posy = $this->marge_haute;
1252  $posx = $this->page_largeur - $this->marge_droite - 100;
1253 
1254  $pdf->SetXY($this->marge_gauche, $posy);
1255 
1256  // Logo
1257  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1258  if ($this->emetteur->logo) {
1259  $logodir = $conf->mycompany->dir_output;
1260  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1261  $logodir = $conf->mycompany->multidir_output[$object->entity];
1262  }
1263  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1264  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1265  } else {
1266  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1267  }
1268  if (is_readable($logo)) {
1269  $height = pdf_getHeightForLogo($logo);
1270  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1271  } else {
1272  $pdf->SetTextColor(200, 0, 0);
1273  $pdf->SetFont('', 'B', $default_font_size - 2);
1274  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1275  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1276  }
1277  } else {
1278  $text = $this->emetteur->name;
1279  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0);
1280  }
1281  }
1282 
1283  $pdf->SetFont('', 'B', $default_font_size + 3);
1284  $pdf->SetXY($posx, $posy);
1285  $pdf->SetTextColor(0, 0, 60);
1286  $title = $outputlangs->transnoentities("CommercialAsk");
1287  $pdf->MultiCell(100, 4, $title, '', 'R');
1288 
1289  $pdf->SetFont('', 'B', $default_font_size);
1290 
1291  $posy += 5;
1292  $pdf->SetXY($posx, $posy);
1293  $pdf->SetTextColor(0, 0, 60);
1294  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1295 
1296  $posy += 1;
1297  $pdf->SetFont('', '', $default_font_size - 2);
1298 
1299  if ($object->ref_fourn) {
1300  $posy += 4;
1301  $pdf->SetXY($posx, $posy);
1302  $pdf->SetTextColor(0, 0, 60);
1303  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_fourn), 65), '', 'R');
1304  }
1305 
1306  if ($object->thirdparty->code_fournisseur) {
1307  $posy += 4;
1308  $pdf->SetXY($posx, $posy);
1309  $pdf->SetTextColor(0, 0, 60);
1310  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1311  }
1312 
1313  // Get contact
1314  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1315  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1316  if (count($arrayidcontact) > 0) {
1317  $usertmp = new User($this->db);
1318  $usertmp->fetch($arrayidcontact[0]);
1319  $posy += 4;
1320  $pdf->SetXY($posx, $posy);
1321  $pdf->SetTextColor(0, 0, 60);
1322  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1323  }
1324  }
1325 
1326  $posy += 2;
1327 
1328  $top_shift = 0;
1329  // Show list of linked objects
1330  $current_y = $pdf->getY();
1331  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1332  if ($current_y < $pdf->getY()) {
1333  $top_shift = $pdf->getY() - $current_y;
1334  }
1335 
1336  if ($showaddress) {
1337  // Sender properties
1338  $carac_emetteur = '';
1339  // Add internal contact of proposal if defined
1340  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1341  if (count($arrayidcontact) > 0) {
1342  $object->fetch_user($arrayidcontact[0]);
1343  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1344  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1345  }
1346 
1347  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1348 
1349  // Show sender
1350  $posy = 42 + $top_shift;
1351  $posx = $this->marge_gauche;
1352  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1353  $posx = $this->page_largeur - $this->marge_droite - 80;
1354  }
1355  $hautcadre = 40;
1356 
1357  // Show sender frame
1358  $pdf->SetTextColor(0, 0, 0);
1359  $pdf->SetFont('', '', $default_font_size - 2);
1360  $pdf->SetXY($posx, $posy - 5);
1361  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1362  $pdf->SetXY($posx, $posy);
1363  $pdf->SetFillColor(230, 230, 230);
1364  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1365  $pdf->SetTextColor(0, 0, 60);
1366 
1367  // Show sender name
1368  $pdf->SetXY($posx + 2, $posy + 3);
1369  $pdf->SetFont('', 'B', $default_font_size);
1370  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1371  $posy = $pdf->getY();
1372 
1373  // Show sender information
1374  $pdf->SetXY($posx + 2, $posy);
1375  $pdf->SetFont('', '', $default_font_size - 1);
1376  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1377 
1378 
1379  // If CUSTOMER contact defined, we use it
1380  $usecontact = false;
1381  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1382  if (count($arrayidcontact) > 0) {
1383  $usecontact = true;
1384  $result = $object->fetch_contact($arrayidcontact[0]);
1385  }
1386 
1387  // Recipient name
1388  if (!empty($usecontact)) {
1389  if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1390  $socname = $object->contact;
1391  } else {
1392  $socname = $object->thirdparty;
1393  }
1394  } else {
1395  $socname = $object->thirdparty;
1396  }
1397 
1398  $carac_client_name = pdfBuildThirdpartyName($socname, $outputlangs);
1399 
1400  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1401 
1402  // Show recipient
1403  $widthrecbox = 100;
1404  if ($this->page_largeur < 210) {
1405  $widthrecbox = 84; // To work with US executive format
1406  }
1407  $posy = 42 + $top_shift;
1408  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1409  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1410  $posx = $this->marge_gauche;
1411  }
1412 
1413  // Show recipient frame
1414  $pdf->SetTextColor(0, 0, 0);
1415  $pdf->SetFont('', '', $default_font_size - 2);
1416  $pdf->SetXY($posx + 2, $posy - 5);
1417  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1418  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1419 
1420  // Show recipient name
1421  $pdf->SetXY($posx + 2, $posy + 3);
1422  $pdf->SetFont('', 'B', $default_font_size);
1423  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1424 
1425  // Show recipient information
1426  $pdf->SetFont('', '', $default_font_size - 1);
1427  $pdf->SetXY($posx + 2, $posy + 4 + (dol_nboflines_bis($carac_client_name, 50) * 4));
1428  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1429  }
1430 
1431  $pdf->SetTextColor(0, 0, 0);
1432  return $top_shift;
1433  }
1434 
1435  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1445  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1446  {
1447  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1448  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1449  }
1450 }
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Classe mere des modeles de propale.
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:45
Class to generate PDF supplier proposal Aurore.
write_file($object, $outputlangs, $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, ...)
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
print *****$script_file(".$version.") pid 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.
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).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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...
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formated text with and (WARNING: string must not have mixed and br sepa...
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
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:2505
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
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:1354
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
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:996
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2123
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:744
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:718
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1318
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:819
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
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:434
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1962
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41