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