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