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