dolibarr  17.0.3
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-2021 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 $update_main_doc_field;
60 
64  public $type;
65 
70  public $phpmin = array(7, 0);
71 
76  public $version = 'dolibarr';
77 
81  public $page_largeur;
82 
86  public $page_hauteur;
87 
91  public $format;
92 
96  public $marge_gauche;
97 
101  public $marge_droite;
102 
106  public $marge_haute;
107 
111  public $marge_basse;
112 
117  public $emetteur;
118 
124  public function __construct($db)
125  {
126  global $conf, $langs, $mysoc;
127 
128  // Translations
129  $langs->loadLangs(array("main", "bills", "sendings", "companies"));
130 
131  $this->db = $db;
132  $this->name = "Typhon";
133  $this->description = $langs->trans("DocumentModelTyphon");
134  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
135 
136  // Page size for A4 format
137  $this->type = 'pdf';
138  $formatarray = pdf_getFormat();
139  $this->page_largeur = $formatarray['width'];
140  $this->page_hauteur = $formatarray['height'];
141  $this->format = array($this->page_largeur, $this->page_hauteur);
142  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
143  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
144  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
145  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
146 
147  $this->option_logo = 1; // Display logo FAC_PDF_LOGO
148  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
149 
150  // Get source company
151  $this->emetteur = $mysoc;
152  if (empty($this->emetteur->country_code)) {
153  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
154  }
155 
156  // Define position of columns
157  $this->posxdesc = $this->marge_gauche + 1;
158  $this->posxcomm = 112;
159  //$this->posxtva=112;
160  //$this->posxup=126;
161  $this->posxqty = 165;
162  $this->posxremainingqty = 185;
163  //$this->posxdiscount=162;
164  //$this->postotalht=174;
165  if ($this->page_largeur < 210) { // To work with US executive format
166  $this->posxcomm -= 20;
167  //$this->posxtva-=20;
168  //$this->posxup-=20;
169  $this->posxqty -= 20;
170  //$this->posxdiscount-=20;
171  //$this->postotalht-=20;
172  }
173 
174  $this->tva = array();
175  $this->tva_array = array();
176  $this->localtax1 = array();
177  $this->localtax2 = array();
178  $this->atleastoneratenotnull = 0;
179  $this->atleastonediscount = 0;
180  }
181 
182 
183  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
195  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
196  {
197  // phpcs:enable
198  global $user, $langs, $conf, $mysoc, $hookmanager;
199 
200  if (!is_object($outputlangs)) {
201  $outputlangs = $langs;
202  }
203  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
204  if (!empty($conf->global->MAIN_USE_FPDF)) {
205  $outputlangs->charset_output = 'ISO-8859-1';
206  }
207 
208  // Load translation files required by the page
209  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "sendings", "deliveries"));
210 
211  if ($conf->expedition->dir_output) {
212  $object->fetch_thirdparty();
213 
214  // Definition of $dir and $file
215  if ($object->specimen) {
216  $dir = $conf->expedition->dir_output."/receipt";
217  $file = $dir."/SPECIMEN.pdf";
218  } else {
219  $objectref = dol_sanitizeFileName($object->ref);
220  $dir = $conf->expedition->dir_output."/receipt/".$objectref;
221  $file = $dir."/".$objectref.".pdf";
222  }
223 
224  if (!file_exists($dir)) {
225  if (dol_mkdir($dir) < 0) {
226  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
227  return 0;
228  }
229  }
230 
231  if (file_exists($dir)) {
232  // Add pdfgeneration hook
233  if (!is_object($hookmanager)) {
234  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
235  $hookmanager = new HookManager($this->db);
236  }
237  $hookmanager->initHooks(array('pdfgeneration'));
238  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
239  global $action;
240  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
241 
242  $nblines = count($object->lines);
243 
244  // Create pdf instance
245  $pdf = pdf_getInstance($this->format);
246  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
247  $heightforinfotot = 30; // 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  // We get the shipment that is the origin of delivery receipt
267  $expedition = new Expedition($this->db);
268  $result = $expedition->fetch($object->origin_id);
269  // Now we get the order that is origin of shipment
270  $commande = new Commande($this->db);
271  if ($expedition->origin == 'commande') {
272  $commande->fetch($expedition->origin_id);
273  }
274  $object->commande = $commande; // We set order of shipment onto delivery.
275  $object->commande->loadExpeditions();
276 
277 
278  $pdf->Open();
279  $pagenb = 0;
280  $pdf->SetDrawColor(128, 128, 128);
281 
282  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
283  $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
284  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
285  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
287  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
288  $pdf->SetCompression(false);
289  }
290 
291  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
292 
293  /*
294  // Positionne $this->atleastonediscount si on a au moins une remise
295  for ($i = 0 ; $i < $nblines ; $i++)
296  {
297  if ($object->lines[$i]->remise_percent)
298  {
299  $this->atleastonediscount++;
300  }
301  }
302  if (empty($this->atleastonediscount))
303  {
304  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
305  $this->posxtva+=($this->postotalht - $this->posxdiscount);
306  $this->posxup+=($this->postotalht - $this->posxdiscount);
307  $this->posxqty+=($this->postotalht - $this->posxdiscount);
308  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
309  //$this->postotalht;
310  }
311  */
312 
313  // New page
314  $pdf->AddPage();
315  if (!empty($tplidx)) {
316  $pdf->useTemplate($tplidx);
317  }
318  $pagenb++;
319  $this->_pagehead($pdf, $object, 1, $outputlangs);
320  $pdf->SetFont('', '', $default_font_size - 1);
321  $pdf->MultiCell(0, 3, ''); // Set interline to 3
322  $pdf->SetTextColor(0, 0, 0);
323 
324  $tab_top = 90;
325  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
326 
327  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
328 
329  // Incoterm
330  $height_incoterms = 0;
331  if (isModEnabled('incoterm')) {
332  $desc_incoterms = $object->getIncotermsForPDF();
333  if ($desc_incoterms) {
334  $tab_top -= 2;
335 
336  $pdf->SetFont('', '', $default_font_size - 1);
337  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
338  $nexY = $pdf->GetY();
339  $height_incoterms = $nexY - $tab_top;
340 
341  // Rect takes a length in 3rd parameter
342  $pdf->SetDrawColor(192, 192, 192);
343  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
344 
345  $tab_top = $nexY + 6;
346  $height_incoterms += 4;
347  }
348  }
349 
350  // Affiche notes
351  if (!empty($object->note_public)) {
352  $tab_top = 88 + $height_incoterms;
353 
354  $pdf->SetFont('', '', $default_font_size - 1);
355  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
356  $nexY = $pdf->GetY();
357  $height_note = $nexY - $tab_top;
358 
359  // Rect takes a length in 3rd parameter
360  $pdf->SetDrawColor(192, 192, 192);
361  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
362 
363  $tab_height = $tab_height - $height_note;
364  $tab_top = $nexY + 6;
365  } else {
366  $height_note = 0;
367  }
368 
369  $iniY = $tab_top + 11;
370  $curY = $tab_top + 11;
371  $nexY = $tab_top + 11;
372 
373  // Loop on each lines
374  for ($i = 0; $i < $nblines; $i++) {
375  $curY = $nexY;
376  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
377  $pdf->SetTextColor(0, 0, 0);
378 
379  $pdf->setTopMargin($tab_top_newpage);
380  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
381  $pageposbefore = $pdf->getPage();
382 
383  // Description of product line
384  $curX = $this->posxdesc - 1;
385 
386  $showpricebeforepagebreak = 1;
387 
388  $pdf->startTransaction();
389  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
390  $pageposafter = $pdf->getPage();
391  if ($pageposafter > $pageposbefore) { // There is a pagebreak
392  $pdf->rollbackTransaction(true);
393  $pageposafter = $pageposbefore;
394  //print $pageposafter.'-'.$pageposbefore;exit;
395  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
396  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
397  $posyafter = $pdf->GetY();
398  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
399  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
400  $pdf->AddPage('', '', true);
401  if (!empty($tplidx)) {
402  $pdf->useTemplate($tplidx);
403  }
404  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
405  $this->_pagehead($pdf, $object, 0, $outputlangs);
406  }
407  $pdf->setPage($pageposafter + 1);
408  }
409  } else {
410  // We found a page break
411  // Allows data in the first page if description is long enough to break in multiples pages
412  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
413  $showpricebeforepagebreak = 1;
414  } else {
415  $showpricebeforepagebreak = 0;
416  }
417  }
418  } else // No pagebreak
419  {
420  $pdf->commitTransaction();
421  }
422 
423  $nexY = $pdf->GetY();
424  $pageposafter = $pdf->getPage();
425  $pdf->setPage($pageposbefore);
426  $pdf->setTopMargin($this->marge_haute);
427  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
428 
429  // We suppose that a too long description is moved completely on next page
430  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
431  $pdf->setPage($pageposafter);
432  $curY = $tab_top_newpage;
433  }
434 
435  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
436 
437  /*
438  // TVA
439  $pdf->SetXY($this->posxcomm, $curY);
440  $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
441 
442  // Prix unitaire HT avant remise
443  $pdf->SetXY($this->posxup, $curY);
444  $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
445  */
446  // Quantity
447  //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
448  $pdf->SetXY($this->posxqty, $curY);
449  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
450 
451  // Remaining to ship
452  $pdf->SetXY($this->posxremainingqty, $curY);
453  $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
454  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0, 'R');
455  /*
456  // Remise sur ligne
457  $pdf->SetXY($this->posxdiscount, $curY);
458  if ($object->lines[$i]->remise_percent)
459  {
460  $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
461  }
462 
463  // Total HT ligne
464  $pdf->SetXY($this->postotalht, $curY);
465  $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
466  $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
467 
468  // Collecte des totaux par valeur de tva
469  // dans le tableau tva["taux"]=total_tva
470  $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
471  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
472  $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
473  */
474 
475  // Add line
476  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
477  $pdf->setPage($pageposafter);
478  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
479  //$pdf->SetDrawColor(190,190,200);
480  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
481  $pdf->SetLineStyle(array('dash'=>0));
482  }
483 
484  $nexY += 2; // Add space between lines
485 
486  // Detect if some page were added automatically and output _tableau for past pages
487  while ($pagenb < $pageposafter) {
488  $pdf->setPage($pagenb);
489  if ($pagenb == 1) {
490  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
491  } else {
492  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
493  }
494  $this->_pagefoot($pdf, $object, $outputlangs, 1);
495  $pagenb++;
496  $pdf->setPage($pagenb);
497  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
498  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
499  $this->_pagehead($pdf, $object, 0, $outputlangs);
500  }
501  if (!empty($tplidx)) {
502  $pdf->useTemplate($tplidx);
503  }
504  }
505  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
506  if ($pagenb == 1) {
507  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
508  } else {
509  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
510  }
511  $this->_pagefoot($pdf, $object, $outputlangs, 1);
512  // New page
513  $pdf->AddPage();
514  if (!empty($tplidx)) {
515  $pdf->useTemplate($tplidx);
516  }
517  $pagenb++;
518  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
519  $this->_pagehead($pdf, $object, 0, $outputlangs);
520  }
521  }
522  }
523 
524  // Show square
525  if ($pagenb == 1) {
526  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
527  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
528  } else {
529  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
530  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
531  }
532 
533  // Affiche zone infos
534  $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
535 
536  // Pied de page
537  $this->_pagefoot($pdf, $object, $outputlangs);
538 
539  if (method_exists($pdf, 'AliasNbPages')) {
540  $pdf->AliasNbPages();
541  }
542 
543  // Check product remaining to be delivered
544  // TODO doit etre modifie
545  //$waitingDelivery = $object->getRemainingDelivered();
546  /*
547  $waitingDelivery='';
548 
549  if (is_array($waitingDelivery) & !empty($waitingDelivery))
550  {
551  $pdf->AddPage();
552 
553  $this->_pagehead($pdf, $object, 1, $outputlangs);
554  $pdf-> SetY(90);
555 
556  $w=array(40,100,50);
557  $header=array($outputlangs->transnoentities('Reference'),
558  $outputlangs->transnoentities('Label'),
559  $outputlangs->transnoentities('Qty')
560  );
561 
562  // Header
563  $num = count($header);
564  for($i = 0; $i < $num; $i++)
565  {
566  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
567  }
568 
569  $pdf->Ln();
570 
571  // Data
572  foreach($waitingDelivery as $value)
573  {
574  $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
575  $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
576  $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
577 
578  if ($pdf->GetY() > 250)
579  {
580  $this->_pagefoot($pdf,$object,$outputlangs,1);
581 
582  $pdf->AddPage('P', 'A4');
583 
584  $pdf->SetFont('','', $default_font_size - 1);
585  $this->_pagehead($pdf, $object, 0, $outputlangs);
586 
587  $pdf-> SetY(40);
588 
589  $num = count($header);
590  for($i = 0; $i < $num; $i++)
591  {
592  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
593  }
594 
595  $pdf->Ln();
596  }
597  }
598 
599  $this->_pagefoot($pdf,$object,$outputlangs);
600 
601  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
602  }*/
603 
604  $pdf->Close();
605 
606  $pdf->Output($file, 'F');
607 
608  // Add pdfgeneration hook
609  if (!is_object($hookmanager)) {
610  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
611  $hookmanager = new HookManager($this->db);
612  }
613  $hookmanager->initHooks(array('pdfgeneration'));
614  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
615  global $action;
616  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
617  if ($reshook < 0) {
618  $this->error = $hookmanager->error;
619  $this->errors = $hookmanager->errors;
620  }
621 
622  if (!empty($conf->global->MAIN_UMASK)) {
623  @chmod($file, octdec($conf->global->MAIN_UMASK));
624  }
625 
626  $this->result = array('fullpath'=>$file);
627 
628  return 1; // No error
629  } else {
630  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
631  return 0;
632  }
633  }
634 
635  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
636  return 0;
637  }
638 
639  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
640  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
650  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
651  {
652  // phpcs:enable
653  global $conf, $mysoc;
654  $default_font_size = pdf_getPDFFontSize($outputlangs);
655 
656  $pdf->SetFont('', '', $default_font_size);
657  $pdf->SetXY($this->marge_gauche, $posy);
658 
659  $larg_sign = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 3;
660  $pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
661  $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
662  $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":", '', 'L');
663 
664  $pdf->Rect(2 * $larg_sign + $this->marge_gauche, $posy + 1, $larg_sign, 25);
665  $pdf->SetXY(2 * $larg_sign + $this->marge_gauche + 2, $posy + 2);
666  $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("ForCustomer").':', '', 'L');
667  }
668 
669  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
682  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
683  {
684  global $conf, $mysoc;
685 
686  // Force to disable hidetop and hidebottom
687  $hidebottom = 0;
688  if ($hidetop) {
689  $hidetop = -1;
690  }
691 
692  $default_font_size = pdf_getPDFFontSize($outputlangs);
693 
694  // Amount in (at tab_top - 1)
695  $pdf->SetTextColor(0, 0, 0);
696  $pdf->SetFont('', '', $default_font_size - 2);
697 
698  // Output Rec
699  $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
700 
701  if (empty($hidetop)) {
702  $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
703  }
704 
705  $pdf->SetDrawColor(128, 128, 128);
706  $pdf->SetFont('', '', $default_font_size - 1);
707 
708  if (empty($hidetop)) {
709  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
710  $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities("Designation"), '', 'L');
711  }
712 
713  // Modif SEB pour avoir une col en plus pour les commentaires clients
714  $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
715  if (empty($hidetop)) {
716  $pdf->SetXY($this->posxcomm, $tab_top + 1);
717  $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities("Comments"), '', 'L');
718  }
719 
720  // Qty
721  $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
722  if (empty($hidetop)) {
723  $pdf->SetXY($this->posxqty, $tab_top + 1);
724  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities("QtyShippedShort"), '', 'R');
725  }
726 
727  // Remain to ship
728  $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
729  if (empty($hidetop)) {
730  $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
731  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities("KeepToShipShort"), '', 'R');
732  }
733  }
734 
735  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
745  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
746  {
747  global $conf, $langs, $hookmanager;
748 
749  $default_font_size = pdf_getPDFFontSize($outputlangs);
750 
751  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
752 
753  // Show Draft Watermark
754  if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK))) {
755  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
756  }
757 
758  $pdf->SetTextColor(0, 0, 60);
759  $pdf->SetFont('', 'B', $default_font_size + 3);
760 
761  $posy = $this->marge_haute;
762  $posx = $this->page_largeur - $this->marge_droite - 100;
763 
764  $pdf->SetXY($this->marge_gauche, $posy);
765 
766  // Logo
767  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
768  if ($this->emetteur->logo) {
769  if (is_readable($logo)) {
770  $height = pdf_getHeightForLogo($logo);
771  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
772  } else {
773  $pdf->SetTextColor(200, 0, 0);
774  $pdf->SetFont('', 'B', $default_font_size - 2);
775  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
776  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
777  }
778  } else {
779  $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
780  }
781 
782  $pdf->SetFont('', 'B', $default_font_size + 2);
783  $pdf->SetXY($posx, $posy);
784  $pdf->SetTextColor(0, 0, 60);
785  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
786 
787  $pdf->SetFont('', '', $default_font_size + 2);
788 
789  $posy += 5;
790  $pdf->SetXY($posx, $posy);
791  $pdf->SetTextColor(0, 0, 60);
792  if ($object->date_valid) {
793  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_delivery, "%d %b %Y", false, $outputlangs, true), '', 'R');
794  } else {
795  $pdf->SetTextColor(255, 0, 0);
796  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryNotValidated"), '', 'R');
797  $pdf->SetTextColor(0, 0, 60);
798  }
799 
800  if ($object->thirdparty->code_client) {
801  $posy += 5;
802  $pdf->SetXY($posx, $posy);
803  $pdf->SetTextColor(0, 0, 60);
804  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
805  }
806 
807  $pdf->SetTextColor(0, 0, 60);
808 
809  $posy += 2;
810 
811  // Show list of linked objects
812  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
813 
814  if ($showaddress) {
815  // Sender properties
816  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
817 
818  // Show sender
819  $posy = 42;
820  $posx = $this->marge_gauche;
821  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
822  $posx = $this->page_largeur - $this->marge_droite - 80;
823  }
824  $hautcadre = 40;
825 
826  // Show sender frame
827  $pdf->SetTextColor(0, 0, 0);
828  $pdf->SetFont('', '', $default_font_size - 2);
829  $pdf->SetXY($posx, $posy - 5);
830  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
831  $pdf->SetXY($posx, $posy);
832  $pdf->SetFillColor(230, 230, 230);
833  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
834  $pdf->SetTextColor(0, 0, 60);
835 
836  // Show sender name
837  $pdf->SetXY($posx + 2, $posy + 3);
838  $pdf->SetFont('', 'B', $default_font_size);
839  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
840  $posy = $pdf->getY();
841 
842  // Show sender information
843  $pdf->SetXY($posx + 2, $posy);
844  $pdf->SetFont('', '', $default_font_size - 1);
845  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
846 
847  // Client destinataire
848  $posy = 42;
849  $posx = 102;
850  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
851  $posx = $this->marge_gauche;
852  }
853  $pdf->SetTextColor(0, 0, 0);
854  $pdf->SetFont('', '', $default_font_size - 2);
855  $pdf->SetXY($posx, $posy - 5);
856  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("DeliveryAddress"), 0, 'L');
857 
858  // If SHIPPING contact defined on order, we use it
859  $usecontact = false;
860  $arrayidcontact = $object->commande->getIdContact('external', 'SHIPPING');
861  if ($arrayidcontact && count($arrayidcontact) > 0) {
862  $usecontact = true;
863  $result = $object->fetch_contact($arrayidcontact[0]);
864  }
865 
866  // Recipient name
867  if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
868  $thirdparty = $object->contact;
869  } else {
870  $thirdparty = $object->thirdparty;
871  }
872 
873  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
874 
875  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
876 
877  // Show recipient
878  $widthrecbox = 100;
879  if ($this->page_largeur < 210) {
880  $widthrecbox = 84; // To work with US executive format
881  }
882  $posy = 42;
883  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
884  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
885  $posx = $this->marge_gauche;
886  }
887 
888  // Show recipient frame
889  $pdf->SetTextColor(0, 0, 0);
890  $pdf->SetFont('', '', $default_font_size - 2);
891  $pdf->SetXY($posx + 2, $posy - 5);
892  //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
893  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
894 
895  // Show recipient name
896  $pdf->SetXY($posx + 2, $posy + 3);
897  $pdf->SetFont('', 'B', $default_font_size);
898  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
899 
900  $posy = $pdf->getY();
901 
902  // Show recipient information
903  $pdf->SetFont('', '', $default_font_size - 1);
904  $pdf->SetXY($posx + 2, $posy);
905  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
906  }
907 
908  $pdf->SetTextColor(0, 0, 60);
909  }
910 
911  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
921  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
922  {
923  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
924  return pdf_pagefoot($pdf, $outputlangs, 'DELIVERY_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
925  }
926 }
pdf_typhon\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_typhon.modules.php:921
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_writelinedesc
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:1359
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
Expedition
Class to manage shipments.
Definition: expedition.class.php:52
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
ModelePDFDeliveryOrder
Classe mere des modeles de bon de livraison.
Definition: modules_delivery.php:37
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_typhon\__construct
__construct($db)
Constructor.
Definition: pdf_typhon.modules.php:124
name
$conf db name
Definition: repair.php:122
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:723
pdf_typhon\_tableau_info
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Definition: pdf_typhon.modules.php:650
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:769
Commande
Class to manage customers orders.
Definition: commande.class.php:46
pdf_typhon\write_file
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_typhon.modules.php:195
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:982
pdf_writeLinkedObjects
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1323
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
pdf_typhon\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_typhon.modules.php:745
pdf_typhon
Class to build Delivery Order documents with typhon model.
Definition: pdf_typhon.modules.php:39
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
dol_htmlentitiesbr
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...
Definition: functions.lib.php:7277
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6789
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
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:1001
pdf_typhon\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
Definition: pdf_typhon.modules.php:682