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