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