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