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