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