dolibarr  13.0.2
pdf_typhon.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5  * Copyright (C) 2008 Chiptronik
6  * Copyright (C) 2011-2020 Philippe Grand <philippe.grand@atoo-net.com>
7  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
8 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
30 require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
31 require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.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 
35 
40 {
44  public $db;
45 
49  public $name;
50 
54  public $description;
55 
59  public $type;
60 
65  public $phpmin = array(5, 6);
66 
71  public $version = 'dolibarr';
72 
76  public $page_largeur;
77 
81  public $page_hauteur;
82 
86  public $format;
87 
91  public $marge_gauche;
92 
96  public $marge_droite;
97 
101  public $marge_haute;
102 
106  public $marge_basse;
107 
112  public $emetteur;
113 
119  public function __construct($db)
120  {
121  global $conf, $langs, $mysoc;
122 
123  // Translations
124  $langs->loadLangs(array("main", "bills", "sendings", "companies"));
125 
126  $this->db = $db;
127  $this->name = "Typhon";
128  $this->description = $langs->trans("DocumentModelTyphon");
129 
130  // Page size for A4 format
131  $this->type = 'pdf';
132  $formatarray = pdf_getFormat();
133  $this->page_largeur = $formatarray['width'];
134  $this->page_hauteur = $formatarray['height'];
135  $this->format = array($this->page_largeur, $this->page_hauteur);
136  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
137  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
138  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
139  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
140 
141  $this->option_logo = 1; // Display logo FAC_PDF_LOGO
142  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
143  $this->option_codeproduitservice = 1; // Display product-service code
144 
145  // Get source company
146  $this->emetteur = $mysoc;
147  if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
148 
149  // Define position of columns
150  $this->posxdesc = $this->marge_gauche + 1;
151  $this->posxcomm = 112;
152  //$this->posxtva=112;
153  //$this->posxup=126;
154  $this->posxqty = 165;
155  $this->posxremainingqty = 185;
156  //$this->posxdiscount=162;
157  //$this->postotalht=174;
158  if ($this->page_largeur < 210) // To work with US executive format
159  {
160  $this->posxcomm -= 20;
161  //$this->posxtva-=20;
162  //$this->posxup-=20;
163  $this->posxqty -= 20;
164  //$this->posxdiscount-=20;
165  //$this->postotalht-=20;
166  }
167 
168  $this->tva = array();
169  $this->atleastoneratenotnull = 0;
170  $this->atleastonediscount = 0;
171  }
172 
173 
174  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
186  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
187  {
188  // phpcs:enable
189  global $user, $langs, $conf, $mysoc, $hookmanager;
190 
191  if (!is_object($outputlangs)) $outputlangs = $langs;
192  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
193  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
194 
195  // Load translation files required by the page
196  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "sendings", "deliveries"));
197 
198  if ($conf->expedition->dir_output)
199  {
200  $object->fetch_thirdparty();
201 
202  // Definition of $dir and $file
203  if ($object->specimen)
204  {
205  $dir = $conf->expedition->dir_output."/receipt";
206  $file = $dir."/SPECIMEN.pdf";
207  } else {
208  $objectref = dol_sanitizeFileName($object->ref);
209  $dir = $conf->expedition->dir_output."/receipt/".$objectref;
210  $file = $dir."/".$objectref.".pdf";
211  }
212 
213  if (!file_exists($dir))
214  {
215  if (dol_mkdir($dir) < 0)
216  {
217  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
218  return 0;
219  }
220  }
221 
222  if (file_exists($dir))
223  {
224  // Add pdfgeneration hook
225  if (!is_object($hookmanager))
226  {
227  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
228  $hookmanager = new HookManager($this->db);
229  }
230  $hookmanager->initHooks(array('pdfgeneration'));
231  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
232  global $action;
233  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
234 
235  $nblines = count($object->lines);
236 
237  // Create pdf instance
238  $pdf = pdf_getInstance($this->format);
239  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
240  $heightforinfotot = 30; // Height reserved to output the info and total part
241  $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
242  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
243  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6;
244  $pdf->SetAutoPageBreak(1, 0);
245 
246  if (class_exists('TCPDF'))
247  {
248  $pdf->setPrintHeader(false);
249  $pdf->setPrintFooter(false);
250  }
251  $pdf->SetFont(pdf_getPDFFont($outputlangs));
252  // Set path to the background PDF File
253  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
254  {
255  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
256  $tplidx = $pdf->importPage(1);
257  }
258 
259  // We get the shipment that is the origin of delivery receipt
260  $expedition = new Expedition($this->db);
261  $result = $expedition->fetch($object->origin_id);
262  // Now we get the order that is origin of shipment
263  $commande = new Commande($this->db);
264  if ($expedition->origin == 'commande')
265  {
266  $commande->fetch($expedition->origin_id);
267  }
268  $object->commande = $commande; // We set order of shipment onto delivery.
269  $object->commande->loadExpeditions();
270 
271 
272  $pdf->Open();
273  $pagenb = 0;
274  $pdf->SetDrawColor(128, 128, 128);
275 
276  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
277  $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
278  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
279  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
280  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
281  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
282 
283  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
284 
285  /*
286  // Positionne $this->atleastonediscount si on a au moins une remise
287  for ($i = 0 ; $i < $nblines ; $i++)
288  {
289  if ($object->lines[$i]->remise_percent)
290  {
291  $this->atleastonediscount++;
292  }
293  }
294  if (empty($this->atleastonediscount))
295  {
296  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
297  $this->posxtva+=($this->postotalht - $this->posxdiscount);
298  $this->posxup+=($this->postotalht - $this->posxdiscount);
299  $this->posxqty+=($this->postotalht - $this->posxdiscount);
300  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
301  //$this->postotalht;
302  }
303  */
304 
305  // New page
306  $pdf->AddPage();
307  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
308  $pagenb++;
309  $this->_pagehead($pdf, $object, 1, $outputlangs);
310  $pdf->SetFont('', '', $default_font_size - 1);
311  $pdf->MultiCell(0, 3, ''); // Set interline to 3
312  $pdf->SetTextColor(0, 0, 0);
313 
314  $tab_top = 90;
315  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
316  $tab_height = 130;
317  $tab_height_newpage = 150;
318 
319  // Incoterm
320  $height_incoterms = 0;
321  if (!empty($conf->incoterm->enabled))
322  {
323  $desc_incoterms = $object->getIncotermsForPDF();
324  if ($desc_incoterms)
325  {
326  $tab_top = 88;
327 
328  $pdf->SetFont('', '', $default_font_size - 1);
329  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
330  $nexY = $pdf->GetY();
331  $height_incoterms = $nexY - $tab_top;
332 
333  // Rect takes a length in 3rd parameter
334  $pdf->SetDrawColor(192, 192, 192);
335  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
336 
337  $tab_top = $nexY + 6;
338  $height_incoterms += 4;
339  }
340  }
341 
342  // Affiche notes
343  if (!empty($object->note_public))
344  {
345  $tab_top = 88 + $height_incoterms;
346 
347  $pdf->SetFont('', '', $default_font_size - 1);
348  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
349  $nexY = $pdf->GetY();
350  $height_note = $nexY - $tab_top;
351 
352  // Rect takes a length in 3rd parameter
353  $pdf->SetDrawColor(192, 192, 192);
354  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
355 
356  $tab_height = $tab_height - $height_note;
357  $tab_top = $nexY + 6;
358  } else {
359  $height_note = 0;
360  }
361 
362  $iniY = $tab_top + 11;
363  $curY = $tab_top + 11;
364  $nexY = $tab_top + 11;
365 
366  // Loop on each lines
367  for ($i = 0; $i < $nblines; $i++)
368  {
369  $curY = $nexY;
370  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
371  $pdf->SetTextColor(0, 0, 0);
372 
373  $pdf->setTopMargin($tab_top_newpage);
374  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
375  $pageposbefore = $pdf->getPage();
376 
377  // Description of product line
378  $curX = $this->posxdesc - 1;
379 
380  $showpricebeforepagebreak = 1;
381 
382  $pdf->startTransaction();
383  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
384  $pageposafter = $pdf->getPage();
385  if ($pageposafter > $pageposbefore) // There is a pagebreak
386  {
387  $pdf->rollbackTransaction(true);
388  $pageposafter = $pageposbefore;
389  //print $pageposafter.'-'.$pageposbefore;exit;
390  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
391  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
392  $posyafter = $pdf->GetY();
393  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text
394  {
395  if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
396  {
397  $pdf->AddPage('', '', true);
398  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
399  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
400  $pdf->setPage($pageposafter + 1);
401  }
402  } else {
403  // We found a page break
404  // Allows data in the first page if description is long enough to break in multiples pages
405  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
406  $showpricebeforepagebreak = 1;
407  else $showpricebeforepagebreak = 0;
408  }
409  } else // No pagebreak
410  {
411  $pdf->commitTransaction();
412  }
413 
414  $nexY = $pdf->GetY();
415  $pageposafter = $pdf->getPage();
416  $pdf->setPage($pageposbefore);
417  $pdf->setTopMargin($this->marge_haute);
418  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
419 
420  // We suppose that a too long description is moved completely on next page
421  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
422  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
423  }
424 
425  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
426 
427  /*
428  // TVA
429  $pdf->SetXY($this->posxcomm, $curY);
430  $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
431 
432  // Prix unitaire HT avant remise
433  $pdf->SetXY($this->posxup, $curY);
434  $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
435  */
436  // Quantity
437  //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
438  $pdf->SetXY($this->posxqty, $curY);
439  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
440 
441  // Remaining to ship
442  $pdf->SetXY($this->posxremainingqty, $curY);
443  $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
444  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0, 'R');
445  /*
446  // Remise sur ligne
447  $pdf->SetXY($this->posxdiscount, $curY);
448  if ($object->lines[$i]->remise_percent)
449  {
450  $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
451  }
452 
453  // Total HT ligne
454  $pdf->SetXY($this->postotalht, $curY);
455  $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
456  $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
457 
458  // Collecte des totaux par valeur de tva
459  // dans le tableau tva["taux"]=total_tva
460  $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
461  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
462  $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
463  */
464 
465  // Add line
466  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
467  {
468  $pdf->setPage($pageposafter);
469  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
470  //$pdf->SetDrawColor(190,190,200);
471  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
472  $pdf->SetLineStyle(array('dash'=>0));
473  }
474 
475  $nexY += 2; // Add space between lines
476 
477  // Detect if some page were added automatically and output _tableau for past pages
478  while ($pagenb < $pageposafter)
479  {
480  $pdf->setPage($pagenb);
481  if ($pagenb == 1)
482  {
483  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
484  } else {
485  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
486  }
487  $this->_pagefoot($pdf, $object, $outputlangs, 1);
488  $pagenb++;
489  $pdf->setPage($pagenb);
490  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
491  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
492  }
493  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
494  {
495  if ($pagenb == 1)
496  {
497  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
498  } else {
499  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
500  }
501  $this->_pagefoot($pdf, $object, $outputlangs, 1);
502  // New page
503  $pdf->AddPage();
504  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
505  $pagenb++;
506  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
507  }
508  }
509 
510  // Show square
511  if ($pagenb == 1)
512  {
513  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
514  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
515  } else {
516  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
517  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
518  }
519 
520  // Affiche zone infos
521  $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
522 
523  // Pied de page
524  $this->_pagefoot($pdf, $object, $outputlangs);
525 
526  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
527 
528  // Check product remaining to be delivered
529  // TODO doit etre modifie
530  //$waitingDelivery = $object->getRemainingDelivered();
531  /*
532  $waitingDelivery='';
533 
534  if (is_array($waitingDelivery) & !empty($waitingDelivery))
535  {
536  $pdf->AddPage();
537 
538  $this->_pagehead($pdf, $object, 1, $outputlangs);
539  $pdf-> SetY(90);
540 
541  $w=array(40,100,50);
542  $header=array($outputlangs->transnoentities('Reference'),
543  $outputlangs->transnoentities('Label'),
544  $outputlangs->transnoentities('Qty')
545  );
546 
547  // Header
548  $num = count($header);
549  for($i = 0; $i < $num; $i++)
550  {
551  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
552  }
553 
554  $pdf->Ln();
555 
556  // Data
557  foreach($waitingDelivery as $value)
558  {
559  $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
560  $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
561  $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
562 
563  if ($pdf->GetY() > 250)
564  {
565  $this->_pagefoot($pdf,$object,$outputlangs,1);
566 
567  $pdf->AddPage('P', 'A4');
568 
569  $pdf->SetFont('','', $default_font_size - 1);
570  $this->_pagehead($pdf, $object, 0, $outputlangs);
571 
572  $pdf-> SetY(40);
573 
574  $num = count($header);
575  for($i = 0; $i < $num; $i++)
576  {
577  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
578  }
579 
580  $pdf->Ln();
581  }
582  }
583 
584  $this->_pagefoot($pdf,$object,$outputlangs);
585 
586  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
587  }*/
588 
589  $pdf->Close();
590 
591  $pdf->Output($file, 'F');
592 
593  // Add pdfgeneration hook
594  if (!is_object($hookmanager))
595  {
596  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
597  $hookmanager = new HookManager($this->db);
598  }
599  $hookmanager->initHooks(array('pdfgeneration'));
600  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
601  global $action;
602  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
603  if ($reshook < 0)
604  {
605  $this->error = $hookmanager->error;
606  $this->errors = $hookmanager->errors;
607  }
608 
609  if (!empty($conf->global->MAIN_UMASK))
610  @chmod($file, octdec($conf->global->MAIN_UMASK));
611 
612  $this->result = array('fullpath'=>$file);
613 
614  return 1; // No error
615  } else {
616  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
617  return 0;
618  }
619  }
620 
621  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
622  return 0;
623  }
624 
625  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
626  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
636  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
637  {
638  // phpcs:enable
639  global $conf, $mysoc;
640  $default_font_size = pdf_getPDFFontSize($outputlangs);
641 
642  $pdf->SetFont('', '', $default_font_size);
643  $pdf->SetXY($this->marge_gauche, $posy);
644 
645  $larg_sign = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 3;
646  $pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
647  $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
648  $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":", '', 'L');
649 
650  $pdf->Rect(2 * $larg_sign + $this->marge_gauche, $posy + 1, $larg_sign, 25);
651  $pdf->SetXY(2 * $larg_sign + $this->marge_gauche + 2, $posy + 2);
652  $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("ForCustomer").':', '', 'L');
653  }
654 
655  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
668  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
669  {
670  global $conf, $mysoc;
671 
672  // Force to disable hidetop and hidebottom
673  $hidebottom = 0;
674  if ($hidetop) $hidetop = -1;
675 
676  $default_font_size = pdf_getPDFFontSize($outputlangs);
677 
678  // Amount in (at tab_top - 1)
679  $pdf->SetTextColor(0, 0, 0);
680  $pdf->SetFont('', '', $default_font_size - 2);
681 
682  // Output Rec
683  $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
684 
685  if (empty($hidetop))
686  {
687  $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
688  }
689 
690  $pdf->SetDrawColor(128, 128, 128);
691  $pdf->SetFont('', '', $default_font_size - 1);
692 
693  if (empty($hidetop))
694  {
695  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
696  $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities("Designation"), '', 'L');
697  }
698 
699  // Modif SEB pour avoir une col en plus pour les commentaires clients
700  $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
701  if (empty($hidetop)) {
702  $pdf->SetXY($this->posxcomm, $tab_top + 1);
703  $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities("Comments"), '', 'L');
704  }
705 
706  // Qty
707  $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
708  if (empty($hidetop)) {
709  $pdf->SetXY($this->posxqty, $tab_top + 1);
710  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities("QtyShippedShort"), '', 'R');
711  }
712 
713  // Remain to ship
714  $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
715  if (empty($hidetop)) {
716  $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
717  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities("KeepToShipShort"), '', 'R');
718  }
719  }
720 
721  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
731  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
732  {
733  global $conf, $langs, $hookmanager;
734 
735  $default_font_size = pdf_getPDFFontSize($outputlangs);
736 
737  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
738 
739  // Show Draft Watermark
740  if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
741  {
742  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
743  }
744 
745  $pdf->SetTextColor(0, 0, 60);
746  $pdf->SetFont('', 'B', $default_font_size + 3);
747 
748  $posy = $this->marge_haute;
749  $posx = $this->page_largeur - $this->marge_droite - 100;
750 
751  $pdf->SetXY($this->marge_gauche, $posy);
752 
753  // Logo
754  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
755  if ($this->emetteur->logo)
756  {
757  if (is_readable($logo))
758  {
759  $height = pdf_getHeightForLogo($logo);
760  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
761  } else {
762  $pdf->SetTextColor(200, 0, 0);
763  $pdf->SetFont('', 'B', $default_font_size - 2);
764  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
765  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
766  }
767  } else $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
768 
769  $pdf->SetFont('', 'B', $default_font_size + 2);
770  $pdf->SetXY($posx, $posy);
771  $pdf->SetTextColor(0, 0, 60);
772  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
773 
774  $pdf->SetFont('', '', $default_font_size + 2);
775 
776  $posy += 5;
777  $pdf->SetXY($posx, $posy);
778  $pdf->SetTextColor(0, 0, 60);
779  if ($object->date_valid)
780  {
781  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_delivery, "%d %b %Y", false, $outputlangs, true), '', 'R');
782  } else {
783  $pdf->SetTextColor(255, 0, 0);
784  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryNotValidated"), '', 'R');
785  $pdf->SetTextColor(0, 0, 60);
786  }
787 
788  if ($object->thirdparty->code_client)
789  {
790  $posy += 5;
791  $pdf->SetXY($posx, $posy);
792  $pdf->SetTextColor(0, 0, 60);
793  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
794  }
795 
796  $pdf->SetTextColor(0, 0, 60);
797 
798  $posy += 2;
799 
800  // Show list of linked objects
801  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
802 
803  if ($showaddress)
804  {
805  // Sender properties
806  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
807 
808  // Show sender
809  $posy = 42;
810  $posx = $this->marge_gauche;
811  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
812  $hautcadre = 40;
813 
814  // Show sender frame
815  $pdf->SetTextColor(0, 0, 0);
816  $pdf->SetFont('', '', $default_font_size - 2);
817  $pdf->SetXY($posx, $posy - 5);
818  $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
819  $pdf->SetXY($posx, $posy);
820  $pdf->SetFillColor(230, 230, 230);
821  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
822  $pdf->SetTextColor(0, 0, 60);
823 
824  // Show sender name
825  $pdf->SetXY($posx + 2, $posy + 3);
826  $pdf->SetFont('', 'B', $default_font_size);
827  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
828  $posy = $pdf->getY();
829 
830  // Show sender information
831  $pdf->SetXY($posx + 2, $posy);
832  $pdf->SetFont('', '', $default_font_size - 1);
833  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
834 
835  // Client destinataire
836  $posy = 42;
837  $posx = 102;
838  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
839  $pdf->SetTextColor(0, 0, 0);
840  $pdf->SetFont('', '', $default_font_size - 2);
841  $pdf->SetXY($posx, $posy - 5);
842  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L');
843 
844  // If SHIPPING contact defined on order, we use it
845  $usecontact = false;
846  $arrayidcontact = $object->commande->getIdContact('external', 'SHIPPING');
847  if ($arrayidcontact && count($arrayidcontact) > 0)
848  {
849  $usecontact = true;
850  $result = $object->fetch_contact($arrayidcontact[0]);
851  }
852 
853  // Recipient name
854  if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
855  $thirdparty = $object->contact;
856  } else {
857  $thirdparty = $object->thirdparty;
858  }
859 
860  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
861 
862  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
863 
864  // Show recipient
865  $widthrecbox = 100;
866  if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
867  $posy = 42;
868  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
869  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
870 
871  // Show recipient frame
872  $pdf->SetTextColor(0, 0, 0);
873  $pdf->SetFont('', '', $default_font_size - 2);
874  $pdf->SetXY($posx + 2, $posy - 5);
875  //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
876  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
877 
878  // Show recipient name
879  $pdf->SetXY($posx + 2, $posy + 3);
880  $pdf->SetFont('', 'B', $default_font_size);
881  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
882 
883  $posy = $pdf->getY();
884 
885  // Show recipient information
886  $pdf->SetFont('', '', $default_font_size - 1);
887  $pdf->SetXY($posx + 2, $posy);
888  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
889  }
890 
891  $pdf->SetTextColor(0, 0, 60);
892  }
893 
894  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
904  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
905  {
906  global $conf;
907  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
908  return pdf_pagefoot($pdf, $outputlangs, 'DELIVERY_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
909  }
910 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:342
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:620
write_file($object, $outputlangs, $srctemplatepath= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct($db)
Constructor.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:663
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:222
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage hooks.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:887
Class to manage shipments.
Class to manage customers orders.
Classe mere des modeles de bon de livraison.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:270
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1135
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
Definition: pdf.lib.php:88
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:376
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1174
Class to build Delivery Order documents with typhon model.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)