dolibarr  7.0.0-beta
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@capnetworks.com>
4  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5  * Copyright (C) 2008 Chiptronik
6  * Copyright (C) 2011-2012 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 {
42  var $db;
43  var $name;
44  var $description;
45  var $type;
46 
47  var $phpmin = array(4,3,0); // Minimum version of PHP required by module
48  var $version = 'dolibarr';
49 
50  var $page_largeur;
51  var $page_hauteur;
52  var $format;
53  var $marge_gauche;
54  var $marge_droite;
55  var $marge_haute;
56  var $marge_basse;
57 
58  var $emetteur; // Objet societe qui emet
59 
65  function __construct($db)
66  {
67  global $conf,$langs,$mysoc;
68 
69  $langs->load("main");
70  $langs->load("bills");
71  $langs->load("sendings");
72  $langs->load("companies");
73 
74  $this->db = $db;
75  $this->name = "typhon";
76  $this->description = $langs->trans("DocumentModelTyphon");
77 
78  // Dimension page pour format A4
79  $this->type = 'pdf';
80  $formatarray=pdf_getFormat();
81  $this->page_largeur = $formatarray['width'];
82  $this->page_hauteur = $formatarray['height'];
83  $this->format = array($this->page_largeur,$this->page_hauteur);
84  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
85  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
86  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
87  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
88 
89  $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
90  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
91  $this->option_codeproduitservice = 1; // Affiche code produit-service
92 
93  $this->franchise=!$mysoc->tva_assuj;
94 
95  // Get source company
96  $this->emetteur=$mysoc;
97  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
98 
99  // Define position of columns
100  $this->posxdesc=$this->marge_gauche+1;
101  $this->posxcomm=112;
102  //$this->posxtva=112;
103  //$this->posxup=126;
104  $this->posxqty=165;
105  $this->posxremainingqty=185;
106  //$this->posxdiscount=162;
107  //$this->postotalht=174;
108  if ($this->page_largeur < 210) // To work with US executive format
109  {
110  $this->posxcomm-=20;
111  //$this->posxtva-=20;
112  //$this->posxup-=20;
113  $this->posxqty-=20;
114  //$this->posxdiscount-=20;
115  //$this->postotalht-=20;
116  }
117 
118  $this->tva=array();
119  $this->atleastoneratenotnull=0;
120  $this->atleastonediscount=0;
121  }
122 
123 
135  function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
136  {
137  global $user,$langs,$conf,$mysoc,$hookmanager;
138 
139  if (! is_object($outputlangs)) $outputlangs=$langs;
140  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
141  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
142 
143  $outputlangs->load("main");
144  $outputlangs->load("dict");
145  $outputlangs->load("companies");
146  $outputlangs->load("bills");
147  $outputlangs->load("products");
148  $outputlangs->load("deliveries");
149  $outputlangs->load("sendings");
150 
151  if ($conf->expedition->dir_output)
152  {
153  $object->fetch_thirdparty();
154 
155  // Definition of $dir and $file
156  if ($object->specimen)
157  {
158  $dir = $conf->expedition->dir_output."/receipt";
159  $file = $dir . "/SPECIMEN.pdf";
160  }
161  else
162  {
163  $objectref = dol_sanitizeFileName($object->ref);
164  $dir = $conf->expedition->dir_output."/receipt/" . $objectref;
165  $file = $dir . "/" . $objectref . ".pdf";
166  }
167 
168  if (! file_exists($dir))
169  {
170  if (dol_mkdir($dir) < 0)
171  {
172  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
173  return 0;
174  }
175  }
176 
177  if (file_exists($dir))
178  {
179  // Add pdfgeneration hook
180  if (! is_object($hookmanager))
181  {
182  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
183  $hookmanager=new HookManager($this->db);
184  }
185  $hookmanager->initHooks(array('pdfgeneration'));
186  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
187  global $action;
188  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
189 
190  $nblines = count($object->lines);
191 
192  // Create pdf instance
193  $pdf=pdf_getInstance($this->format);
194  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
195  $heightforinfotot = 30; // Height reserved to output the info and total part
196  $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
197  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
198  $pdf->SetAutoPageBreak(1,0);
199 
200  if (class_exists('TCPDF'))
201  {
202  $pdf->setPrintHeader(false);
203  $pdf->setPrintFooter(false);
204  }
205  $pdf->SetFont(pdf_getPDFFont($outputlangs));
206  // Set path to the background PDF File
207  if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
208  {
209  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
210  $tplidx = $pdf->importPage(1);
211  }
212 
213  // We get the shipment that is the origin of delivery receipt
214  $expedition=new Expedition($this->db);
215  $result = $expedition->fetch($object->origin_id);
216  // Now we get the order that is origin of shipment
217  $commande = new Commande($this->db);
218  if ($expedition->origin == 'commande')
219  {
220  $commande->fetch($expedition->origin_id);
221  }
222  $object->commande=$commande; // We set order of shipment onto delivery.
223  $object->commande->loadExpeditions();
224 
225 
226  $pdf->Open();
227  $pagenb=0;
228  $pdf->SetDrawColor(128,128,128);
229 
230  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
231  $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
232  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
233  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
234  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
235  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
236 
237  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
238 
239  /*
240  // Positionne $this->atleastonediscount si on a au moins une remise
241  for ($i = 0 ; $i < $nblines ; $i++)
242  {
243  if ($object->lines[$i]->remise_percent)
244  {
245  $this->atleastonediscount++;
246  }
247  }
248  if (empty($this->atleastonediscount))
249  {
250  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
251  $this->posxtva+=($this->postotalht - $this->posxdiscount);
252  $this->posxup+=($this->postotalht - $this->posxdiscount);
253  $this->posxqty+=($this->postotalht - $this->posxdiscount);
254  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
255  //$this->postotalht;
256  }
257  */
258 
259  // New page
260  $pdf->AddPage();
261  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
262  $pagenb++;
263  $this->_pagehead($pdf, $object, 1, $outputlangs);
264  $pdf->SetFont('','', $default_font_size - 1);
265  $pdf->MultiCell(0, 3, ''); // Set interline to 3
266  $pdf->SetTextColor(0,0,0);
267 
268  $tab_top = 90;
269  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
270  $tab_height = 130;
271  $tab_height_newpage = 150;
272 
273  // Incoterm
274  $height_incoterms = 0;
275  if ($conf->incoterm->enabled)
276  {
277  $desc_incoterms = $object->getIncotermsForPDF();
278  if ($desc_incoterms)
279  {
280  $tab_top = 88;
281 
282  $pdf->SetFont('','', $default_font_size - 1);
283  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
284  $nexY = $pdf->GetY();
285  $height_incoterms=$nexY-$tab_top;
286 
287  // Rect prend une longueur en 3eme param
288  $pdf->SetDrawColor(192,192,192);
289  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
290 
291  $tab_top = $nexY+6;
292  $height_incoterms += 4;
293  }
294  }
295 
296  // Affiche notes
297  if (! empty($object->note_public))
298  {
299  $tab_top = 88 + $height_incoterms;
300 
301  $pdf->SetFont('','', $default_font_size - 1);
302  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
303  $nexY = $pdf->GetY();
304  $height_note=$nexY-$tab_top;
305 
306  // Rect prend une longueur en 3eme param
307  $pdf->SetDrawColor(192,192,192);
308  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
309 
310  $tab_height = $tab_height - $height_note;
311  $tab_top = $nexY+6;
312  }
313  else
314  {
315  $height_note=0;
316  }
317 
318  $iniY = $tab_top + 11;
319  $curY = $tab_top + 11;
320  $nexY = $tab_top + 11;
321 
322  // Loop on each lines
323  for ($i = 0 ; $i < $nblines ; $i++)
324  {
325  $curY = $nexY;
326  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
327  $pdf->SetTextColor(0,0,0);
328 
329  $pdf->setTopMargin($tab_top_newpage);
330  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
331  $pageposbefore=$pdf->getPage();
332 
333  // Description of product line
334  $curX = $this->posxdesc-1;
335 
336  $showpricebeforepagebreak=1;
337 
338  $pdf->startTransaction();
339  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,3,$curX,$curY,$hideref,$hidedesc);
340  $pageposafter=$pdf->getPage();
341  if ($pageposafter > $pageposbefore) // There is a pagebreak
342  {
343  $pdf->rollbackTransaction(true);
344  $pageposafter=$pageposbefore;
345  //print $pageposafter.'-'.$pageposbefore;exit;
346  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
347  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxcomm-$curX,4,$curX,$curY,$hideref,$hidedesc);
348  $posyafter=$pdf->GetY();
349  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
350  {
351  if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
352  {
353  $pdf->AddPage('','',true);
354  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
355  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
356  $pdf->setPage($pageposafter+1);
357  }
358  }
359  else
360  {
361  // We found a page break
362  $showpricebeforepagebreak=0;
363  }
364  }
365  else // No pagebreak
366  {
367  $pdf->commitTransaction();
368  }
369 
370  $nexY = $pdf->GetY();
371  $pageposafter=$pdf->getPage();
372  $pdf->setPage($pageposbefore);
373  $pdf->setTopMargin($this->marge_haute);
374  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
375 
376  // We suppose that a too long description is moved completely on next page
377  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
378  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
379  }
380 
381  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
382 
383  /*
384  // TVA
385  $pdf->SetXY($this->posxcomm, $curY);
386  $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
387 
388  // Prix unitaire HT avant remise
389  $pdf->SetXY($this->posxup, $curY);
390  $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
391  */
392  // Quantity
393  //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
394  $pdf->SetXY($this->posxqty, $curY);
395  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
396 
397  // Remaining to ship
398  $pdf->SetXY($this->posxremainingqty, $curY);
399  $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
400  $pdf->MultiCell($this->page_largeur-$this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0, 'R');
401  /*
402  // Remise sur ligne
403  $pdf->SetXY($this->posxdiscount, $curY);
404  if ($object->lines[$i]->remise_percent)
405  {
406  $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
407  }
408 
409  // Total HT ligne
410  $pdf->SetXY($this->postotalht, $curY);
411  $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
412  $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
413 
414  // Collecte des totaux par valeur de tva
415  // dans le tableau tva["taux"]=total_tva
416  $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
417  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
418  $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
419  */
420 
421  // Add line
422  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
423  {
424  $pdf->setPage($pageposafter);
425  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
426  //$pdf->SetDrawColor(190,190,200);
427  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
428  $pdf->SetLineStyle(array('dash'=>0));
429  }
430 
431  $nexY+=2; // Passe espace entre les lignes
432 
433  // Detect if some page were added automatically and output _tableau for past pages
434  while ($pagenb < $pageposafter)
435  {
436  $pdf->setPage($pagenb);
437  if ($pagenb == 1)
438  {
439  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
440  }
441  else
442  {
443  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
444  }
445  $this->_pagefoot($pdf,$object,$outputlangs,1);
446  $pagenb++;
447  $pdf->setPage($pagenb);
448  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
449  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
450  }
451  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
452  {
453  if ($pagenb == 1)
454  {
455  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
456  }
457  else
458  {
459  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
460  }
461  $this->_pagefoot($pdf,$object,$outputlangs,1);
462  // New page
463  $pdf->AddPage();
464  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
465  $pagenb++;
466  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
467  }
468  }
469 
470  // Show square
471  if ($pagenb == 1)
472  {
473  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
474  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
475  }
476  else
477  {
478  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
479  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
480  }
481 
482  // Affiche zone infos
483  $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
484 
485  // Pied de page
486  $this->_pagefoot($pdf,$object,$outputlangs);
487 
488  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
489 
490  // Check product remaining to be delivered
491  // TODO doit etre modifie
492  //$waitingDelivery = $object->getRemainingDelivered();
493  /*
494  $waitingDelivery='';
495 
496  if (is_array($waitingDelivery) & !empty($waitingDelivery))
497  {
498  $pdf->AddPage();
499 
500  $this->_pagehead($pdf, $object, 1, $outputlangs);
501  $pdf-> SetY(90);
502 
503  $w=array(40,100,50);
504  $header=array($outputlangs->transnoentities('Reference'),
505  $outputlangs->transnoentities('Label'),
506  $outputlangs->transnoentities('Qty')
507  );
508 
509  // Header
510  $num = count($header);
511  for($i = 0; $i < $num; $i++)
512  {
513  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
514  }
515 
516  $pdf->Ln();
517 
518  // Data
519  foreach($waitingDelivery as $value)
520  {
521  $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
522  $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
523  $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
524 
525  if ($pdf->GetY() > 250)
526  {
527  $this->_pagefoot($pdf,$object,$outputlangs,1);
528 
529  $pdf->AddPage('P', 'A4');
530 
531  $pdf->SetFont('','', $default_font_size - 1);
532  $this->_pagehead($pdf, $object, 0, $outputlangs);
533 
534  $pdf-> SetY(40);
535 
536  $num = count($header);
537  for($i = 0; $i < $num; $i++)
538  {
539  $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
540  }
541 
542  $pdf->Ln();
543  }
544  }
545 
546  $this->_pagefoot($pdf,$object,$outputlangs);
547 
548  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
549  }*/
550 
551  $pdf->Close();
552 
553  $pdf->Output($file,'F');
554 
555  // Add pdfgeneration hook
556  if (! is_object($hookmanager))
557  {
558  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
559  $hookmanager=new HookManager($this->db);
560  }
561  $hookmanager->initHooks(array('pdfgeneration'));
562  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
563  global $action;
564  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
565 
566  if (! empty($conf->global->MAIN_UMASK))
567  @chmod($file, octdec($conf->global->MAIN_UMASK));
568 
569  $this->result = array('fullpath'=>$file);
570 
571  return 1; // pas d'erreur
572  }
573  else
574  {
575  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
576  return 0;
577  }
578  }
579 
580  $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
581  return 0;
582  }
583 
593  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
594  {
595  global $conf,$mysoc;
596  $default_font_size = pdf_getPDFFontSize($outputlangs);
597 
598  $pdf->SetFont('','', $default_font_size);
599  $pdf->SetXY($this->marge_gauche, $posy);
600 
601  $larg_sign = ($this->page_largeur-$this->marge_gauche-$this->marge_droite)/3;
602  $pdf->Rect($this->marge_gauche, $posy + 1, $larg_sign, 25);
603  $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
604  $pdf->MultiCell($larg_sign,2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":",'','L');
605 
606  $pdf->Rect(2*$larg_sign+$this->marge_gauche, $posy + 1, $larg_sign, 25);
607  $pdf->SetXY(2*$larg_sign+$this->marge_gauche + 2, $posy + 2);
608  $pdf->MultiCell($larg_sign,2, $outputlangs->trans("ForCustomer").':','','L');
609  }
610 
623  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
624  {
625  global $conf,$mysoc;
626 
627  // Force to disable hidetop and hidebottom
628  $hidebottom=0;
629  if ($hidetop) $hidetop=-1;
630 
631  $default_font_size = pdf_getPDFFontSize($outputlangs);
632 
633  // Amount in (at tab_top - 1)
634  $pdf->SetTextColor(0,0,0);
635  $pdf->SetFont('','', $default_font_size - 2);
636 
637  // Output Rec
638  $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
639 
640  if (empty($hidetop))
641  {
642  $pdf->line($this->marge_gauche, $tab_top+10, $this->page_largeur-$this->marge_droite, $tab_top+10);
643  }
644 
645  $pdf->SetDrawColor(128,128,128);
646  $pdf->SetFont('','', $default_font_size - 1);
647 
648  if (empty($hidetop))
649  {
650  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
651  $pdf->MultiCell($this->posxcomm - $this->posxdesc,2, $outputlangs->transnoentities("Designation"),'','L');
652  }
653 
654  // Modif SEB pour avoir une col en plus pour les commentaires clients
655  $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
656  if (empty($hidetop)) {
657  $pdf->SetXY($this->posxcomm, $tab_top+1);
658  $pdf->MultiCell($this->posxqty - $this->posxcomm,2, $outputlangs->transnoentities("Comments"),'','L');
659  }
660 
661  // Qty
662  $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
663  if (empty($hidetop)) {
664  $pdf->SetXY($this->posxqty, $tab_top+1);
665  $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities("QtyShippedShort"),'','R');
666  }
667 
668  // Remain to ship
669  $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
670  if (empty($hidetop)) {
671  $pdf->SetXY($this->posxremainingqty, $tab_top+1);
672  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->posxremainingqty, 2, $outputlangs->transnoentities("KeepToShipShort"),'','R');
673  }
674  }
675 
685  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
686  {
687  global $conf,$langs,$hookmanager;
688 
689  $default_font_size = pdf_getPDFFontSize($outputlangs);
690 
691  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
692 
693  // Show Draft Watermark
694  if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
695  {
696  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
697  }
698 
699  $pdf->SetTextColor(0,0,60);
700  $pdf->SetFont('','B', $default_font_size + 3);
701 
702  $posy=$this->marge_haute;
703  $posx=$this->page_largeur-$this->marge_droite-100;
704 
705  $pdf->SetXY($this->marge_gauche,$posy);
706 
707  // Logo
708  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
709  if ($this->emetteur->logo)
710  {
711  if (is_readable($logo))
712  {
713  $height=pdf_getHeightForLogo($logo);
714  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
715  }
716  else
717  {
718  $pdf->SetTextColor(200,0,0);
719  $pdf->SetFont('','B', $default_font_size - 2);
720  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
721  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
722  }
723  }
724  else $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
725 
726  $pdf->SetFont('','B', $default_font_size + 2);
727  $pdf->SetXY($posx,$posy);
728  $pdf->SetTextColor(0,0,60);
729  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
730 
731  $pdf->SetFont('','',$default_font_size + 2);
732 
733  $posy+=5;
734  $pdf->SetXY($posx,$posy);
735  $pdf->SetTextColor(0,0,60);
736  if ($object->date_valid)
737  {
738  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date_delivery,"%d %b %Y",false,$outputlangs,true), '', 'R');
739  }
740  else
741  {
742  $pdf->SetTextColor(255,0,0);
743  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryNotValidated"), '', 'R');
744  $pdf->SetTextColor(0,0,60);
745  }
746 
747  if ($object->thirdparty->code_client)
748  {
749  $posy+=5;
750  $pdf->SetXY($posx,$posy);
751  $pdf->SetTextColor(0,0,60);
752  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
753  }
754 
755  $pdf->SetTextColor(0,0,60);
756 
757  $posy+=2;
758 
759  // Add list of linked orders on shipment
760  // Currently not supported by pdf_writeLinkedObjects, link for delivery to order is done through shipment)
761  if ($object->origin == 'expedition' || $object->origin == 'shipping')
762  {
763  $Yoff=$posy-5;
764 
765  include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
766  $shipment = new Expedition($this->db);
767  $shipment->fetch($object->origin_id);
768 
769  $origin = $shipment->origin;
770  $origin_id = $shipment->origin_id;
771 
772  if ($conf->$origin->enabled)
773  {
774  $outputlangs->load('orders');
775 
776  $classname = ucfirst($origin);
777  $linkedobject = new $classname($this->db);
778  $result=$linkedobject->fetch($origin_id);
779  if ($result >= 0)
780  {
781  $pdf->SetFont('','', $default_font_size - 2);
782  $text=$linkedobject->ref;
783  if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
784  $Yoff = $Yoff+8;
785  $pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff);
786  $pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
787  $Yoff = $Yoff+3;
788  $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
789  $pdf->MultiCell(60, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
790  }
791  }
792 
793  $posy=$Yoff;
794  }
795 
796  // Show list of linked objects
797  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
798 
799  if ($showaddress)
800  {
801  // Sender properties
802  $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
803 
804  // Show sender
805  $posy=42;
806  $posx=$this->marge_gauche;
807  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
808  $hautcadre=40;
809 
810  // Show sender frame
811  $pdf->SetTextColor(0,0,0);
812  $pdf->SetFont('','', $default_font_size - 2);
813  $pdf->SetXY($posx,$posy-5);
814  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
815  $pdf->SetXY($posx,$posy);
816  $pdf->SetFillColor(230,230,230);
817  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
818  $pdf->SetTextColor(0,0,60);
819 
820  // Show sender name
821  $pdf->SetXY($posx+2,$posy+3);
822  $pdf->SetFont('','B',$default_font_size);
823  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
824  $posy=$pdf->getY();
825 
826  // Show sender information
827  $pdf->SetXY($posx+2,$posy);
828  $pdf->SetFont('','', $default_font_size - 1);
829  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
830 
831  // Client destinataire
832  $posy=42;
833  $posx=102;
834  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
835  $pdf->SetTextColor(0,0,0);
836  $pdf->SetFont('','', $default_font_size - 2);
837  $pdf->SetXY($posx,$posy-5);
838  $pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L');
839 
840  // If SHIPPING contact defined on order, we use it
841  $usecontact=false;
842  $arrayidcontact=$object->commande->getIdContact('external','SHIPPING');
843  if (count($arrayidcontact) > 0)
844  {
845  $usecontact=true;
846  $result=$object->fetch_contact($arrayidcontact[0]);
847  }
848 
849  //Recipient name
850  // On peut utiliser le nom de la societe du contact
851  if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
852  $thirdparty = $object->contact;
853  } else {
854  $thirdparty = $object->thirdparty;
855  }
856 
857  $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
858 
859  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
860 
861  // Show recipient
862  $widthrecbox=100;
863  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
864  $posy=42;
865  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
866  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
867 
868  // Show recipient frame
869  $pdf->SetTextColor(0,0,0);
870  $pdf->SetFont('','', $default_font_size - 2);
871  $pdf->SetXY($posx+2,$posy-5);
872  //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
873  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
874 
875  // Show recipient name
876  $pdf->SetXY($posx+2,$posy+3);
877  $pdf->SetFont('','B', $default_font_size);
878  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
879 
880  $posy = $pdf->getY();
881 
882  // Show recipient information
883  $pdf->SetFont('','', $default_font_size - 1);
884  $pdf->SetXY($posx+2,$posy);
885  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
886  }
887 
888  $pdf->SetTextColor(0,0,60);
889  }
890 
900  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
901  {
902  global $conf;
903  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
904  return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
905  }
906 
907 }
908 
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:350
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:580
__construct($db)
Constructor.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:623
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:384
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></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:554
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:256
_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:233
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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:852
Class to manage shipments.
Class to manage customers orders.
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:277
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1100
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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:1139
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Classe permettant de generer les bons de livraison au modele Typho.
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.
type
Definition: viewcat.php:283
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.