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