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