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