dolibarr 18.0.6
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
32require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40require_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 $version = 'dolibarr';
77
82 public $emetteur;
83
84 public $posxpiece;
85 public $posxcomment;
86 public $posxtva;
87 public $posxup;
88 public $posxqty;
89 public $posxtype;
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 (!empty($conf->global->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 (!empty($conf->global->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 (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
254 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->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 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
272
273 // New page
274 $pdf->AddPage();
275 if (!empty($tplidx)) {
276 $pdf->useTemplate($tplidx);
277 }
278 $pagenb++;
279 $this->_pagehead($pdf, $object, 1, $outputlangs);
280 $pdf->SetFont('', '', $default_font_size - 1);
281 $pdf->MultiCell(0, 3, ''); // Set interline to 3
282 $pdf->SetTextColor(0, 0, 0);
283
284 $tab_top = 95;
285 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 65 : 10);
286
287 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
288
289 // Show notes
290 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
291 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
292 // Get first sale rep
293 if (is_object($object->thirdparty)) {
294 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
295 $salerepobj = new User($this->db);
296 $salerepobj->fetch($salereparray[0]['id']);
297 if (!empty($salerepobj->signature)) {
298 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
299 }
300 }
301 }
302 if ($notetoshow) {
303 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
304 complete_substitutions_array($substitutionarray, $outputlangs, $object);
305 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
306 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
307
308 $tab_top = 95;
309
310 $pdf->SetFont('', '', $default_font_size - 1);
311 $pdf->writeHTMLCell(190, 3, $this->posxpiece - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
312 $nexY = $pdf->GetY();
313 $height_note = $nexY - $tab_top;
314
315 // Rect takes a length in 3rd parameter
316 $pdf->SetDrawColor(192, 192, 192);
317 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
318
319 $tab_height = $tab_height - $height_note;
320 $tab_top = $nexY + 6;
321 } else {
322 $height_note = 0;
323 }
324
325 $iniY = $tab_top + 7;
326 $initialY = $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 (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
398 $showpricebeforepagebreak = 1;
399 } else {
400 $showpricebeforepagebreak = 0;
401 }
402 }
403 } else // No pagebreak
404 {
405 $pdf->commitTransaction();
406 }
407 $i++;
408 //nexY
409 $nexY = $pdf->GetY();
410 $pageposafter = $pdf->getPage();
411 $pdf->setPage($pageposbefore);
412 $pdf->setTopMargin($this->marge_haute);
413 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
414
415 //$nblineFollowComment = 1;
416 // Search number of lines coming to know if there is enough room
417 // if ($i < ($nblines - 1)) // If it's not last line
418 // {
419 // //Fetch current description to know on which line the next one should be placed
420 // $follow_comment = $object->lines[$i]->comments;
421 // $follow_type = $object->lines[$i]->type_fees_code;
422
423 // //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
424 // $nbLineCommentNeed = dol_nboflines_bis($follow_comment,52,$outputlangs->charset_output);
425 // $nbLineTypeNeed = dol_nboflines_bis($follow_type,4,$outputlangs->charset_output);
426
427 // $nblineFollowComment = max($nbLineCommentNeed, $nbLineTypeNeed);
428 // }
429
430 //$nexY+=$nblineFollowComment*($pdf->getFontSize()*1.3); // Add space between lines
431 $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
432
433 // Detect if some page were added automatically and output _tableau for past pages
434 while ($pagenb < $pageposafter) {
435 $pdf->setPage($pagenb);
436 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
437 if ($pagenb == 1) {
438 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
439 } else {
440 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
441 }
442 $this->_pagefoot($pdf, $object, $outputlangs, 1);
443 $pagenb++;
444 $pdf->setPage($pagenb);
445 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
446 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
447 $this->_pagehead($pdf, $object, 0, $outputlangs);
448 }
449 if (!empty($tplidx)) {
450 $pdf->useTemplate($tplidx);
451 }
452 }
453 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
454 if ($pagenb == 1) {
455 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
456 } else {
457 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
458 }
459 $this->_pagefoot($pdf, $object, $outputlangs, 1);
460 // New page
461 $pdf->AddPage();
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
464 }
465 $pagenb++;
466 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
467 $this->_pagehead($pdf, $object, 0, $outputlangs);
468 }
469 }
470 }
471
472 // Show square
473 if ($pagenb == 1) {
474 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
475 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
476 } else {
477 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
478 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
479 }
480
481 $pdf->SetFont('', '', 10);
482
483 // Show total area box
484 $posy = $bottomlasttab + 5;
485 $posy_start_of_totals = $posy;
486 $pdf->SetXY(130, $posy);
487 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
488 $pdf->SetXY(180, $posy);
489 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ht), 1, 'R');
490 $pdf->SetFillColor(248, 248, 248);
491
492 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
493 // TODO Show vat amout per tax level
494 $posy += 5;
495 $pdf->SetXY(130, $posy);
496 $pdf->SetTextColor(0, 0, 60);
497 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalVAT"), 1, 'L');
498 $pdf->SetXY(180, $posy);
499 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_tva), 1, 'R');
500 }
501
502 $posy += 5;
503 $pdf->SetXY(130, $posy);
504 $pdf->SetFont('', 'B', 10);
505 $pdf->SetTextColor(0, 0, 60);
506 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalTTC"), 1, 'L');
507 $pdf->SetXY(180, $posy);
508 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ttc), 1, 'R');
509
510 // show payments zone
511 $sumPayments = $object->getSumPayments();
512 if ($sumPayments > 0 && empty($conf->global->PDF_EXPENSEREPORT_NO_PAYMENT_DETAILS)) {
513 $posy = $this->tablePayments($pdf, $object, $posy_start_of_totals, $outputlangs);
514 }
515
516 // Page footer
517 $this->_pagefoot($pdf, $object, $outputlangs);
518 if (method_exists($pdf, 'AliasNbPages')) {
519 $pdf->AliasNbPages();
520 }
521
522 $pdf->Close();
523
524 $pdf->Output($file, 'F');
525
526 // Add pdfgeneration hook
527 $hookmanager->initHooks(array('pdfgeneration'));
528 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
529 global $action;
530 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
531 if ($reshook < 0) {
532 $this->error = $hookmanager->error;
533 $this->errors = $hookmanager->errors;
534 }
535
536 dolChmod($file);
537
538 $this->result = array('fullpath'=>$file);
539
540 return 1; // No error
541 } else {
542 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
543 return 0;
544 }
545 } else {
546 $this->error = $langs->trans("ErrorConstantNotDefined", "EXPENSEREPORT_OUTPUTDIR");
547 return 0;
548 }
549 }
550
561 protected function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails = 0)
562 {
563 global $conf;
564 $pdf->SetFont('', '', $default_font_size - 1);
565 $pdf->SetTextColor(0, 0, 0);
566
567 // Accountancy piece
568 $pdf->SetXY($this->posxpiece, $curY);
569 $pdf->writeHTMLCell($this->posxcomment - $this->posxpiece - 0.8, 4, $this->posxpiece - 1, $curY, $linenumber + 1, 0, 1);
570
571 // Date
572 //$pdf->SetXY($this->posxdate -1, $curY);
573 //$pdf->MultiCell($this->posxtype-$this->posxdate-0.8, 4, dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs), 0, 'C');
574
575 // Type
576 $pdf->SetXY($this->posxtype - 1, $curY);
577 $nextColumnPosX = $this->posxup;
578 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
579 $nextColumnPosX = $this->posxtva;
580 }
581 if (isModEnabled('project')) {
582 $nextColumnPosX = $this->posxprojet;
583 }
584
585 $expensereporttypecode = $object->lines[$linenumber]->type_fees_code;
586 $expensereporttypecodetoshow = ($outputlangs->trans(($expensereporttypecode)) == $expensereporttypecode ? $object->lines[$linenumber]->type_fees_libelle : $outputlangs->trans($expensereporttypecode));
587
588
589 if ($expensereporttypecodetoshow == $expensereporttypecode) {
590 $expensereporttypecodetoshow = preg_replace('/^(EX_|TF_)/', '', $expensereporttypecodetoshow);
591 }
592 //$expensereporttypecodetoshow = dol_trunc($expensereporttypecodetoshow, 9);
593
594 //$pdf->MultiCell($nextColumnPosX-$this->posxtype-0.8, 4, $expensereporttypecodetoshow, 0, 'C');
595
596 // Project
597 //if (isModEnabled('project'))
598 //{
599 // $pdf->SetFont('','', $default_font_size - 1);
600 // $pdf->SetXY($this->posxprojet, $curY);
601 // $pdf->MultiCell($this->posxtva-$this->posxprojet-0.8, 4, $object->lines[$linenumber]->projet_ref, 0, 'C');
602 //}
603
604 // VAT Rate
605 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
606 $vat_rate = pdf_getlinevatrate($object, $linenumber, $outputlangs, $hidedetails);
607 $pdf->SetXY($this->posxtva, $curY);
608 $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 4, $vat_rate, 0, 'R');
609 }
610
611 // Unit price
612 $pdf->SetXY($this->posxup, $curY);
613 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 4, price($object->lines[$linenumber]->value_unit), 0, 'R');
614
615 // Quantity
616 $pdf->SetXY($this->posxqty, $curY);
617 $pdf->MultiCell($this->postotalht - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R');
618
619 // Total without taxes
620 $pdf->SetXY($this->postotalht, $curY);
621 $pdf->MultiCell($this->postotalttc - $this->postotalht - 0.8, 4, price($object->lines[$linenumber]->total_ht), 0, 'R');
622
623 // Total with all taxes
624 $pdf->SetXY($this->postotalttc - 1, $curY);
625 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R');
626
627 // Comments
628 $pdf->SetXY($this->posxcomment, $curY);
629 $comment = $outputlangs->trans("Date").':'.dol_print_date($object->lines[$linenumber]->date, "day", false, $outputlangs).' ';
630 $comment .= $outputlangs->trans("Type").':'.$expensereporttypecodetoshow.'<br>';
631 if (!empty($object->lines[$linenumber]->projet_ref)) {
632 $comment .= $outputlangs->trans("Project").':'.$object->lines[$linenumber]->projet_ref.'<br>';
633 }
634 $comment .= $object->lines[$linenumber]->comments;
635 $pdf->writeHTMLCell($this->posxtva - $this->posxcomment - 0.8, 4, $this->posxcomment - 1, $curY, $comment, 0, 1);
636 }
637
638 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
648 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
649 {
650 // global $conf, $langs, $hookmanager;
651 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
652
653 // Load traductions files required by page
654 $outputlangs->loadLangs(array("main", "trips", "companies"));
655
656 $default_font_size = pdf_getPDFFontSize($outputlangs);
657
658 /*
659 // ajout du fondu vert en bas de page à droite
660 $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
661 $pdf->Image($image_fondue,20,107,200,190);
662
663 pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
664 */
665
666 // Draft watermark
667 if ($object->fk_statut == 0 && !empty($conf->global->EXPENSEREPORT_DRAFT_WATERMARK)) {
668 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->EXPENSEREPORT_DRAFT_WATERMARK);
669 }
670
671 $pdf->SetTextColor(0, 0, 60);
672 $pdf->SetFont('', 'B', $default_font_size + 3);
673
674 $posy = $this->marge_haute;
675 $posx = $this->page_largeur - $this->marge_droite - 100;
676
677 $pdf->SetXY($this->marge_gauche, $posy);
678
679 // Logo
680 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
681 if ($this->emetteur->logo) {
682 if (is_readable($logo)) {
683 $height = pdf_getHeightForLogo($logo);
684 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
685 } else {
686 $pdf->SetTextColor(200, 0, 0);
687 $pdf->SetFont('', 'B', $default_font_size - 2);
688 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
689 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
690 }
691 } else {
692 $text = $this->emetteur->name;
693 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
694 }
695
696 $pdf->SetFont('', 'B', $default_font_size + 4);
697 $pdf->SetXY($posx, $posy);
698 $pdf->SetTextColor(0, 0, 60);
699 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $langs->trans("ExpenseReport"), 0, 'R');
700
701 $pdf->SetFont('', '', $default_font_size - 1);
702
703 // Ref complete
704 $posy += 8;
705 $pdf->SetXY($posx, $posy);
706 $pdf->SetTextColor(0, 0, 60);
707 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
708
709 // Date start period
710 $posy += 5;
711 $pdf->SetXY($posx, $posy);
712 $pdf->SetTextColor(0, 0, 60);
713 $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');
714
715 // Date end period
716 $posy += 5;
717 $pdf->SetXY($posx, $posy);
718 $pdf->SetTextColor(0, 0, 60);
719 $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');
720
721 // Status Expense Report
722 $posy += 6;
723 $pdf->SetXY($posx, $posy);
724 $pdf->SetFont('', 'B', $default_font_size + 2);
725 $pdf->SetTextColor(111, 81, 124);
726 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities($object->statuts_short[$object->status]), '', 'R');
727
728 if ($showaddress) {
729 // Sender properties
730 $carac_emetteur = '';
731 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->address);
732 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->zip).' '.$outputlangs->convToOutputCharset($this->emetteur->town);
733 $carac_emetteur .= "\n";
734 if ($this->emetteur->phone) {
735 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Phone")." : ".$outputlangs->convToOutputCharset($this->emetteur->phone);
736 }
737 if ($this->emetteur->fax) {
738 $carac_emetteur .= ($carac_emetteur ? ($this->emetteur->tel ? " - " : "\n") : '').$outputlangs->transnoentities("Fax")." : ".$outputlangs->convToOutputCharset($this->emetteur->fax);
739 }
740 if ($this->emetteur->email) {
741 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($this->emetteur->email);
742 }
743 if ($this->emetteur->url) {
744 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Web")." : ".$outputlangs->convToOutputCharset($this->emetteur->url);
745 }
746
747 // Receiver Properties
748 $receiver = new User($this->db);
749 $receiver->fetch($object->fk_user_author);
750 $receiver_account = new UserBankAccount($this->db);
751 $receiver_account->fetch(0, '', $object->fk_user_author);
752 $expense_receiver = '';
753 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->address);
754 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->zip).' '.$outputlangs->convToOutputCharset($receiver->town);
755 $expense_receiver .= "\n";
756 if ($receiver->email) {
757 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($receiver->email);
758 }
759 if ($receiver_account->iban) {
760 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("IBAN")." : ".$outputlangs->convToOutputCharset($receiver_account->iban);
761 }
762
763 // Show sender
764 $posy = 50;
765 $posx = $this->marge_gauche;
766 $hautcadre = 40;
767 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
768 $posx = 118;
769 }
770
771 // Show sender frame
772 $pdf->SetTextColor(0, 0, 0);
773 $pdf->SetFont('', 'B', $default_font_size - 2);
774 $pdf->SetXY($posx, $posy - 5);
775 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripSociete"), '', 'L');
776 $pdf->SetXY($posx, $posy);
777 $pdf->SetFillColor(224, 224, 224);
778 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
779 $pdf->SetTextColor(0, 0, 60);
780
781 // Show sender information
782 if (empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
783 $pdf->SetXY($posx + 2, $posy + 3);
784 $pdf->SetFont('', 'B', $default_font_size);
785 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
786 $pdf->SetXY($posx + 2, $posy + 8);
787 $pdf->SetFont('', '', $default_font_size - 1);
788 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
789 } else {
790 $pdf->SetXY($posx + 2, $posy + 3);
791 $pdf->SetFont('', 'B', $default_font_size);
792 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset(dolGetFirstLastname($receiver->firstname, $receiver->lastname)), 0, 'L');
793 $pdf->SetXY($posx + 2, $posy + 8);
794 $pdf->SetFont('', '', $default_font_size - 1);
795 $pdf->MultiCell(80, 4, $expense_receiver, 0, 'L');
796 }
797
798 // Show recipient
799 $posy = 50;
800 $posx = 100;
801 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
802 $posx = $this->marge_gauche;
803 }
804
805 // Show recipient frame
806 $pdf->SetTextColor(0, 0, 0);
807 $pdf->SetFont('', 'B', 8);
808 $pdf->SetXY($posx, $posy - 5);
809 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L');
810 $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre);
811
812 // Informations for expense report (dates and users workflow)
813 if ($object->fk_user_author > 0) {
814 $userfee = new User($this->db);
815 $userfee->fetch($object->fk_user_author);
816 $posy += 3;
817 $pdf->SetXY($posx + 2, $posy);
818 $pdf->SetFont('', '', 10);
819 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
820 $posy = $pdf->GetY() + 1;
821 $pdf->SetXY($posx + 2, $posy);
822 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create, "day", false, $outputlangs), 0, 'L');
823 }
824
825 if ($object->fk_statut == 99) {
826 if ($object->fk_user_refuse > 0) {
827 $userfee = new User($this->db);
828 $userfee->fetch($object->fk_user_refuse);
829 $posy += 6;
830 $pdf->SetXY($posx + 2, $posy);
831 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
832 $posy += 5;
833 $pdf->SetXY($posx + 2, $posy);
834 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse), 0, 'L');
835 $posy += 5;
836 $pdf->SetXY($posx + 2, $posy);
837 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse, "day", false, $outputlangs), 0, 'L');
838 }
839 } elseif ($object->fk_statut == 4) {
840 if ($object->fk_user_cancel > 0) {
841 $userfee = new User($this->db);
842 $userfee->fetch($object->fk_user_cancel);
843 $posy += 6;
844 $pdf->SetXY($posx + 2, $posy);
845 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
846 $posy += 5;
847 $pdf->SetXY($posx + 2, $posy);
848 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel), 0, 'L');
849 $posy += 5;
850 $pdf->SetXY($posx + 2, $posy);
851 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel, "day", false, $outputlangs), 0, 'L');
852 }
853 } else {
854 if ($object->fk_user_approve > 0) {
855 $userfee = new User($this->db);
856 $userfee->fetch($object->fk_user_approve);
857 $posy += 6;
858 $pdf->SetXY($posx + 2, $posy);
859 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
860 $posy += 5;
861 $pdf->SetXY($posx + 2, $posy);
862 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs), 0, 'L');
863 }
864 }
865
866 if ($object->fk_statut == 6) {
867 if ($object->fk_user_paid > 0) {
868 $userfee = new User($this->db);
869 $userfee->fetch($object->fk_user_paid);
870 $posy += 6;
871 $pdf->SetXY($posx + 2, $posy);
872 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
873 $posy += 5;
874 $pdf->SetXY($posx + 2, $posy);
875 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement, "day", false, $outputlangs), 0, 'L');
876 }
877 }
878 }
879 }
880
881 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
895 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
896 {
897 global $conf;
898
899 // Force to disable hidetop and hidebottom
900 $hidebottom = 0;
901 if ($hidetop) {
902 $hidetop = -1;
903 }
904
905 $currency = !empty($currency) ? $currency : $conf->currency;
906 $default_font_size = pdf_getPDFFontSize($outputlangs);
907
908 // Amount in (at tab_top - 1)
909 $pdf->SetTextColor(0, 0, 0);
910 $pdf->SetFont('', '', $default_font_size - 2);
911 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
912 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 4), $tab_top - 4);
913 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
914
915 $pdf->SetDrawColor(128, 128, 128);
916
917 // Rect takes a length in 3rd parameter
918 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
919 // line prend une position y en 3eme param
920 if (empty($hidetop)) {
921 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
922 }
923
924 $pdf->SetFont('', '', 8);
925
926 // Accountancy piece
927 if (empty($hidetop)) {
928 $pdf->SetXY($this->posxpiece - 1, $tab_top + 1);
929 $pdf->MultiCell($this->posxcomment - $this->posxpiece - 0.8, 1, '', '', 'R');
930 }
931
932 // Comments
933 $pdf->line($this->posxcomment - 1, $tab_top, $this->posxcomment - 1, $tab_top + $tab_height);
934 if (empty($hidetop)) {
935 $pdf->SetXY($this->posxcomment - 1, $tab_top + 1);
936 $pdf->MultiCell($this->posxdate - $this->posxcomment - 0.8, 1, $outputlangs->transnoentities("Description"), '', 'L');
937 }
938
939 // Date
940 //$pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height);
941 //if (empty($hidetop))
942 //{
943 // $pdf->SetXY($this->posxdate-1, $tab_top+1);
944 // $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C');
945 //}
946
947 // Type
948 //$pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height);
949 //if (empty($hidetop))
950 //{
951 // $pdf->SetXY($this->posxtype-1, $tab_top+1);
952 // $pdf->MultiCell($this->posxprojet-$this->posxtype - 1, 2, $outputlangs->transnoentities("Type"), '', 'C');
953 //}
954
955 //if (isModEnabled('project'))
956 //{
957 // // Project
958 // $pdf->line($this->posxprojet - 1, $tab_top, $this->posxprojet - 1, $tab_top + $tab_height);
959 // if (empty($hidetop)) {
960 // $pdf->SetXY($this->posxprojet - 1, $tab_top + 1);
961 // $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 2, $outputlangs->transnoentities("Project"), '', 'C');
962 // }
963 //}
964
965 // VAT
966 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
967 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
968 if (empty($hidetop)) {
969 $pdf->SetXY($this->posxtva - 0.8, $tab_top + 1);
970 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C');
971 }
972 }
973
974 // Unit price
975 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
976 if (empty($hidetop)) {
977 $pdf->SetXY($this->posxup - 0.8, $tab_top + 1);
978 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUTTC"), '', 'C');
979 }
980
981 // Quantity
982 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
983 if (empty($hidetop)) {
984 $pdf->SetXY($this->posxqty - 0.8, $tab_top + 1);
985 $pdf->MultiCell($this->postotalht - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
986 }
987
988 // Total without taxes
989 $pdf->line($this->postotalht - 1, $tab_top, $this->postotalht - 1, $tab_top + $tab_height);
990 if (empty($hidetop)) {
991 $pdf->SetXY($this->postotalht - 0.8, $tab_top + 1);
992 $pdf->MultiCell($this->postotalttc - $this->postotalht + 1, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
993 }
994
995 // Total with all taxes
996 $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height);
997 if (empty($hidetop)) {
998 $pdf->SetXY($this->postotalttc - 0.8, $tab_top + 1);
999 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R');
1000 }
1001
1002 $pdf->SetTextColor(0, 0, 0);
1003 }
1004
1014 protected function tablePayments(&$pdf, $object, $posy, $outputlangs)
1015 {
1016 global $conf;
1017
1018 $sign = 1;
1019 $tab3_posx = $this->marge_gauche;
1020 $tab3_top = $posy;
1021 $tab3_width = 88;
1022 $tab3_height = 5;
1023
1024 $default_font_size = pdf_getPDFFontSize($outputlangs);
1025
1026 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1027 $pdf->SetFont('', '', $default_font_size - 2);
1028 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1029 $pdf->SetTextColor(0, 0, 0);
1030 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1031
1032 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width + 2, $tab3_top); // Top border line of table title
1033
1034 $pdf->SetXY($tab3_posx, $tab3_top + 1);
1035 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Date"), 0, 'L', 0);
1036 $pdf->SetXY($tab3_posx + 19, $tab3_top + 1); // Old value 17
1037 $pdf->MultiCell(15, 3, $outputlangs->transnoentities("Amount"), 0, 'C', 0);
1038 $pdf->SetXY($tab3_posx + 35, $tab3_top + 1);
1039 $pdf->MultiCell(30, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1040 if (isModEnabled("banque")) {
1041 $pdf->SetXY($tab3_posx + 65, $tab3_top + 1);
1042 $pdf->MultiCell(25, 3, $outputlangs->transnoentities("BankAccount"), 0, 'L', 0);
1043 }
1044 $pdf->line($tab3_posx, $tab3_top + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $tab3_height); // Bottom border line of table title
1045
1046 $y = 0;
1047
1048 // Loop on each payment
1049 // TODO create method on expensereport class to get payments
1050 // Payments already done (from payment on this expensereport)
1051 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1052 $sql .= "c.code as p_code, c.libelle as payment_type,";
1053 $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1054 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1055 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1056 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1057 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1058 $sql .= " WHERE e.rowid = ".((int) $object->id);
1059 $sql .= " AND p.fk_expensereport = e.rowid";
1060 $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
1061 $sql .= " ORDER BY dp";
1062
1063 $resql = $this->db->query($sql);
1064 if ($resql) {
1065 $num = $this->db->num_rows($resql);
1066 $totalpaid = 0;
1067 $i = 0;
1068 while ($i < $num) {
1069 $y += $tab3_height;
1070 $row = $this->db->fetch_object($resql);
1071
1072 $pdf->SetXY($tab3_posx, $tab3_top + $y + 1);
1073 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->dp), 'day', false, $outputlangs, true), 0, 'L', 0);
1074 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y + 1);
1075 $pdf->MultiCell(15, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'R', 0);
1076 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y + 1);
1077 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->p_code);
1078
1079 $pdf->MultiCell(40, 3, $oper, 0, 'L', 0);
1080 if (isModEnabled("banque")) {
1081 $pdf->SetXY($tab3_posx + 65, $tab3_top + $y + 1);
1082 $pdf->MultiCell(30, 3, $row->baref, 0, 'L', 0);
1083 }
1084
1085 $pdf->line($tab3_posx, $tab3_top + $y + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $y + $tab3_height); // Bottom line border of table
1086 $totalpaid += $row->amount;
1087 $i++;
1088 }
1089 if ($num > 0 && $object->paid == 0) {
1090 $y += $tab3_height;
1091
1092 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1093 $pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
1094 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1095 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AlreadyPaid"), 0, 'L', 0);
1096 $y += $tab3_height - 2;
1097 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1098 $pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
1099 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1100 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AmountExpected"), 0, 'L', 0);
1101 $y += $tab3_height - 2;
1102 $remaintopay = $object->total_ttc - $totalpaid;
1103 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1104 $pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
1105 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1106 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("RemainderToPay"), 0, 'L', 0);
1107 }
1108 } else {
1109 $this->error = $this->db->lasterror();
1110 return -1;
1111 }
1112 return -1;
1113 }
1114
1115 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1125 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1126 {
1127 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1128 return pdf_pagefoot($pdf, $outputlangs, 'EXPENSEREPORT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1129 }
1130}
Class to manage hooks.
Parent class for trips and expenses templates.
Class to manage bank accounts description of users.
Class to manage Dolibarr users.
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return 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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:85
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1010
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1839
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
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:758
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:778
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123