dolibarr  17.0.4
pdf_standard.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2016-2023 Philippe Grand <philippe.grand@atoo-net.com>
5  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
6  * Copyright (C) 2018 Francis Appels <francis.appels@z-application.com>
7  * Copyright (C) 2019 Markus Welters <markus@welters.de>
8  * Copyright (C) 2019 Rafael Ingenleuf <ingenleuf@welters.de>
9  * Copyright (C) 2020 Marc Guenneugues <marc.guenneugues@simicar.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  * or see https://www.gnu.org/
24  */
25 
32 require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
33 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
41 
46 {
50  public $db;
51 
55  public $name;
56 
60  public $description;
61 
65  public $update_main_doc_field;
66 
70  public $type;
71 
76  public $phpmin = array(7, 0);
77 
82  public $version = 'dolibarr';
83 
88  public $emetteur;
89 
90  public $posxpiece;
91  public $posxcomment;
92  public $posxtva;
93  public $posxup;
94  public $posxqty;
95  public $posxtype;
96  public $posxprojet;
97  public $postotalht;
98  public $postotalttc;
99 
100 
106  public function __construct($db)
107  {
108  global $conf, $langs, $mysoc, $user;
109 
110  // Translations
111  $langs->loadLangs(array("main", "trips", "projects"));
112 
113  $this->db = $db;
114  $this->name = "";
115  $this->description = $langs->trans('PDFStandardExpenseReports');
116  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
117 
118  // Page size for A4 format
119  $this->type = 'pdf';
120  $formatarray = pdf_getFormat();
121  $this->page_largeur = $formatarray['width'];
122  $this->page_hauteur = $formatarray['height'];
123  $this->format = array($this->page_largeur, $this->page_hauteur);
124  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
125  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
126  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
127  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
128 
129  $this->option_logo = 1; // Display logo
130  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
131  $this->option_modereg = 1; // Display payment mode
132  $this->option_condreg = 1; // Display payment terms
133  $this->option_multilang = 1; // Available in several languages
134  $this->option_escompte = 0; // Displays if there has been a discount
135  $this->option_credit_note = 0; // Support credit notes
136  $this->option_freetext = 1; // Support add of a personalised text
137  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
138 
139  // Get source company
140  $this->emetteur = $mysoc;
141 
142  if (empty($this->emetteur->country_code)) {
143  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
144  }
145 
146  // Define position of columns
147  $this->posxpiece = $this->marge_gauche + 1;
148  $this->posxcomment = $this->marge_gauche + 10;
149  //$this->posxdate=88;
150  //$this->posxtype=107;
151  //$this->posxprojet=120;
152  $this->posxtva = 112;
153  $this->posxup = 127;
154  $this->posxqty = 150;
155  $this->postotalht = 160;
156  $this->postotalttc = 180;
157  // if (!isModEnabled('project')) {
158  // $this->posxtva-=20;
159  // $this->posxup-=20;
160  // $this->posxqty-=20;
161  // $this->postotalttc-=20;
162  // }
163  if ($this->page_largeur < 210) { // To work with US executive format
164  $this->posxdate -= 20;
165  $this->posxtype -= 20;
166  $this->posxprojet -= 20;
167  $this->posxtva -= 20;
168  $this->posxup -= 20;
169  $this->posxqty -= 20;
170  $this->postotalttc -= 20;
171  }
172 
173  $this->tva = array();
174  $this->tva_array = array();
175  $this->localtax1 = array();
176  $this->localtax2 = array();
177  $this->atleastoneratenotnull = 0;
178  $this->atleastonediscount = 0;
179  }
180 
181 
182  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
194  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
195  {
196  // phpcs:enable
197  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
198 
199  if (!is_object($outputlangs)) {
200  $outputlangs = $langs;
201  }
202  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
203  if (!empty($conf->global->MAIN_USE_FPDF)) {
204  $outputlangs->charset_output = 'ISO-8859-1';
205  }
206 
207  // Load traductions files required by page
208  $outputlangs->loadLangs(array("main", "trips", "projects", "dict", "bills", "banks"));
209 
210  $nblines = count($object->lines);
211 
212  if ($conf->expensereport->dir_output) {
213  // Definition of $dir and $file
214  if ($object->specimen) {
215  $dir = $conf->expensereport->dir_output;
216  $file = $dir."/SPECIMEN.pdf";
217  } else {
218  $objectref = dol_sanitizeFileName($object->ref);
219  $dir = $conf->expensereport->dir_output."/".$objectref;
220  $file = $dir."/".$objectref.".pdf";
221  }
222 
223  if (!file_exists($dir)) {
224  if (dol_mkdir($dir) < 0) {
225  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
226  return 0;
227  }
228  }
229 
230  if (file_exists($dir)) {
231  // Add pdfgeneration hook
232  if (!is_object($hookmanager)) {
233  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
234  $hookmanager = new HookManager($this->db);
235  }
236  $hookmanager->initHooks(array('pdfgeneration'));
237  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
238  global $action;
239  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
240 
241  // Create pdf instance
242  $pdf = pdf_getInstance($this->format);
243  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
244  $heightforinfotot = 40; // Height reserved to output the info and total part
245  $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
246  $heightforfooter = $this->marge_basse + 12; // Height reserved to output the footer (value include bottom margin)
247  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
248  $heightforfooter += 6;
249  }
250 
251  $pdf->SetAutoPageBreak(1, 0);
252 
253  if (class_exists('TCPDF')) {
254  $pdf->setPrintHeader(false);
255  $pdf->setPrintFooter(false);
256  }
257  $pdf->SetFont(pdf_getPDFFont($outputlangs));
258  // Set path to the background PDF File
259  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
260  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
261  $tplidx = $pdf->importPage(1);
262  }
263 
264  $pdf->Open();
265  $pagenb = 0;
266  $pdf->SetDrawColor(128, 128, 128);
267 
268  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
269  $pdf->SetSubject($outputlangs->transnoentities("Trips"));
270  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
271  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
272  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Trips"));
273  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
274  $pdf->SetCompression(false);
275  }
276 
277  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
278 
279  // New page
280  $pdf->AddPage();
281  if (!empty($tplidx)) {
282  $pdf->useTemplate($tplidx);
283  }
284  $pagenb++;
285  $this->_pagehead($pdf, $object, 1, $outputlangs);
286  $pdf->SetFont('', '', $default_font_size - 1);
287  $pdf->MultiCell(0, 3, ''); // Set interline to 3
288  $pdf->SetTextColor(0, 0, 0);
289 
290  $tab_top = 95;
291  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 65 : 10);
292 
293  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
294 
295  // Show notes
296  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
297  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
298  // Get first sale rep
299  if (is_object($object->thirdparty)) {
300  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
301  $salerepobj = new User($this->db);
302  $salerepobj->fetch($salereparray[0]['id']);
303  if (!empty($salerepobj->signature)) {
304  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
305  }
306  }
307  }
308  if ($notetoshow) {
309  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
310  complete_substitutions_array($substitutionarray, $outputlangs, $object);
311  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
312  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
313 
314  $tab_top = 95;
315 
316  $pdf->SetFont('', '', $default_font_size - 1);
317  $pdf->writeHTMLCell(190, 3, $this->posxpiece - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
318  $nexY = $pdf->GetY();
319  $height_note = $nexY - $tab_top;
320 
321  // Rect takes a length in 3rd parameter
322  $pdf->SetDrawColor(192, 192, 192);
323  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
324 
325  $tab_height = $tab_height - $height_note;
326  $tab_top = $nexY + 6;
327  } else {
328  $height_note = 0;
329  }
330 
331  $iniY = $tab_top + 7;
332  $initialY = $tab_top + 7;
333  $nexY = $tab_top + 7;
334 
335  $showpricebeforepagebreak = 1;
336  $pdf->setTopMargin($tab_top_newpage);
337  // Loop on each lines
338  $i = 0;
339  while ($i < $nblines) {
340  $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
341  $pdf->SetTextColor(0, 0, 0);
342 
343  $pdf->setTopMargin($tab_top_newpage);
344  if (empty($showpricebeforepagebreak) && ($i !== ($nblines - 1))) {
345  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
346  } else {
347  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
348  }
349 
350  $pageposbefore = $pdf->getPage();
351  $curY = $nexY;
352  $pdf->startTransaction();
353  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
354  $pageposafter = $pdf->getPage();
355  if ($pageposafter > $pageposbefore) {
356  // There is a pagebreak
357  $pdf->rollbackTransaction(true);
358 
359  $pageposafter = $pageposbefore;
360  //print $pageposafter.'-'.$pageposbefore;exit;
361  if (empty($showpricebeforepagebreak)) {
362  $pdf->AddPage('', '', true);
363  if (!empty($tplidx)) {
364  $pdf->useTemplate($tplidx);
365  }
366  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
367  $this->_pagehead($pdf, $object, 0, $outputlangs);
368  }
369  $pdf->setPage($pageposafter + 1);
370  $showpricebeforepagebreak = 1;
371  $nexY = $tab_top_newpage;
372  $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
373  $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
374  $pdf->SetTextColor(0, 0, 0);
375 
376  $pdf->setTopMargin($tab_top_newpage);
377  continue;
378  } else {
379  $pdf->setPageOrientation('', 1, $heightforfooter);
380  $showpricebeforepagebreak = 0;
381  }
382 
383  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
384  $pageposafter = $pdf->getPage();
385  $posyafter = $pdf->GetY();
386  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
387  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
388  // There is no space left for total+free text
389  if ($i == ($nblines - 1)) {
390  // No more lines, and no space left to show total, so we create a new page
391  $pdf->AddPage('', '', true);
392  if (!empty($tplidx)) {
393  $pdf->useTemplate($tplidx);
394  }
395  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
396  $this->_pagehead($pdf, $object, 0, $outputlangs);
397  }
398  $pdf->setPage($pageposafter + 1);
399  }
400  } else {
401  // We found a page break
402  // Allows data in the first page if description is long enough to break in multiples pages
403  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
404  $showpricebeforepagebreak = 1;
405  } else {
406  $showpricebeforepagebreak = 0;
407  }
408  }
409  } else // No pagebreak
410  {
411  $pdf->commitTransaction();
412  }
413  $i++;
414  //nexY
415  $nexY = $pdf->GetY();
416  $pageposafter = $pdf->getPage();
417  $pdf->setPage($pageposbefore);
418  $pdf->setTopMargin($this->marge_haute);
419  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
420 
421  //$nblineFollowComment = 1;
422  // Search number of lines coming to know if there is enough room
423  // if ($i < ($nblines - 1)) // If it's not last line
424  // {
425  // //Fetch current description to know on which line the next one should be placed
426  // $follow_comment = $object->lines[$i]->comments;
427  // $follow_type = $object->lines[$i]->type_fees_code;
428 
429  // //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
430  // $nbLineCommentNeed = dol_nboflines_bis($follow_comment,52,$outputlangs->charset_output);
431  // $nbLineTypeNeed = dol_nboflines_bis($follow_type,4,$outputlangs->charset_output);
432 
433  // $nblineFollowComment = max($nbLineCommentNeed, $nbLineTypeNeed);
434  // }
435 
436  //$nexY+=$nblineFollowComment*($pdf->getFontSize()*1.3); // Add space between lines
437  $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
438 
439  // Detect if some page were added automatically and output _tableau for past pages
440  while ($pagenb < $pageposafter) {
441  $pdf->setPage($pagenb);
442  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
443  if ($pagenb == 1) {
444  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
445  } else {
446  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
447  }
448  $this->_pagefoot($pdf, $object, $outputlangs, 1);
449  $pagenb++;
450  $pdf->setPage($pagenb);
451  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
452  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
453  $this->_pagehead($pdf, $object, 0, $outputlangs);
454  }
455  if (!empty($tplidx)) {
456  $pdf->useTemplate($tplidx);
457  }
458  }
459  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
460  if ($pagenb == 1) {
461  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
462  } else {
463  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
464  }
465  $this->_pagefoot($pdf, $object, $outputlangs, 1);
466  // New page
467  $pdf->AddPage();
468  if (!empty($tplidx)) {
469  $pdf->useTemplate($tplidx);
470  }
471  $pagenb++;
472  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
473  $this->_pagehead($pdf, $object, 0, $outputlangs);
474  }
475  }
476  }
477 
478  // Show square
479  if ($pagenb == 1) {
480  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
481  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
482  } else {
483  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
484  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
485  }
486 
487  $pdf->SetFont('', '', 10);
488 
489  // Show total area box
490  $posy = $bottomlasttab + 5;
491  $posy_start_of_totals = $posy;
492  $pdf->SetXY(130, $posy);
493  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
494  $pdf->SetXY(180, $posy);
495  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ht), 1, 'R');
496  $pdf->SetFillColor(248, 248, 248);
497 
498  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
499  // TODO Show vat amout per tax level
500  $posy += 5;
501  $pdf->SetXY(130, $posy);
502  $pdf->SetTextColor(0, 0, 60);
503  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalVAT"), 1, 'L');
504  $pdf->SetXY(180, $posy);
505  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_tva), 1, 'R');
506  }
507 
508  $posy += 5;
509  $pdf->SetXY(130, $posy);
510  $pdf->SetFont('', 'B', 10);
511  $pdf->SetTextColor(0, 0, 60);
512  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalTTC"), 1, 'L');
513  $pdf->SetXY(180, $posy);
514  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ttc), 1, 'R');
515 
516  // show payments zone
517  $sumPayments = $object->getSumPayments();
518  if ($sumPayments > 0 && empty($conf->global->PDF_EXPENSEREPORT_NO_PAYMENT_DETAILS)) {
519  $posy = $this->tablePayments($pdf, $object, $posy_start_of_totals, $outputlangs);
520  }
521 
522  // Page footer
523  $this->_pagefoot($pdf, $object, $outputlangs);
524  if (method_exists($pdf, 'AliasNbPages')) {
525  $pdf->AliasNbPages();
526  }
527 
528  $pdf->Close();
529 
530  $pdf->Output($file, 'F');
531 
532  // Add pdfgeneration hook
533  $hookmanager->initHooks(array('pdfgeneration'));
534  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
535  global $action;
536  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
537  if ($reshook < 0) {
538  $this->error = $hookmanager->error;
539  $this->errors = $hookmanager->errors;
540  }
541 
542  if (!empty($conf->global->MAIN_UMASK)) {
543  @chmod($file, octdec($conf->global->MAIN_UMASK));
544  }
545 
546  $this->result = array('fullpath'=>$file);
547 
548  return 1; // No error
549  } else {
550  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
551  return 0;
552  }
553  } else {
554  $this->error = $langs->trans("ErrorConstantNotDefined", "EXPENSEREPORT_OUTPUTDIR");
555  return 0;
556  }
557  }
558 
569  protected function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails = 0)
570  {
571  global $conf;
572  $pdf->SetFont('', '', $default_font_size - 1);
573  $pdf->SetTextColor(0, 0, 0);
574 
575  // Accountancy piece
576  $pdf->SetXY($this->posxpiece, $curY);
577  $pdf->writeHTMLCell($this->posxcomment - $this->posxpiece - 0.8, 4, $this->posxpiece - 1, $curY, $linenumber + 1, 0, 1);
578 
579  // Date
580  //$pdf->SetXY($this->posxdate -1, $curY);
581  //$pdf->MultiCell($this->posxtype-$this->posxdate-0.8, 4, dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs), 0, 'C');
582 
583  // Type
584  $pdf->SetXY($this->posxtype - 1, $curY);
585  $nextColumnPosX = $this->posxup;
586  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
587  $nextColumnPosX = $this->posxtva;
588  }
589  if (isModEnabled('project')) {
590  $nextColumnPosX = $this->posxprojet;
591  }
592 
593  $expensereporttypecode = $object->lines[$linenumber]->type_fees_code;
594  $expensereporttypecodetoshow = ($outputlangs->trans(($expensereporttypecode)) == $expensereporttypecode ? $object->lines[$linenumber]->type_fees_libelle : $outputlangs->trans($expensereporttypecode));
595 
596 
597  if ($expensereporttypecodetoshow == $expensereporttypecode) {
598  $expensereporttypecodetoshow = preg_replace('/^(EX_|TF_)/', '', $expensereporttypecodetoshow);
599  }
600  //$expensereporttypecodetoshow = dol_trunc($expensereporttypecodetoshow, 9);
601 
602  //$pdf->MultiCell($nextColumnPosX-$this->posxtype-0.8, 4, $expensereporttypecodetoshow, 0, 'C');
603 
604  // Project
605  //if (isModEnabled('project'))
606  //{
607  // $pdf->SetFont('','', $default_font_size - 1);
608  // $pdf->SetXY($this->posxprojet, $curY);
609  // $pdf->MultiCell($this->posxtva-$this->posxprojet-0.8, 4, $object->lines[$linenumber]->projet_ref, 0, 'C');
610  //}
611 
612  // VAT Rate
613  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
614  $vat_rate = pdf_getlinevatrate($object, $linenumber, $outputlangs, $hidedetails);
615  $pdf->SetXY($this->posxtva, $curY);
616  $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 4, $vat_rate, 0, 'R');
617  }
618 
619  // Unit price
620  $pdf->SetXY($this->posxup, $curY);
621  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 4, price($object->lines[$linenumber]->value_unit), 0, 'R');
622 
623  // Quantity
624  $pdf->SetXY($this->posxqty, $curY);
625  $pdf->MultiCell($this->postotalht - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R');
626 
627  // Total without taxes
628  $pdf->SetXY($this->postotalht, $curY);
629  $pdf->MultiCell($this->postotalttc - $this->postotalht - 0.8, 4, price($object->lines[$linenumber]->total_ht), 0, 'R');
630 
631  // Total with all taxes
632  $pdf->SetXY($this->postotalttc - 1, $curY);
633  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R');
634 
635  // Comments
636  $pdf->SetXY($this->posxcomment, $curY);
637  $comment = $outputlangs->trans("Date").':'.dol_print_date($object->lines[$linenumber]->date, "day", false, $outputlangs).' ';
638  $comment .= $outputlangs->trans("Type").':'.$expensereporttypecodetoshow.'<br>';
639  if (!empty($object->lines[$linenumber]->projet_ref)) {
640  $comment .= $outputlangs->trans("Project").':'.$object->lines[$linenumber]->projet_ref.'<br>';
641  }
642  $comment .= $object->lines[$linenumber]->comments;
643  $pdf->writeHTMLCell($this->posxtva - $this->posxcomment - 0.8, 4, $this->posxcomment - 1, $curY, $comment, 0, 1);
644  }
645 
646  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
656  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
657  {
658  // global $conf, $langs, $hookmanager;
659  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
660 
661  // Load traductions files required by page
662  $outputlangs->loadLangs(array("main", "trips", "companies"));
663 
664  $default_font_size = pdf_getPDFFontSize($outputlangs);
665 
666  /*
667  // ajout du fondu vert en bas de page à droite
668  $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
669  $pdf->Image($image_fondue,20,107,200,190);
670 
671  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
672  */
673 
674  // Draft watermark
675  if ($object->fk_statut == 0 && !empty($conf->global->EXPENSEREPORT_DRAFT_WATERMARK)) {
676  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->EXPENSEREPORT_DRAFT_WATERMARK);
677  }
678 
679  $pdf->SetTextColor(0, 0, 60);
680  $pdf->SetFont('', 'B', $default_font_size + 3);
681 
682  $posy = $this->marge_haute;
683  $posx = $this->page_largeur - $this->marge_droite - 100;
684 
685  $pdf->SetXY($this->marge_gauche, $posy);
686 
687  // Logo
688  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
689  if ($this->emetteur->logo) {
690  if (is_readable($logo)) {
691  $height = pdf_getHeightForLogo($logo);
692  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
693  } else {
694  $pdf->SetTextColor(200, 0, 0);
695  $pdf->SetFont('', 'B', $default_font_size - 2);
696  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
697  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
698  }
699  } else {
700  $text = $this->emetteur->name;
701  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
702  }
703 
704  $pdf->SetFont('', 'B', $default_font_size + 4);
705  $pdf->SetXY($posx, $posy);
706  $pdf->SetTextColor(0, 0, 60);
707  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $langs->trans("ExpenseReport"), 0, 'R');
708 
709  $pdf->SetFont('', '', $default_font_size - 1);
710 
711  // Ref complete
712  $posy += 8;
713  $pdf->SetXY($posx, $posy);
714  $pdf->SetTextColor(0, 0, 60);
715  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
716 
717  // Date start period
718  $posy += 5;
719  $pdf->SetXY($posx, $posy);
720  $pdf->SetTextColor(0, 0, 60);
721  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("DateStart")." : ".($object->date_debut > 0 ?dol_print_date($object->date_debut, "day", false, $outputlangs) : ''), '', 'R');
722 
723  // Date end period
724  $posy += 5;
725  $pdf->SetXY($posx, $posy);
726  $pdf->SetTextColor(0, 0, 60);
727  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("DateEnd")." : ".($object->date_fin > 0 ?dol_print_date($object->date_fin, "day", false, $outputlangs) : ''), '', 'R');
728 
729  // Status Expense Report
730  $posy += 6;
731  $pdf->SetXY($posx, $posy);
732  $pdf->SetFont('', 'B', $default_font_size + 2);
733  $pdf->SetTextColor(111, 81, 124);
734  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities($object->statuts_short[$object->status]), '', 'R');
735 
736  if ($showaddress) {
737  // Sender properties
738  $carac_emetteur = '';
739  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->address);
740  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->zip).' '.$outputlangs->convToOutputCharset($this->emetteur->town);
741  $carac_emetteur .= "\n";
742  if ($this->emetteur->phone) {
743  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Phone")." : ".$outputlangs->convToOutputCharset($this->emetteur->phone);
744  }
745  if ($this->emetteur->fax) {
746  $carac_emetteur .= ($carac_emetteur ? ($this->emetteur->tel ? " - " : "\n") : '').$outputlangs->transnoentities("Fax")." : ".$outputlangs->convToOutputCharset($this->emetteur->fax);
747  }
748  if ($this->emetteur->email) {
749  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($this->emetteur->email);
750  }
751  if ($this->emetteur->url) {
752  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Web")." : ".$outputlangs->convToOutputCharset($this->emetteur->url);
753  }
754 
755  // Receiver Properties
756  $receiver = new User($this->db);
757  $receiver->fetch($object->fk_user_author);
758  $receiver_account = new UserBankAccount($this->db);
759  $receiver_account->fetch(0, '', $object->fk_user_author);
760  $expense_receiver = '';
761  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->address);
762  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->zip).' '.$outputlangs->convToOutputCharset($receiver->town);
763  $expense_receiver .= "\n";
764  if ($receiver->email) {
765  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($receiver->email);
766  }
767  if ($receiver_account->iban) {
768  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("IBAN")." : ".$outputlangs->convToOutputCharset($receiver_account->iban);
769  }
770 
771  // Show sender
772  $posy = 50;
773  $posx = $this->marge_gauche;
774  $hautcadre = 40;
775  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
776  $posx = 118;
777  }
778 
779  // Show sender frame
780  $pdf->SetTextColor(0, 0, 0);
781  $pdf->SetFont('', 'B', $default_font_size - 2);
782  $pdf->SetXY($posx, $posy - 5);
783  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripSociete"), '', 'L');
784  $pdf->SetXY($posx, $posy);
785  $pdf->SetFillColor(224, 224, 224);
786  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
787  $pdf->SetTextColor(0, 0, 60);
788 
789  // Show sender information
790  if (empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
791  $pdf->SetXY($posx + 2, $posy + 3);
792  $pdf->SetFont('', 'B', $default_font_size);
793  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
794  $pdf->SetXY($posx + 2, $posy + 8);
795  $pdf->SetFont('', '', $default_font_size - 1);
796  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
797  } else {
798  $pdf->SetXY($posx + 2, $posy + 3);
799  $pdf->SetFont('', 'B', $default_font_size);
800  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset(dolGetFirstLastname($receiver->firstname, $receiver->lastname)), 0, 'L');
801  $pdf->SetXY($posx + 2, $posy + 8);
802  $pdf->SetFont('', '', $default_font_size - 1);
803  $pdf->MultiCell(80, 4, $expense_receiver, 0, 'L');
804  }
805 
806  // Show recipient
807  $posy = 50;
808  $posx = 100;
809  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
810  $posx = $this->marge_gauche;
811  }
812 
813  // Show recipient frame
814  $pdf->SetTextColor(0, 0, 0);
815  $pdf->SetFont('', 'B', 8);
816  $pdf->SetXY($posx, $posy - 5);
817  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L');
818  $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre);
819 
820  // Informations for expense report (dates and users workflow)
821  if ($object->fk_user_author > 0) {
822  $userfee = new User($this->db);
823  $userfee->fetch($object->fk_user_author);
824  $posy += 3;
825  $pdf->SetXY($posx + 2, $posy);
826  $pdf->SetFont('', '', 10);
827  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
828  $posy = $pdf->GetY() + 1;
829  $pdf->SetXY($posx + 2, $posy);
830  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create, "day", false, $outputlangs), 0, 'L');
831  }
832 
833  if ($object->fk_statut == 99) {
834  if ($object->fk_user_refuse > 0) {
835  $userfee = new User($this->db);
836  $userfee->fetch($object->fk_user_refuse);
837  $posy += 6;
838  $pdf->SetXY($posx + 2, $posy);
839  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
840  $posy += 5;
841  $pdf->SetXY($posx + 2, $posy);
842  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse), 0, 'L');
843  $posy += 5;
844  $pdf->SetXY($posx + 2, $posy);
845  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse, "day", false, $outputlangs), 0, 'L');
846  }
847  } elseif ($object->fk_statut == 4) {
848  if ($object->fk_user_cancel > 0) {
849  $userfee = new User($this->db);
850  $userfee->fetch($object->fk_user_cancel);
851  $posy += 6;
852  $pdf->SetXY($posx + 2, $posy);
853  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
854  $posy += 5;
855  $pdf->SetXY($posx + 2, $posy);
856  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel), 0, 'L');
857  $posy += 5;
858  $pdf->SetXY($posx + 2, $posy);
859  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel, "day", false, $outputlangs), 0, 'L');
860  }
861  } else {
862  if ($object->fk_user_approve > 0) {
863  $userfee = new User($this->db);
864  $userfee->fetch($object->fk_user_approve);
865  $posy += 6;
866  $pdf->SetXY($posx + 2, $posy);
867  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
868  $posy += 5;
869  $pdf->SetXY($posx + 2, $posy);
870  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs), 0, 'L');
871  }
872  }
873 
874  if ($object->fk_statut == 6) {
875  if ($object->fk_user_paid > 0) {
876  $userfee = new User($this->db);
877  $userfee->fetch($object->fk_user_paid);
878  $posy += 6;
879  $pdf->SetXY($posx + 2, $posy);
880  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
881  $posy += 5;
882  $pdf->SetXY($posx + 2, $posy);
883  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement, "day", false, $outputlangs), 0, 'L');
884  }
885  }
886  }
887  }
888 
889  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
903  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
904  {
905  global $conf;
906 
907  // Force to disable hidetop and hidebottom
908  $hidebottom = 0;
909  if ($hidetop) {
910  $hidetop = -1;
911  }
912 
913  $currency = !empty($currency) ? $currency : $conf->currency;
914  $default_font_size = pdf_getPDFFontSize($outputlangs);
915 
916  // Amount in (at tab_top - 1)
917  $pdf->SetTextColor(0, 0, 0);
918  $pdf->SetFont('', '', $default_font_size - 2);
919  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
920  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 4), $tab_top - 4);
921  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
922 
923  $pdf->SetDrawColor(128, 128, 128);
924 
925  // Rect takes a length in 3rd parameter
926  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
927  // line prend une position y en 3eme param
928  if (empty($hidetop)) {
929  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
930  }
931 
932  $pdf->SetFont('', '', 8);
933 
934  // Accountancy piece
935  if (empty($hidetop)) {
936  $pdf->SetXY($this->posxpiece - 1, $tab_top + 1);
937  $pdf->MultiCell($this->posxcomment - $this->posxpiece - 0.8, 1, '', '', 'R');
938  }
939 
940  // Comments
941  $pdf->line($this->posxcomment - 1, $tab_top, $this->posxcomment - 1, $tab_top + $tab_height);
942  if (empty($hidetop)) {
943  $pdf->SetXY($this->posxcomment - 1, $tab_top + 1);
944  $pdf->MultiCell($this->posxdate - $this->posxcomment - 0.8, 1, $outputlangs->transnoentities("Description"), '', 'L');
945  }
946 
947  // Date
948  //$pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height);
949  //if (empty($hidetop))
950  //{
951  // $pdf->SetXY($this->posxdate-1, $tab_top+1);
952  // $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C');
953  //}
954 
955  // Type
956  //$pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height);
957  //if (empty($hidetop))
958  //{
959  // $pdf->SetXY($this->posxtype-1, $tab_top+1);
960  // $pdf->MultiCell($this->posxprojet-$this->posxtype - 1, 2, $outputlangs->transnoentities("Type"), '', 'C');
961  //}
962 
963  //if (isModEnabled('project'))
964  //{
965  // // Project
966  // $pdf->line($this->posxprojet - 1, $tab_top, $this->posxprojet - 1, $tab_top + $tab_height);
967  // if (empty($hidetop)) {
968  // $pdf->SetXY($this->posxprojet - 1, $tab_top + 1);
969  // $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 2, $outputlangs->transnoentities("Project"), '', 'C');
970  // }
971  //}
972 
973  // VAT
974  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
975  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
976  if (empty($hidetop)) {
977  $pdf->SetXY($this->posxtva - 0.8, $tab_top + 1);
978  $pdf->MultiCell($this->posxup - $this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C');
979  }
980  }
981 
982  // Unit price
983  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
984  if (empty($hidetop)) {
985  $pdf->SetXY($this->posxup - 0.8, $tab_top + 1);
986  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUTTC"), '', 'C');
987  }
988 
989  // Quantity
990  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
991  if (empty($hidetop)) {
992  $pdf->SetXY($this->posxqty - 0.8, $tab_top + 1);
993  $pdf->MultiCell($this->postotalht - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
994  }
995 
996  // Total without taxes
997  $pdf->line($this->postotalht - 1, $tab_top, $this->postotalht - 1, $tab_top + $tab_height);
998  if (empty($hidetop)) {
999  $pdf->SetXY($this->postotalht - 0.8, $tab_top + 1);
1000  $pdf->MultiCell($this->postotalttc - $this->postotalht + 1, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
1001  }
1002 
1003  // Total with all taxes
1004  $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height);
1005  if (empty($hidetop)) {
1006  $pdf->SetXY($this->postotalttc - 0.8, $tab_top + 1);
1007  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R');
1008  }
1009 
1010  $pdf->SetTextColor(0, 0, 0);
1011  }
1012 
1022  protected function tablePayments(&$pdf, $object, $posy, $outputlangs)
1023  {
1024  global $conf;
1025 
1026  $sign = 1;
1027  $tab3_posx = $this->marge_gauche;
1028  $tab3_top = $posy;
1029  $tab3_width = 88;
1030  $tab3_height = 5;
1031 
1032  $default_font_size = pdf_getPDFFontSize($outputlangs);
1033 
1034  $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1035  $pdf->SetFont('', '', $default_font_size - 2);
1036  $pdf->SetXY($tab3_posx, $tab3_top - 4);
1037  $pdf->SetTextColor(0, 0, 0);
1038  $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1039 
1040  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width + 2, $tab3_top); // Top border line of table title
1041 
1042  $pdf->SetXY($tab3_posx, $tab3_top + 1);
1043  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Date"), 0, 'L', 0);
1044  $pdf->SetXY($tab3_posx + 19, $tab3_top + 1); // Old value 17
1045  $pdf->MultiCell(15, 3, $outputlangs->transnoentities("Amount"), 0, 'C', 0);
1046  $pdf->SetXY($tab3_posx + 35, $tab3_top + 1);
1047  $pdf->MultiCell(30, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1048  if (isModEnabled("banque")) {
1049  $pdf->SetXY($tab3_posx + 65, $tab3_top + 1);
1050  $pdf->MultiCell(25, 3, $outputlangs->transnoentities("BankAccount"), 0, 'L', 0);
1051  }
1052  $pdf->line($tab3_posx, $tab3_top + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $tab3_height); // Bottom border line of table title
1053 
1054  $y = 0;
1055 
1056  // Loop on each payment
1057  // TODO create method on expensereport class to get payments
1058  // Payments already done (from payment on this expensereport)
1059  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1060  $sql .= "c.code as p_code, c.libelle as payment_type,";
1061  $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1062  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1063  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1064  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1065  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1066  $sql .= " WHERE e.rowid = ".((int) $object->id);
1067  $sql .= " AND p.fk_expensereport = e.rowid";
1068  $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
1069  $sql .= " ORDER BY dp";
1070 
1071  $resql = $this->db->query($sql);
1072  if ($resql) {
1073  $num = $this->db->num_rows($resql);
1074  $totalpaid = 0;
1075  $i = 0;
1076  while ($i < $num) {
1077  $y += $tab3_height;
1078  $row = $this->db->fetch_object($resql);
1079 
1080  $pdf->SetXY($tab3_posx, $tab3_top + $y + 1);
1081  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->dp), 'day', false, $outputlangs, true), 0, 'L', 0);
1082  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y + 1);
1083  $pdf->MultiCell(15, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'R', 0);
1084  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y + 1);
1085  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->p_code);
1086 
1087  $pdf->MultiCell(40, 3, $oper, 0, 'L', 0);
1088  if (isModEnabled("banque")) {
1089  $pdf->SetXY($tab3_posx + 65, $tab3_top + $y + 1);
1090  $pdf->MultiCell(30, 3, $row->baref, 0, 'L', 0);
1091  }
1092 
1093  $pdf->line($tab3_posx, $tab3_top + $y + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $y + $tab3_height); // Bottom line border of table
1094  $totalpaid += $row->amount;
1095  $i++;
1096  }
1097  if ($num > 0 && $object->paid == 0) {
1098  $y += $tab3_height;
1099 
1100  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1101  $pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
1102  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1103  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AlreadyPaid"), 0, 'L', 0);
1104  $y += $tab3_height - 2;
1105  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1106  $pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
1107  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1108  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AmountExpected"), 0, 'L', 0);
1109  $y += $tab3_height - 2;
1110  $remaintopay = $object->total_ttc - $totalpaid;
1111  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1112  $pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
1113  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1114  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("RemainderToPay"), 0, 'L', 0);
1115  }
1116  } else {
1117  $this->error = $this->db->lasterror();
1118  return -1;
1119  }
1120  }
1121 
1122  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1132  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1133  {
1134  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1135  return pdf_pagefoot($pdf, $outputlangs, 'EXPENSEREPORT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1136  }
1137 }
Class to manage hooks.
Parent class for trips and expenses templates.
Class to manage bank accounts description of users.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class to generate expense report based on standard model.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails=0)
tablePayments(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
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...
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.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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_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.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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_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:1001
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1824
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:749
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:769
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