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