dolibarr  16.0.5
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(5, 5);
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 = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
135  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
136  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
137  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->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 (!empty($conf->global->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 (empty($conf->global->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 (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
323 
324  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
325 
326  // New page
327  $pdf->AddPage();
328  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
329  $pagenb++;
330  $this->_pagehead($pdf, $object, 1, $outputlangs);
331  $pdf->SetFont('', '', $default_font_size - 1);
332  $pdf->MultiCell(0, 3, ''); // Set interline to 3
333  $pdf->SetTextColor(0, 0, 0);
334 
335  $tab_top = 90;
336  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
337  $tab_height = 130;
338  $tab_height_newpage = 150;
339 
340  // Incoterm
341  $height_incoterms = 0;
342  if ($conf->incoterm->enabled) {
343  $desc_incoterms = $object->getIncotermsForPDF();
344  if ($desc_incoterms) {
345  $tab_top = 88;
346 
347  $pdf->SetFont('', '', $default_font_size - 1);
348  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
349  $nexY = $pdf->GetY();
350  $height_incoterms = $nexY - $tab_top;
351 
352  // Rect takes a length in 3rd parameter
353  $pdf->SetDrawColor(192, 192, 192);
354  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
355 
356  $tab_top = $nexY + 6;
357  $height_incoterms += 4;
358  }
359  }
360 
361  if (!empty($object->note_public) || !empty($object->tracking_number)) {
362  $tab_top = 88 + $height_incoterms;
363  $tab_top_alt = $tab_top;
364 
365  $pdf->SetFont('', 'B', $default_font_size - 2);
366 
367  //$tab_top_alt += 1;
368 
369  // Tracking number
370  if (!empty($object->tracking_number)) {
371  $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
372  $tab_top_alt = $pdf->GetY();
373 
374  $object->getUrlTrackingStatus($object->tracking_number);
375  if (!empty($object->tracking_url)) {
376  if ($object->shipping_method_id > 0) {
377  // Get code using getLabelFromKey
378  $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
379  $label = '';
380  if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
381  $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
382  //var_dump($object->tracking_url != $object->tracking_number);exit;
383  if ($object->tracking_url != $object->tracking_number) {
384  $label .= " : ";
385  $label .= $object->tracking_url;
386  }
387  $pdf->SetFont('', 'B', $default_font_size - 2);
388  $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
389 
390  $tab_top_alt = $pdf->GetY();
391  }
392  }
393  }
394 
395  // Notes
396  if (!empty($object->note_public)) {
397  $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
398  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
399  }
400 
401  $nexY = $pdf->GetY();
402  $height_note = $nexY - $tab_top;
403 
404  // Rect takes a length in 3rd parameter
405  $pdf->SetDrawColor(192, 192, 192);
406  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
407 
408  $tab_height = $tab_height - $height_note;
409  $tab_top = $nexY + 6;
410  } else {
411  $height_note = 0;
412  }
413 
414  $iniY = $tab_top + 7;
415  $curY = $tab_top + 7;
416  $nexY = $tab_top + 7;
417 
418  $TCacheEntrepots=array();
419  // Loop on each lines
420  for ($i = 0; $i < $nblines; $i++) {
421  $curY = $nexY;
422  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
423  $pdf->SetTextColor(0, 0, 0);
424 
425  // Define size of image if we need it
426  $imglinesize = array();
427  if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
428 
429  $pdf->setTopMargin($tab_top_newpage);
430  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
431  $pageposbefore = $pdf->getPage();
432 
433  $showpricebeforepagebreak = 1;
434  $posYAfterImage = 0;
435  $posYAfterDescription = 0;
436 
437  // We start with Photo of product line
438  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
439  $pdf->AddPage('', '', true);
440  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
441  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
442  $pdf->setPage($pageposbefore + 1);
443 
444  $curY = $tab_top_newpage;
445 
446  // Allows data in the first page if description is long enough to break in multiples pages
447  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
448  $showpricebeforepagebreak = 1;
449  else $showpricebeforepagebreak = 0;
450  }
451 
452  if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
453  $curX = $this->posxpicture - 1;
454  $pdf->Image($realpatharray[$i], $curX + (($this->posxqty - $this->posxweightvol - $imglinesize['width']
455  + (!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
456  // $pdf->Image does not increase value return by getY, so we save it manually
457  $posYAfterImage = $curY + $imglinesize['height'];
458  }
459 
460  // Description of product line
461  $curX = $this->posxdesc - 1;
462 
463  $pdf->startTransaction();
464  if (method_exists($object->lines[$i], 'fetch_product')) {
465  $object->lines[$i]->fetch_product();
466  $object->lines[$i]->label = $object->lines[$i]->product->label;
467  $object->lines[$i]->description = $object->lines[$i]->product->description;
468  $object->lines[$i]->weight = $object->lines[$i]->product->weight;
469  $object->lines[$i]->weight_units = $object->lines[$i]->product->weight_units;
470  $object->lines[$i]->length = $object->lines[$i]->product->length;
471  $object->lines[$i]->length_units = $object->lines[$i]->product->length_units;
472  $object->lines[$i]->surface = $object->lines[$i]->product->surface;
473  $object->lines[$i]->surface_units = $object->lines[$i]->product->surface_units;
474  $object->lines[$i]->volume = $object->lines[$i]->product->volume;
475  $object->lines[$i]->volume_units = $object->lines[$i]->product->volume_units;
476  $object->lines[$i]->fk_unit = $object->lines[$i]->product->fk_unit;
477  //var_dump($object->lines[$i]);exit;
478  }
479 
480  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
481 
482  $pageposafter = $pdf->getPage();
483  if ($pageposafter > $pageposbefore) { // There is a pagebreak
484  $pdf->rollbackTransaction(true);
485  $pageposafter = $pageposbefore;
486  //print $pageposafter.'-'.$pageposbefore;exit;
487  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
488  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
489 
490  $pageposafter = $pdf->getPage();
491  $posyafter = $pdf->GetY();
492  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
493  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
494  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
495  $pdf->AddPage('', '', true);
496  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
497  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
498  $pdf->setPage($pageposafter + 1);
499  }
500  } else {
501  // We found a page break
502 
503  // Allows data in the first page if description is long enough to break in multiples pages
504  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
505  $showpricebeforepagebreak = 1;
506  else $showpricebeforepagebreak = 0;
507  }
508  } else // No pagebreak
509  {
510  $pdf->commitTransaction();
511  }
512  $posYAfterDescription = $pdf->GetY();
513 
514  $nexY = $pdf->GetY();
515  $pageposafter = $pdf->getPage();
516 
517  $pdf->setPage($pageposbefore);
518  $pdf->setTopMargin($this->marge_haute);
519  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
520 
521  // We suppose that a too long description or photo were moved completely on next page
522  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
523  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
524  }
525 
526  // We suppose that a too long description is moved completely on next page
527  if ($pageposafter > $pageposbefore) {
528  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
529  }
530 
531  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
532 
533  // Lot / série
534  if (!empty($conf->productbatch->enabled)) {
535  $pdf->SetXY($this->posxlot, $curY);
536  $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 3, $object->lines[$i]->batch, '', 'C');
537  }
538 
539  // Weight
540  $pdf->SetXY($this->posxweightvol, $curY);
541  $weighttxt = '';
542  if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) {
543  $weighttxt = round($object->lines[$i]->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units, 1);
544  }
545  $voltxt = '';
546  if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) {
547  $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);
548  }
549 
550  // Weight
551  if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
552  $pdf->writeHTMLCell($this->posxqty - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt) ? '<br>' : '').$voltxt, 0, 0, false, true, 'C');
553  //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
554  }
555 
556  // Qty
557  $pdf->SetXY($this->posxqty, $curY);
558  $pdf->writeHTMLCell($this->posxwarehousesource - $this->posxqty + 2, 3, $this->posxqty - 1, $curY, $object->lines[$i]->qty, 0, 0, false, true, 'C');
559  //$pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
560 
561  // Warehouse source
562  $wh_source = new Entrepot($db);
563  if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_source])) $wh_source = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source];
564  else {
565  $wh_source->fetch($object->lines[$i]->fk_warehouse_source);
566  $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source] = $wh_source;
567  }
568  $pdf->SetXY($this->posxwarehousesource, $curY);
569  $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 3, $wh_source->ref.(!empty($wh_source->lieu) ? ' - '.$wh_source->lieu : ''), '', 'C');
570 
571  // Warehouse destination
572  $wh_destination = new Entrepot($db);
573  if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination])) $wh_destination = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination];
574  else {
575  $wh_destination->fetch($object->lines[$i]->fk_warehouse_destination);
576  $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination] = $wh_destination;
577  }
578  $pdf->SetXY($this->posxwarehousedestination, $curY);
579  $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination), 3, $wh_destination->ref.(!empty($wh_destination->lieu) ? ' - '.$wh_destination->lieu : ''), '', 'C');
580 
581  if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
582  $pdf->SetXY($this->posxpuht, $curY);
583  $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
584 
585  $pdf->SetXY($this->posxtotalht, $curY);
586  $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs), '', 'R');
587  }
588 
589  $nexY += 3;
590  if ($weighttxt && $voltxt) $nexY += 2;
591 
592  // Add line
593  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
594  $pdf->setPage($pageposafter);
595  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
596  //$pdf->SetDrawColor(190,190,200);
597  $pdf->line($this->marge_gauche, $nexY - 1, $this->page_largeur - $this->marge_droite, $nexY - 1);
598  $pdf->SetLineStyle(array('dash'=>0));
599  }
600 
601  // Detect if some page were added automatically and output _tableau for past pages
602  while ($pagenb < $pageposafter) {
603  $pdf->setPage($pagenb);
604  if ($pagenb == 1) {
605  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
606  } else {
607  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
608  }
609  $this->_pagefoot($pdf, $object, $outputlangs, 1);
610  $pagenb++;
611  $pdf->setPage($pagenb);
612  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
613  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
614  }
615  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
616  if ($pagenb == 1) {
617  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
618  } else {
619  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
620  }
621  $this->_pagefoot($pdf, $object, $outputlangs, 1);
622  // New page
623  $pdf->AddPage();
624  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
625  $pagenb++;
626  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
627  }
628  }
629 
630  // Show square
631  if ($pagenb == 1) {
632  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
633  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
634  } else {
635  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
636  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
637  }
638 
639  // Affiche zone totaux
640  $posy = $this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
641 
642  // Pied de page
643  $this->_pagefoot($pdf, $object, $outputlangs);
644  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
645 
646  $pdf->Close();
647 
648  $pdf->Output($file, 'F');
649 
650  // Add pdfgeneration hook
651  $hookmanager->initHooks(array('pdfgeneration'));
652  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
653  global $action;
654  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
655  if ($reshook < 0) {
656  $this->error = $hookmanager->error;
657  $this->errors = $hookmanager->errors;
658  }
659 
660  if (!empty($conf->global->MAIN_UMASK))
661  @chmod($file, octdec($conf->global->MAIN_UMASK));
662 
663  $this->result = array('fullpath'=>$file);
664 
665  return 1; // No error
666  } else {
667  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
668  return 0;
669  }
670  } else {
671  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
672  return 0;
673  }
674  }
675 
676  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
677  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
688  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
689  {
690  // phpcs:enable
691  global $conf, $mysoc;
692 
693  $sign = 1;
694 
695  $default_font_size = pdf_getPDFFontSize($outputlangs);
696 
697  $tab2_top = $posy;
698  $tab2_hl = 4;
699  $pdf->SetFont('', 'B', $default_font_size - 1);
700 
701  // Tableau total
702  $col1x = $this->posxqty - 50; $col2x = $this->posxqty;
703  /*if ($this->page_largeur < 210) // To work with US executive format
704  {
705  $col2x-=20;
706  }*/
707  if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxwarehousesource - $this->posxqty);
708  else $largcol2 = ($this->posxwarehousedestination - $this->posxqty);
709 
710  $useborder = 0;
711  $index = 0;
712 
713  $totalWeighttoshow = '';
714  $totalVolumetoshow = '';
715 
716  // Load dim data
717  $tmparray = $object->getTotalWeightVolume();
718  $totalWeight = $tmparray['weight'];
719  $totalVolume = $tmparray['volume'];
720  $totalQty = 0;
721  if (!empty($object->lines))
722  foreach ($object->lines as $line) {
723  $totalQty+=$line->qty;
724  }
725  // Set trueVolume and volume_units not currently stored into database
726  if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
727  $object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
728  $object->volume_units = $object->size_units * 3;
729  }
730 
731  if ($totalWeight != '') $totalWeighttoshow = showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
732  if ($totalVolume != '') $totalVolumetoshow = showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
733  if ($object->trueWeight) $totalWeighttoshow = showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
734  if ($object->trueVolume) $totalVolumetoshow = showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
735 
736  $pdf->SetFillColor(255, 255, 255);
737  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
738  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
739 
740  if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) {
741  $pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index);
742  $pdf->MultiCell($this->posxwarehousesource - $this->posxqty, $tab2_hl, $totalQty, 0, 'C', 1);
743  }
744 
745  if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
746  $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
747  $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
748 
749  $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
750  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
751  }
752 
753  if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
754  // Total Weight
755  if ($totalWeighttoshow) {
756  $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
757  $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
758 
759  $index++;
760  }
761  if ($totalVolumetoshow) {
762  $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
763  $pdf->MultiCell(($this->posxqty - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
764 
765  $index++;
766  }
767  if (!$totalWeighttoshow && !$totalVolumetoshow) $index++;
768  }
769 
770  $pdf->SetTextColor(0, 0, 0);
771 
772  return ($tab2_top + ($tab2_hl * $index));
773  }
774 
775  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
788  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
789  {
790  // phpcs:enable
791  global $conf;
792 
793  // Force to disable hidetop and hidebottom
794  $hidebottom = 0;
795  if ($hidetop) $hidetop = -1;
796 
797  $default_font_size = pdf_getPDFFontSize($outputlangs);
798 
799  // Amount in (at tab_top - 1)
800  $pdf->SetTextColor(0, 0, 0);
801  $pdf->SetFont('', '', $default_font_size - 2);
802 
803  // Output Rect
804  $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
805 
806  $pdf->SetDrawColor(128, 128, 128);
807  $pdf->SetFont('', '', $default_font_size - 1);
808 
809  if (empty($hidetop)) {
810  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
811 
812  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
813  $pdf->MultiCell($this->posxlot - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
814  }
815 
816  if (!empty($conf->productbatch->enabled) && $this->atLeastOneBatch) {
817  $pdf->line($this->posxlot - 1, $tab_top, $this->posxlot - 1, $tab_top + $tab_height);
818  if (empty($hidetop)) {
819  $pdf->SetXY($this->posxlot, $tab_top + 1);
820  $pdf->MultiCell(($this->posxweightvol - $this->posxlot), 2, $outputlangs->transnoentities("Batch"), '', 'C');
821  }
822  }
823 
824  if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
825  $pdf->line($this->posxweightvol - 1, $tab_top, $this->posxweightvol - 1, $tab_top + $tab_height);
826  if (empty($hidetop)) {
827  $pdf->SetXY($this->posxweightvol - 1, $tab_top + 1);
828  $pdf->MultiCell(($this->posxqty - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"), '', 'C');
829  }
830  }
831 
832  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
833  if (empty($hidetop)) {
834  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
835  $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 2, $outputlangs->transnoentities("Qty"), '', 'C');
836  }
837 
838  $pdf->line($this->posxwarehousesource - 1, $tab_top, $this->posxwarehousesource - 1, $tab_top + $tab_height);
839  if (empty($hidetop)) {
840  $pdf->SetXY($this->posxwarehousesource - 1, $tab_top + 1);
841  $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 2, $outputlangs->transnoentities("WarehouseSource"), '', 'C');
842  }
843 
844 
845  $pdf->line($this->posxwarehousedestination - 1, $tab_top, $this->posxwarehousedestination - 1, $tab_top + $tab_height);
846  if (empty($hidetop)) {
847  $pdf->SetXY($this->posxwarehousedestination-2.5, $tab_top + 1);
848  $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination+4), 2, $outputlangs->transnoentities("WarehouseTarget"), '', 'C');
849  }
850 
851  /*if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
852  $pdf->line($this->posxpuht - 1, $tab_top, $this->posxpuht - 1, $tab_top + $tab_height);
853  if (empty($hidetop))
854  {
855  $pdf->SetXY($this->posxpuht - 1, $tab_top + 1);
856  $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
857  }
858 
859  $pdf->line($this->posxtotalht - 1, $tab_top, $this->posxtotalht - 1, $tab_top + $tab_height);
860  if (empty($hidetop))
861  {
862  $pdf->SetXY($this->posxtotalht - 1, $tab_top + 1);
863  $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
864  }
865  }*/
866  }
867 
874  public function atLeastOneBatch($object)
875  {
876 
877  global $conf;
878 
879  $atLeastOneBatch = false;
880 
881  if (empty($conf->productbatch->enabled)) return false;
882 
883  foreach ($object->lines as $line) {
884  if (!empty($line->batch)) {
885  return true;
886  }
887  }
888 
889  return false;
890  }
891 
892  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
902  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
903  {
904  // phpcs:enable
905  global $conf, $langs, $mysoc;
906 
907  $langs->load("orders");
908 
909  $default_font_size = pdf_getPDFFontSize($outputlangs);
910 
911  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
912 
913  // Show Draft Watermark
914  if ($object->statut == 0 && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK))) {
915  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
916  }
917 
918  //Prepare la suite
919  $pdf->SetTextColor(0, 0, 60);
920  $pdf->SetFont('', 'B', $default_font_size + 3);
921 
922  $w = 110;
923 
924  $posy = $this->marge_haute;
925  $posx = $this->page_largeur - $this->marge_droite - $w;
926 
927  $pdf->SetXY($this->marge_gauche, $posy);
928 
929  // Logo
930  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
931  if ($this->emetteur->logo) {
932  if (is_readable($logo)) {
933  $height = pdf_getHeightForLogo($logo);
934  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
935  } else {
936  $pdf->SetTextColor(200, 0, 0);
937  $pdf->SetFont('', 'B', $default_font_size - 2);
938  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
939  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
940  }
941  } else {
942  $text = $this->emetteur->name;
943  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
944  }
945 
946  // Show barcode
947  if (!empty($conf->barcode->enabled)) {
948  $posx = 105;
949  } else {
950  $posx = $this->marge_gauche + 3;
951  }
952  //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
953  if (!empty($conf->barcode->enabled)) {
954  // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
955  //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
956  //$pdf->Image($logo,10, 5, 0, 24);
957  }
958 
959  $pdf->SetDrawColor(128, 128, 128);
960  if (!empty($conf->barcode->enabled)) {
961  // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
962  //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
963  //$pdf->Image($logo,10, 5, 0, 24);
964  }
965 
966 
967  $posx = $this->page_largeur - $w - $this->marge_droite;
968  $posy = $this->marge_haute;
969 
970  $pdf->SetFont('', 'B', $default_font_size + 2);
971  $pdf->SetXY($posx, $posy);
972  $pdf->SetTextColor(0, 0, 60);
973  $title = $outputlangs->transnoentities("StockTransferSheet");
974  $pdf->MultiCell($w, 4, $title, '', 'R');
975 
976  $pdf->SetFont('', '', $default_font_size + 1);
977 
978  $posy += 5;
979 
980  $pdf->SetXY($posx, $posy);
981  $pdf->SetTextColor(0, 0, 60);
982  $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
983 
984  // Date prévue depart
985  if (!empty($object->date_prevue_depart)) {
986  $posy += 4;
987  $pdf->SetXY($posx, $posy);
988  $pdf->SetTextColor(0, 0, 60);
989  $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueDepart")." : ".dol_print_date($object->date_prevue_depart, "day", false, $outputlangs, true), '', 'R');
990  }
991 
992  // Date prévue arrivée
993  if (!empty($object->date_prevue_arrivee)) {
994  $posy += 4;
995  $pdf->SetXY($posx, $posy);
996  $pdf->SetTextColor(0, 0, 60);
997  $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueArrivee")." : ".dol_print_date($object->date_prevue_arrivee, "day", false, $outputlangs, true), '', 'R');
998  }
999 
1000  // Date reelle depart
1001  if (!empty($object->date_reelle_depart)) {
1002  $posy += 4;
1003  $pdf->SetXY($posx, $posy);
1004  $pdf->SetTextColor(0, 0, 60);
1005  $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleDepart")." : ".dol_print_date($object->date_reelle_depart, "day", false, $outputlangs, true), '', 'R');
1006  }
1007 
1008  // Date reelle arrivée
1009  if (!empty($object->date_reelle_arrivee)) {
1010  $posy += 4;
1011  $pdf->SetXY($posx, $posy);
1012  $pdf->SetTextColor(0, 0, 60);
1013  $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
1014  }
1015 
1016  if (!empty($object->thirdparty->code_client)) {
1017  $posy += 4;
1018  $pdf->SetXY($posx, $posy);
1019  $pdf->SetTextColor(0, 0, 60);
1020  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1021  }
1022 
1023 
1024  $pdf->SetFont('', '', $default_font_size + 3);
1025  $Yoff = 25;
1026 
1027  // Add list of linked orders
1028  $origin = $object->origin;
1029  $origin_id = $object->origin_id;
1030 
1031  // TODO move to external function
1032  if (!empty($conf->$origin->enabled)) { // commonly $origin='commande'
1033  $outputlangs->load('orders');
1034 
1035  $classname = ucfirst($origin);
1036  $linkedobject = new $classname($this->db);
1037  $result = $linkedobject->fetch($origin_id);
1038  if ($result >= 0) {
1039  //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
1040 
1041  $pdf->SetFont('', '', $default_font_size - 2);
1042  $text = $linkedobject->ref;
1043  if ($linkedobject->ref_client) $text .= ' ('.$linkedobject->ref_client.')';
1044  $Yoff = $Yoff + 8;
1045  $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1046  $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), 0, 'R');
1047  $Yoff = $Yoff + 3;
1048  $pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
1049  $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
1050  }
1051  }
1052 
1053  if ($showaddress) {
1054  // Sender properties
1055  $carac_emetteur = '';
1056  // Add internal contact of origin element if defined
1057  $arrayidcontact = array();
1058  $arrayidcontact = $object->getIdContact('external', 'STFROM');
1059 
1060  $usecontact = false;
1061  if (count($arrayidcontact) > 0) {
1062  /*$object->fetch_user(reset($arrayidcontact));
1063  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
1064  $usecontact = true;
1065  $result = $object->fetch_contact($arrayidcontact[0]);
1066  }
1067 
1068  if ($usecontact) $thirdparty = $object->contact;
1069  else $thirdparty = $this->emetteur;
1070 
1071  if (!empty($thirdparty)) $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1072 
1073  if ($usecontact) $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
1074  else $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1075 
1076  // Show sender
1077  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1078  $posx = $this->marge_gauche;
1079  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1080 
1081  $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1082  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1083 
1084  // Show sender frame
1085  $pdf->SetTextColor(0, 0, 0);
1086  $pdf->SetFont('', '', $default_font_size - 2);
1087  $pdf->SetXY($posx, $posy - 5);
1088  $pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1089  $pdf->SetXY($posx, $posy);
1090  $pdf->SetFillColor(230, 230, 230);
1091  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1092  $pdf->SetTextColor(0, 0, 60);
1093  $pdf->SetFillColor(255, 255, 255);
1094 
1095  // Show sender name
1096  $pdf->SetXY($posx + 2, $posy + 3);
1097  $pdf->SetFont('', 'B', $default_font_size);
1098  $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_emetteur_name), 0, 'L');
1099  $posy = $pdf->getY();
1100 
1101  // Show sender information
1102  $pdf->SetXY($posx + 2, $posy);
1103  $pdf->SetFont('', '', $default_font_size - 1);
1104  $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1105 
1106 
1107  // If SHIPPING contact defined, we use it
1108  $usecontact = false;
1109  $arrayidcontact = $object->getIdContact('external', 'STDEST');
1110  if (count($arrayidcontact) > 0) {
1111  $usecontact = true;
1112  $result = $object->fetch_contact($arrayidcontact[0]);
1113  }
1114 
1115  //Recipient name
1116  // On peut utiliser le nom de la societe du contact
1117  if ($usecontact/* && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)*/) {
1118  $thirdparty = $object->contact;
1119  } else {
1120  $thirdparty = $object->thirdparty;
1121  }
1122 
1123  if (!empty($thirdparty)) $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1124 
1125  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);
1126 
1127  // Show recipient
1128  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1129  if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1130  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1131  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1132  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1133 
1134  // Show recipient frame
1135  $pdf->SetTextColor(0, 0, 0);
1136  $pdf->SetFont('', '', $default_font_size - 2);
1137  $pdf->SetXY($posx + 2, $posy - 5);
1138  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1139  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1140 
1141  // Show recipient name
1142  $pdf->SetXY($posx + 2, $posy + 3);
1143  $pdf->SetFont('', 'B', $default_font_size);
1144  $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1145 
1146  $posy = $pdf->getY();
1147 
1148  // Show recipient information
1149  $pdf->SetFont('', '', $default_font_size - 1);
1150  $pdf->SetXY($posx + 2, $posy);
1151  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1152  }
1153 
1154  $pdf->SetTextColor(0, 0, 0);
1155  }
1156 
1157  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1167  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1168  {
1169  // phpcs:enable
1170  global $conf;
1171  $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1172  return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1173  }
1174 }
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_getSizeForImage
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:2474
pdf_writelinedesc
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:1345
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_eagle\__construct
__construct($db=0)
Constructor.
Definition: pdf_eagle.modules.php:121
pdf_eagle\atLeastOneBatch
atLeastOneBatch($object)
 * Used to know if at least one line of Stock Transfer object has a batch set  *
Definition: pdf_eagle.modules.php:874
pdf_eagle\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
Definition: pdf_eagle.modules.php:788
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
name
$conf db name
Definition: repair.php:122
pdf_eagle\_tableau_tot
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
Definition: pdf_eagle.modules.php:688
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:619
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:711
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
pdf_eagle\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_eagle.modules.php:902
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:757
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
pdf_build_address
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:427
pdf_eagle\write_file
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_eagle.modules.php:194
Product
Class to manage products or services.
Definition: product.class.php:46
pdf_eagle
Class to build sending documents with model Eagle.
Definition: pdf_eagle.modules.php:40
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
Entrepot
Class to manage warehouses.
Definition: entrepot.class.php:35
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
price
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.
Definition: functions.lib.php:5541
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
showDimensionInBestUnit
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
Definition: functions.lib.php:5788
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
ModelePdfStockTransfer
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
pdf_eagle\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_eagle.modules.php:1167
pdf_pagefoot
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:989