dolibarr  9.0.0
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-2018 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 <http://www.gnu.org/licenses/>.
21  * or see http://www.gnu.org/
22  */
23 
31 require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
32 require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
35 
36 
41 {
45  public $db;
46 
50  public $name;
51 
55  public $description;
56 
60  public $type;
61 
66  public $phpmin = array(5, 4);
67 
72  public $version = 'dolibarr';
73 
77  public $page_largeur;
78 
82  public $page_hauteur;
83 
87  public $format;
88 
92  public $marge_gauche;
93 
97  public $marge_droite;
98 
102  public $marge_haute;
103 
107  public $marge_basse;
108 
113  public $emetteur;
114 
120  function __construct($db)
121  {
122  global $conf,$langs,$mysoc;
123 
124  // Translations
125  $langs->loadLangs(array("main", "bills", "sendings", "companies"));
126 
127  $this->db = $db;
128  $this->name = "typhon";
129  $this->description = $langs->trans("DocumentModelTyphon");
130 
131  // Dimension page pour format A4
132  $this->type = 'pdf';
133  $formatarray=pdf_getFormat();
134  $this->page_largeur = $formatarray['width'];
135  $this->page_hauteur = $formatarray['height'];
136  $this->format = array($this->page_largeur,$this->page_hauteur);
137  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
138  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
139  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
140  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
141 
142  $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
143  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
144  $this->option_codeproduitservice = 1; // Affiche code produit-service
145 
146  $this->franchise=!$mysoc->tva_assuj;
147 
148  // Get source company
149  $this->emetteur=$mysoc;
150  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
151 
152  // Define position of columns
153  $this->posxdesc=$this->marge_gauche+1;
154  $this->posxcomm=112;
155  //$this->posxtva=112;
156  //$this->posxup=126;
157  $this->posxqty=165;
158  $this->posxremainingqty=185;
159  //$this->posxdiscount=162;
160  //$this->postotalht=174;
161  if ($this->page_largeur < 210) // To work with US executive format
162  {
163  $this->posxcomm-=20;
164  //$this->posxtva-=20;
165  //$this->posxup-=20;
166  $this->posxqty-=20;
167  //$this->posxdiscount-=20;
168  //$this->postotalht-=20;
169  }
170 
171  $this->tva=array();
172  $this->atleastoneratenotnull=0;
173  $this->atleastonediscount=0;
174  }
175 
176 
177  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
189  function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
190  {
191  // phpcs:enable
192  global $user,$langs,$conf,$mysoc,$hookmanager;
193 
194  if (! is_object($outputlangs)) $outputlangs=$langs;
195  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
196  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
197 
198  // Load translation files required by the page
199  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "sendings", "deliveries"));
200 
201  if ($conf->expedition->dir_output)
202  {
203  $object->fetch_thirdparty();
204 
205  // Definition of $dir and $file
206  if ($object->specimen)
207  {
208  $dir = $conf->expedition->dir_output."/receipt";
209  $file = $dir . "/SPECIMEN.pdf";
210  }
211  else
212  {
213  $objectref = dol_sanitizeFileName($object->ref);
214  $dir = $conf->expedition->dir_output."/receipt/" . $objectref;
215  $file = $dir . "/" . $objectref . ".pdf";
216  }
217 
218  if (! file_exists($dir))
219  {
220  if (dol_mkdir($dir) < 0)
221  {
222  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
223  return 0;
224  }
225  }
226 
227  if (file_exists($dir))
228  {
229  // Add pdfgeneration hook
230  if (! is_object($hookmanager))
231  {
232  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
233  $hookmanager=new HookManager($this->db);
234  }
235  $hookmanager->initHooks(array('pdfgeneration'));
236  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
237  global $action;
238  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
239 
240  $nblines = count($object->lines);
241 
242  // Create pdf instance
243  $pdf=pdf_getInstance($this->format);
244  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
245  $heightforinfotot = 30; // Height reserved to output the info and total part
246  $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
247  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
248  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
249  $pdf->SetAutoPageBreak(1,0);
250 
251  if (class_exists('TCPDF'))
252  {
253  $pdf->setPrintHeader(false);
254  $pdf->setPrintFooter(false);
255  }
256  $pdf->SetFont(pdf_getPDFFont($outputlangs));
257  // Set path to the background PDF File
258  if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
259  {
260  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
261  $tplidx = $pdf->importPage(1);
262  }
263 
264  // We get the shipment that is the origin of delivery receipt
265  $expedition=new Expedition($this->db);
266  $result = $expedition->fetch($object->origin_id);
267  // Now we get the order that is origin of shipment
268  $commande = new Commande($this->db);
269  if ($expedition->origin == 'commande')
270  {
271  $commande->fetch($expedition->origin_id);
272  }
273  $object->commande=$commande; // We set order of shipment onto delivery.
274  $object->commande->loadExpeditions();
275 
276 
277  $pdf->Open();
278  $pagenb=0;
279  $pdf->SetDrawColor(128,128,128);
280 
281  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
282  $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
283  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
284  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
285  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
286  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
287 
288  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
289 
290  /*
291  // Positionne $this->atleastonediscount si on a au moins une remise
292  for ($i = 0 ; $i < $nblines ; $i++)
293  {
294  if ($object->lines[$i]->remise_percent)
295  {
296  $this->atleastonediscount++;
297  }
298  }
299  if (empty($this->atleastonediscount))
300  {
301  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
302  $this->posxtva+=($this->postotalht - $this->posxdiscount);
303  $this->posxup+=($this->postotalht - $this->posxdiscount);
304  $this->posxqty+=($this->postotalht - $this->posxdiscount);
305  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
306  //$this->postotalht;
307  }
308  */
309 
310  // New page
311  $pdf->AddPage();
312  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
313  $pagenb++;
314  $this->_pagehead($pdf, $object, 1, $outputlangs);
315  $pdf->SetFont('','', $default_font_size - 1);
316  $pdf->MultiCell(0, 3, ''); // Set interline to 3
317  $pdf->SetTextColor(0,0,0);
318 
319  $tab_top = 90;
320  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
321  $tab_height = 130;
322  $tab_height_newpage = 150;
323 
324  // Incoterm
325  $height_incoterms = 0;
326  if ($conf->incoterm->enabled)
327  {
328  $desc_incoterms = $object->getIncotermsForPDF();
329  if ($desc_incoterms)
330  {
331  $tab_top = 88;
332 
333  $pdf->SetFont('','', $default_font_size - 1);
334  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
335  $nexY = $pdf->GetY();
336  $height_incoterms=$nexY-$tab_top;
337 
338  // Rect prend une longueur en 3eme param
339  $pdf->SetDrawColor(192,192,192);
340  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
341 
342  $tab_top = $nexY+6;
343  $height_incoterms += 4;
344  }
345  }
346 
347  // Affiche notes
348  if (! empty($object->note_public))
349  {
350  $tab_top = 88 + $height_incoterms;
351 
352  $pdf->SetFont('','', $default_font_size - 1);
353  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
354  $nexY = $pdf->GetY();
355  $height_note=$nexY-$tab_top;
356 
357  // Rect prend une longueur en 3eme param
358  $pdf->SetDrawColor(192,192,192);
359  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
360 
361  $tab_height = $tab_height - $height_note;
362  $tab_top = $nexY+6;
363  }
364  else
365  {
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  {
376  $curY = $nexY;
377  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
378  $pdf->SetTextColor(0,0,0);
379 
380  $pdf->setTopMargin($tab_top_newpage);
381  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
382  $pageposbefore=$pdf->getPage();
383 
384  // Description of product line
385  $curX = $this->posxdesc-1;
386 
387  $showpricebeforepagebreak=1;
388 
389  $pdf->startTransaction();
390  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,3,$curX,$curY,$hideref,$hidedesc);
391  $pageposafter=$pdf->getPage();
392  if ($pageposafter > $pageposbefore) // There is a pagebreak
393  {
394  $pdf->rollbackTransaction(true);
395  $pageposafter=$pageposbefore;
396  //print $pageposafter.'-'.$pageposbefore;exit;
397  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
398  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,4,$curX,$curY,$hideref,$hidedesc);
399  $posyafter=$pdf->GetY();
400  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
401  {
402  if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
403  {
404  $pdf->AddPage('','',true);
405  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
406  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
407  $pdf->setPage($pageposafter+1);
408  }
409  }
410  else
411  {
412  // We found a page break
413  $showpricebeforepagebreak=0;
414  }
415  }
416  else // No pagebreak
417  {
418  $pdf->commitTransaction();
419  }
420 
421  $nexY = $pdf->GetY();
422  $pageposafter=$pdf->getPage();
423  $pdf->setPage($pageposbefore);
424  $pdf->setTopMargin($this->marge_haute);
425  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
426 
427  // We suppose that a too long description is moved completely on next page
428  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
429  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
430  }
431 
432  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
433 
434  /*
435  // TVA
436  $pdf->SetXY($this->posxcomm, $curY);
437  $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
438 
439  // Prix unitaire HT avant remise
440  $pdf->SetXY($this->posxup, $curY);
441  $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
442  */
443  // Quantity
444  //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
445  $pdf->SetXY($this->posxqty, $curY);
446  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
447 
448  // Remaining to ship
449  $pdf->SetXY($this->posxremainingqty, $curY);
450  $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
451  $pdf->MultiCell($this->page_largeur-$this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0, 'R');
452  /*
453  // Remise sur ligne
454  $pdf->SetXY($this->posxdiscount, $curY);
455  if ($object->lines[$i]->remise_percent)
456  {
457  $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
458  }
459 
460  // Total HT ligne
461  $pdf->SetXY($this->postotalht, $curY);
462  $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
463  $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
464 
465  // Collecte des totaux par valeur de tva
466  // dans le tableau tva["taux"]=total_tva
467  $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
468  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
469  $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
470  */
471 
472  // Add line
473  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
474  {
475  $pdf->setPage($pageposafter);
476  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
477  //$pdf->SetDrawColor(190,190,200);
478  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
479  $pdf->SetLineStyle(array('dash'=>0));
480  }
481 
482  $nexY+=2; // Passe espace entre les lignes
483 
484  // Detect if some page were added automatically and output _tableau for past pages
485  while ($pagenb < $pageposafter)
486  {
487  $pdf->setPage($pagenb);
488  if ($pagenb == 1)
489  {
490  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
491  }
492  else
493  {
494  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
495  }
496  $this->_pagefoot($pdf,$object,$outputlangs,1);
497  $pagenb++;
498  $pdf->setPage($pagenb);
499  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
500  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
501  }
502  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
503  {
504  if ($pagenb == 1)
505  {
506  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
507  }
508  else
509  {
510  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
511  }
512  $this->_pagefoot($pdf,$object,$outputlangs,1);
513  // New page
514  $pdf->AddPage();
515  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
516  $pagenb++;
517  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
518  }
519  }
520 
521  // Show square
522  if ($pagenb == 1)
523  {
524  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
525  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
526  }
527  else
528  {
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')) $pdf->AliasNbPages();
540 
541  // Check product remaining to be delivered
542  // TODO doit etre modifie
543  //$waitingDelivery = $object->getRemainingDelivered();
544  /*
545  $waitingDelivery='';
546 
547  if (is_array($waitingDelivery) & !empty($waitingDelivery))
548  {
549  $pdf->AddPage();
550 
551  $this->_pagehead($pdf, $object, 1, $outputlangs);
552  $pdf-> SetY(90);
553 
554  $w=array(40,100,50);
555  $header=array($outputlangs->transnoentities('Reference'),
556  $outputlangs->transnoentities('Label'),
557  $outputlangs->transnoentities('Qty')
558  );
559 
560  // Header
561  $num = count($header);
562  for($i = 0; $i < $num; $i++)
563  {
564  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
565  }
566 
567  $pdf->Ln();
568 
569  // Data
570  foreach($waitingDelivery as $value)
571  {
572  $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
573  $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
574  $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
575 
576  if ($pdf->GetY() > 250)
577  {
578  $this->_pagefoot($pdf,$object,$outputlangs,1);
579 
580  $pdf->AddPage('P', 'A4');
581 
582  $pdf->SetFont('','', $default_font_size - 1);
583  $this->_pagehead($pdf, $object, 0, $outputlangs);
584 
585  $pdf-> SetY(40);
586 
587  $num = count($header);
588  for($i = 0; $i < $num; $i++)
589  {
590  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
591  }
592 
593  $pdf->Ln();
594  }
595  }
596 
597  $this->_pagefoot($pdf,$object,$outputlangs);
598 
599  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
600  }*/
601 
602  $pdf->Close();
603 
604  $pdf->Output($file,'F');
605 
606  // Add pdfgeneration hook
607  if (! is_object($hookmanager))
608  {
609  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
610  $hookmanager=new HookManager($this->db);
611  }
612  $hookmanager->initHooks(array('pdfgeneration'));
613  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
614  global $action;
615  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
616 
617  if (! empty($conf->global->MAIN_UMASK))
618  @chmod($file, octdec($conf->global->MAIN_UMASK));
619 
620  $this->result = array('fullpath'=>$file);
621 
622  return 1; // pas d'erreur
623  }
624  else
625  {
626  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
627  return 0;
628  }
629  }
630 
631  $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
632  return 0;
633  }
634 
635  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
645  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
646  {
647  // phpcs:enable
648  global $conf,$mysoc;
649  $default_font_size = pdf_getPDFFontSize($outputlangs);
650 
651  $pdf->SetFont('','', $default_font_size);
652  $pdf->SetXY($this->marge_gauche, $posy);
653 
654  $larg_sign = ($this->page_largeur-$this->marge_gauche-$this->marge_droite)/3;
655  $pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
656  $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
657  $pdf->MultiCell($larg_sign,2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":",'','L');
658 
659  $pdf->Rect(2*$larg_sign+$this->marge_gauche, $posy + 1, $larg_sign, 25);
660  $pdf->SetXY(2*$larg_sign+$this->marge_gauche + 2, $posy + 2);
661  $pdf->MultiCell($larg_sign,2, $outputlangs->trans("ForCustomer").':','','L');
662  }
663 
676  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
677  {
678  global $conf,$mysoc;
679 
680  // Force to disable hidetop and hidebottom
681  $hidebottom=0;
682  if ($hidetop) $hidetop=-1;
683 
684  $default_font_size = pdf_getPDFFontSize($outputlangs);
685 
686  // Amount in (at tab_top - 1)
687  $pdf->SetTextColor(0,0,0);
688  $pdf->SetFont('','', $default_font_size - 2);
689 
690  // Output Rec
691  $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
692 
693  if (empty($hidetop))
694  {
695  $pdf->line($this->marge_gauche, $tab_top+10, $this->page_largeur-$this->marge_droite, $tab_top+10);
696  }
697 
698  $pdf->SetDrawColor(128,128,128);
699  $pdf->SetFont('','', $default_font_size - 1);
700 
701  if (empty($hidetop))
702  {
703  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
704  $pdf->MultiCell($this->posxcomm - $this->posxdesc,2, $outputlangs->transnoentities("Designation"),'','L');
705  }
706 
707  // Modif SEB pour avoir une col en plus pour les commentaires clients
708  $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
709  if (empty($hidetop)) {
710  $pdf->SetXY($this->posxcomm, $tab_top+1);
711  $pdf->MultiCell($this->posxqty - $this->posxcomm,2, $outputlangs->transnoentities("Comments"),'','L');
712  }
713 
714  // Qty
715  $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
716  if (empty($hidetop)) {
717  $pdf->SetXY($this->posxqty, $tab_top+1);
718  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities("QtyShippedShort"),'','R');
719  }
720 
721  // Remain to ship
722  $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
723  if (empty($hidetop)) {
724  $pdf->SetXY($this->posxremainingqty, $tab_top+1);
725  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->posxremainingqty, 2, $outputlangs->transnoentities("KeepToShipShort"),'','R');
726  }
727  }
728 
738  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
739  {
740  global $conf,$langs,$hookmanager;
741 
742  $default_font_size = pdf_getPDFFontSize($outputlangs);
743 
744  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
745 
746  // Show Draft Watermark
747  if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
748  {
749  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
750  }
751 
752  $pdf->SetTextColor(0,0,60);
753  $pdf->SetFont('','B', $default_font_size + 3);
754 
755  $posy=$this->marge_haute;
756  $posx=$this->page_largeur-$this->marge_droite-100;
757 
758  $pdf->SetXY($this->marge_gauche,$posy);
759 
760  // Logo
761  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
762  if ($this->emetteur->logo)
763  {
764  if (is_readable($logo))
765  {
766  $height=pdf_getHeightForLogo($logo);
767  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
768  }
769  else
770  {
771  $pdf->SetTextColor(200,0,0);
772  $pdf->SetFont('','B', $default_font_size - 2);
773  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
774  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
775  }
776  }
777  else $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
778 
779  $pdf->SetFont('','B', $default_font_size + 2);
780  $pdf->SetXY($posx,$posy);
781  $pdf->SetTextColor(0,0,60);
782  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
783 
784  $pdf->SetFont('','',$default_font_size + 2);
785 
786  $posy+=5;
787  $pdf->SetXY($posx,$posy);
788  $pdf->SetTextColor(0,0,60);
789  if ($object->date_valid)
790  {
791  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date_delivery,"%d %b %Y",false,$outputlangs,true), '', 'R');
792  }
793  else
794  {
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  {
802  $posy+=5;
803  $pdf->SetXY($posx,$posy);
804  $pdf->SetTextColor(0,0,60);
805  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
806  }
807 
808  $pdf->SetTextColor(0,0,60);
809 
810  $posy+=2;
811 
812  // Show list of linked objects
813  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
814 
815  if ($showaddress)
816  {
817  // Sender properties
818  $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur, $object->thirdparty, '', 0, 'source', $object);
819 
820  // Show sender
821  $posy=42;
822  $posx=$this->marge_gauche;
823  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
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(66,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)) $posx=$this->marge_gauche;
851  $pdf->SetTextColor(0,0,0);
852  $pdf->SetFont('','', $default_font_size - 2);
853  $pdf->SetXY($posx,$posy-5);
854  $pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L');
855 
856  // If SHIPPING contact defined on order, we use it
857  $usecontact=false;
858  $arrayidcontact=$object->commande->getIdContact('external','SHIPPING');
859  if (count($arrayidcontact) > 0)
860  {
861  $usecontact=true;
862  $result=$object->fetch_contact($arrayidcontact[0]);
863  }
864 
865  //Recipient name
866  // On peut utiliser le nom de la societe du contact
867  if ($usecontact && !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) $widthrecbox=84; // To work with US executive format
880  $posy=42;
881  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
882  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
883 
884  // Show recipient frame
885  $pdf->SetTextColor(0,0,0);
886  $pdf->SetFont('','', $default_font_size - 2);
887  $pdf->SetXY($posx+2,$posy-5);
888  //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
889  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
890 
891  // Show recipient name
892  $pdf->SetXY($posx+2,$posy+3);
893  $pdf->SetFont('','B', $default_font_size);
894  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
895 
896  $posy = $pdf->getY();
897 
898  // Show recipient information
899  $pdf->SetFont('','', $default_font_size - 1);
900  $pdf->SetXY($posx+2,$posy);
901  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
902  }
903 
904  $pdf->SetTextColor(0,0,60);
905  }
906 
916  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
917  {
918  global $conf;
919  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
920  return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
921  }
922 }
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:319
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:600
__construct($db)
Constructor.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:643
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:353
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:201
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Class to manage hooks.
type
Definition: viewcat.php:284
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:872
Class to manage shipments.
Class to manage customers orders.
$version
Dolibarr version of the loaded document string.
Classe mere des modeles de bon de livraison.
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:245
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1119
dol_print_date($time, $format='', $tzoutput='tzserver', $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:1158
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to build Delivery Order documents with typhon model.
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...
_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.