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