dolibarr 18.0.6
pdf_standard.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
3 * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
5 * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
29require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
30require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/functionsnumtoword.lib.php';
35
36
41{
45 public $db;
46
50 public $name;
51
55 public $description;
56
60 public $update_main_doc_field;
61
65 public $type;
66
71 public $version = 'dolibarr';
72
77 public $emetteur;
78
79 public $posxdate;
80 public $posxreffacturefourn;
81 public $posxreffacture;
82 public $posxtype;
83 public $posxtotalht;
84 public $posxtva;
85 public $posxtotalttc;
86
87
93 public function __construct($db)
94 {
95 global $langs, $mysoc;
96
97 // Load translation files required by the page
98 $langs->loadLangs(array("main", "bills"));
99
100 $this->db = $db;
101 $this->name = "standard";
102 $this->description = $langs->trans('DocumentModelStandardPDF');
103 $this->update_main_doc_field = 0; // Save the name of generated file as the main doc when generating a doc with this template
104
105 // Page size for A4 format
106 $this->type = 'pdf';
107 $formatarray = pdf_getFormat();
108 $this->page_largeur = $formatarray['width'];
109 $this->page_hauteur = $formatarray['height'];
110 $this->format = array($this->page_largeur, $this->page_hauteur);
111 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
112 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
113 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
114 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
115
116 $this->option_logo = 1; // Display logo
117 $this->option_multilang = 1; // Available in several languages
118
119 // Define column position
120 $this->posxdate = $this->marge_gauche + 1;
121 $this->posxreffacturefourn = 30;
122 $this->posxreffacture = 65;
123 $this->posxtype = 100;
124 $this->posxtotalht = 80;
125 $this->posxtva = 90;
126 $this->posxtotalttc = 180;
127
128 if ($this->page_largeur < 210) { // To work with US executive format
129 $this->posxreffacturefourn -= 20;
130 $this->posxreffacture -= 20;
131 $this->posxtype -= 20;
132 $this->posxtotalht -= 20;
133 $this->posxtva -= 20;
134 $this->posxtotalttc -= 20;
135 }
136
137 $this->tva = array();
138 $this->tva_array = array();
139 $this->localtax1 = array();
140 $this->localtax2 = array();
141 $this->atleastoneratenotnull = 0;
142 $this->atleastonediscount = 0;
143
144 // Get source company
145 $this->emetteur = $mysoc;
146 if (!$this->emetteur->country_code) {
147 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
148 }
149 }
150
151
152 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
164 public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
165 {
166 // phpcs:enable
167 global $user, $langs, $conf, $mysoc, $hookmanager;
168
169 if (!is_object($outputlangs)) {
170 $outputlangs = $langs;
171 }
172 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
173 if (!empty($conf->global->MAIN_USE_FPDF)) {
174 $outputlangs->charset_output = 'ISO-8859-1';
175 }
176
177 // Load translation files required by the page
178 $outputlangs->loadLangs(array("main", "suppliers", "companies", "bills", "dict", "products"));
179
180 $object->factures = array();
181
182 if ($conf->fournisseur->payment->dir_output) {
183 $object->fetch_thirdparty();
187 $sql = 'SELECT f.rowid, f.ref, f.datef, f.ref_supplier, f.total_ht, f.total_tva, f.total_ttc, pf.amount, f.rowid as facid, f.paye';
188 $sql .= ', f.fk_statut, s.nom as name, s.rowid as socid';
189 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
190 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
191 $sql .= ' AND pf.fk_paiementfourn = '.((int) $object->id);
192 $resql = $this->db->query($sql);
193 if ($resql) {
194 if ($this->db->num_rows($resql) > 0) {
195 while ($objp = $this->db->fetch_object($resql)) {
196 $objp->type = $outputlangs->trans('SupplierInvoice');
197 $object->lines[] = $objp;
198 }
199 }
200 }
201
202 $total = $object->amount;
203
204 // Definition of $dir and $file
205 if ($object->specimen) {
206 $dir = $conf->fournisseur->payment->dir_output;
207 $file = $dir."/SPECIMEN.pdf";
208 } else {
209 $objectref = dol_sanitizeFileName($object->ref);
210 //$objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
211 $dir = $conf->fournisseur->payment->dir_output.'/'.$objectref;
212 $file = $dir."/".$objectref.".pdf";
213 //if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
214 // $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
215 //}
216 }
217
218 if (!file_exists($dir)) {
219 if (dol_mkdir($dir) < 0) {
220 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
221 return 0;
222 }
223 }
224
225 if (file_exists($dir)) {
226 // Add pdfgeneration hook
227 if (!is_object($hookmanager)) {
228 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
229 $hookmanager = new HookManager($this->db);
230 }
231 $hookmanager->initHooks(array('pdfgeneration'));
232 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
233 global $action;
234 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
235
236 $nblines = (empty($object->lines) ? 0 : count($object->lines));
237
238 $pdf = pdf_getInstance($this->format);
239 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
240 $heightforinfotot = 50; // Height reserved to output the info and total part
241 $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
242 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
243 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
244 $heightforfooter += 6;
245 }
246 $pdf->SetAutoPageBreak(1, 0);
247
248 if (class_exists('TCPDF')) {
249 $pdf->setPrintHeader(false);
250 $pdf->setPrintFooter(false);
251 }
252 $pdf->SetFont(pdf_getPDFFont($outputlangs));
253 // Set path to the background PDF File
254 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
255 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
256 $tplidx = $pdf->importPage(1);
257 }
258
259 $pdf->Open();
260 $pagenb = 0;
261 $pdf->SetDrawColor(128, 128, 128);
262
263 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
264 $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
265 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
266 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
267 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
268 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
269 $pdf->SetCompression(false);
270 }
271
272 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
273
274
275 // New page
276 $pdf->AddPage();
277 if (!empty($tplidx)) {
278 $pdf->useTemplate($tplidx);
279 }
280 $pagenb++;
281 $this->_pagehead($pdf, $object, 1, $outputlangs);
282 $pdf->SetFont('', '', $default_font_size - 1);
283 $pdf->MultiCell(0, 3, ''); // Set interline to 3
284 $pdf->SetTextColor(0, 0, 0);
285
286 $tab_top = 90;
287 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
288
289 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
290
291 // Incoterm
292 $height_incoterms = 0;
293
294 $height_note = 0;
295
296 $iniY = $tab_top + 7;
297 $curY = $tab_top + 7;
298 $nexY = $tab_top + 7;
299
300 // Loop on each lines
301 for ($i = 0; $i < $nblines; $i++) {
302 $curY = $nexY;
303 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
304 $pdf->SetTextColor(0, 0, 0);
305
306 $pdf->setTopMargin($tab_top_newpage);
307 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
308 $pageposbefore = $pdf->getPage();
309
310 // Description of product line
311 $curX = $this->posxdate - 1;
312 $showpricebeforepagebreak = 1;
313
314 $pdf->startTransaction();
315 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,1);
316 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
317 $pageposafter = $pdf->getPage();
318 if ($pageposafter > $pageposbefore) { // There is a pagebreak
319 $pdf->rollbackTransaction(true);
320 $pageposafter = $pageposbefore;
321 //print $pageposafter.'-'.$pageposbefore;exit;
322 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
323 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
324 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
325 $posyafter = $pdf->GetY();
326 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
327 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
328 $pdf->AddPage('', '', true);
329 if (!empty($tplidx)) {
330 $pdf->useTemplate($tplidx);
331 }
332 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
333 $this->_pagehead($pdf, $object, 0, $outputlangs);
334 }
335 $pdf->setPage($pageposafter + 1);
336 }
337 } else {
338 // We found a page break
339 // Allows data in the first page if description is long enough to break in multiples pages
340 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
341 $showpricebeforepagebreak = 1;
342 } else {
343 $showpricebeforepagebreak = 0;
344 }
345 }
346 } else // No pagebreak
347 {
348 $pdf->commitTransaction();
349 }
350
351 $nexY = $pdf->GetY();
352 $pageposafter = $pdf->getPage();
353 $pdf->setPage($pageposbefore);
354 $pdf->setTopMargin($this->marge_haute);
355 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
356
357 // We suppose that a too long description is moved completely on next page
358 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
359 $pdf->setPage($pageposafter);
360 $curY = $tab_top_newpage;
361 }
362
363 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
364
365 // ref fourn
366 $pdf->SetXY($this->posxreffacturefourn, $curY);
367 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0, 'L', 0);
368
369 // ref facture fourn
370 $pdf->SetXY($this->posxreffacture, $curY);
371 $pdf->MultiCell($this->posxreffacture - 0.8, 3, $object->lines[$i]->ref, 0, 'L', 0);
372
373 // type
374 $pdf->SetXY($this->posxtype, $curY);
375 $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0, 'L', 0);
376
377 // Total ht
378 $pdf->SetXY($this->posxtotalht, $curY);
379 $pdf->MultiCell($this->posxtotalht - 0.8, 3, price($object->lines[$i]->total_ht), 0, 'R', 0);
380
381 // Total tva
382 $pdf->SetXY($this->posxtva, $curY);
383 $pdf->MultiCell($this->posxtva - 0.8, 3, price($object->lines[$i]->total_tva), 0, 'R', 0);
384
385 // Total TTC line
386 $pdf->SetXY($this->posxtotalttc, $curY);
387 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R', 0);
388
389
390 // Add line
391 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
392 $pdf->setPage($pageposafter);
393 $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
394 //$pdf->SetDrawColor(190,190,200);
395 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
396 $pdf->SetLineStyle(array('dash'=>0));
397 }
398
399 $nexY += 2; // Add space between lines
400
401 // Detect if some page were added automatically and output _tableau for past pages
402 while ($pagenb < $pageposafter) {
403 $pdf->setPage($pagenb);
404 if ($pagenb == 1) {
405 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
406 } else {
407 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
408 }
409 $this->_pagefoot($pdf, $object, $outputlangs, 1);
410 $pagenb++;
411 $pdf->setPage($pagenb);
412 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
413 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
414 $this->_pagehead($pdf, $object, 0, $outputlangs);
415 }
416 if (!empty($tplidx)) {
417 $pdf->useTemplate($tplidx);
418 }
419 }
420 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
421 if ($pagenb == 1) {
422 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
423 } else {
424 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
425 }
426 $this->_pagefoot($pdf, $object, $outputlangs, 1);
427 // New page
428 $pdf->AddPage();
429 if (!empty($tplidx)) {
430 $pdf->useTemplate($tplidx);
431 }
432 $pagenb++;
433 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
434 $this->_pagehead($pdf, $object, 0, $outputlangs);
435 }
436 }
437 }
438
439 // Show square
440 if ($pagenb == 1) {
441 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
442 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
443 } else {
444 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
445 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
446 }
447
448 // Display check zone
449 $posy = $this->_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
450
451 // Affiche zone totaux
452 //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
453
454 // Footer page
455 $this->_pagefoot($pdf, $object, $outputlangs);
456 if (method_exists($pdf, 'AliasNbPages')) {
457 $pdf->AliasNbPages();
458 }
459
460 $pdf->Close();
461
462 $pdf->Output($file, 'F');
463
464 // Add pdfgeneration hook
465 $hookmanager->initHooks(array('pdfgeneration'));
466 $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
467 global $action;
468 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
469 if ($reshook < 0) {
470 $this->error = $hookmanager->error;
471 $this->errors = $hookmanager->errors;
472 }
473
474 dolChmod($file);
475
476 $this->result = array('fullpath'=>$file);
477
478 return 1; // No error
479 } else {
480 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
481 return 0;
482 }
483 } else {
484 $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
485 return 0;
486 }
487 }
488
489 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
490 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
500 protected function _tableau_cheque(&$pdf, $object, $posy, $outputlangs)
501 {
502 // phpcs:enable
503 global $conf, $mysoc;
504
505 $default_font_size = pdf_getPDFFontSize($outputlangs);
506
507 $pdf->SetFont('', '', $default_font_size - 1);
508 $pdf->SetFillColor(255, 255, 255);
509
510 // N° payment
511 $pdf->SetXY($this->marge_gauche, $posy);
512 $pdf->MultiCell(30, 4, 'N° '.$outputlangs->transnoentities("Payment"), 0, 'L', 1);
513
514 // Ref payment
515 $pdf->SetXY($this->marge_gauche + 30, $posy);
516 $pdf->MultiCell(50, 4, $object->ref, 0, 'L', 1);
517
518 // Total payments
519 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
520 $pdf->MultiCell(50, 4, price($object->amount), 0, 'R', 1);
521 $posy += 20;
522
523 // translate amount
524 $currency = $conf->currency;
525 $translateinletter = strtoupper(dol_convertToWord(price2num($object->amount, 'MT'), $outputlangs, $currency));
526 $pdf->SetXY($this->marge_gauche + 50, $posy);
527 $pdf->SetFont('', '', $default_font_size - 3);
528 $pdf->MultiCell(90, 8, $translateinletter, 0, 'L', 1);
529 $pdf->SetFont('', '', $default_font_size - 1);
530 $posy += 8;
531
532 // To
533 $pdf->SetXY($this->marge_gauche + 50, $posy);
534 $pdf->MultiCell(150, 4, $object->thirdparty->nom, 0, 'L', 1);
535
536 $LENGTHAMOUNT = 35;
537 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
538 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(price($object->amount).' '.$currency, 18, '*', STR_PAD_LEFT), 0, 'R', 1);
539 $posy += 10;
540
541 // City
542 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
543 $pdf->MultiCell(150, 4, $mysoc->town, 0, 'L', 1);
544 $posy += 4;
545
546 // Date
547 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
548 $pdf->MultiCell(150, 4, date("d").' '.$outputlangs->transnoentitiesnoconv(date("F")).' '.date("Y"), 0, 'L', 1);
549 return $posy;
550 }
551
552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
566 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
567 {
568 global $conf, $mysoc;
569
570 // Force to disable hidetop and hidebottom
571 $hidebottom = 0;
572 if ($hidetop) {
573 $hidetop = -1;
574 }
575
576 $currency = !empty($currency) ? $currency : $conf->currency;
577 $default_font_size = pdf_getPDFFontSize($outputlangs);
578
579 // Amount in (at tab_top - 1)
580 $pdf->SetTextColor(0, 0, 0);
581 $pdf->SetFont('', '', $default_font_size - 2);
582
583 /*$titre = strtoupper($mysoc->town).' - '.dol_print_date(dol_now(), 'day', 'tzserver', $outputlangs);
584 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3) - 60, $tab_top - 6);
585 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);*/
586
587 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
588 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
589 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
590
591
592 $pdf->SetDrawColor(128, 128, 128);
593 $pdf->SetFont('', '', $default_font_size - 1);
594
595 // Output Rect
596 //$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
597 }
598
599 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
609 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
610 {
611 global $langs, $conf, $mysoc;
612
613 // Load translation files required by the page
614 $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
615
616 $default_font_size = pdf_getPDFFontSize($outputlangs);
617
618 // Do not add the BACKGROUND as this is for suppliers
619 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
620
621 $pdf->SetTextColor(0, 0, 60);
622 $pdf->SetFont('', 'B', $default_font_size + 3);
623
624 $posy = $this->marge_haute;
625 $posx = $this->page_largeur - $this->marge_droite - 100;
626
627 $pdf->SetXY($this->marge_gauche, $posy);
628
629 // Logo
630 $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
631 if ($mysoc->logo) {
632 if (is_readable($logo)) {
633 $height = pdf_getHeightForLogo($logo);
634 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
635 } else {
636 $pdf->SetTextColor(200, 0, 0);
637 $pdf->SetFont('', 'B', $default_font_size - 2);
638 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
639 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
640 }
641 } else {
642 $text = $this->emetteur->name;
643 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
644 }
645 /*
646 $pdf->SetFont('','B', $default_font_size + 3);
647 $pdf->SetXY($posx,$posy);
648 $pdf->SetTextColor(0,0,60);
649 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
650 $posy+=1;
651
652 if ($object->ref_supplier)
653 {
654 $posy+=4;
655 $pdf->SetFont('','B', $default_font_size);
656 $pdf->SetXY($posx,$posy);
657 $pdf->SetTextColor(0,0,60);
658 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
659 $posy+=1;
660 }
661
662 $pdf->SetFont('','', $default_font_size - 1);
663
664 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
665 $object->fetch_projet();
666 if (!empty($object->project->ref)) {
667 $posy += 3;
668 $pdf->SetXY($posx, $posy);
669 $pdf->SetTextColor(0, 0, 60);
670 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
671 }
672 }
673
674 if (!empty($conf->global->PDF_SHOW_PROJECT))
675 {
676 $object->fetch_projet();
677 if (!empty($object->project->ref))
678 {
679 $outputlangs->load("projects");
680 $posy+=4;
681 $pdf->SetXY($posx,$posy);
682 $langs->load("projects");
683 $pdf->SetTextColor(0,0,60);
684 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->project->ref), '', 'R');
685 }
686 }
687
688 if ($object->date)
689 {
690 $posy+=4;
691 $pdf->SetXY($posx,$posy);
692 $pdf->SetTextColor(0,0,60);
693 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
694 }
695 else
696 {
697 $posy+=4;
698 $pdf->SetXY($posx,$posy);
699 $pdf->SetTextColor(255,0,0);
700 $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
701 }
702
703 if ($object->thirdparty->code_fournisseur)
704 {
705 $posy+=4;
706 $pdf->SetXY($posx,$posy);
707 $pdf->SetTextColor(0,0,60);
708 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
709 }
710
711 $posy+=1;
712 $pdf->SetTextColor(0,0,60);
713
714 // Show list of linked objects
715 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
716 */
717 if ($showaddress) {
718 // Sender properties
719 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
720
721 // Show payer
722 $posy = 42;
723 $posx = $this->marge_gauche;
724 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
725 $posx = $this->page_largeur - $this->marge_droite - 80;
726 }
727 $hautcadre = 40;
728
729 // Show sender frame
730 $pdf->SetTextColor(0, 0, 0);
731 $pdf->SetFont('', '', $default_font_size - 2);
732 $pdf->SetXY($posx, $posy - 5);
733 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("PayedBy"), 0, 'L');
734 $pdf->SetXY($posx, $posy);
735 $pdf->SetFillColor(230, 230, 230);
736 $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
737 $pdf->SetTextColor(0, 0, 60);
738
739 // Show sender name
740 $pdf->SetXY($posx + 2, $posy + 3);
741 $pdf->SetFont('', 'B', $default_font_size);
742 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
743 $posy = $pdf->getY();
744
745 // Show sender information
746 $pdf->SetXY($posx + 2, $posy);
747 $pdf->SetFont('', '', $default_font_size - 1);
748 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
749
750 // Paid
751 $thirdparty = $object->thirdparty;
752
753 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
754
755 $usecontact = 0;
756
757 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
758
759 // Show recipient
760 $widthrecbox = 90;
761 if ($this->page_largeur < 210) {
762 $widthrecbox = 84; // To work with US executive format
763 }
764 $posy = 42;
765 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
766 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
767 $posx = $this->marge_gauche;
768 }
769
770 // Show recipient frame
771 $pdf->SetTextColor(0, 0, 0);
772 $pdf->SetFont('', '', $default_font_size - 2);
773 $pdf->SetXY($posx + 2, $posy - 5);
774 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("PayedTo"), 0, 'L');
775 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
776
777 // Show recipient name
778 $pdf->SetXY($posx + 2, $posy + 3);
779 $pdf->SetFont('', 'B', $default_font_size);
780 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
781
782 $posy = $pdf->getY();
783
784 // Show recipient information
785 $pdf->SetFont('', '', $default_font_size - 1);
786 $pdf->SetXY($posx + 2, $posy);
787 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
788
789 // Show default IBAN account
790 $iban = '';
791 $sql = "SELECT iban_prefix as iban";
792 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as rib";
793 $sql .= " WHERE fk_soc = ".($object->thirdparty->id);
794 $sql .= " AND rib.default_rib = 1";
795 $sql .= " AND rib.type = 'ban'";
796 $sql .= " LIMIT 1";
797 $resql = $this->db->query($sql);
798 if ($resql) {
799 $obj = $this->db->fetch_object($resql);
800 if ($obj) {
801 $iban = $obj->iban;
802 }
803 }
804
805 if (!empty($iban)) {
806 $pdf->SetFont('', '', $default_font_size - 1);
807 $pdf->SetXY($posx + 2, $posy + 15);
808 $pdf->MultiCell($widthrecbox, 4, $langs->trans("IBAN").': '.$iban, 0, 'L');
809 }
810 }
811 }
812
813 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
823 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
824 {
825 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
826 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
827 }
828}
Class to manage hooks.
Parent class for supplier invoices models.
Class to generate expense report based on standard model.
__construct($db)
Constructor.
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_cheque(&$pdf, $object, $posy, $outputlangs)
Show total to pay.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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 dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
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_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition pdf.lib.php:435
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:387
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