dolibarr 21.0.0-beta
pdf_eagle.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) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Nick Fragoulis
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/stocktransfer/modules_stocktransfer.php';
33require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
37
38
43{
47 public $db;
48
52 public $name;
53
57 public $description;
58
62 public $type;
63
68 public $version = 'dolibarr';
69
73 public $posxlot;
74
78 public $posxweightvol;
79
83 public $posxwarehousesource;
84
88 public $posxwarehousedestination;
89
95 public $atLeastOneBatch;
96
102 public function __construct(DoliDB $db)
103 {
104 global $langs, $mysoc;
105
106 $this->db = $db;
107 $this->name = $langs->trans("StockTransferSheet");
108 $this->description = $langs->trans("DocumentModelStandardPDF");
109
110 $this->type = 'pdf';
111 $formatarray = pdf_getFormat();
112 $this->page_largeur = $formatarray['width'];
113 $this->page_hauteur = $formatarray['height'];
114 $this->format = array($this->page_largeur, $this->page_hauteur);
115 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
116 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
117 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
118 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
119 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
120 $this->option_logo = 1; // Display logo
121
122 // Define position of columns
123 $this->posxdesc = $this->marge_gauche + 1;
124 $this->posxlot = $this->page_largeur - $this->marge_droite - 135;
125 $this->posxweightvol = $this->page_largeur - $this->marge_droite - 115;
126 $this->posxqty = $this->page_largeur - $this->marge_droite - 95;
127 $this->posxwarehousesource = $this->page_largeur - $this->marge_droite - 70;
128 $this->posxwarehousedestination = $this->page_largeur - $this->marge_droite - 35;
129 $this->posxpuht = $this->page_largeur - $this->marge_droite;
130
131 /*if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) { // Show also the prices
132 $this->posxqty = $this->page_largeur - $this->marge_droite - 118;
133 $this->posxwarehousesource = $this->page_largeur - $this->marge_droite - 96;
134 $this->posxwarehousedestination = $this->page_largeur - $this->marge_droite - 68;
135 $this->posxpuht = $this->page_largeur - $this->marge_droite - 40;
136 $this->posxtotalht = $this->page_largeur - $this->marge_droite - 20;
137 }*/
138
139 if (getDolGlobalString('STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME')) {
140 $this->posxweightvol = $this->posxqty;
141 }
142
143 $this->posxpicture = $this->posxweightvol - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images
144 //var_dump($this->posxpicture, $this->posxweightvol);exit;
145
146 // To work with US executive format
147 if ($this->page_largeur < 210) {
148 $this->posxqty -= 20;
149 $this->posxpicture -= 20;
150 $this->posxwarehousesource -= 20;
151 $this->posxwarehousedestination -= 20;
152 }
153
154 /*if (!empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) {
155 $this->posxqty += ($this->posxwarehousedestination - $this->posxwarehousesource);
156 $this->posxpicture += ($this->posxwarehousedestination - $this->posxwarehousesource);
157 $this->posxwarehousesource = $this->posxwarehousedestination;
158 }*/
159
160 if ($mysoc === null) {
161 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
162 return;
163 }
164
165 // Get source company
166 $this->emetteur = $mysoc;
167 if (empty($this->emetteur->country_code)) {
168 $this->emetteur->country_code = substr($langs->defaultlang, -2);
169 }
170 }
171
172
173 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
185 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
186 {
187 // phpcs:enable
188 global $user, $conf, $langs, $hookmanager;
189
190 $object->fetch_thirdparty();
191
192 $this->atLeastOneBatch = $this->atLeastOneBatch($object);
193
194 if (!is_object($outputlangs)) {
195 $outputlangs = $langs;
196 }
197 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
198 if (getDolGlobalString('MAIN_USE_FPDF')) {
199 $outputlangs->charset_output = 'ISO-8859-1';
200 }
201
202 // Load translation files required by page
203 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch", "stocks", "stocktransfer@stocktransfer"));
204
205 global $outputlangsbis;
206 $outputlangsbis = null;
207 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
208 $outputlangsbis = new Translate('', $conf);
209 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
210 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
211 }
212
213 $nblines = is_array($object->lines) ? count($object->lines) : 0;
214
215 // Loop on each lines to detect if there is at least one image to show
216 $realpatharray = array();
217 $this->atleastonephoto = false;
218 if (getDolGlobalString('MAIN_GENERATE_STOCKTRANSFER_WITH_PICTURE')) {
219 $objphoto = new Product($this->db);
220
221 for ($i = 0; $i < $nblines; $i++) {
222 if (empty($object->lines[$i]->fk_product)) {
223 continue;
224 }
225
226 $objphoto = new Product($this->db);
227 $objphoto->fetch($object->lines[$i]->fk_product);
228 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
229 $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
230 $dir = $conf->product->dir_output.'/'.$pdir;
231 } else {
232 $pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
233 $dir = $conf->product->dir_output.'/'.$pdir;
234 }
235
236 $realpath = '';
237
238 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
239 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) {
240 // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
241 if ($obj['photo_vignette']) {
242 $filename = $obj['photo_vignette'];
243 } else {
244 $filename = $obj['photo'];
245 }
246 } else {
247 $filename = $obj['photo'];
248 }
249
250 $realpath = $dir.$filename;
251 $this->atleastonephoto = true;
252 break;
253 }
254
255 if ($realpath) {
256 $realpatharray[$i] = $realpath;
257 }
258 }
259 }
260
261 if (count($realpatharray) == 0) {
262 $this->posxpicture = $this->posxweightvol;
263 }
264
265
266 if (!empty($this->atLeastOneBatch)) {
267 $this->posxpicture = $this->posxlot;
268 if (getDolGlobalString('MAIN_GENERATE_STOCKTRANSFER_WITH_PICTURE')) {
269 $this->posxpicture -= getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20);
270 } // width of images
271 }
272
273 if ($conf->stocktransfer->dir_output) {
274 // Definition of $dir and $file
275 if ($object->specimen) {
276 $dir = $conf->stocktransfer->dir_output;
277 $file = $dir."/SPECIMEN.pdf";
278 } else {
279 $stocktransferref = dol_sanitizeFileName($object->ref);
280 $dir = $conf->stocktransfer->dir_output.'/'.$object->element."/".$stocktransferref;
281 $file = $dir."/".$stocktransferref.".pdf";
282 }
283
284 if (!file_exists($dir)) {
285 if (dol_mkdir($dir) < 0) {
286 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
287 return 0;
288 }
289 }
290
291 if (file_exists($dir)) {
292 // Add pdfgeneration hook
293 if (!is_object($hookmanager)) {
294 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
295 $hookmanager = new HookManager($this->db);
296 }
297 $hookmanager->initHooks(array('pdfgeneration'));
298 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
299 global $action;
300 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
301
302 // Set nblines with the new facture lines content after hook
303 $nblines = is_array($object->lines) ? count($object->lines) : 0;
304
305 $pdf = pdf_getInstance($this->format);
306 $default_font_size = pdf_getPDFFontSize($outputlangs);
307 $heightforinfotot = 8; // Height reserved to output the info and total part
308 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
309 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
310 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
311 $heightforfooter += 6;
312 }
313 $pdf->SetAutoPageBreak(1, 0);
314
315 if (class_exists('TCPDF')) {
316 $pdf->setPrintHeader(false);
317 $pdf->setPrintFooter(false);
318 }
319 $pdf->SetFont(pdf_getPDFFont($outputlangs));
320 // Set path to the background PDF File
321 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
322 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
323 $tplidx = $pdf->importPage(1);
324 }
325
326 $pdf->Open();
327 $pagenb = 0;
328 $pdf->SetDrawColor(128, 128, 128);
329
330 if (method_exists($pdf, 'AliasNbPages')) {
331 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
332 }
333
334 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
335 $pdf->SetSubject($outputlangs->transnoentities("StockTransfer"));
336 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
337 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
338 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("StockTransfer"));
339 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
340 $pdf->SetCompression(false);
341 }
342
343 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
344 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
345
346 // New page
347 $pdf->AddPage();
348 if (!empty($tplidx)) {
349 $pdf->useTemplate($tplidx);
350 }
351 $pagenb++;
352 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
353 $pdf->SetFont('', '', $default_font_size - 1);
354 $pdf->MultiCell(0, 3, ''); // Set interline to 3
355 $pdf->SetTextColor(0, 0, 0);
356
357 $tab_top = 90; // position of top tab
358 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
359
360 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
361
362 $tab_height_newpage = 150;
363
364 // Incoterm
365 $height_incoterms = 0;
366 if (isModEnabled('incoterm')) {
367 $desc_incoterms = $object->getIncotermsForPDF();
368 if ($desc_incoterms) {
369 $tab_top -= 2;
370
371 $pdf->SetFont('', '', $default_font_size - 1);
372 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
373 $nexY = $pdf->GetY();
374 $height_incoterms = $nexY - $tab_top;
375
376 // Rect takes a length in 3rd parameter
377 $pdf->SetDrawColor(192, 192, 192);
378 $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');
379
380 $tab_top = $nexY + 6;
381 $height_incoterms += 4;
382 }
383 }
384
385 // Public note and Tracking code
386 if (!empty($object->note_public) || !empty($object->tracking_number)) {
387 $tab_top_alt = $tab_top;
388
389 //$tab_top_alt += 1;
390
391 // Tracking number
392 if (!empty($object->tracking_number)) {
393 $height_trackingnumber = 4;
394
395 $pdf->SetFont('', 'B', $default_font_size - 2);
396 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
397 $tab_top_alt = $pdf->GetY();
398
399 $object->getUrlTrackingStatus($object->tracking_number);
400 if (!empty($object->tracking_url)) {
401 if ($object->shipping_method_id > 0) {
402 // Get code using getLabelFromKey
403 $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
404 $label = '';
405 if ($object->tracking_url != $object->tracking_number) {
406 $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
407 }
408 $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
409 //var_dump($object->tracking_url != $object->tracking_number);exit;
410 if ($object->tracking_url != $object->tracking_number) {
411 $label .= " : ";
412 $label .= $object->tracking_url;
413 }
414
415 $height_trackingnumber += 4;
416 $pdf->SetFont('', 'B', $default_font_size - 2);
417 $pdf->writeHTMLCell(60, $height_trackingnumber, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
418 }
419 }
420 $tab_top = $pdf->GetY();
421 }
422
423 // Notes
424 if (!empty($object->note_public)) {
425 $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
426 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
427 }
428
429 $nexY = $pdf->GetY();
430 $height_note = $nexY - $tab_top;
431
432 // Rect takes a length in 3rd parameter
433 $pdf->SetDrawColor(192, 192, 192);
434 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
435
436 $tab_height -= $height_note;
437 $tab_top = $nexY + 6;
438 } else {
439 $height_note = 0;
440 }
441
442 // Show barcode
443 $height_barcode = 0;
444 //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
445 if (isModEnabled('barcode') && getDolGlobalString('BARCODE_ON_STOCKTRANSFER_PDF')) {
446 require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/doc/tcpdfbarcode.modules.php';
447
448 $encoding = 'QRCODE';
449 $module = new modTcpdfbarcode();
450 $barcode_path = '';
451 $result = 0;
452 if ($module->encodingIsSupported($encoding)) {
453 $result = $module->writeBarCode($object->ref, $encoding);
454
455 // get path of qrcode image
456 $newcode = $object->ref;
457 if (!preg_match('/^\w+$/', $newcode) || dol_strlen($newcode) > 32) {
458 $newcode = dol_hash($newcode, 'md5');
459 }
460 $barcode_path = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png';
461 }
462
463 if ($result > 0) {
464 $tab_top -= 2;
465
466 $pdf->Image($barcode_path, $this->marge_gauche, $tab_top, 20, 20);
467
468 $nexY = $pdf->GetY();
469 $height_barcode = 20;
470
471 $tab_top += 22;
472 } else {
473 $this->error = 'Failed to generate barcode';
474 }
475 }
476
477 $iniY = $tab_top + 7;
478 $curY = $tab_top + 7;
479 $nexY = $tab_top + 7;
480
481 $TCacheEntrepots = array();
482 // Loop on each lines
483 for ($i = 0; $i < $nblines; $i++) {
484 $curY = $nexY;
485 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
486 $pdf->SetTextColor(0, 0, 0);
487
488 // Define size of image if we need it
489 $imglinesize = array();
490 if (!empty($realpatharray[$i])) {
491 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
492 }
493
494 $pdf->setTopMargin($tab_top_newpage);
495 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
496 $pageposbefore = $pdf->getPage();
497
498 $showpricebeforepagebreak = 1;
499 $posYAfterImage = 0;
500 $posYAfterDescription = 0;
501 $heightforsignature = 0;
502
503 // We start with Photo of product line
504 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
505 $pdf->AddPage('', '', true);
506 if (!empty($tplidx)) {
507 $pdf->useTemplate($tplidx);
508 }
509 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
510 $this->_pagehead($pdf, $object, 0, $outputlangs);
511 }
512 $pdf->setPage($pageposbefore + 1);
513
514 $curY = $tab_top_newpage;
515
516 // Allows data in the first page if description is long enough to break in multiples pages
517 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
518 $showpricebeforepagebreak = 1;
519 } else {
520 $showpricebeforepagebreak = 0;
521 }
522 }
523
524 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
525 $curX = $this->posxpicture - 1;
526 $pdf->Image($realpatharray[$i], $curX + (($this->posxqty - $this->posxweightvol - $imglinesize['width']
527 + (getDolGlobalString('STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME') ? getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20) : 0)) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
528 // $pdf->Image does not increase value return by getY, so we save it manually
529 $posYAfterImage = $curY + $imglinesize['height'];
530 }
531
532 // Description of product line
533 $curX = $this->posxdesc - 1;
534
535 $pdf->startTransaction();
536 if (method_exists($object->lines[$i], 'fetch_product')) {
537 $object->lines[$i]->fetch_product();
538 $object->lines[$i]->label = $object->lines[$i]->product->label;
539 $object->lines[$i]->description = $object->lines[$i]->product->description;
540 $object->lines[$i]->weight = $object->lines[$i]->product->weight;
541 $object->lines[$i]->weight_units = $object->lines[$i]->product->weight_units;
542 $object->lines[$i]->length = $object->lines[$i]->product->length;
543 $object->lines[$i]->length_units = $object->lines[$i]->product->length_units;
544 $object->lines[$i]->surface = $object->lines[$i]->product->surface;
545 $object->lines[$i]->surface_units = $object->lines[$i]->product->surface_units;
546 $object->lines[$i]->volume = $object->lines[$i]->product->volume;
547 $object->lines[$i]->volume_units = $object->lines[$i]->product->volume_units;
548 $object->lines[$i]->fk_unit = $object->lines[$i]->product->fk_unit;
549 //var_dump($object->lines[$i]);exit;
550 }
551
552 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
553
554 $pageposafter = $pdf->getPage();
555 if ($pageposafter > $pageposbefore) { // There is a pagebreak
556 $pdf->rollbackTransaction(true);
557 $pageposafter = $pageposbefore;
558 //print $pageposafter.'-'.$pageposbefore;exit;
559 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
560 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
561
562 $pageposafter = $pdf->getPage();
563 $posyafter = $pdf->GetY();
564 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
565 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
566 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
567 $pdf->AddPage('', '', true);
568 if (!empty($tplidx)) {
569 $pdf->useTemplate($tplidx);
570 }
571 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
572 $this->_pagehead($pdf, $object, 0, $outputlangs);
573 }
574 $pdf->setPage($pageposafter + 1);
575 }
576 } else {
577 // We found a page break
578
579 // Allows data in the first page if description is long enough to break in multiples pages
580 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
581 $showpricebeforepagebreak = 1;
582 } else {
583 $showpricebeforepagebreak = 0;
584 }
585 }
586 } else { // No pagebreak
587 $pdf->commitTransaction();
588 }
589 $posYAfterDescription = $pdf->GetY();
590
591 $nexY = max($pdf->GetY(), $posYAfterImage);
592 $pageposafter = $pdf->getPage();
593
594 $pdf->setPage($pageposbefore);
595 $pdf->setTopMargin($this->marge_haute);
596 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
597
598 // We suppose that a too long description or photo were moved completely on next page
599 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
600 $pdf->setPage($pageposafter);
601 $curY = $tab_top_newpage;
602 }
603
604 // We suppose that a too long description is moved completely on next page
605 if ($pageposafter > $pageposbefore) {
606 $pdf->setPage($pageposafter);
607 $curY = $tab_top_newpage;
608 }
609
610 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
611
612 // Lot / série
613 if (isModEnabled('productbatch')) {
614 $pdf->SetXY($this->posxlot, $curY);
615 $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 3, $object->lines[$i]->batch, '', 'C');
616 }
617
618 // weight
619
620 $pdf->SetXY($this->posxweightvol, $curY);
621 $weighttxt = '';
622 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->weight) {
623 $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1);
624 }
625 $voltxt = '';
626 if (empty($object->lines[$i]->fk_product_type) && $object->lines[$i]->volume) {
627 $voltxt = round($object->lines[$i]->volume * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units ? $object->lines[$i]->volume_units : 0, 1);
628 }
629
630 // Weight
631 if (!getDolGlobalString('STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME')) {
632 $pdf->writeHTMLCell($this->posxqty - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, 0, 0, false, true, 'C');
633 //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
634 }
635
636 // Qty
637 $pdf->SetXY($this->posxqty, $curY);
638 $pdf->writeHTMLCell($this->posxwarehousesource - $this->posxqty + 2, 3, $this->posxqty - 1, $curY, $object->lines[$i]->qty, 0, 0, false, true, 'C');
639 //$pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
640
641 // Warehouse source
642 $wh_source = new Entrepot($this->db);
643 if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_source])) {
644 $wh_source = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source];
645 } else {
646 $wh_source->fetch($object->lines[$i]->fk_warehouse_source);
647 $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source] = $wh_source;
648 }
649 $pdf->SetXY($this->posxwarehousesource, $curY);
650 $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 3, $wh_source->ref.(!empty($wh_source->lieu) ? ' - '.$wh_source->lieu : ''), '', 'C');
651
652 // Warehouse destination
653 $wh_destination = new Entrepot($this->db);
654 if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination])) {
655 $wh_destination = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination];
656 } else {
657 $wh_destination->fetch($object->lines[$i]->fk_warehouse_destination);
658 $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination] = $wh_destination;
659 }
660 $pdf->SetXY($this->posxwarehousedestination, $curY);
661 $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination), 3, $wh_destination->ref.(!empty($wh_destination->lieu) ? ' - '.$wh_destination->lieu : ''), '', 'C');
662
663 if (getDolGlobalString('STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT')) {
664 $pdf->SetXY($this->posxpuht, $curY);
665 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
666
667 $pdf->SetXY($this->posxtotalht, $curY);
668 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
669 }
670
671 $nexY += 3;
672 if ($weighttxt && $voltxt) {
673 $nexY += 2;
674 }
675
676 // Add line
677 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
678 $pdf->setPage($pageposafter);
679 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
680 //$pdf->SetDrawColor(190,190,200);
681 $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
682 $pdf->SetLineStyle(array('dash' => 0));
683 }
684
685 // Detect if some page were added automatically and output _tableau for past pages
686 while ($pagenb < $pageposafter) {
687 $pdf->setPage($pagenb);
688 if ($pagenb == 1) {
689 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
690 } else {
691 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
692 }
693 $this->_pagefoot($pdf, $object, $outputlangs, 1);
694 $pagenb++;
695 $pdf->setPage($pagenb);
696 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
697 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
698 $this->_pagehead($pdf, $object, 0, $outputlangs);
699 }
700 if (!empty($tplidx)) {
701 $pdf->useTemplate($tplidx);
702 }
703 }
704 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
705 if ($pagenb == 1) {
706 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
707 } else {
708 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
709 }
710 $this->_pagefoot($pdf, $object, $outputlangs, 1);
711 // New page
712 $pdf->AddPage();
713 if (!empty($tplidx)) {
714 $pdf->useTemplate($tplidx);
715 }
716 $pagenb++;
717 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
718 $this->_pagehead($pdf, $object, 0, $outputlangs);
719 }
720 }
721 }
722
723 // Show square
724 if ($pagenb == 1) {
725 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
726 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
727 } else {
728 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
729 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
730 }
731
732 // Display total area
733 $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
734
735 // Pagefoot
736 $this->_pagefoot($pdf, $object, $outputlangs);
737 if (method_exists($pdf, 'AliasNbPages')) {
738 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
739 }
740
741 $pdf->Close();
742
743 $pdf->Output($file, 'F');
744
745 // Add pdfgeneration hook
746 $hookmanager->initHooks(array('pdfgeneration'));
747 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
748 global $action;
749 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
750 if ($reshook < 0) {
751 $this->error = $hookmanager->error;
752 $this->errors = $hookmanager->errors;
753 }
754
755 dolChmod($file);
756
757 $this->result = array('fullpath' => $file);
758
759 return 1; // No error
760 } else {
761 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
762 return 0;
763 }
764 } else {
765 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "STOCKTRANSFER_OUTPUTDIR");
766 return 0;
767 }
768 }
769
770 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
771 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
782 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
783 {
784 // phpcs:enable
785 $default_font_size = pdf_getPDFFontSize($outputlangs);
786
787 $tab2_top = $posy;
788 $tab2_hl = 4;
789 $pdf->SetFont('', 'B', $default_font_size - 1);
790
791 // Total table
792 $col1x = $this->posxqty - 50;
793 $col2x = $this->posxqty;
794 /*if ($this->page_largeur < 210) // To work with US executive format
795 {
796 $col2x-=20;
797 }*/
798 if (!getDolGlobalString('STOCKTRANSFER_PDF_HIDE_ORDERED')) {
799 $largcol2 = ($this->posxwarehousesource - $this->posxqty);
800 } else {
801 $largcol2 = ($this->posxwarehousedestination - $this->posxqty);
802 }
803
804 $useborder = 0;
805 $index = 0;
806
807 $totalWeight = '';
808 $totalVolume = '';
809 $totalWeighttoshow = '';
810 $totalVolumetoshow = '';
811
812 // Load dim data
813 $tmparray = $object->getTotalWeightVolume();
814 if (!empty($tmparray)) {
815 $totalWeight = $tmparray['weight'];
816 $totalVolume = $tmparray['volume'];
817 }
818 $totalQty = 0;
819 if (!empty($object->lines)) {
820 foreach ($object->lines as $line) {
821 $totalQty += $line->qty;
822 }
823 }
824 // Set trueVolume and volume_units not currently stored into database
825 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
826 $object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
827 $object->volume_units = $object->size_units * 3;
828 }
829
830 if ($totalWeight != '') {
831 $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
832 }
833 if ($totalVolume != '') {
834 $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
835 }
836 if (!empty($object->trueWeight)) {
837 $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
838 }
839 if (!empty($object->trueVolume)) {
840 $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
841 }
842
843 $pdf->SetFillColor(255, 255, 255);
844 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
845 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
846
847 if (!getDolGlobalString('STOCKTRANSFER_PDF_HIDE_ORDERED')) {
848 $pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index);
849 $pdf->MultiCell($this->posxwarehousesource - $this->posxqty, $tab2_hl, $totalQty, 0, 'C', 1);
850 }
851
852 if (getDolGlobalString('STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT')) {
853 $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
854 $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
855
856 $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
857 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
858 }
859
860 if (!getDolGlobalString('STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME')) {
861 // Total Weight
862 if ($totalWeighttoshow) {
863 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
864 $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
865
866 $index++;
867 }
868 if ($totalVolumetoshow) {
869 $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
870 $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
871
872 $index++;
873 }
874 if (!$totalWeighttoshow && !$totalVolumetoshow) {
875 $index++;
876 }
877 }
878
879 $pdf->SetTextColor(0, 0, 0);
880
881 return ($tab2_top + ($tab2_hl * $index));
882 }
883
884 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
897 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
898 {
899 // phpcs:enable
900 global $conf;
901
902 // Force to disable hidetop and hidebottom
903 $hidebottom = 0;
904 if ($hidetop) {
905 $hidetop = -1;
906 }
907
908 $default_font_size = pdf_getPDFFontSize($outputlangs);
909
910 // Amount in (at tab_top - 1)
911 $pdf->SetTextColor(0, 0, 0);
912 $pdf->SetFont('', '', $default_font_size - 2);
913
914 // Output Rect
915 $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
916
917 $pdf->SetDrawColor(128, 128, 128);
918 $pdf->SetFont('', '', $default_font_size - 1);
919
920 // Description
921 if (empty($hidetop)) {
922 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
923
924 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
925 $pdf->MultiCell($this->posxlot - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
926 }
927
928 if (isModEnabled('productbatch') && $this->atLeastOneBatch) {
929 $pdf->line($this->posxlot - 1, $tab_top, $this->posxlot - 1, $tab_top + $tab_height);
930 if (empty($hidetop)) {
931 $pdf->SetXY($this->posxlot, $tab_top + 1);
932 $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 2, $outputlangs->transnoentities("Batch"), '', 'C');
933 }
934 }
935
936 if (!getDolGlobalString('STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME')) {
937 $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
938 if (empty($hidetop)) {
939 $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
940 $pdf->MultiCell(($this->posxqty - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
941 }
942 }
943
944 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
945 if (empty($hidetop)) {
946 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
947 $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 2, $outputlangs->transnoentities("Qty"), '', 'C');
948 }
949
950 $pdf->line($this->posxwarehousesource - 1, $tab_top, $this->posxwarehousesource - 1, $tab_top + $tab_height);
951 if (empty($hidetop)) {
952 $pdf->SetXY($this->posxwarehousesource - 1, $tab_top + 1);
953 $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 2, $outputlangs->transnoentities("WarehouseSource"), '', 'C');
954 }
955
956
957 $pdf->line($this->posxwarehousedestination - 1, $tab_top, $this->posxwarehousedestination - 1, $tab_top + $tab_height);
958 if (empty($hidetop)) {
959 $pdf->SetXY($this->posxwarehousedestination - 2.5, $tab_top + 1);
960 $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination + 4), 2, $outputlangs->transnoentities("WarehouseTarget"), '', 'C');
961 }
962
963 /*if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
964 $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
965 if (empty($hidetop))
966 {
967 $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
968 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
969 }
970
971 $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
972 if (empty($hidetop))
973 {
974 $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
975 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
976 }
977 }*/
978 }
979
986 public function atLeastOneBatch($object)
987 {
988 //$atLeastOneBatch = false;
989
990 if (!isModEnabled('productbatch')) {
991 return false;
992 }
993
994 if (!empty($object->lines)) {
995 foreach ($object->lines as $line) {
996 if (!empty($line->batch)) {
997 return true;
998 }
999 }
1000 }
1001
1002 return false;
1003 }
1004
1005 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1015 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1016 {
1017 // phpcs:enable
1018 global $conf, $langs;
1019
1020 // Load traductions files required by page
1021 $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1022
1023 $default_font_size = pdf_getPDFFontSize($outputlangs);
1024
1025 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1026
1027 // Show Draft Watermark
1028 if ($object->statut == 0 && (getDolGlobalString('STOCKTRANSFER_DRAFT_WATERMARK'))) {
1029 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
1030 }
1031
1032 //Prepare next
1033 $pdf->SetTextColor(0, 0, 60);
1034 $pdf->SetFont('', 'B', $default_font_size + 3);
1035
1036 $w = 110;
1037
1038 $posy = $this->marge_haute;
1039 $posx = $this->page_largeur - $this->marge_droite - $w;
1040
1041 $pdf->SetXY($this->marge_gauche, $posy);
1042
1043 // Logo
1044 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1045 if ($this->emetteur->logo) {
1046 if (is_readable($logo)) {
1047 $height = pdf_getHeightForLogo($logo);
1048 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1049 } else {
1050 $pdf->SetTextColor(200, 0, 0);
1051 $pdf->SetFont('', 'B', $default_font_size - 2);
1052 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1053 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1054 }
1055 } else {
1056 $text = $this->emetteur->name;
1057 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1058 }
1059
1060 $pdf->SetDrawColor(128, 128, 128);
1061
1062 $posx = $this->page_largeur - $w - $this->marge_droite;
1063 $posy = $this->marge_haute;
1064
1065 $pdf->SetFont('', 'B', $default_font_size + 2);
1066 $pdf->SetXY($posx, $posy);
1067 $pdf->SetTextColor(0, 0, 60);
1068 $title = $outputlangs->transnoentities("StockTransferSheet").' '.$object->ref;
1069 $pdf->MultiCell($w, 4, $title, '', 'R');
1070
1071 $pdf->SetFont('', '', $default_font_size + 1);
1072
1073 // Date prévue depart
1074 if (!empty($object->date_prevue_depart)) {
1075 $posy += 4;
1076 $pdf->SetXY($posx, $posy);
1077 $pdf->SetTextColor(0, 0, 60);
1078 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueDepart")." : ".dol_print_date($object->date_prevue_depart, "day", false, $outputlangs, true), '', 'R');
1079 }
1080
1081 // Date prévue arrivée
1082 if (!empty($object->date_prevue_arrivee)) {
1083 $posy += 4;
1084 $pdf->SetXY($posx, $posy);
1085 $pdf->SetTextColor(0, 0, 60);
1086 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueArrivee")." : ".dol_print_date($object->date_prevue_arrivee, "day", false, $outputlangs, true), '', 'R');
1087 }
1088
1089 // Date reelle depart
1090 if (!empty($object->date_reelle_depart)) {
1091 $posy += 4;
1092 $pdf->SetXY($posx, $posy);
1093 $pdf->SetTextColor(0, 0, 60);
1094 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleDepart")." : ".dol_print_date($object->date_reelle_depart, "day", false, $outputlangs, true), '', 'R');
1095 }
1096
1097 // Date reelle arrivée
1098 if (!empty($object->date_reelle_arrivee)) {
1099 $posy += 4;
1100 $pdf->SetXY($posx, $posy);
1101 $pdf->SetTextColor(0, 0, 60);
1102 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
1103 }
1104
1105 if (!empty($object->thirdparty->code_client)) {
1106 $posy += 4;
1107 $pdf->SetXY($posx, $posy);
1108 $pdf->SetTextColor(0, 0, 60);
1109 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1110 }
1111
1112
1113 $pdf->SetFont('', '', $default_font_size + 3);
1114 $Yoff = 25;
1115
1116 // Add list of linked orders
1117 $origin = $object->origin;
1118 $origin_id = $object->origin_id;
1119
1120 // TODO move to external function
1121 if (isModEnabled($origin)) { // commonly $origin='commande'
1122 $outputlangs->load('orders');
1123
1124 $classname = ucfirst($origin);
1125 $linkedobject = new $classname($this->db);
1126 '@phan-var-force CommonObject $linkedobject';
1127 $result = $linkedobject->fetch($origin_id);
1128 if ($result >= 0) {
1129 //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
1130
1131 $pdf->SetFont('', '', $default_font_size - 2);
1132 $text = $linkedobject->ref;
1133 if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) {
1134 $text .= ' ('.$linkedobject->ref_client.')';
1135 }
1136 $Yoff += 8;
1137 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1138 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
1139 $Yoff += 3;
1140 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1141 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
1142 }
1143 }
1144
1145 $top_shift = 0;
1146
1147 if ($showaddress) {
1148 // Sender properties
1149 $carac_emetteur = '';
1150 // Add internal contact of origin element if defined
1151 $arrayidcontact = array();
1152 $arrayidcontact = $object->getIdContact('external', 'STFROM');
1153
1154 $usecontact = false;
1155 if (count($arrayidcontact) > 0) {
1156 /*$object->fetch_user(reset($arrayidcontact));
1157 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
1158 $usecontact = true;
1159 $result = $object->fetch_contact($arrayidcontact[0]);
1160 }
1161
1162 if ($usecontact) {
1163 $thirdparty = $object->contact;
1164 } else {
1165 $thirdparty = $this->emetteur;
1166 }
1167
1168 if (!empty($thirdparty)) {
1169 $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1170 }
1171
1172 if ($usecontact) {
1173 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
1174 } else {
1175 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1176 }
1177
1178 // Show sender
1179 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1180 $posx = $this->marge_gauche;
1181 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1182 $posx = $this->page_largeur - $this->marge_droite - 80;
1183 }
1184
1185 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1186 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1187
1188 // Show sender frame
1189 $pdf->SetTextColor(0, 0, 0);
1190 $pdf->SetFont('', '', $default_font_size - 2);
1191 $pdf->SetXY($posx, $posy - 5);
1192 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1193 $pdf->SetXY($posx, $posy);
1194 $pdf->SetFillColor(230, 230, 230);
1195 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1196 $pdf->SetTextColor(0, 0, 60);
1197 $pdf->SetFillColor(255, 255, 255);
1198
1199 // Show sender name
1200 $pdf->SetXY($posx + 2, $posy + 3);
1201 $pdf->SetFont('', 'B', $default_font_size);
1202 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_emetteur_name), 0, 'L');
1203 $posy = $pdf->getY();
1204
1205 // Show sender information
1206 $pdf->SetXY($posx + 2, $posy);
1207 $pdf->SetFont('', '', $default_font_size - 1);
1208 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1209
1210
1211 // If SHIPPING contact defined, we use it
1212 $usecontact = false;
1213 $arrayidcontact = $object->getIdContact('external', 'STDEST');
1214 if (count($arrayidcontact) > 0) {
1215 $usecontact = true;
1216 $result = $object->fetch_contact($arrayidcontact[0]);
1217 }
1218
1219 //Recipient name
1220 // On peut utiliser le nom de la societe du contact
1221 if ($usecontact/* && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)*/) {
1222 $thirdparty = $object->contact;
1223 } else {
1224 $thirdparty = $object->thirdparty;
1225 }
1226
1227 $carac_client_name = '';
1228 if (!empty($thirdparty)) {
1229 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1230 }
1231
1232 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), ($usecontact ? 1 : 0), 'targetwithdetails', $object);
1233
1234 // Show recipient
1235 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1236 if ($this->page_largeur < 210) {
1237 $widthrecbox = 84; // To work with US executive format
1238 }
1239 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1240 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1241 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1242 $posx = $this->marge_gauche;
1243 }
1244
1245 // Show recipient frame
1246 $pdf->SetTextColor(0, 0, 0);
1247 $pdf->SetFont('', '', $default_font_size - 2);
1248 $pdf->SetXY($posx + 2, $posy - 5);
1249 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1250 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1251
1252 // Show recipient name
1253 $pdf->SetXY($posx + 2, $posy + 3);
1254 $pdf->SetFont('', 'B', $default_font_size);
1255 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1256
1257 $posy = $pdf->getY();
1258
1259 // Show recipient information
1260 $pdf->SetXY($posx + 2, $posy);
1261 $pdf->SetFont('', '', $default_font_size - 1);
1262 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1263 }
1264
1265 $pdf->SetTextColor(0, 0, 0);
1266
1267 return $top_shift;
1268 }
1269
1270 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1280 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1281 {
1282 // phpcs:enable
1283 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1284 return pdf_pagefoot($pdf, $outputlangs, 'STOCKTRANSFER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1285 }
1286}
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 warehouses.
Class to manage hooks.
Parent class for documents 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 Eagle.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
__construct(DoliDB $db)
Constructor.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
atLeastOneBatch($object)
Used to know if at least one line of Stock Transfer object has a batch set.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:785
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.