dolibarr  18.0.0-alpha
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(7, 0);
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 = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
118  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
119  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
120  $this->marge_basse = getDolGlobalInt('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 (getDolGlobalString('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 = (!getDolGlobalInt('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 (!getDolGlobalInt('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 (!getDolGlobalInt('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 (!getDolGlobalInt('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  dolChmod($file);
482 
483  $this->result = array('fullpath'=>$file);
484 
485  return 1; // No error
486  } else {
487  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
488  return 0;
489  }
490  } else {
491  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
492  return 0;
493  }
494  }
495 
496  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
497  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
507  protected function _tableau_cheque(&$pdf, $object, $posy, $outputlangs)
508  {
509  // phpcs:enable
510  global $conf, $mysoc;
511 
512  $default_font_size = pdf_getPDFFontSize($outputlangs);
513 
514  $pdf->SetFont('', '', $default_font_size - 1);
515  $pdf->SetFillColor(255, 255, 255);
516 
517  // N° payment
518  $pdf->SetXY($this->marge_gauche, $posy);
519  $pdf->MultiCell(30, 4, 'N° '.$outputlangs->transnoentities("Payment"), 0, 'L', 1);
520 
521  // Ref payment
522  $pdf->SetXY($this->marge_gauche + 30, $posy);
523  $pdf->MultiCell(50, 4, $object->ref, 0, 'L', 1);
524 
525  // Total payments
526  $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
527  $pdf->MultiCell(50, 4, price($object->amount), 0, 'R', 1);
528  $posy += 20;
529 
530  // translate amount
531  $currency = $conf->currency;
532  $translateinletter = strtoupper(dol_convertToWord($object->amount, $outputlangs, $currency));
533  $pdf->SetXY($this->marge_gauche + 50, $posy);
534  $pdf->MultiCell(90, 8, $translateinletter, 0, 'L', 1);
535  $posy += 8;
536 
537  // To
538  $pdf->SetXY($this->marge_gauche + 50, $posy);
539  $pdf->MultiCell(150, 4, $object->thirdparty->nom, 0, 'L', 1);
540 
541  $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
542  $pdf->MultiCell(35, 4, str_pad(price($object->amount).' '.$currency, 18, '*', STR_PAD_LEFT), 0, 'R', 1);
543  $posy += 10;
544 
545  // City
546  $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
547  $pdf->MultiCell(150, 4, $mysoc->town, 0, 'L', 1);
548  $posy += 4;
549 
550  // Date
551  $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
552  $pdf->MultiCell(150, 4, date("d").' '.$outputlangs->transnoentitiesnoconv(date("F")).' '.date("Y"), 0, 'L', 1);
553  }
554 
555  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
569  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
570  {
571  global $conf, $mysoc;
572 
573  // Force to disable hidetop and hidebottom
574  $hidebottom = 0;
575  if ($hidetop) {
576  $hidetop = -1;
577  }
578 
579  $currency = !empty($currency) ? $currency : $conf->currency;
580  $default_font_size = pdf_getPDFFontSize($outputlangs);
581 
582  // Amount in (at tab_top - 1)
583  $pdf->SetTextColor(0, 0, 0);
584  $pdf->SetFont('', '', $default_font_size - 2);
585 
586  /*$titre = strtoupper($mysoc->town).' - '.dol_print_date(dol_now(), 'day', 'tzserver', $outputlangs);
587  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3) - 60, $tab_top - 6);
588  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);*/
589 
590  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
591  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
592  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
593 
594 
595  $pdf->SetDrawColor(128, 128, 128);
596  $pdf->SetFont('', '', $default_font_size - 1);
597 
598  // Output Rect
599  //$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
600  }
601 
602  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
612  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
613  {
614  global $langs, $conf, $mysoc;
615 
616  // Load translation files required by the page
617  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
618 
619  $default_font_size = pdf_getPDFFontSize($outputlangs);
620 
621  // Do not add the BACKGROUND as this is for suppliers
622  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
623 
624  $pdf->SetTextColor(0, 0, 60);
625  $pdf->SetFont('', 'B', $default_font_size + 3);
626 
627  $posy = $this->marge_haute;
628  $posx = $this->page_largeur - $this->marge_droite - 100;
629 
630  $pdf->SetXY($this->marge_gauche, $posy);
631 
632  // Logo
633  $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
634  if ($mysoc->logo) {
635  if (is_readable($logo)) {
636  $height = pdf_getHeightForLogo($logo);
637  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
638  } else {
639  $pdf->SetTextColor(200, 0, 0);
640  $pdf->SetFont('', 'B', $default_font_size - 2);
641  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
642  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
643  }
644  } else {
645  $text = $this->emetteur->name;
646  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
647  }
648  /*
649  $pdf->SetFont('','B', $default_font_size + 3);
650  $pdf->SetXY($posx,$posy);
651  $pdf->SetTextColor(0,0,60);
652  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
653  $posy+=1;
654 
655  if ($object->ref_supplier)
656  {
657  $posy+=4;
658  $pdf->SetFont('','B', $default_font_size);
659  $pdf->SetXY($posx,$posy);
660  $pdf->SetTextColor(0,0,60);
661  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
662  $posy+=1;
663  }
664 
665  $pdf->SetFont('','', $default_font_size - 1);
666 
667  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
668  $object->fetch_projet();
669  if (!empty($object->project->ref)) {
670  $posy += 3;
671  $pdf->SetXY($posx, $posy);
672  $pdf->SetTextColor(0, 0, 60);
673  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
674  }
675  }
676 
677  if (!empty($conf->global->PDF_SHOW_PROJECT))
678  {
679  $object->fetch_projet();
680  if (!empty($object->project->ref))
681  {
682  $outputlangs->load("projects");
683  $posy+=4;
684  $pdf->SetXY($posx,$posy);
685  $langs->load("projects");
686  $pdf->SetTextColor(0,0,60);
687  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->project->ref), '', 'R');
688  }
689  }
690 
691  if ($object->date)
692  {
693  $posy+=4;
694  $pdf->SetXY($posx,$posy);
695  $pdf->SetTextColor(0,0,60);
696  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
697  }
698  else
699  {
700  $posy+=4;
701  $pdf->SetXY($posx,$posy);
702  $pdf->SetTextColor(255,0,0);
703  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
704  }
705 
706  if ($object->thirdparty->code_fournisseur)
707  {
708  $posy+=4;
709  $pdf->SetXY($posx,$posy);
710  $pdf->SetTextColor(0,0,60);
711  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
712  }
713 
714  $posy+=1;
715  $pdf->SetTextColor(0,0,60);
716 
717  // Show list of linked objects
718  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
719  */
720  if ($showaddress) {
721  // Sender properties
722  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
723 
724  // Show payer
725  $posy = 42;
726  $posx = $this->marge_gauche;
727  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
728  $posx = $this->page_largeur - $this->marge_droite - 80;
729  }
730  $hautcadre = 40;
731 
732  // Show sender frame
733  $pdf->SetTextColor(0, 0, 0);
734  $pdf->SetFont('', '', $default_font_size - 2);
735  $pdf->SetXY($posx, $posy - 5);
736  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("PayedBy"), 0, 'L');
737  $pdf->SetXY($posx, $posy);
738  $pdf->SetFillColor(230, 230, 230);
739  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
740  $pdf->SetTextColor(0, 0, 60);
741 
742  // Show sender name
743  $pdf->SetXY($posx + 2, $posy + 3);
744  $pdf->SetFont('', 'B', $default_font_size);
745  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
746  $posy = $pdf->getY();
747 
748  // Show sender information
749  $pdf->SetXY($posx + 2, $posy);
750  $pdf->SetFont('', '', $default_font_size - 1);
751  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
752 
753  // Paid
754  $thirdparty = $object->thirdparty;
755 
756  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
757 
758  $usecontact = 0;
759 
760  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
761 
762  // Show recipient
763  $widthrecbox = 90;
764  if ($this->page_largeur < 210) {
765  $widthrecbox = 84; // To work with US executive format
766  }
767  $posy = 42;
768  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
769  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
770  $posx = $this->marge_gauche;
771  }
772 
773  // Show recipient frame
774  $pdf->SetTextColor(0, 0, 0);
775  $pdf->SetFont('', '', $default_font_size - 2);
776  $pdf->SetXY($posx + 2, $posy - 5);
777  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("PayedTo"), 0, 'L');
778  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
779 
780  // Show recipient name
781  $pdf->SetXY($posx + 2, $posy + 3);
782  $pdf->SetFont('', 'B', $default_font_size);
783  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
784 
785  $posy = $pdf->getY();
786 
787  // Show recipient information
788  $pdf->SetFont('', '', $default_font_size - 1);
789  $pdf->SetXY($posx + 2, $posy);
790  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
791 
792  // Show default IBAN account
793  $sql = "SELECT iban_prefix as iban";
794  $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as rib";
795  $sql .= " WHERE fk_soc = ".($object->thirdparty->id);
796  $sql .= " AND rib.default_rib = 1";
797  $sql .= " AND rib.type = 'ban'";
798  $sql .= " LIMIT 1";
799  $resql = $this->db->query($sql);
800  if ($resql) {
801  $obj = $this->db->fetch_object($resql);
802  $iban = $obj->iban;
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 }
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:1236
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:25
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
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
dolChmod
dolChmod($filepath, $newmask='')
Change mod of a file.
Definition: functions.lib.php:6882
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:434
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
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:507
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
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:5708
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
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:996