dolibarr 20.0.2
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
30require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
34
35
40{
44 public $db;
45
49 public $name;
50
54 public $description;
55
59 public $update_main_doc_field;
60
64 public $type;
65
70 public $version = 'dolibarr';
71
72 public $posxweightvol;
73 public $posxqtytoship;
74 public $posxqtyordered;
75
76
82 public function __construct(DoliDB $db)
83 {
84 global $conf, $langs, $mysoc;
85
86 $this->db = $db;
87 $this->name = "rouget";
88 $this->description = $langs->trans("DocumentModelStandardPDF").' ('.$langs->trans("OldImplementation").')';
89 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
90
91 $this->type = 'pdf';
92 $formatarray = pdf_getFormat();
93 $this->page_largeur = $formatarray['width'];
94 $this->page_hauteur = $formatarray['height'];
95 $this->format = array($this->page_largeur, $this->page_hauteur);
96 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
97 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
98 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
99 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
100
101 $this->option_logo = 1; // Display logo
102 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
103 $this->watermark = '';
104
105 // Get source company
106 $this->emetteur = $mysoc;
107 if (!$this->emetteur->country_code) {
108 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
109 }
110
111 // Define position of columns
112 $this->posxdesc = $this->marge_gauche + 1;
113 $this->posxweightvol = $this->page_largeur - $this->marge_droite - 82;
114 $this->posxqtyordered = $this->page_largeur - $this->marge_droite - 60;
115 $this->posxqtytoship = $this->page_largeur - $this->marge_droite - 28;
116 $this->posxpuht = $this->page_largeur - $this->marge_droite;
117
118 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) { // Show also the prices
119 $this->posxweightvol = $this->page_largeur - $this->marge_droite - 118;
120 $this->posxqtyordered = $this->page_largeur - $this->marge_droite - 96;
121 $this->posxqtytoship = $this->page_largeur - $this->marge_droite - 68;
122 $this->posxpuht = $this->page_largeur - $this->marge_droite - 40;
123 $this->posxtotalht = $this->page_largeur - $this->marge_droite - 20;
124 }
125
126 if (getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
127 $this->posxweightvol = $this->posxqtyordered;
128 }
129
130 $this->posxpicture = $this->posxweightvol - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images
131
132 // To work with US executive format
133 if ($this->page_largeur < 210) {
134 $this->posxweightvol -= 20;
135 $this->posxpicture -= 20;
136 $this->posxqtyordered -= 20;
137 $this->posxqtytoship -= 20;
138 }
139
140 if (getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
141 $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
142 $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
143 $this->posxqtyordered = $this->posxqtytoship;
144 }
145 }
146
147 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
159 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
160 {
161 // phpcs:enable
162 global $user, $conf, $langs, $hookmanager;
163
164 $object->fetch_thirdparty();
165
166 if (!is_object($outputlangs)) {
167 $outputlangs = $langs;
168 }
169 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
170 if (getDolGlobalString('MAIN_USE_FPDF')) {
171 $outputlangs->charset_output = 'ISO-8859-1';
172 }
173
174 // Load traductions files required by page
175 $outputlangs->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch", "other"));
176
177 // Show Draft Watermark
178 if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('SHIPPING_DRAFT_WATERMARK'))) {
179 $this->watermark = getDolGlobalString('SHIPPING_DRAFT_WATERMARK');
180 }
181
182 global $outputlangsbis;
183 $outputlangsbis = null;
184 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
185 $outputlangsbis = new Translate('', $conf);
186 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
187 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
188 }
189
190 $nblines = is_array($object->lines) ? count($object->lines) : 0;
191
192 // Loop on each lines to detect if there is at least one image to show
193 $realpatharray = array();
194 $this->atleastonephoto = false;
195 if (getDolGlobalString('MAIN_GENERATE_SHIPMENT_WITH_PICTURE')) {
196 $objphoto = new Product($this->db);
197
198 for ($i = 0; $i < $nblines; $i++) {
199 if (empty($object->lines[$i]->fk_product)) {
200 continue;
201 }
202
203 $objphoto = new Product($this->db);
204 $objphoto->fetch($object->lines[$i]->fk_product);
205 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
206 $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
207 $dir = $conf->product->dir_output.'/'.$pdir;
208 } else {
209 $pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
210 $dir = $conf->product->dir_output.'/'.$pdir;
211 }
212
213 $realpath = '';
214
215 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
216 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) {
217 // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
218 if ($obj['photo_vignette']) {
219 $filename = $obj['photo_vignette'];
220 } else {
221 $filename = $obj['photo'];
222 }
223 } else {
224 $filename = $obj['photo'];
225 }
226
227 $realpath = $dir.$filename;
228 $this->atleastonephoto = true;
229 break;
230 }
231
232 if ($realpath) {
233 $realpatharray[$i] = $realpath;
234 }
235 }
236 }
237
238 if (count($realpatharray) == 0) {
239 $this->posxpicture = $this->posxweightvol;
240 }
241
242 if ($conf->expedition->dir_output) {
243 // Definition of $dir and $file
244 if ($object->specimen) {
245 $dir = $conf->expedition->dir_output."/sending";
246 $file = $dir."/SPECIMEN.pdf";
247 } else {
248 $expref = dol_sanitizeFileName($object->ref);
249 $dir = $conf->expedition->dir_output."/sending/".$expref;
250 $file = $dir."/".$expref.".pdf";
251 }
252
253 if (!file_exists($dir)) {
254 if (dol_mkdir($dir) < 0) {
255 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
256 return 0;
257 }
258 }
259
260 if (file_exists($dir)) {
261 // Add pdfgeneration hook
262 if (!is_object($hookmanager)) {
263 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
264 $hookmanager = new HookManager($this->db);
265 }
266 $hookmanager->initHooks(array('pdfgeneration'));
267 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
268 global $action;
269 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
270
271 // Set nblines with the new facture lines content after hook
272 $nblines = is_array($object->lines) ? count($object->lines) : 0;
273
274 $pdf = pdf_getInstance($this->format);
275 $default_font_size = pdf_getPDFFontSize($outputlangs);
276 $heightforinfotot = 8; // Height reserved to output the info and total part
277 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
278 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
279 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
280 $heightforfooter += 6;
281 }
282 $pdf->SetAutoPageBreak(1, 0);
283
284 if (class_exists('TCPDF')) {
285 $pdf->setPrintHeader(false);
286 $pdf->setPrintFooter(false);
287 }
288 $pdf->SetFont(pdf_getPDFFont($outputlangs));
289 // Set path to the background PDF File
290 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
291 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
292 $tplidx = $pdf->importPage(1);
293 }
294
295 $pdf->Open();
296 $pagenb = 0;
297 $pdf->SetDrawColor(128, 128, 128);
298
299 if (method_exists($pdf, 'AliasNbPages')) {
300 $pdf->AliasNbPages();
301 }
302
303 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
304 $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
305 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
306 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
307 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
308 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
309 $pdf->SetCompression(false);
310 }
311
312 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
313 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
314
315 // New page
316 $pdf->AddPage();
317 if (!empty($tplidx)) {
318 $pdf->useTemplate($tplidx);
319 }
320 $pagenb++;
321 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
322 $pdf->SetFont('', '', $default_font_size - 1);
323 $pdf->MultiCell(0, 3, ''); // Set interline to 3
324 $pdf->SetTextColor(0, 0, 0);
325
326 $tab_top = 90; // position of top tab
327 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift: 10);
328
329 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
330
331 // Incoterm
332 $height_incoterms = 0;
333 if (isModEnabled('incoterm')) {
334 $desc_incoterms = $object->getIncotermsForPDF();
335 if ($desc_incoterms) {
336 $tab_top -= 2;
337
338 $pdf->SetFont('', '', $default_font_size - 1);
339 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
340 $nexY = $pdf->GetY();
341 $height_incoterms = $nexY - $tab_top;
342
343 // Rect takes a length in 3rd parameter
344 $pdf->SetDrawColor(192, 192, 192);
345 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
346
347 $tab_top = $nexY + 6;
348 $height_incoterms += 4;
349 }
350 }
351
352 // Public note and Tracking code
353 if (!empty($object->note_public) || !empty($object->tracking_number)) {
354 $tab_top_alt = $tab_top;
355
356 //$tab_top_alt += 1;
357
358 // Tracking number
359 if (!empty($object->tracking_number)) {
360 $height_trackingnumber = 4;
361
362 $pdf->SetFont('', 'B', $default_font_size - 2);
363 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
364 $tab_top_alt = $pdf->GetY();
365
366 $object->getUrlTrackingStatus($object->tracking_number);
367 if (!empty($object->tracking_url)) {
368 if ($object->shipping_method_id > 0) {
369 // Get code using getLabelFromKey
370 $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
371 $label = '';
372 if ($object->tracking_url != $object->tracking_number) {
373 $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
374 }
375 $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
376 //var_dump($object->tracking_url != $object->tracking_number);exit;
377 if ($object->tracking_url != $object->tracking_number) {
378 $label .= " : ";
379 $label .= $object->tracking_url;
380 }
381
382 $height_trackingnumber += 4;
383 $pdf->SetFont('', 'B', $default_font_size - 2);
384 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
385 }
386 }
387 $tab_top = $pdf->GetY();
388 }
389
390 // Notes
391 if (!empty($object->note_public)) {
392 $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
393 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
394 }
395
396 $nexY = $pdf->GetY();
397 $height_note = $nexY - $tab_top;
398
399 // Rect takes a length in 3rd parameter
400 $pdf->SetDrawColor(192, 192, 192);
401 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
402
403 $tab_height = $tab_height - $height_note;
404 $tab_top = $nexY + 6;
405 } else {
406 $height_note = 0;
407 }
408
409 // Show barcode
410 $height_barcode = 0;
411 //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
412 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_SHIPPING_PDF')) {
413 require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/doc/tcpdfbarcode.modules.php';
414
415 $encoding = 'QRCODE';
416 $module = new modTcpdfbarcode();
417 $barcode_path = '';
418 $result = 0;
419 if ($module->encodingIsSupported($encoding)) {
420 $result = $module->writeBarCode($object->ref, $encoding);
421
422 // get path of qrcode image
423 $newcode = $object->ref;
424 if (!preg_match('/^\w+$/', $newcode) || dol_strlen($newcode) > 32) {
425 $newcode = dol_hash($newcode, 'md5');
426 }
427 $barcode_path = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png';
428 }
429
430 if ($result > 0) {
431 $tab_top -= 2;
432
433 $pdf->Image($barcode_path, $this->marge_gauche, $tab_top, 20, 20);
434
435 $nexY = $pdf->GetY();
436 $height_barcode = 20;
437
438 $tab_top += 22;
439 } else {
440 $this->error = 'Failed to generate barcode';
441 }
442 }
443
444
445 $iniY = $tab_top + 7;
446 $curY = $tab_top + 7;
447 $nexY = $tab_top + 7;
448
449 // Loop on each lines
450 for ($i = 0; $i < $nblines; $i++) {
451 $curY = $nexY;
452 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
453 $pdf->SetTextColor(0, 0, 0);
454
455 // Define size of image if we need it
456 $imglinesize = array();
457 if (!empty($realpatharray[$i])) {
458 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
459 }
460
461 $pdf->setTopMargin($tab_top_newpage);
462 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
463 $pageposbefore = $pdf->getPage();
464
465 $showpricebeforepagebreak = 1;
466 $posYAfterImage = 0;
467 $posYAfterDescription = 0;
468 $heightforsignature = 0;
469
470 // We start with Photo of product line
471 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
472 $pdf->AddPage('', '', true);
473 if (!empty($tplidx)) {
474 $pdf->useTemplate($tplidx);
475 }
476 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
477 $this->_pagehead($pdf, $object, 0, $outputlangs);
478 }
479 $pdf->setPage($pageposbefore + 1);
480
481 $curY = $tab_top_newpage;
482
483 // Allows data in the first page if description is long enough to break in multiples pages
484 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
485 $showpricebeforepagebreak = 1;
486 } else {
487 $showpricebeforepagebreak = 0;
488 }
489 }
490
491 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
492 $curX = $this->posxpicture - 1;
493 $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
494 // $pdf->Image does not increase value return by getY, so we save it manually
495 $posYAfterImage = $curY + $imglinesize['height'];
496 }
497
498 // Description of product line
499 $curX = $this->posxdesc - 1;
500
501 $pdf->startTransaction();
502 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
503
504 $pageposafter = $pdf->getPage();
505 if ($pageposafter > $pageposbefore) { // There is a pagebreak
506 $pdf->rollbackTransaction(true);
507 $pageposafter = $pageposbefore;
508 //print $pageposafter.'-'.$pageposbefore;exit;
509 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
510 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
511
512 $pageposafter = $pdf->getPage();
513 $posyafter = $pdf->GetY();
514 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
515 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
516 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
517 $pdf->AddPage('', '', true);
518 if (!empty($tplidx)) {
519 $pdf->useTemplate($tplidx);
520 }
521 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
522 $this->_pagehead($pdf, $object, 0, $outputlangs);
523 }
524 $pdf->setPage($pageposafter + 1);
525 }
526 } else {
527 // We found a page break
528
529 // Allows data in the first page if description is long enough to break in multiples pages
530 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
531 $showpricebeforepagebreak = 1;
532 } else {
533 $showpricebeforepagebreak = 0;
534 }
535 }
536 } else { // No pagebreak
537 $pdf->commitTransaction();
538 }
539 $posYAfterDescription = $pdf->GetY();
540
541 $nexY = max($pdf->GetY(), $posYAfterImage);
542 $pageposafter = $pdf->getPage();
543
544 $pdf->setPage($pageposbefore);
545 $pdf->setTopMargin($this->marge_haute);
546 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
547
548 // We suppose that a too long description or photo were moved completely on next page
549 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
550 $pdf->setPage($pageposafter);
551 $curY = $tab_top_newpage;
552 }
553
554 // We suppose that a too long description is moved completely on next page
555 if ($pageposafter > $pageposbefore) {
556 $pdf->setPage($pageposafter);
557 $curY = $tab_top_newpage;
558 }
559
560 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
561
562 // weight
563
564 $pdf->SetXY($this->posxweightvol, $curY);
565 $weighttxt = '';
566 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->weight) {
567 $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1);
568 }
569 $voltxt = '';
570 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->volume) {
571 $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0, 1);
572 }
573
574 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
575 $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, 0, 0, false, true, 'C');
576 //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
577 }
578
579 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
580 $pdf->SetXY($this->posxqtyordered, $curY);
581 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked, '', 'C');
582 }
583
584 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
585 $pdf->SetXY($this->posxqtytoship, $curY);
586 $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped, '', 'C');
587 }
588
589 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
590 $pdf->SetXY($this->posxpuht, $curY);
591 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
592
593 $pdf->SetXY($this->posxtotalht, $curY);
594 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
595 }
596
597 $nexY += 3;
598 if ($weighttxt && $voltxt) {
599 $nexY += 2;
600 }
601
602 // Add line
603 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
604 $pdf->setPage($pageposafter);
605 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
606 //$pdf->SetDrawColor(190,190,200);
607 $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
608 $pdf->SetLineStyle(array('dash' => 0));
609 }
610
611 // Detect if some page were added automatically and output _tableau for past pages
612 while ($pagenb < $pageposafter) {
613 $pdf->setPage($pagenb);
614 if ($pagenb == 1) {
615 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
616 } else {
617 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
618 }
619 $this->_pagefoot($pdf, $object, $outputlangs, 1);
620 $pagenb++;
621 $pdf->setPage($pagenb);
622 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
623 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
624 $this->_pagehead($pdf, $object, 0, $outputlangs);
625 }
626 if (!empty($tplidx)) {
627 $pdf->useTemplate($tplidx);
628 }
629 }
630 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
631 if ($pagenb == 1) {
632 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
633 } else {
634 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
635 }
636 $this->_pagefoot($pdf, $object, $outputlangs, 1);
637 // New page
638 $pdf->AddPage();
639 if (!empty($tplidx)) {
640 $pdf->useTemplate($tplidx);
641 }
642 $pagenb++;
643 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
644 $this->_pagehead($pdf, $object, 0, $outputlangs);
645 }
646 }
647 }
648
649 // Show square
650 if ($pagenb == 1) {
651 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
652 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
653 } else {
654 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
655 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
656 }
657
658 // Display total area
659 $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
660
661 // Pagefoot
662 $this->_pagefoot($pdf, $object, $outputlangs);
663 if (method_exists($pdf, 'AliasNbPages')) {
664 $pdf->AliasNbPages();
665 }
666
667 $pdf->Close();
668
669 $pdf->Output($file, 'F');
670
671 // Add pdfgeneration hook
672 $hookmanager->initHooks(array('pdfgeneration'));
673 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
674 global $action;
675 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
676 if ($reshook < 0) {
677 $this->error = $hookmanager->error;
678 $this->errors = $hookmanager->errors;
679 }
680
681 dolChmod($file);
682
683 $this->result = array('fullpath' => $file);
684
685 return 1; // No error
686 } else {
687 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
688 return 0;
689 }
690 } else {
691 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
692 return 0;
693 }
694 }
695
696 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
697 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
708 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
709 {
710 // phpcs:enable
711 global $conf, $mysoc;
712
713 $sign = 1;
714
715 $default_font_size = pdf_getPDFFontSize($outputlangs);
716
717 $tab2_top = $posy;
718 $tab2_hl = 4;
719 $pdf->SetFont('', 'B', $default_font_size - 1);
720
721 // Total table
722 $col1x = $this->posxweightvol - 50;
723 $col2x = $this->posxweightvol;
724 /*if ($this->page_largeur < 210) // To work with US executive format
725 {
726 $col2x-=20;
727 }*/
728 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
729 $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
730 } else {
731 $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
732 }
733
734 $useborder = 0;
735 $index = 0;
736
737 $totalWeighttoshow = '';
738 $totalVolumetoshow = '';
739
740 // Load dim data
741 $tmparray = $object->getTotalWeightVolume();
742 $totalWeight = $tmparray['weight'];
743 $totalVolume = $tmparray['volume'];
744 $totalOrdered = $tmparray['ordered'];
745 $totalToShip = $tmparray['toship'];
746
747 // Set trueVolume and volume_units not currently stored into database
748 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
749 $object->trueVolume = price(((float) $object->trueWidth * (float) $object->trueHeight * (float) $object->trueDepth), 0, $outputlangs, 0, 0);
750 $object->volume_units = (float) $object->size_units * 3;
751 }
752
753 if (!empty($totalWeight)) {
754 $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs, -1, 'no', 1);
755 }
756 if (!empty($totalVolume)) {
757 $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs, -1, 'no', 1);
758 }
759 if (!empty($object->trueWeight)) {
760 $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
761 }
762 if (!empty($object->trueVolume)) {
763 $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
764 }
765
766 $pdf->SetFillColor(255, 255, 255);
767 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
768 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
769
770 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
771 $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
772 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
773 }
774
775 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
776 $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
777 $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
778 }
779
780 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
781 $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
782 $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
783
784 $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
785 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
786 }
787
788 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
789 // Total Weight
790 if ($totalWeighttoshow) {
791 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
792 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
793
794 $index++;
795 }
796 if ($totalVolumetoshow) {
797 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
798 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
799
800 $index++;
801 }
802 if (!$totalWeighttoshow && !$totalVolumetoshow) {
803 $index++;
804 }
805 }
806
807 $pdf->SetTextColor(0, 0, 0);
808
809 return ($tab2_top + ($tab2_hl * $index));
810 }
811
812 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
825 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
826 {
827 // phpcs:enable
828 global $conf;
829
830 // Force to disable hidetop and hidebottom
831 $hidebottom = 0;
832 if ($hidetop) {
833 $hidetop = -1;
834 }
835
836 $default_font_size = pdf_getPDFFontSize($outputlangs);
837
838 // Amount in (at tab_top - 1)
839 $pdf->SetTextColor(0, 0, 0);
840 $pdf->SetFont('', '', $default_font_size - 2);
841
842 // Output Rect
843 $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
844
845 $pdf->SetDrawColor(128, 128, 128);
846 $pdf->SetFont('', '', $default_font_size - 1);
847
848 // Description
849 if (empty($hidetop)) {
850 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
851
852 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
853 $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
854 }
855
856 if (!getDolGlobalString('SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME')) {
857 $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
858 if (empty($hidetop)) {
859 $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
860 $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
861 }
862 }
863
864 if (!getDolGlobalString('SHIPPING_PDF_HIDE_ORDERED')) {
865 $pdf->line($this->posxqtyordered - 1, $tab_top, $this->posxqtyordered - 1, $tab_top + $tab_height);
866 if (empty($hidetop)) {
867 $pdf->SetXY($this->posxqtyordered - 1, $tab_top + 1);
868 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"), '', 'C');
869 }
870 }
871
872 if (!getDolGlobalString('SHIPPING_PDF_HIDE_QTYTOSHIP')) {
873 $pdf->line($this->posxqtytoship - 1, $tab_top, $this->posxqtytoship - 1, $tab_top + $tab_height);
874 if (empty($hidetop)) {
875 $pdf->SetXY($this->posxqtytoship, $tab_top + 1);
876 $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"), '', 'C');
877 }
878 }
879
880 if (getDolGlobalString('SHIPPING_PDF_DISPLAY_AMOUNT_HT')) {
881 $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
882 if (empty($hidetop)) {
883 $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
884 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
885 }
886
887 $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
888 if (empty($hidetop)) {
889 $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
890 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
891 }
892 }
893 }
894
895 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
905 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
906 {
907 // phpcs:enable
908 global $conf, $langs, $mysoc;
909
910 $langs->load("orders");
911
912 $default_font_size = pdf_getPDFFontSize($outputlangs);
913
914 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
915
916 //Prepare next
917 $pdf->SetTextColor(0, 0, 60);
918 $pdf->SetFont('', 'B', $default_font_size + 3);
919
920 $w = 110;
921
922 $posy = $this->marge_haute;
923 $posx = $this->page_largeur - $this->marge_droite - $w;
924
925 $pdf->SetXY($this->marge_gauche, $posy);
926
927 // Logo
928 if ($this->emetteur->logo) {
929 $logodir = $conf->mycompany->dir_output;
930 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
931 $logodir = $conf->mycompany->multidir_output[$object->entity];
932 }
933 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
934 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
935 } else {
936 $logo = $logodir.'/logos/'.$this->emetteur->logo;
937 }
938 if (is_readable($logo)) {
939 $height = pdf_getHeightForLogo($logo);
940 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
941 } else {
942 $pdf->SetTextColor(200, 0, 0);
943 $pdf->SetFont('', 'B', $default_font_size - 2);
944 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
945 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
946 }
947 } else {
948 $text = $this->emetteur->name;
949 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
950 }
951
952 $pdf->SetDrawColor(128, 128, 128);
953
954 $posx = $this->page_largeur - $w - $this->marge_droite;
955 $posy = $this->marge_haute;
956
957 $pdf->SetFont('', 'B', $default_font_size + 2);
958 $pdf->SetXY($posx, $posy);
959 $pdf->SetTextColor(0, 0, 60);
960 $title = $outputlangs->transnoentities("SendingSheet");
961 $pdf->MultiCell($w, 4, $title, '', 'R');
962
963 $pdf->SetFont('', '', $default_font_size + 1);
964
965 $posy += 5;
966
967 $pdf->SetXY($posx, $posy);
968 $pdf->SetTextColor(0, 0, 60);
969 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending")." : ".$object->ref, '', 'R');
970
971 // Date planned delivery
972 if (!empty($object->date_delivery)) {
973 $posy += 4;
974 $pdf->SetXY($posx, $posy);
975 $pdf->SetTextColor(0, 0, 60);
976 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
977 }
978
979 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
980 $posy += 4;
981 $pdf->SetXY($posx, $posy);
982 $pdf->SetTextColor(0, 0, 60);
983 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
984 }
985
986
987 $pdf->SetFont('', '', $default_font_size + 3);
988 $Yoff = 25;
989
990 // Add list of linked orders
991 $origin = $object->origin;
992 $origin_id = $object->origin_id;
993
994 $object->fetch_origin();
995
996 // TODO move to external function
997 if (isModEnabled($origin)) { // commonly $origin='commande'
998 $outputlangs->load('orders');
999
1000 $classname = ucfirst($origin);
1001 $linkedobject = new $classname($this->db);
1002 $result = $linkedobject->fetch($origin_id);
1003 if ($result >= 0) {
1004 //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
1005
1006 $pdf->SetFont('', '', $default_font_size - 2);
1007 $text = $linkedobject->ref;
1008 if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) {
1009 $text .= ' ('.$linkedobject->ref_client.')';
1010 }
1011 $Yoff = $Yoff + 8;
1012 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1013 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
1014 $Yoff = $Yoff + 3;
1015 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1016 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
1017 }
1018 }
1019
1020 $top_shift = 0;
1021 // Show list of linked objects
1022 /*
1023 $current_y = $pdf->getY();
1024 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1025 if ($current_y < $pdf->getY()) {
1026 $top_shift = $pdf->getY() - $current_y;
1027 }
1028 */
1029
1030 if ($showaddress) {
1031 // Sender properties
1032 $carac_emetteur = '';
1033 // Add internal contact of origin element if defined
1034 $arrayidcontact = array();
1035 if (!empty($origin) && is_object($object->origin_object)) {
1036 $arrayidcontact = $object->origin_object->getIdContact('internal', 'SALESREPFOLL');
1037 }
1038 if (is_array($arrayidcontact) && count($arrayidcontact) > 0) {
1039 $object->fetch_user(reset($arrayidcontact));
1040 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1041 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1042 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1043 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1044 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1045 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1046 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1047 $carac_emetteur .= "\n";
1048 }
1049
1050 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1051
1052 // Show sender
1053 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1054 $posx = $this->marge_gauche;
1055 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1056 $posx = $this->page_largeur - $this->marge_droite - 80;
1057 }
1058
1059 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1060 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1061
1062 // Show sender frame
1063 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1064 $pdf->SetTextColor(0, 0, 0);
1065 $pdf->SetFont('', '', $default_font_size - 2);
1066 $pdf->SetXY($posx, $posy - 5);
1067 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender"), 0, 'L');
1068 $pdf->SetXY($posx, $posy);
1069 $pdf->SetFillColor(230, 230, 230);
1070 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1071 $pdf->SetTextColor(0, 0, 60);
1072 $pdf->SetFillColor(255, 255, 255);
1073 }
1074
1075 // Show sender name
1076 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1077 $pdf->SetXY($posx + 2, $posy + 3);
1078 $pdf->SetFont('', 'B', $default_font_size);
1079 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1080 $posy = $pdf->getY();
1081 }
1082
1083 // Show sender information
1084 $pdf->SetXY($posx + 2, $posy);
1085 $pdf->SetFont('', '', $default_font_size - 1);
1086 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1087
1088
1089 // If SHIPPING contact defined, we use it
1090 $usecontact = false;
1091 $arrayidcontact = $object->origin_object->getIdContact('external', 'SHIPPING');
1092 if (count($arrayidcontact) > 0) {
1093 $usecontact = true;
1094 $result = $object->fetch_contact($arrayidcontact[0]);
1095 }
1096
1097 // Recipient name
1098 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1099 $thirdparty = $object->contact;
1100 } else {
1101 $thirdparty = $object->thirdparty;
1102 }
1103
1104 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1105
1106 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
1107
1108 // Show recipient
1109 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1110 if ($this->page_largeur < 210) {
1111 $widthrecbox = 84; // To work with US executive format
1112 }
1113 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1114 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1115 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1116 $posx = $this->marge_gauche;
1117 }
1118
1119 // Show recipient frame
1120 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1121 $pdf->SetTextColor(0, 0, 0);
1122 $pdf->SetFont('', '', $default_font_size - 2);
1123 $pdf->SetXY($posx + 2, $posy - 5);
1124 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient"), 0, 'L');
1125 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1126 }
1127
1128 // Show recipient name
1129 $pdf->SetXY($posx + 2, $posy + 3);
1130 $pdf->SetFont('', 'B', $default_font_size);
1131 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1132
1133 $posy = $pdf->getY();
1134
1135 // Show recipient information
1136 $pdf->SetXY($posx + 2, $posy);
1137 $pdf->SetFont('', '', $default_font_size - 1);
1138 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1139 }
1140
1141 $pdf->SetTextColor(0, 0, 0);
1142
1143 return $top_shift;
1144 }
1145
1146 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1156 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1157 {
1158 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1159 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);
1160 }
1161}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect 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.
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 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_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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:2637
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:1438
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:290
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:315
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1027
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:267
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:436
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:388
measuringUnitString($unit, $measuring_style='', $scale='', $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:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.