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