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