dolibarr 23.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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024 Nick Fragoulis
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
34require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37
38
43{
47 public $db;
48
52 public $name;
53
57 public $description;
58
62 public $update_main_doc_field;
63
67 public $type;
68
73 public $version = 'dolibarr';
74
78 public $posxcomm; // For customer comment column
82 public $posxweightvol; // For weight or volume
86 public $posxremainingqty;
87
88
94 public function __construct($db)
95 {
96 global $conf, $langs, $mysoc;
97
98 // Translations
99 $langs->loadLangs(array("main", "bills", "sendings", "companies"));
100
101 $this->db = $db;
102 $this->name = "Typhon";
103 $this->description = $langs->trans("DocumentModelTyphon");
104 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
105
106 // Page size for A4 format
107 $this->type = 'pdf';
108 $formatarray = pdf_getFormat();
109 $this->page_largeur = $formatarray['width'];
110 $this->page_hauteur = $formatarray['height'];
111 $this->format = array($this->page_largeur, $this->page_hauteur);
112 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
113 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
114 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
115 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
116 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
117 $this->option_logo = 1; // Display logo FAC_PDF_LOGO
118 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
119
120 // Define position of columns
121 $this->posxdesc = $this->marge_gauche + 1;
122 $this->posxcomm = 112; // customer comment
123 //$this->posxtva=112;
124 //$this->posxup=126;
125 $this->posxqty = 165;
126 $this->posxremainingqty = 185;
127 //$this->posxdiscount=162;
128 //$this->postotalht=174;
129 if ($this->page_largeur < 210) { // To work with US executive format
130 $this->posxcomm -= 20;
131 //$this->posxtva-=20;
132 //$this->posxup-=20;
133 $this->posxqty -= 20;
134 //$this->posxdiscount-=20;
135 //$this->postotalht-=20;
136 }
137
138 if ($mysoc === null) {
139 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
140 return;
141 }
142
143 // Get source company
144 $this->emetteur = $mysoc;
145 if (empty($this->emetteur->country_code)) {
146 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
147 }
148 }
149
150
151 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
163 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 {
165 // phpcs:enable
166 global $user, $langs, $conf, $mysoc, $hookmanager;
167
168 if (!is_object($outputlangs)) {
169 $outputlangs = $langs;
170 }
171 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
172 if (getDolGlobalString('MAIN_USE_FPDF')) {
173 $outputlangs->charset_output = 'ISO-8859-1';
174 }
175
176 // Load translation files required by the page
177 $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "sendings"));
178
179 if ($conf->expedition->dir_output) {
180 $object->fetch_thirdparty();
181
182 // Definition of $dir and $file
183 if ($object->specimen) {
184 $dir = $conf->expedition->dir_output."/receipt";
185 $file = $dir."/SPECIMEN.pdf";
186 } else {
187 $objectref = dol_sanitizeFileName($object->ref);
188 $dir = $conf->expedition->dir_output."/receipt/".$objectref;
189 $file = $dir."/".$objectref.".pdf";
190 }
191
192 if (!file_exists($dir)) {
193 if (dol_mkdir($dir) < 0) {
194 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
195 return 0;
196 }
197 }
198
199 if (file_exists($dir)) {
200 // Add pdfgeneration hook
201 if (!is_object($hookmanager)) {
202 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
203 $hookmanager = new HookManager($this->db);
204 }
205 $hookmanager->initHooks(array('pdfgeneration'));
206 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
207 global $action;
208 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
209
210 $nblines = count($object->lines);
211
212 // Create pdf instance
213 $pdf = pdf_getInstance($this->format);
214 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
215 $heightforinfotot = 30; // Height reserved to output the info and total part
216 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
217 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
218 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
219 $heightforfooter += 6;
220 }
221 $pdf->setAutoPageBreak(true, 0);
222
223 if (class_exists('TCPDF')) {
224 $pdf->setPrintHeader(false);
225 $pdf->setPrintFooter(false);
226 }
227 $pdf->SetFont(pdf_getPDFFont($outputlangs));
228 // Set path to the background PDF File
229 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
230 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
231 $tplidx = $pdf->importPage(1);
232 }
233
234 // We get the shipment that is the origin of delivery receipt
235 $expedition = new Expedition($this->db);
236 $result = $expedition->fetch($object->origin_id);
237 // Now we get the order that is origin of shipment
238 $commande = new Commande($this->db);
239 if ($expedition->origin == 'commande') {
240 $commande->fetch($expedition->origin_id);
241 }
242 $object->commande = $commande; // We set order of shipment onto delivery.
243 $object->commande->loadExpeditions();
244
245
246 $pdf->Open();
247 $pagenb = 0;
248 $pdf->SetDrawColor(128, 128, 128);
249
250 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
251 $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
252 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
253 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
254 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
255 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
256 $pdf->SetCompression(false);
257 }
258
259 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
260 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
261
262 /*
263 // Positionne $this->atleastonediscount si on a au moins une remise
264 for ($i = 0 ; $i < $nblines ; $i++)
265 {
266 if ($object->lines[$i]->remise_percent)
267 {
268 $this->atleastonediscount++;
269 }
270 }
271 if (empty($this->atleastonediscount))
272 {
273 $this->posxpicture+=($this->postotalht - $this->posxdiscount);
274 $this->posxtva+=($this->postotalht - $this->posxdiscount);
275 $this->posxup+=($this->postotalht - $this->posxdiscount);
276 $this->posxqty+=($this->postotalht - $this->posxdiscount);
277 $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
278 //$this->postotalht;
279 }
280 */
281
282 // New page
283 $pdf->AddPage();
284 if (!empty($tplidx)) {
285 $pdf->useTemplate($tplidx);
286 }
287 $pagenb++;
288 $this->_pagehead($pdf, $object, 1, $outputlangs);
289 $pdf->SetFont('', '', $default_font_size - 1);
290 $pdf->MultiCell(0, 3, ''); // Set interline to 3
291 $pdf->SetTextColor(0, 0, 0);
292
293 $tab_top = 90;
294 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
295
296 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
297
298 // Incoterm
299 $height_incoterms = 0;
300 if (isModEnabled('incoterm')) {
301 $desc_incoterms = $object->getIncotermsForPDF();
302 if ($desc_incoterms) {
303 $tab_top -= 2;
304
305 $pdf->SetFont('', '', $default_font_size - 1);
306 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
307 $nexY = $pdf->GetY();
308 $height_incoterms = $nexY - $tab_top;
309
310 // Rect takes a length in 3rd parameter
311 $pdf->SetDrawColor(192, 192, 192);
312 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
313
314 $tab_top = $nexY + 6;
315 $height_incoterms += 4;
316 }
317 }
318
319 // Affiche notes
320 if (!empty($object->note_public)) {
321 $tab_top = 88 + $height_incoterms;
322
323 $pdf->SetFont('', '', $default_font_size - 1);
324 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
325 $nexY = $pdf->GetY();
326 $height_note = $nexY - $tab_top;
327
328 // Rect takes a length in 3rd parameter
329 $pdf->SetDrawColor(192, 192, 192);
330 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
331
332 $tab_height -= $height_note;
333 $tab_top = $nexY + 6;
334 } else {
335 $height_note = 0;
336 }
337
338 $iniY = $tab_top + 11;
339 $curY = $tab_top + 11;
340 $nexY = $tab_top + 11;
341
342 // Loop on each lines
343 for ($i = 0; $i < $nblines; $i++) {
344 $curY = $nexY;
345 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
346 $pdf->SetTextColor(0, 0, 0);
347
348 $pdf->setTopMargin($tab_top_newpage);
349 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
350 $pageposbefore = $pdf->getPage();
351
352 // Description of product line
353 $curX = $this->posxdesc - 1;
354
355 $showpricebeforepagebreak = 1;
356
357 $pdf->startTransaction();
358 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
359 $pageposafter = $pdf->getPage();
360 if ($pageposafter > $pageposbefore) { // There is a pagebreak
361 $pdf->rollbackTransaction(true);
362 $pageposafter = $pageposbefore;
363 //print $pageposafter.'-'.$pageposbefore;exit;
364 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
365 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
366 $posyafter = $pdf->GetY();
367 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
368 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
369 $pdf->AddPage('', '', true);
370 if (!empty($tplidx)) {
371 $pdf->useTemplate($tplidx);
372 }
373 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
374 $this->_pagehead($pdf, $object, 0, $outputlangs);
375 }
376 $pdf->setPage($pageposafter + 1);
377 }
378 } else {
379 // We found a page break
380 // Allows data in the first page if description is long enough to break in multiples pages
381 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
382 $showpricebeforepagebreak = 1;
383 } else {
384 $showpricebeforepagebreak = 0;
385 }
386 }
387 } else { // No pagebreak
388 $pdf->commitTransaction();
389 }
390
391 $nexY = $pdf->GetY();
392 $pageposafter = $pdf->getPage();
393 $pdf->setPage($pageposbefore);
394 $pdf->setTopMargin($this->marge_haute);
395 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
396
397 // We suppose that a too long description is moved completely on next page
398 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
399 $pdf->setPage($pageposafter);
400 $curY = $tab_top_newpage;
401 }
402
403 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
404
405 /*
406 // TVA
407 $pdf->SetXY($this->posxcomm, $curY);
408 $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
409
410 // Prix unitaire HT avant remise
411 $pdf->SetXY($this->posxup, $curY);
412 $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
413 */
414 // Quantity
415 //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
416 $pdf->SetXY($this->posxqty, $curY);
417 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, (string) $object->lines[$i]->qty_shipped, 0, 'R');
418
419 // Remaining to ship
420 $pdf->SetXY($this->posxremainingqty, $curY);
421 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
422 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, (string) $qtyRemaining, 0, 'R');
423 /*
424 // Remise sur ligne
425 $pdf->SetXY($this->posxdiscount, $curY);
426 if ($object->lines[$i]->remise_percent)
427 {
428 $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
429 }
430
431 // Total HT ligne
432 $pdf->SetXY($this->postotalht, $curY);
433 $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
434 $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
435
436 // Collecte des totaux par valeur de tva
437 // dans le tableau tva["taux"]=total_tva
438 $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
439 if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
440 $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
441 */
442
443 // Add line
444 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
445 $pdf->setPage($pageposafter);
446 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
447 //$pdf->SetDrawColor(190,190,200);
448 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
449 $pdf->SetLineStyle(array('dash' => 0));
450 }
451
452 $nexY += 2; // Add space between lines
453
454 // Detect if some page were added automatically and output _tableau for past pages
455 while ($pagenb < $pageposafter) {
456 $pdf->setPage($pagenb);
457 if ($pagenb == 1) {
458 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
459 } else {
460 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
461 }
462 $this->_pagefoot($pdf, $object, $outputlangs, 1);
463 $pagenb++;
464 $pdf->setPage($pagenb);
465 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
466 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
467 $this->_pagehead($pdf, $object, 0, $outputlangs);
468 }
469 if (!empty($tplidx)) {
470 $pdf->useTemplate($tplidx);
471 }
472 }
473 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
474 if ($pagenb == 1) {
475 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
476 } else {
477 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
478 }
479 $this->_pagefoot($pdf, $object, $outputlangs, 1);
480 // New page
481 $pdf->AddPage();
482 if (!empty($tplidx)) {
483 $pdf->useTemplate($tplidx);
484 }
485 $pagenb++;
486 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
487 $this->_pagehead($pdf, $object, 0, $outputlangs);
488 }
489 }
490 }
491
492 // Show square
493 if ($pagenb == 1) {
494 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
495 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
496 } else {
497 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
498 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
499 }
500
501 // Affiche zone infos
502 $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
503
504 // Pied de page
505 $this->_pagefoot($pdf, $object, $outputlangs);
506
507 if (method_exists($pdf, 'AliasNbPages')) {
508 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
509 }
510
511 // Check product remaining to be delivered
512 // TODO doit etre modifie
513 //$waitingDelivery = $object->getRemainingDelivered();
514 /*
515 $waitingDelivery='';
516
517 if (is_array($waitingDelivery) & !empty($waitingDelivery))
518 {
519 $pdf->AddPage();
520
521 $this->_pagehead($pdf, $object, 1, $outputlangs);
522 $pdf-> SetY(90);
523
524 $w=array(40,100,50);
525 $header=array($outputlangs->transnoentities('Reference'),
526 $outputlangs->transnoentities('Label'),
527 $outputlangs->transnoentities('Qty')
528 );
529
530 // Header
531 $num = count($header);
532 for($i = 0; $i < $num; $i++)
533 {
534 $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
535 }
536
537 $pdf->Ln();
538
539 // Data
540 foreach($waitingDelivery as $value)
541 {
542 $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
543 $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
544 $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
545
546 if ($pdf->GetY() > 250)
547 {
548 $this->_pagefoot($pdf,$object,$outputlangs,1);
549
550 $pdf->AddPage('P', 'A4');
551
552 $pdf->SetFont('','', $default_font_size - 1);
553 $this->_pagehead($pdf, $object, 0, $outputlangs);
554
555 $pdf-> SetY(40);
556
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 }
566
567 $this->_pagefoot($pdf,$object,$outputlangs);
568
569 if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
570 }*/
571
572 $pdf->Close();
573
574 $pdf->Output($file, 'F');
575
576 // Add pdfgeneration hook
577 if (!is_object($hookmanager)) {
578 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
579 $hookmanager = new HookManager($this->db);
580 }
581 $hookmanager->initHooks(array('pdfgeneration'));
582 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
583 global $action;
584 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
585 $this->warnings = $hookmanager->warnings;
586 if ($reshook < 0) {
587 $this->error = $hookmanager->error;
588 $this->errors = $hookmanager->errors;
589 dolChmod($file);
590 return -1;
591 }
592
593 dolChmod($file);
594
595 $this->result = array('fullpath' => $file);
596
597 return 1; // No error
598 } else {
599 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
600 return 0;
601 }
602 }
603
604 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
605 return 0;
606 }
607
608 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
609 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
619 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
620 {
621 // phpcs:enable
622 global $conf, $mysoc;
623 $default_font_size = pdf_getPDFFontSize($outputlangs);
624
625 $pdf->SetFont('', '', $default_font_size);
626 $pdf->SetXY($this->marge_gauche, $posy);
627
628 $larg_sign = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 3;
629 $pdf->RoundedRect($this->marge_gauche, $posy + 1, $larg_sign, 25, $this->corner_radius, '1234', 'D');
630 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
631 $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":", '', 'L');
632
633 $pdf->RoundedRect(2 * $larg_sign + $this->marge_gauche, $posy + 1, $larg_sign, 25, $this->corner_radius, '1234', 'D');
634 $pdf->SetXY(2 * $larg_sign + $this->marge_gauche + 2, $posy + 2);
635 $pdf->MultiCell($larg_sign, 2, $outputlangs->trans("ForCustomer").':', '', 'L');
636 }
637
638 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
651 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
652 {
653 global $conf, $mysoc;
654
655 // Force to disable hidetop and hidebottom
656 $hidebottom = 0;
657 if ($hidetop) {
658 $hidetop = -1;
659 }
660
661 $default_font_size = pdf_getPDFFontSize($outputlangs);
662
663 // Amount in (at tab_top - 1)
664 $pdf->SetTextColor(0, 0, 0);
665 $pdf->SetFont('', '', $default_font_size - 2);
666
667 // Output Rec
668 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
669
670 if (empty($hidetop)) {
671 $pdf->line($this->marge_gauche, $tab_top + 10, $this->page_largeur - $this->marge_droite, $tab_top + 10);
672 }
673
674 $pdf->SetDrawColor(128, 128, 128);
675 $pdf->SetFont('', '', $default_font_size - 1);
676
677 if (empty($hidetop)) {
678 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
679 $pdf->MultiCell($this->posxcomm - $this->posxdesc, 2, $outputlangs->transnoentities("Designation"), '', 'L');
680 }
681
682 // Modif SEB pour avoir une col en plus pour les commentaires clients
683 $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
684 if (empty($hidetop)) {
685 $pdf->SetXY($this->posxcomm, $tab_top + 1);
686 $pdf->MultiCell($this->posxqty - $this->posxcomm, 2, $outputlangs->transnoentities("Comments"), '', 'L');
687 }
688
689 // Qty
690 $pdf->line($this->posxqty, $tab_top, $this->posxqty, $tab_top + $tab_height);
691 if (empty($hidetop)) {
692 $pdf->SetXY($this->posxqty, $tab_top + 1);
693 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 2, $outputlangs->transnoentities("QtyShippedShort"), '', 'R');
694 }
695
696 // Remain to ship
697 $pdf->line($this->posxremainingqty, $tab_top, $this->posxremainingqty, $tab_top + $tab_height);
698 if (empty($hidetop)) {
699 $pdf->SetXY($this->posxremainingqty, $tab_top + 1);
700 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 2, $outputlangs->transnoentities("KeepToShipShort"), '', 'R');
701 }
702 }
703
704 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
714 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
715 {
716 global $conf, $langs;
717
718 $default_font_size = pdf_getPDFFontSize($outputlangs);
719
720 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
721
722 // Show Draft Watermark
723 if ($object->statut == 0 && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')) {
724 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
725 }
726
727 $pdf->SetTextColor(0, 0, 60);
728 $pdf->SetFont('', 'B', $default_font_size + 3);
729
730 $posy = $this->marge_haute;
731 $posx = $this->page_largeur - $this->marge_droite - 100;
732
733 $pdf->SetXY($this->marge_gauche, $posy);
734
735 // Logo
736 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
737 if ($this->emetteur->logo) {
738 if (is_readable($logo)) {
739 $height = pdf_getHeightForLogo($logo);
740 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
741 } else {
742 $pdf->SetTextColor(200, 0, 0);
743 $pdf->SetFont('', 'B', $default_font_size - 2);
744 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
745 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
746 }
747 } else {
748 $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
749 }
750
751 $pdf->SetFont('', 'B', $default_font_size + 2);
752 $pdf->SetXY($posx, $posy);
753 $pdf->SetTextColor(0, 0, 60);
754 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
755
756 $pdf->SetFont('', '', $default_font_size + 2);
757
758 $posy += 5;
759 $pdf->SetXY($posx, $posy);
760 $pdf->SetTextColor(0, 0, 60);
761 if ($object->date_valid) {
762 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_delivery, "%d %b %Y", false, $outputlangs, true), '', 'R');
763 } else {
764 $pdf->SetTextColor(255, 0, 0);
765 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryNotValidated"), '', 'R');
766 $pdf->SetTextColor(0, 0, 60);
767 }
768
769 if ($object->thirdparty->code_client) {
770 $posy += 5;
771 $pdf->SetXY($posx, $posy);
772 $pdf->SetTextColor(0, 0, 60);
773 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
774 }
775
776 $pdf->SetTextColor(0, 0, 60);
777
778 $posy += 2;
779
780 // Show list of linked objects
781 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
782
783 if ($showaddress) {
784 // Sender properties
785 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
786
787 // Show sender
788 $posy = 42;
789 $posx = $this->marge_gauche;
790 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
791 $posx = $this->page_largeur - $this->marge_droite - 80;
792 }
793 $hautcadre = 40;
794
795 // Show sender frame
796 $pdf->SetTextColor(0, 0, 0);
797 $pdf->SetFont('', '', $default_font_size - 2);
798 $pdf->SetXY($posx, $posy - 5);
799 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
800 $pdf->SetXY($posx, $posy);
801 $pdf->SetFillColor(230, 230, 230);
802 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'D');
803 $pdf->SetTextColor(0, 0, 60);
804
805 // Show sender name
806 $pdf->SetXY($posx + 2, $posy + 3);
807 $pdf->SetFont('', 'B', $default_font_size);
808 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
809 $posy = $pdf->getY();
810
811 // Show sender information
812 $pdf->SetXY($posx + 2, $posy);
813 $pdf->SetFont('', '', $default_font_size - 1);
814 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
815
816 // Client destinataire
817 $posy = 42;
818 $posx = 102;
819 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
820 $posx = $this->marge_gauche;
821 }
822 $pdf->SetTextColor(0, 0, 0);
823 $pdf->SetFont('', '', $default_font_size - 2);
824 $pdf->SetXY($posx, $posy - 5);
825 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("DeliveryAddress"), 0, 'L');
826
827 // If SHIPPING contact defined on order, we use it
828 $usecontact = false;
829 $arrayidcontact = $object->commande->getIdContact('external', 'SHIPPING');
830 if ($arrayidcontact && count($arrayidcontact) > 0) {
831 $usecontact = true;
832 $result = $object->fetch_contact($arrayidcontact[0]);
833 }
834
835 // Recipient name
836 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
837 $thirdparty = $object->contact;
838 } else {
839 $thirdparty = $object->thirdparty;
840 }
841
842 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
843
844 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
845
846 // Show recipient
847 $widthrecbox = 100;
848 if ($this->page_largeur < 210) {
849 $widthrecbox = 84; // To work with US executive format
850 }
851 $posy = 42;
852 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
853 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
854 $posx = $this->marge_gauche;
855 }
856
857 // Show recipient frame
858 $pdf->SetTextColor(0, 0, 0);
859 $pdf->SetFont('', '', $default_font_size - 2);
860 $pdf->SetXY($posx + 2, $posy - 5);
861 //$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
862 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
863
864 // Show recipient name
865 $pdf->SetXY($posx + 2, $posy + 3);
866 $pdf->SetFont('', 'B', $default_font_size);
867 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
868
869 $posy = $pdf->getY();
870
871 // Show recipient information
872 $pdf->SetFont('', '', $default_font_size - 1);
873 $pdf->SetXY($posx + 2, $posy);
874 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
875 }
876
877 $pdf->SetTextColor(0, 0, 60);
878
879 return 0;
880 }
881
882 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
892 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
893 {
894 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
895 return pdf_pagefoot($pdf, $outputlangs, 'DELIVERY_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
896 }
897}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage customers orders.
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage hooks.
Class 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.
global $mysoc
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.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1535
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:312
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:1110
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:742
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1497
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:433
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:388
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:844
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128