dolibarr  20.0.0-beta
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 $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 = null, $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  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
267  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
268 
269 
270  // New page
271  $pdf->AddPage();
272  if (!empty($tplidx)) {
273  $pdf->useTemplate($tplidx);
274  }
275  $pagenb++;
276  $this->_pagehead($pdf, $object, 1, $outputlangs);
277  $pdf->SetFont('', '', $default_font_size - 1);
278  $pdf->MultiCell(0, 3, ''); // Set interline to 3
279  $pdf->SetTextColor(0, 0, 0);
280 
281  $tab_top = 90;
282  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
283 
284  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
285 
286  // Incoterm
287  $height_incoterms = 0;
288 
289  $height_note = 0;
290 
291  $iniY = $tab_top + 7;
292  $curY = $tab_top + 7;
293  $nexY = $tab_top + 7;
294 
295  // Loop on each lines
296  for ($i = 0; $i < $nblines; $i++) {
297  $curY = $nexY;
298  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
299  $pdf->SetTextColor(0, 0, 0);
300 
301  $pdf->setTopMargin($tab_top_newpage);
302  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
303  $pageposbefore = $pdf->getPage();
304 
305  // Description of product line
306  $curX = $this->posxdate - 1;
307  $showpricebeforepagebreak = 1;
308 
309  $pdf->startTransaction();
310  //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,1);
311  $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
312  $pageposafter = $pdf->getPage();
313  if ($pageposafter > $pageposbefore) { // There is a pagebreak
314  $pdf->rollbackTransaction(true);
315  $pageposafter = $pageposbefore;
316  //print $pageposafter.'-'.$pageposbefore;exit;
317  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
318  //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
319  $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
320  $posyafter = $pdf->GetY();
321  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
322  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
323  $pdf->AddPage('', '', true);
324  if (!empty($tplidx)) {
325  $pdf->useTemplate($tplidx);
326  }
327  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
328  $this->_pagehead($pdf, $object, 0, $outputlangs);
329  }
330  $pdf->setPage($pageposafter + 1);
331  }
332  } else {
333  // We found a page break
334  // Allows data in the first page if description is long enough to break in multiples pages
335  if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
336  $showpricebeforepagebreak = 1;
337  } else {
338  $showpricebeforepagebreak = 0;
339  }
340  }
341  } else { // No pagebreak
342  $pdf->commitTransaction();
343  }
344 
345  $nexY = $pdf->GetY();
346  $pageposafter = $pdf->getPage();
347  $pdf->setPage($pageposbefore);
348  $pdf->setTopMargin($this->marge_haute);
349  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
350 
351  // We suppose that a too long description is moved completely on next page
352  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
353  $pdf->setPage($pageposafter);
354  $curY = $tab_top_newpage;
355  }
356 
357  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
358 
359  // ref fourn
360  $pdf->SetXY($this->posxreffacturefourn, $curY);
361  $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0, 'L', 0);
362 
363  // ref facture fourn
364  $pdf->SetXY($this->posxreffacture, $curY);
365  $pdf->MultiCell($this->posxreffacture - 0.8, 3, $object->lines[$i]->ref, 0, 'L', 0);
366 
367  // type
368  $pdf->SetXY($this->posxtype, $curY);
369  $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0, 'L', 0);
370 
371  // Total ht
372  $pdf->SetXY($this->posxtotalht, $curY);
373  $pdf->MultiCell($this->posxtotalht - 0.8, 3, price($object->lines[$i]->total_ht), 0, 'R', 0);
374 
375  // Total tva
376  $pdf->SetXY($this->posxtva, $curY);
377  $pdf->MultiCell($this->posxtva - 0.8, 3, price($object->lines[$i]->total_tva), 0, 'R', 0);
378 
379  // Total TTC line
380  $pdf->SetXY($this->posxtotalttc, $curY);
381  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R', 0);
382 
383 
384  // Add line
385  if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
386  $pdf->setPage($pageposafter);
387  $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
388  //$pdf->SetDrawColor(190,190,200);
389  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
390  $pdf->SetLineStyle(array('dash' => 0));
391  }
392 
393  $nexY += 2; // Add space between lines
394 
395  // Detect if some page were added automatically and output _tableau for past pages
396  while ($pagenb < $pageposafter) {
397  $pdf->setPage($pagenb);
398  if ($pagenb == 1) {
399  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
400  } else {
401  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
402  }
403  $this->_pagefoot($pdf, $object, $outputlangs, 1);
404  $pagenb++;
405  $pdf->setPage($pagenb);
406  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
407  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
408  $this->_pagehead($pdf, $object, 0, $outputlangs);
409  }
410  if (!empty($tplidx)) {
411  $pdf->useTemplate($tplidx);
412  }
413  }
414  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
415  if ($pagenb == 1) {
416  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
417  } else {
418  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
419  }
420  $this->_pagefoot($pdf, $object, $outputlangs, 1);
421  // New page
422  $pdf->AddPage();
423  if (!empty($tplidx)) {
424  $pdf->useTemplate($tplidx);
425  }
426  $pagenb++;
427  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
428  $this->_pagehead($pdf, $object, 0, $outputlangs);
429  }
430  }
431  }
432 
433  // Show square
434  if ($pagenb == 1) {
435  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
436  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
437  } else {
438  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
439  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
440  }
441 
442  // Display check zone
443  $posy = $this->_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
444 
445  // Affiche zone totaux
446  //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
447 
448  // Footer page
449  $this->_pagefoot($pdf, $object, $outputlangs);
450  if (method_exists($pdf, 'AliasNbPages')) {
451  $pdf->AliasNbPages();
452  }
453 
454  $pdf->Close();
455 
456  $pdf->Output($file, 'F');
457 
458  // Add pdfgeneration hook
459  $hookmanager->initHooks(array('pdfgeneration'));
460  $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
461  global $action;
462  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
463  if ($reshook < 0) {
464  $this->error = $hookmanager->error;
465  $this->errors = $hookmanager->errors;
466  }
467 
468  dolChmod($file);
469 
470  $this->result = array('fullpath' => $file);
471 
472  return 1; // No error
473  } else {
474  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
475  return 0;
476  }
477  } else {
478  $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
479  return 0;
480  }
481  }
482 
483  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
484  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
494  protected function _tableau_cheque(&$pdf, $object, $posy, $outputlangs)
495  {
496  // phpcs:enable
497  global $conf, $mysoc;
498 
499  $default_font_size = pdf_getPDFFontSize($outputlangs);
500 
501  $pdf->SetFont('', '', $default_font_size - 1);
502  $pdf->SetFillColor(255, 255, 255);
503 
504  // N° payment
505  $pdf->SetXY($this->marge_gauche, $posy);
506  $pdf->MultiCell(30, 4, 'N° '.$outputlangs->transnoentities("Payment"), 0, 'L', 1);
507 
508  // Ref payment
509  $pdf->SetXY($this->marge_gauche + 30, $posy);
510  $pdf->MultiCell(50, 4, $object->ref, 0, 'L', 1);
511 
512  // Total payments
513  $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
514  $pdf->MultiCell(50, 4, price($object->amount), 0, 'R', 1);
515  $posy += 20;
516 
517  // translate amount
518  $currency = $conf->currency;
519  $translateinletter = strtoupper(dol_convertToWord(price2num($object->amount, 'MT'), $outputlangs, $currency));
520  $pdf->SetXY($this->marge_gauche + 50, $posy);
521  $pdf->SetFont('', '', $default_font_size - 3);
522  $pdf->MultiCell(90, 8, $translateinletter, 0, 'L', 1);
523  $pdf->SetFont('', '', $default_font_size - 1);
524  $posy += 8;
525 
526  // To
527  $pdf->SetXY($this->marge_gauche + 50, $posy);
528  $pdf->MultiCell(150, 4, $object->thirdparty->name, 0, 'L', 1);
529 
530  $LENGTHAMOUNT = 35;
531  $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
532  $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(price($object->amount).' '.$currency, 18, '*', STR_PAD_LEFT), 0, 'R', 1);
533  $posy += 10;
534 
535  // City
536  $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
537  $pdf->MultiCell(150, 4, $mysoc->town, 0, 'L', 1);
538  $posy += 4;
539 
540  // Date
541  $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
542  $pdf->MultiCell(150, 4, date("d").' '.$outputlangs->transnoentitiesnoconv(date("F")).' '.date("Y"), 0, 'L', 1);
543  return $posy;
544  }
545 
546  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
560  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
561  {
562  global $conf, $mysoc;
563 
564  // Force to disable hidetop and hidebottom
565  $hidebottom = 0;
566  if ($hidetop) {
567  $hidetop = -1;
568  }
569 
570  $currency = !empty($currency) ? $currency : $conf->currency;
571  $default_font_size = pdf_getPDFFontSize($outputlangs);
572 
573  // Amount in (at tab_top - 1)
574  $pdf->SetTextColor(0, 0, 0);
575  $pdf->SetFont('', '', $default_font_size - 2);
576 
577  /*$titre = strtoupper($mysoc->town).' - '.dol_print_date(dol_now(), 'day', 'tzserver', $outputlangs);
578  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3) - 60, $tab_top - 6);
579  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);*/
580 
581  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
582  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
583  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
584 
585 
586  $pdf->SetDrawColor(128, 128, 128);
587  $pdf->SetFont('', '', $default_font_size - 1);
588 
589  // Output Rect
590  //$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
591  }
592 
593  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
603  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
604  {
605  global $langs, $conf, $mysoc;
606 
607  // Load translation files required by the page
608  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
609 
610  $default_font_size = pdf_getPDFFontSize($outputlangs);
611 
612  // Do not add the BACKGROUND as this is for suppliers
613  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
614 
615  $pdf->SetTextColor(0, 0, 60);
616  $pdf->SetFont('', 'B', $default_font_size + 3);
617 
618  $posy = $this->marge_haute;
619  $posx = $this->page_largeur - $this->marge_droite - 100;
620 
621  $pdf->SetXY($this->marge_gauche, $posy);
622 
623  // Logo
624  $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
625  if ($mysoc->logo) {
626  if (is_readable($logo)) {
627  $height = pdf_getHeightForLogo($logo);
628  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
629  } else {
630  $pdf->SetTextColor(200, 0, 0);
631  $pdf->SetFont('', 'B', $default_font_size - 2);
632  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
633  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
634  }
635  } else {
636  $text = $this->emetteur->name;
637  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
638  }
639  /*
640  $pdf->SetFont('','B', $default_font_size + 3);
641  $pdf->SetXY($posx,$posy);
642  $pdf->SetTextColor(0,0,60);
643  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
644  $posy+=1;
645 
646  if ($object->ref_supplier)
647  {
648  $posy+=4;
649  $pdf->SetFont('','B', $default_font_size);
650  $pdf->SetXY($posx,$posy);
651  $pdf->SetTextColor(0,0,60);
652  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
653  $posy+=1;
654  }
655 
656  $pdf->SetFont('','', $default_font_size - 1);
657 
658  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
659  $object->fetch_projet();
660  if (!empty($object->project->ref)) {
661  $posy += 3;
662  $pdf->SetXY($posx, $posy);
663  $pdf->SetTextColor(0, 0, 60);
664  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
665  }
666  }
667 
668  if (!empty($conf->global->PDF_SHOW_PROJECT))
669  {
670  $object->fetch_projet();
671  if (!empty($object->project->ref))
672  {
673  $outputlangs->load("projects");
674  $posy+=4;
675  $pdf->SetXY($posx,$posy);
676  $langs->load("projects");
677  $pdf->SetTextColor(0,0,60);
678  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->project->ref), '', 'R');
679  }
680  }
681 
682  if ($object->date)
683  {
684  $posy+=4;
685  $pdf->SetXY($posx,$posy);
686  $pdf->SetTextColor(0,0,60);
687  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
688  }
689  else
690  {
691  $posy+=4;
692  $pdf->SetXY($posx,$posy);
693  $pdf->SetTextColor(255,0,0);
694  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
695  }
696 
697  if ($object->thirdparty->code_fournisseur)
698  {
699  $posy+=4;
700  $pdf->SetXY($posx,$posy);
701  $pdf->SetTextColor(0,0,60);
702  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
703  }
704 
705  $posy+=1;
706  $pdf->SetTextColor(0,0,60);
707 
708  // Show list of linked objects
709  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
710  */
711  if ($showaddress) {
712  // Sender properties
713  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
714 
715  // Show payer
716  $posy = 42;
717  $posx = $this->marge_gauche;
718  if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
719  $posx = $this->page_largeur - $this->marge_droite - 80;
720  }
721  $hautcadre = 40;
722 
723  // Show sender frame
724  $pdf->SetTextColor(0, 0, 0);
725  $pdf->SetFont('', '', $default_font_size - 2);
726  $pdf->SetXY($posx, $posy - 5);
727  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("PayedBy"), 0, 'L');
728  $pdf->SetXY($posx, $posy);
729  $pdf->SetFillColor(230, 230, 230);
730  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
731  $pdf->SetTextColor(0, 0, 60);
732 
733  // Show sender name
734  $pdf->SetXY($posx + 2, $posy + 3);
735  $pdf->SetFont('', 'B', $default_font_size);
736  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
737  $posy = $pdf->getY();
738 
739  // Show sender information
740  $pdf->SetXY($posx + 2, $posy);
741  $pdf->SetFont('', '', $default_font_size - 1);
742  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
743 
744  // Paid
745  $thirdparty = $object->thirdparty;
746 
747  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
748 
749  $usecontact = 0;
750 
751  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
752 
753  // Show recipient
754  $widthrecbox = 90;
755  if ($this->page_largeur < 210) {
756  $widthrecbox = 84; // To work with US executive format
757  }
758  $posy = 42;
759  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
760  if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
761  $posx = $this->marge_gauche;
762  }
763 
764  // Show recipient frame
765  $pdf->SetTextColor(0, 0, 0);
766  $pdf->SetFont('', '', $default_font_size - 2);
767  $pdf->SetXY($posx + 2, $posy - 5);
768  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("PayedTo"), 0, 'L');
769  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
770 
771  // Show recipient name
772  $pdf->SetXY($posx + 2, $posy + 3);
773  $pdf->SetFont('', 'B', $default_font_size);
774  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
775 
776  $posy = $pdf->getY();
777 
778  // Show recipient information
779  $pdf->SetFont('', '', $default_font_size - 1);
780  $pdf->SetXY($posx + 2, $posy);
781  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
782 
783  // Show default IBAN account
784  $iban = '';
785  $sql = "SELECT iban_prefix as iban";
786  $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as rib";
787  $sql .= " WHERE fk_soc = ".($object->thirdparty->id);
788  $sql .= " AND rib.default_rib = 1";
789  $sql .= " AND rib.type = 'ban'";
790  $sql .= " LIMIT 1";
791  $resql = $this->db->query($sql);
792  if ($resql) {
793  $obj = $this->db->fetch_object($resql);
794  if ($obj) {
795  $iban = $obj->iban;
796  }
797  }
798 
799  if (!empty($iban)) {
800  $pdf->SetFont('', '', $default_font_size - 1);
801  $pdf->SetXY($posx + 2, $posy + 15);
802  $pdf->MultiCell($widthrecbox, 4, $langs->trans("IBAN").': '.$iban, 0, 'L');
803  }
804  }
805 
806  return 0;
807  }
808 
809  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
819  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
820  {
821  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
822  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
823  }
824 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class to manage hooks.
Parent class for supplier invoices models.
Class to generate expense report based on standard model.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_cheque(&$pdf, $object, $posy, $outputlangs)
Show total to pay.
write_file($object, $outputlangs=null, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid 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:290
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:86
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:315
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1020
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:267
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition: pdf.lib.php:436
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:388
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:123
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:126