dolibarr 24.0.0-beta
pdf_rouget.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Nick Fragoulis
9 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
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/expedition/modules_expedition.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/product.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
77 public $posxweightvol;
81 public $posxqtytoship;
85 public $posxqtyordered;
86
87
93 public function __construct(DoliDB $db)
94 {
95 global $langs, $mysoc;
96
97 $this->db = $db;
98 $this->name = "rouget";
99 $this->description = $langs->trans("DocumentModelStandardPDF").' ('.$langs->trans("OldImplementation").')';
100 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
101
102 $this->type = 'pdf';
103 $formatarray = pdf_getFormat();
104 $this->page_largeur = $formatarray['width'];
105 $this->page_hauteur = $formatarray['height'];
106 $this->format = array($this->page_largeur, $this->page_hauteur);
107 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
108 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
109 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
110 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
111 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
112 $this->option_logo = 1; // Display logo
113 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
114 $this->watermark = '';
115
116 // Define position of columns
117 $this->posxdesc = $this->marge_gauche + 1;
118 $this->posxweightvol = $this->page_largeur - $this->marge_droite - 82;
119 $this->posxqtyordered = $this->page_largeur - $this->marge_droite - 60;
120 $this->posxqtytoship = $this->page_largeur - $this->marge_droite - 28;
121 $this->posxpuht = $this->page_largeur - $this->marge_droite;
122
123 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) { // Show also the prices
124 $this->posxweightvol = $this->page_largeur - $this->marge_droite - 118;
125 $this->posxqtyordered = $this->page_largeur - $this->marge_droite - 96;
126 $this->posxqtytoship = $this->page_largeur - $this->marge_droite - 68;
127 $this->posxpuht = $this->page_largeur - $this->marge_droite - 40;
128 $this->posxtotalht = $this->page_largeur - $this->marge_droite - 20;
129 }
130
131 if (getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
132 $this->posxweightvol = $this->posxqtyordered;
133 }
134
135 $this->posxpicture = $this->posxweightvol - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images
136
137 // To work with US executive format
138 if ($this->page_largeur < 210) {
139 $this->posxweightvol -= 20;
140 $this->posxpicture -= 20;
141 $this->posxqtyordered -= 20;
142 $this->posxqtytoship -= 20;
143 }
144
145 if (getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
146 $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
147 $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
148 $this->posxqtyordered = $this->posxqtytoship;
149 }
150
151 if ($mysoc === null) {
152 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
153 return;
154 }
155
156 // Get source company
157 $this->emetteur = $mysoc;
158 if (!$this->emetteur->country_code) {
159 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
160 }
161 }
162
163 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
175 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
176 {
177 // phpcs:enable
178 global $user, $conf, $langs, $hookmanager;
179
180 $object->fetch_thirdparty();
181
182 if (!is_object($outputlangs)) {
183 $outputlangs = $langs;
184 }
185 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
186 if (getDolGlobalString('MAIN_USE_FPDF')) {
187 $outputlangs->charset_output = 'ISO-8859-1';
188 }
189
190 // Load traductions files required by page
191 $outputlangs->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "sendings", "productbatch", "other", "compta"));
192
193 // Show Draft Watermark
194 if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('SHIPPING_DRAFT_WATERMARK'))) {
195 $this->watermark = getDolGlobalString('SHIPPING_DRAFT_WATERMARK');
196 }
197
198 global $outputlangsbis;
199 $outputlangsbis = null;
200 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
201 $outputlangsbis = new Translate('', $conf);
202 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
203 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "sendings", "productbatch", "other", "compta"));
204 }
205
206 $nblines = is_array($object->lines) ? count($object->lines) : 0;
207
208 // Loop on each lines to detect if there is at least one image to show
209 $realpatharray = array();
210 $this->atleastonephoto = false;
211 if (getDolGlobalString('MAIN_GENERATE_SHIPMENT_WITH_PICTURE')) {
212 $objphoto = new Product($this->db);
213
214 for ($i = 0; $i < $nblines; $i++) {
215 if (empty($object->lines[$i]->fk_product)) {
216 continue;
217 }
218
219 $objphoto = new Product($this->db);
220 $objphoto->fetch($object->lines[$i]->fk_product);
221 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
222 $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
223 $dir = $conf->product->dir_output.'/'.$pdir;
224 } else {
225 $pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
226 $dir = $conf->product->dir_output.'/'.$pdir;
227 }
228
229 $realpath = '';
230
231 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
232 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) {
233 // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
234 if ($obj['photo_vignette']) {
235 $filename = $obj['photo_vignette'];
236 } else {
237 $filename = $obj['photo'];
238 }
239 } else {
240 $filename = $obj['photo'];
241 }
242
243 $realpath = $dir.$filename;
244 $this->atleastonephoto = true;
245 break;
246 }
247
248 if ($realpath) {
249 $realpatharray[$i] = $realpath;
250 }
251 }
252 }
253
254 if (count($realpatharray) == 0) {
255 $this->posxpicture = $this->posxweightvol;
256 }
257
258 if ($conf->expedition->dir_output) {
259 // Definition of $dir and $file
260 if ($object->specimen) {
261 $dir = $conf->expedition->dir_output."/sending";
262 $file = $dir."/SPECIMEN.pdf";
263 } else {
264 $expref = dol_sanitizeFileName($object->ref);
265 $dir = $conf->expedition->dir_output."/sending/".$expref;
266 $file = $dir."/".$expref.".pdf";
267 }
268
269 if (!file_exists($dir)) {
270 if (dol_mkdir($dir) < 0) {
271 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
272 return 0;
273 }
274 }
275
276 if (file_exists($dir)) {
277 // Add pdfgeneration hook
278 if (!is_object($hookmanager)) {
279 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
280 $hookmanager = new HookManager($this->db);
281 }
282 $hookmanager->initHooks(array('pdfgeneration'));
283 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
284 global $action;
285 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
286
287 // Set nblines with the new facture lines content after hook
288 $nblines = is_array($object->lines) ? count($object->lines) : 0;
289
290 $pdf = pdf_getInstance($this->format);
291 $default_font_size = pdf_getPDFFontSize($outputlangs);
292 $heightforinfotot = 8; // Height reserved to output the info and total part
293 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
294 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
295 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
296 $heightforfooter += 6;
297 }
298 $pdf->setAutoPageBreak(true, 0);
299
300 if (class_exists('TCPDF')) {
301 $pdf->setPrintHeader(false);
302 $pdf->setPrintFooter(false);
303 }
304 $pdf->SetFont(pdf_getPDFFont($outputlangs));
305 // Set path to the background PDF File
306 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
307 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
308 $tplidx = $pdf->importPage(1);
309 }
310
311 $pdf->Open();
312 $pagenb = 0;
313 $pdf->SetDrawColor(128, 128, 128);
314
315 if (method_exists($pdf, 'AliasNbPages')) {
316 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
317 }
318
319 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
320 $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
321 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
322 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
323 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
324 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
325 $pdf->SetCompression(false);
326 }
327
328 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
329 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
330
331 // New page
332 $pdf->AddPage();
333 if (!empty($tplidx)) {
334 $pdf->useTemplate($tplidx);
335 }
336 $pagenb++;
337 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
338 $pdf->SetFont('', '', $default_font_size - 1);
339 $pdf->MultiCell(0, 3, ''); // Set interline to 3
340 $pdf->SetTextColor(0, 0, 0);
341
342 $tab_top = 90; // position of top tab
343 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
344
345 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
346
347 // Incoterm
348 $height_incoterms = 0;
349 if (isModEnabled('incoterm')) {
350 $desc_incoterms = $object->getIncotermsForPDF();
351 if ($desc_incoterms) {
352 $tab_top -= 2;
353
354 $pdf->SetFont('', '', $default_font_size - 1);
355 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
356 $nexY = $pdf->GetY();
357 $height_incoterms = $nexY - $tab_top;
358
359 // Rect takes a length in 3rd parameter
360 $pdf->SetDrawColor(192, 192, 192);
361 $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');
362
363 $tab_top = $nexY + 6;
364 $height_incoterms += 4;
365 }
366 }
367
368 // Public note and Tracking code
369 if (!empty($object->note_public) || !empty($object->tracking_number)) {
370 $tab_top_alt = $tab_top;
371
372 //$tab_top_alt += 1;
373
374 // Tracking number
375 if (!empty($object->tracking_number)) {
376 $height_trackingnumber = 4;
377
378 $pdf->SetFont('', 'B', $default_font_size - 2);
379 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
380 $tab_top_alt = $pdf->GetY();
381
382 $object->getUrlTrackingStatus((string) $object->tracking_number);
383 if (!empty($object->tracking_url)) {
384 if ($object->shipping_method_id > 0) {
385 // Get code using getLabelFromKey
386 $code = $outputlangs->getLabelFromKey($this->db, (string) $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
387 $label = '';
388 if ($object->tracking_url != $object->tracking_number) {
389 $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
390 }
391 $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
392 //var_dump($object->tracking_url != $object->tracking_number);exit;
393 if ($object->tracking_url != $object->tracking_number) {
394 $label .= " : ";
395 $label .= $object->tracking_url;
396 }
397
398 $height_trackingnumber += 4;
399 $pdf->SetFont('', 'B', $default_font_size - 2);
400 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
401 }
402 }
403 $tab_top = $pdf->GetY();
404 }
405
406 // Notes
407 if (!empty($object->note_public)) {
408 $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
409 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr((string) $object->note_public), 0, 1);
410 }
411
412 $nexY = $pdf->GetY();
413 $height_note = $nexY - $tab_top;
414
415 // Rect takes a length in 3rd parameter
416 $pdf->SetDrawColor(192, 192, 192);
417 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 3, $this->corner_radius, '1234', 'D');
418
419 $tab_height -= $height_note;
420 $tab_top = $nexY + 6;
421 } else {
422 $height_note = 0;
423 }
424
425 // Show barcode
426 $height_barcode = 0;
427 //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
428 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_SHIPPING_PDF')) {
429 require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/doc/tcpdfbarcode.modules.php';
430
431 $encoding = 'QRCODE';
432 $module = new modTcpdfbarcode();
433 $barcode_path = '';
434 $result = 0;
435 if ($module->encodingIsSupported($encoding)) {
436 $result = $module->writeBarCode((string) $object->ref, $encoding);
437
438 // get path of qrcode image
439 $newcode = (string) $object->ref;
440 if (!preg_match('/^\w+$/', $newcode) || dol_strlen($newcode) > 32) {
441 $newcode = dol_hash($newcode, 'md5');
442 }
443 $barcode_path = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png';
444 }
445
446 if ($result > 0) {
447 $tab_top -= 2;
448
449 $pdf->Image($barcode_path, $this->marge_gauche, $tab_top, 20, 20);
450
451 $nexY = $pdf->GetY();
452 $height_barcode = 20;
453
454 $tab_top += 22;
455 } else {
456 $this->error = 'Failed to generate barcode';
457 }
458 }
459
460
461 $iniY = $tab_top + 7;
462 $curY = $tab_top + 7;
463 $nexY = $tab_top + 7;
464
465 // Loop on each lines
466 for ($i = 0; $i < $nblines; $i++) {
467 $curY = $nexY;
468 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
469 $pdf->SetTextColor(0, 0, 0);
470
471 // Define size of image if we need it
472 $imglinesize = array();
473 if (!empty($realpatharray[$i])) {
474 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
475 }
476
477 $pdf->setTopMargin($tab_top_newpage);
478 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
479 $pageposbefore = $pdf->getPage();
480
481 $showpricebeforepagebreak = 1;
482 $posYAfterImage = 0;
483 $posYAfterDescription = 0;
484 $heightforsignature = 0;
485
486 // We start with Photo of product line
487 if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
488 $pdf->AddPage('', '', true);
489 if (!empty($tplidx)) {
490 $pdf->useTemplate($tplidx);
491 }
492 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
493 $this->_pagehead($pdf, $object, 0, $outputlangs);
494 }
495 $pdf->setPage($pageposbefore + 1);
496
497 $curY = $tab_top_newpage;
498
499 // Allows data in the first page if description is long enough to break in multiples pages
500 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
501 $showpricebeforepagebreak = 1;
502 } else {
503 $showpricebeforepagebreak = 0;
504 }
505 }
506
507 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
508 $curX = $this->posxpicture - 1;
509 $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
510 // $pdf->Image does not increase value return by getY, so we save it manually
511 $posYAfterImage = $curY + $imglinesize['height'];
512 }
513
514 // Description of product line
515 $curX = $this->posxdesc - 1;
516
517 $pdf->startTransaction();
518 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
519
520 $pageposafter = $pdf->getPage();
521 if ($pageposafter > $pageposbefore) { // There is a pagebreak
522 $pdf->rollbackTransaction(true);
523 $pageposafter = $pageposbefore;
524 //print $pageposafter.'-'.$pageposbefore;exit;
525 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
526 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
527
528 $pageposafter = $pdf->getPage();
529 $posyafter = $pdf->GetY();
530 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
531 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
532 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
533 $pdf->AddPage('', '', true);
534 if (!empty($tplidx)) {
535 $pdf->useTemplate($tplidx);
536 }
537 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
538 $this->_pagehead($pdf, $object, 0, $outputlangs);
539 }
540 $pdf->setPage($pageposafter + 1);
541 }
542 } else {
543 // We found a page break
544
545 // Allows data in the first page if description is long enough to break in multiples pages
546 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
547 $showpricebeforepagebreak = 1;
548 } else {
549 $showpricebeforepagebreak = 0;
550 }
551 }
552 } else { // No pagebreak
553 $pdf->commitTransaction();
554 }
555 $posYAfterDescription = $pdf->GetY();
556
557 $nexY = max($pdf->GetY(), $posYAfterImage);
558 $pageposafter = $pdf->getPage();
559
560 $pdf->setPage($pageposbefore);
561 $pdf->setTopMargin($this->marge_haute);
562 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
563
564 // We suppose that a too long description or photo were moved completely on next page
565 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
566 $pdf->setPage($pageposafter);
567 $curY = $tab_top_newpage;
568 }
569
570 // We suppose that a too long description is moved completely on next page
571 if ($pageposafter > $pageposbefore) {
572 $pdf->setPage($pageposafter);
573 $curY = $tab_top_newpage;
574 }
575
576 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
577
578 // weight
579
580 $pdf->SetXY($this->posxweightvol, $curY);
581 $weighttxt = '';
582 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->weight) {
583 $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, getDolGlobalInt('SHIPMENT_ROUND_WEIGHT_ON_PDF', 5)).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1);
584 }
585 $voltxt = '';
586 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->volume && !getDolGlobalString('SHIPPING_PDF_HIDE_VOLUME')) {
587 $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, getDolGlobalInt('SHIPMENT_ROUND_VOLUME_ON_PDF', 5)).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0, 1);
588 }
589
590 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
591 $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, 0, 0, false, true, 'C');
592 //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
593 }
594
595 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
596 $pdf->SetXY($this->posxqtyordered, $curY);
597 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, (string) $object->lines[$i]->qty_asked, '', 'C');
598 }
599
600 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
601 $pdf->SetXY($this->posxqtytoship, $curY);
602 $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, (string) $object->lines[$i]->qty_shipped, '', 'C');
603 }
604
605 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
606 $pdf->SetXY($this->posxpuht, $curY);
607 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
608
609 $pdf->SetXY($this->posxtotalht, $curY);
610 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
611 }
612
613 $nexY += 3;
614 if ($weighttxt && $voltxt) {
615 $nexY += 2;
616 }
617
618 // Add line
619 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
620 $pdf->setPage($pageposafter);
621 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
622 //$pdf->SetDrawColor(190,190,200);
623 $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
624 $pdf->SetLineStyle(array('dash' => 0));
625 }
626
627 // Detect if some page were added automatically and output _tableau for past pages
628 while ($pagenb < $pageposafter) {
629 $pdf->setPage($pagenb);
630 if ($pagenb == 1) {
631 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
632 } else {
633 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
634 }
635 $this->_pagefoot($pdf, $object, $outputlangs, 1);
636 $pagenb++;
637 $pdf->setPage($pagenb);
638 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
639 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
640 $this->_pagehead($pdf, $object, 0, $outputlangs);
641 }
642 if (!empty($tplidx)) {
643 $pdf->useTemplate($tplidx);
644 }
645 }
646 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
647 if ($pagenb == 1) {
648 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
649 } else {
650 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
651 }
652 $this->_pagefoot($pdf, $object, $outputlangs, 1);
653 // New page
654 $pdf->AddPage();
655 if (!empty($tplidx)) {
656 $pdf->useTemplate($tplidx);
657 }
658 $pagenb++;
659 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
660 $this->_pagehead($pdf, $object, 0, $outputlangs);
661 }
662 }
663 }
664
665 // Show square
666 if ($pagenb == 1) {
667 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
668 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
669 } else {
670 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
671 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
672 }
673
674 // Display total area
675 $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
676
677 // Pagefoot
678 $this->_pagefoot($pdf, $object, $outputlangs);
679 if (method_exists($pdf, 'AliasNbPages')) {
680 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
681 }
682
683 $pdf->Close();
684
685 $pdf->Output($file, 'F');
686
687 // Add pdfgeneration hook
688 $hookmanager->initHooks(array('pdfgeneration'));
689 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
690 global $action;
691 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
692 $this->warnings = $hookmanager->warnings;
693 if ($reshook < 0) {
694 $this->error = $hookmanager->error;
695 $this->errors = $hookmanager->errors;
696 dolChmod($file);
697 return -1;
698 }
699
700 dolChmod($file);
701
702 $this->result = array('fullpath' => $file);
703
704 return 1; // No error
705 } else {
706 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
707 return 0;
708 }
709 } else {
710 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
711 return 0;
712 }
713 }
714
715 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
716 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
727 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
728 {
729 // phpcs:enable
730 global $conf, $mysoc;
731
732 $sign = 1;
733
734 $default_font_size = pdf_getPDFFontSize($outputlangs);
735
736 $tab2_top = $posy;
737 $tab2_hl = 4;
738 $pdf->SetFont('', 'B', $default_font_size - 1);
739
740 // Total table
741 $col1x = $this->posxweightvol - 50;
742 $col2x = $this->posxweightvol;
743 /*if ($this->page_largeur < 210) // To work with US executive format
744 {
745 $col2x-=20;
746 }*/
747 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
748 $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
749 } else {
750 $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
751 }
752
753 $useborder = 0;
754 $index = 0;
755
756 $totalWeighttoshow = '';
757 $totalVolumetoshow = '';
758
759 // Load dim data
760 $tmparray = $object->getTotalWeightVolume();
761 $totalWeight = $tmparray['weight'];
762 $totalVolume = $tmparray['volume'];
763 $totalOrdered = $tmparray['ordered'];
764 $totalToShip = $tmparray['toship'];
765
766 // Set trueVolume and volume_units not currently stored into database
767 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
768 $object->trueVolume = price(((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth), 0, $outputlangs, 0, 0);
769 $object->volume_units = (float) $object->size_units * 3;
770 }
771
772 if (!empty($totalWeight)) {
773 $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
774 }
775 if (!empty($totalVolume) && !getDolGlobalString('SHIPPING_PDF_HIDE_VOLUME')) {
776 $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
777 }
778 if (!empty($object->trueWeight)) {
779 $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, (int) $object->weight_units, "weight", $outputlangs);
780 }
781 if (!empty($object->trueVolume) && !getDolGlobalString('SHIPPING_PDF_HIDE_VOLUME')) {
782 $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
783 }
784
785 $pdf->SetFillColor(255, 255, 255);
786 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
787 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', true);
788
789 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
790 $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
791 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, (string) $totalOrdered, 0, 'C', true);
792 }
793
794 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
795 $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
796 $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, (string) $totalToShip, 0, 'C', true);
797 }
798
799 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
800 $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
801 $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', true);
802
803 $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
804 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', true);
805 }
806
807 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
808 // Total Weight
809 if ($totalWeighttoshow) {
810 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
811 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', true);
812
813 $index++;
814 }
815 if ($totalVolumetoshow) {
816 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
817 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', true);
818
819 $index++;
820 }
821 if (!$totalWeighttoshow && !$totalVolumetoshow) {
822 $index++;
823 }
824 }
825
826 $pdf->SetTextColor(0, 0, 0);
827
828 return ($tab2_top + ($tab2_hl * $index));
829 }
830
831 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
844 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
845 {
846 // phpcs:enable
847 global $conf;
848
849 // Force to disable hidetop and hidebottom
850 $hidebottom = 0;
851 if ($hidetop) {
852 $hidetop = -1;
853 }
854
855 $default_font_size = pdf_getPDFFontSize($outputlangs);
856
857 // Amount in (at tab_top - 1)
858 $pdf->SetTextColor(0, 0, 0);
859 $pdf->SetFont('', '', $default_font_size - 2);
860
861 // Output Rect
862 $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
863
864 $pdf->SetDrawColor(128, 128, 128);
865 $pdf->SetFont('', '', $default_font_size - 1);
866
867 // Description
868 if (empty($hidetop)) {
869 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
870
871 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
872 $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
873 }
874
875 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
876 $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
877 if (empty($hidetop)) {
878 $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
879 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
880 }
881 }
882
883 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
884 $pdf->line($this->posxqtyordered - 1, $tab_top, $this->posxqtyordered - 1, $tab_top + $tab_height);
885 if (empty($hidetop)) {
886 $pdf->SetXY($this->posxqtyordered - 1, $tab_top + 1);
887 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
888 }
889 }
890
891 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
892 $pdf->line($this->posxqtytoship - 1, $tab_top, $this->posxqtytoship - 1, $tab_top + $tab_height);
893 if (empty($hidetop)) {
894 $pdf->SetXY($this->posxqtytoship, $tab_top + 1);
895 $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"), '', 'C');
896 }
897 }
898
899 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
900 $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
901 if (empty($hidetop)) {
902 $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
903 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
904 }
905
906 $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
907 if (empty($hidetop)) {
908 $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
909 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
910 }
911 }
912 }
913
914 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
924 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
925 {
926 // phpcs:enable
927 global $conf, $langs, $mysoc;
928
929 $langs->load("orders");
930
931 $default_font_size = pdf_getPDFFontSize($outputlangs);
932
933 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
934
935 //Prepare next
936 $pdf->SetTextColor(0, 0, 60);
937 $pdf->SetFont('', 'B', $default_font_size + 3);
938
939 $w = 110;
940
941 $posy = $this->marge_haute;
942 $posx = $this->page_largeur - $this->marge_droite - $w;
943
944 $pdf->SetXY($this->marge_gauche, $posy);
945
946 // Logo
947 if ($this->emetteur->logo) {
948 $logodir = $conf->mycompany->dir_output;
949 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
950 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
951 }
952 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
953 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
954 } else {
955 $logo = $logodir.'/logos/'.$this->emetteur->logo;
956 }
957 if (is_readable($logo)) {
958 $height = pdf_getHeightForLogo($logo);
959 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
960 } else {
961 $pdf->SetTextColor(200, 0, 0);
962 $pdf->SetFont('', 'B', $default_font_size - 2);
963 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
964 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
965 }
966 } else {
967 $text = $this->emetteur->name;
968 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
969 }
970
971 $pdf->SetDrawColor(128, 128, 128);
972
973 $posx = $this->page_largeur - $w - $this->marge_droite;
974 $posy = $this->marge_haute;
975
976 $pdf->SetFont('', 'B', $default_font_size + 2);
977 $pdf->SetXY($posx, $posy);
978 $pdf->SetTextColor(0, 0, 60);
979 $title = $outputlangs->transnoentities("SendingSheet");
980 $pdf->MultiCell($w, 4, $title, '', 'R');
981
982 $pdf->SetFont('', '', $default_font_size + 1);
983
984 $posy += 5;
985
986 $pdf->SetXY($posx, $posy);
987 $pdf->SetTextColor(0, 0, 60);
988 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending")." : ".$object->ref, '', 'R');
989
990 // Date planned delivery
991 if (!empty($object->date_delivery)) {
992 $posy += 4;
993 $pdf->SetXY($posx, $posy);
994 $pdf->SetTextColor(0, 0, 60);
995 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
996 }
997
998 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
999 $posy += 4;
1000 $pdf->SetXY($posx, $posy);
1001 $pdf->SetTextColor(0, 0, 60);
1002 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
1003 }
1004
1005 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && !empty($object->thirdparty->code_compta_client)) {
1006 $posy += 4;
1007 $pdf->SetXY($posx, $posy);
1008 $pdf->SetTextColor(0, 0, 60);
1009 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
1010 }
1011
1012 $pdf->SetFont('', '', $default_font_size + 3);
1013 $Yoff = 25;
1014
1015 // Add list of linked orders
1016 $origin = $object->origin;
1017 $origin_id = $object->origin_id;
1018
1019 $object->fetch_origin();
1020
1021 // TODO move to external function
1022 if (isModEnabled($origin)) { // commonly $origin='commande'
1023 $outputlangs->load('orders');
1024
1025 $classname = ucfirst($origin);
1026 $linkedobject = new $classname($this->db);
1027 '@phan-var-force Commande|Facture $linkedobject';
1028 $result = $linkedobject->fetch($origin_id);
1029 if ($result >= 0) {
1030 //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
1031
1032 $pdf->SetFont('', '', $default_font_size - 2);
1033 $text = $linkedobject->ref;
1034 if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) {
1035 $text .= ' ('.$linkedobject->ref_client.')';
1036 }
1037 $Yoff += 8;
1038 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1039 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities((string) $text), 0, 'R');
1040 $Yoff += 3;
1041 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1042 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
1043 }
1044 }
1045
1046 $top_shift = 0;
1047 // Show list of linked objects
1048 /*
1049 $current_y = $pdf->getY();
1050 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1051 if ($current_y < $pdf->getY()) {
1052 $top_shift = $pdf->getY() - $current_y;
1053 }
1054 */
1055
1056 if ($showaddress) {
1057 // Sender properties
1058 $carac_emetteur = '';
1059 // Add internal contact of origin element if defined
1060 $arrayidcontact = array();
1061 if (!empty($origin) && is_object($object->origin_object)) {
1062 $arrayidcontact = $object->origin_object->getIdContact('internal', 'SALESREPFOLL');
1063 }
1064 if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
1065 $object->fetch_user(reset($arrayidcontact));
1066 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1067 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1068 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1069 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1070 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1071 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1072 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1073 $carac_emetteur .= "\n";
1074 }
1075
1076 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1077
1078 // Show sender
1079 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1080 $posx = $this->marge_gauche;
1081 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1082 $posx = $this->page_largeur - $this->marge_droite - 80;
1083 }
1084
1085 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1086 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1087
1088 // Show sender frame
1089 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1090 $pdf->SetTextColor(0, 0, 0);
1091 $pdf->SetFont('', '', $default_font_size - 2);
1092 $pdf->SetXY($posx, $posy - 5);
1093 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
1094 $pdf->SetXY($posx, $posy);
1095 $pdf->SetFillColor(230, 230, 230);
1096 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1097 $pdf->SetTextColor(0, 0, 60);
1098 $pdf->SetFillColor(255, 255, 255);
1099 }
1100
1101 // Show sender name
1102 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1103 $pdf->SetXY($posx + 2, $posy + 3);
1104 $pdf->SetFont('', 'B', $default_font_size);
1105 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1106 $posy = $pdf->getY();
1107 }
1108
1109 // Show sender information
1110 $pdf->SetXY($posx + 2, $posy);
1111 $pdf->SetFont('', '', $default_font_size - 1);
1112 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1113
1114
1115 // If SHIPPING contact defined, we use it
1116 $usecontact = false;
1117 $arrayidcontact = $object->origin_object->getIdContact('external', 'SHIPPING');
1118 if (count($arrayidcontact) > 0) {
1119 $usecontact = true;
1120 $result = $object->fetch_contact($arrayidcontact[0]);
1121 }
1122
1123 // Recipient name
1124 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1125 $thirdparty = $object->contact;
1126 } else {
1127 $thirdparty = $object->thirdparty;
1128 }
1129
1130 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1131
1132 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), ($usecontact ? 1 : 0), 'targetwithdetails', $object);
1133
1134 // Show recipient
1135 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1136 if ($this->page_largeur < 210) {
1137 $widthrecbox = 84; // To work with US executive format
1138 }
1139 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1140 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1141 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1142 $posx = $this->marge_gauche;
1143 }
1144
1145 // Show recipient frame
1146 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1147 $pdf->SetTextColor(0, 0, 0);
1148 $pdf->SetFont('', '', $default_font_size - 2);
1149 $pdf->SetXY($posx + 2, $posy - 5);
1150 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
1151 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1152 }
1153
1154 // Show recipient name
1155 $pdf->SetXY($posx + 2, $posy + 3);
1156 $pdf->SetFont('', 'B', $default_font_size);
1157 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1158
1159 $posy = $pdf->getY();
1160
1161 // Show recipient information
1162 $pdf->SetXY($posx + 2, $posy);
1163 $pdf->SetFont('', '', $default_font_size - 1);
1164 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1165 }
1166
1167 $pdf->SetTextColor(0, 0, 0);
1168
1169 return $top_shift;
1170 }
1171
1172 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1182 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1183 {
1184 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1185 return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1186 }
1187}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage Dolibarr database access.
Class to manage hooks.
Parent class of sending receipts models.
Class to manage products or services.
Class to manage translations.
Class to generate barcode images using tcpdf barcode generator.
Class to build sending documents with model Rouget.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct(DoliDB $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.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition pdf.lib.php:3160
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
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:1846
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:317
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:747
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:1421
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
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:438
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:393
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.