dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 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 $conf, $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", "deliveries", "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", "deliveries", "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(1, 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->getFullName($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($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, $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($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($object->ref, $encoding);
437
438 // get path of qrcode image
439 $newcode = $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('', 1, $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('', 1, $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('', 1, 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, $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, $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('', 1, 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 if ($reshook < 0) {
693 $this->error = $hookmanager->error;
694 $this->errors = $hookmanager->errors;
695 }
696
697 dolChmod($file);
698
699 $this->result = array('fullpath' => $file);
700
701 return 1; // No error
702 } else {
703 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
704 return 0;
705 }
706 } else {
707 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
708 return 0;
709 }
710 }
711
712 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
713 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
724 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
725 {
726 // phpcs:enable
727 global $conf, $mysoc;
728
729 $sign = 1;
730
731 $default_font_size = pdf_getPDFFontSize($outputlangs);
732
733 $tab2_top = $posy;
734 $tab2_hl = 4;
735 $pdf->SetFont('', 'B', $default_font_size - 1);
736
737 // Total table
738 $col1x = $this->posxweightvol - 50;
739 $col2x = $this->posxweightvol;
740 /*if ($this->page_largeur < 210) // To work with US executive format
741 {
742 $col2x-=20;
743 }*/
744 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
745 $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
746 } else {
747 $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
748 }
749
750 $useborder = 0;
751 $index = 0;
752
753 $totalWeighttoshow = '';
754 $totalVolumetoshow = '';
755
756 // Load dim data
757 $tmparray = $object->getTotalWeightVolume();
758 $totalWeight = $tmparray['weight'];
759 $totalVolume = $tmparray['volume'];
760 $totalOrdered = $tmparray['ordered'];
761 $totalToShip = $tmparray['toship'];
762
763 // Set trueVolume and volume_units not currently stored into database
764 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
765 $object->trueVolume = price(((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth), 0, $outputlangs, 0, 0);
766 $object->volume_units = (float) $object->size_units * 3;
767 }
768
769 if (!empty($totalWeight)) {
770 $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
771 }
772 if (!empty($totalVolume) && !getDolGlobalString('SHIPPING_PDF_HIDE_VOLUME')) {
773 $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
774 }
775 if (!empty($object->trueWeight)) {
776 $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, (int) $object->weight_units, "weight", $outputlangs);
777 }
778 if (!empty($object->trueVolume) && !getDolGlobalString('SHIPPING_PDF_HIDE_VOLUME')) {
779 $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
780 }
781
782 $pdf->SetFillColor(255, 255, 255);
783 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
784 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
785
786 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
787 $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
788 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
789 }
790
791 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
792 $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
793 $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
794 }
795
796 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
797 $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
798 $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
799
800 $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
801 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
802 }
803
804 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
805 // Total Weight
806 if ($totalWeighttoshow) {
807 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
808 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
809
810 $index++;
811 }
812 if ($totalVolumetoshow) {
813 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
814 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
815
816 $index++;
817 }
818 if (!$totalWeighttoshow && !$totalVolumetoshow) {
819 $index++;
820 }
821 }
822
823 $pdf->SetTextColor(0, 0, 0);
824
825 return ($tab2_top + ($tab2_hl * $index));
826 }
827
828 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
841 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
842 {
843 // phpcs:enable
844 global $conf;
845
846 // Force to disable hidetop and hidebottom
847 $hidebottom = 0;
848 if ($hidetop) {
849 $hidetop = -1;
850 }
851
852 $default_font_size = pdf_getPDFFontSize($outputlangs);
853
854 // Amount in (at tab_top - 1)
855 $pdf->SetTextColor(0, 0, 0);
856 $pdf->SetFont('', '', $default_font_size - 2);
857
858 // Output Rect
859 $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
860
861 $pdf->SetDrawColor(128, 128, 128);
862 $pdf->SetFont('', '', $default_font_size - 1);
863
864 // Description
865 if (empty($hidetop)) {
866 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
867
868 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
869 $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
870 }
871
872 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
873 $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
874 if (empty($hidetop)) {
875 $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
876 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
877 }
878 }
879
880 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
881 $pdf->line($this->posxqtyordered - 1, $tab_top, $this->posxqtyordered - 1, $tab_top + $tab_height);
882 if (empty($hidetop)) {
883 $pdf->SetXY($this->posxqtyordered - 1, $tab_top + 1);
884 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
885 }
886 }
887
888 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
889 $pdf->line($this->posxqtytoship - 1, $tab_top, $this->posxqtytoship - 1, $tab_top + $tab_height);
890 if (empty($hidetop)) {
891 $pdf->SetXY($this->posxqtytoship, $tab_top + 1);
892 $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"), '', 'C');
893 }
894 }
895
896 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
897 $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
898 if (empty($hidetop)) {
899 $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
900 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
901 }
902
903 $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
904 if (empty($hidetop)) {
905 $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
906 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
907 }
908 }
909 }
910
911 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
921 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
922 {
923 // phpcs:enable
924 global $conf, $langs, $mysoc;
925
926 $langs->load("orders");
927
928 $default_font_size = pdf_getPDFFontSize($outputlangs);
929
930 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
931
932 //Prepare next
933 $pdf->SetTextColor(0, 0, 60);
934 $pdf->SetFont('', 'B', $default_font_size + 3);
935
936 $w = 110;
937
938 $posy = $this->marge_haute;
939 $posx = $this->page_largeur - $this->marge_droite - $w;
940
941 $pdf->SetXY($this->marge_gauche, $posy);
942
943 // Logo
944 if ($this->emetteur->logo) {
945 $logodir = $conf->mycompany->dir_output;
946 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
947 $logodir = $conf->mycompany->multidir_output[$object->entity];
948 }
949 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
950 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
951 } else {
952 $logo = $logodir.'/logos/'.$this->emetteur->logo;
953 }
954 if (is_readable($logo)) {
955 $height = pdf_getHeightForLogo($logo);
956 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
957 } else {
958 $pdf->SetTextColor(200, 0, 0);
959 $pdf->SetFont('', 'B', $default_font_size - 2);
960 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
961 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
962 }
963 } else {
964 $text = $this->emetteur->name;
965 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
966 }
967
968 $pdf->SetDrawColor(128, 128, 128);
969
970 $posx = $this->page_largeur - $w - $this->marge_droite;
971 $posy = $this->marge_haute;
972
973 $pdf->SetFont('', 'B', $default_font_size + 2);
974 $pdf->SetXY($posx, $posy);
975 $pdf->SetTextColor(0, 0, 60);
976 $title = $outputlangs->transnoentities("SendingSheet");
977 $pdf->MultiCell($w, 4, $title, '', 'R');
978
979 $pdf->SetFont('', '', $default_font_size + 1);
980
981 $posy += 5;
982
983 $pdf->SetXY($posx, $posy);
984 $pdf->SetTextColor(0, 0, 60);
985 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending")." : ".$object->ref, '', 'R');
986
987 // Date planned delivery
988 if (!empty($object->date_delivery)) {
989 $posy += 4;
990 $pdf->SetXY($posx, $posy);
991 $pdf->SetTextColor(0, 0, 60);
992 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
993 }
994
995 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
996 $posy += 4;
997 $pdf->SetXY($posx, $posy);
998 $pdf->SetTextColor(0, 0, 60);
999 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1000 }
1001
1002 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && !empty($object->thirdparty->code_compta_client)) {
1003 $posy += 4;
1004 $pdf->SetXY($posx, $posy);
1005 $pdf->SetTextColor(0, 0, 60);
1006 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
1007 }
1008
1009 $pdf->SetFont('', '', $default_font_size + 3);
1010 $Yoff = 25;
1011
1012 // Add list of linked orders
1013 $origin = $object->origin;
1014 $origin_id = $object->origin_id;
1015
1016 $object->fetch_origin();
1017
1018 // TODO move to external function
1019 if (isModEnabled($origin)) { // commonly $origin='commande'
1020 $outputlangs->load('orders');
1021
1022 $classname = ucfirst($origin);
1023 $linkedobject = new $classname($this->db);
1024 '@phan-var-force Commande|Facture $linkedobject';
1025 $result = $linkedobject->fetch($origin_id);
1026 if ($result >= 0) {
1027 //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
1028
1029 $pdf->SetFont('', '', $default_font_size - 2);
1030 $text = $linkedobject->ref;
1031 if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) {
1032 $text .= ' ('.$linkedobject->ref_client.')';
1033 }
1034 $Yoff += 8;
1035 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1036 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
1037 $Yoff += 3;
1038 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1039 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
1040 }
1041 }
1042
1043 $top_shift = 0;
1044 // Show list of linked objects
1045 /*
1046 $current_y = $pdf->getY();
1047 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1048 if ($current_y < $pdf->getY()) {
1049 $top_shift = $pdf->getY() - $current_y;
1050 }
1051 */
1052
1053 if ($showaddress) {
1054 // Sender properties
1055 $carac_emetteur = '';
1056 // Add internal contact of origin element if defined
1057 $arrayidcontact = array();
1058 if (!empty($origin) && is_object($object->origin_object)) {
1059 $arrayidcontact = $object->origin_object->getIdContact('internal', 'SALESREPFOLL');
1060 }
1061 if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
1062 $object->fetch_user(reset($arrayidcontact));
1063 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1064 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1065 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1066 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1067 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1068 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1069 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1070 $carac_emetteur .= "\n";
1071 }
1072
1073 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1074
1075 // Show sender
1076 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1077 $posx = $this->marge_gauche;
1078 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1079 $posx = $this->page_largeur - $this->marge_droite - 80;
1080 }
1081
1082 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1083 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1084
1085 // Show sender frame
1086 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1087 $pdf->SetTextColor(0, 0, 0);
1088 $pdf->SetFont('', '', $default_font_size - 2);
1089 $pdf->SetXY($posx, $posy - 5);
1090 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
1091 $pdf->SetXY($posx, $posy);
1092 $pdf->SetFillColor(230, 230, 230);
1093 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1094 $pdf->SetTextColor(0, 0, 60);
1095 $pdf->SetFillColor(255, 255, 255);
1096 }
1097
1098 // Show sender name
1099 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1100 $pdf->SetXY($posx + 2, $posy + 3);
1101 $pdf->SetFont('', 'B', $default_font_size);
1102 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1103 $posy = $pdf->getY();
1104 }
1105
1106 // Show sender information
1107 $pdf->SetXY($posx + 2, $posy);
1108 $pdf->SetFont('', '', $default_font_size - 1);
1109 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1110
1111
1112 // If SHIPPING contact defined, we use it
1113 $usecontact = false;
1114 $arrayidcontact = $object->origin_object->getIdContact('external', 'SHIPPING');
1115 if (count($arrayidcontact) > 0) {
1116 $usecontact = true;
1117 $result = $object->fetch_contact($arrayidcontact[0]);
1118 }
1119
1120 // Recipient name
1121 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1122 $thirdparty = $object->contact;
1123 } else {
1124 $thirdparty = $object->thirdparty;
1125 }
1126
1127 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1128
1129 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), ($usecontact ? 1 : 0), 'targetwithdetails', $object);
1130
1131 // Show recipient
1132 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1133 if ($this->page_largeur < 210) {
1134 $widthrecbox = 84; // To work with US executive format
1135 }
1136 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1137 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1138 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1139 $posx = $this->marge_gauche;
1140 }
1141
1142 // Show recipient frame
1143 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1144 $pdf->SetTextColor(0, 0, 0);
1145 $pdf->SetFont('', '', $default_font_size - 2);
1146 $pdf->SetXY($posx + 2, $posy - 5);
1147 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
1148 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1149 }
1150
1151 // Show recipient name
1152 $pdf->SetXY($posx + 2, $posy + 3);
1153 $pdf->SetFont('', 'B', $default_font_size);
1154 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1155
1156 $posy = $pdf->getY();
1157
1158 // Show recipient information
1159 $pdf->SetXY($posx + 2, $posy);
1160 $pdf->SetFont('', '', $default_font_size - 1);
1161 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1162 }
1163
1164 $pdf->SetTextColor(0, 0, 0);
1165
1166 return $top_shift;
1167 }
1168
1169 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1179 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1180 {
1181 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1182 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);
1183 }
1184}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_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.
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).
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:2648
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1442
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1027
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:434
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:386
measuringUnitString($unitid, $measuring_style='', $unitscale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.