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