dolibarr 21.0.3
pdf_eagle_proforma.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
12 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2024 Nick Fragoulis
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 * or see https://www.gnu.org/
28 */
29
36require_once DOL_DOCUMENT_ROOT.'/core/modules/stocktransfer/modules_stocktransfer.php';
37require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
41
42
47{
51 public $db;
52
56 public $name;
57
61 public $description;
62
66 public $update_main_doc_field;
67
71 public $type;
72
77 public $version = 'dolibarr';
78
79
85 public function __construct($db)
86 {
87 global $langs, $mysoc;
88
89 // Translations
90 $langs->loadLangs(array("main", "bills", "products", "stocks"));
91
92 $this->db = $db;
93 $this->name = $langs->trans("StockTransferSheetProforma");
94 $this->description = $langs->trans('StockTransferSheetProforma');
95 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
96
97 // Dimension page
98 $this->type = 'pdf';
99 $formatarray = pdf_getFormat();
100 $this->page_largeur = $formatarray['width'];
101 $this->page_hauteur = $formatarray['height'];
102 $this->format = array($this->page_largeur, $this->page_hauteur);
103 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
104 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
105 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
106 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
107 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
108 $this->option_logo = 1; // Display logo
109 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
110 $this->option_modereg = 1; // Display payment mode
111 $this->option_condreg = 1; // Display payment terms
112 $this->option_multilang = 1; // Available in several languages
113 $this->option_escompte = 0; // Displays if there has been a discount
114 $this->option_credit_note = 0; // Support credit notes
115 $this->option_freetext = 1; // Support add of a personalised text
116 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
117
118 // Define position of columns
119 $this->posxdesc = $this->marge_gauche + 1;
120
121
122 $this->tabTitleHeight = 5; // default height
123
124 $this->tva = array();
125 $this->localtax1 = array();
126 $this->localtax2 = array();
127 $this->atleastoneratenotnull = 0;
128 $this->atleastonediscount = 0;
129
130 if ($mysoc === null) {
131 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
132 return;
133 }
134
135 // Get source company
136 $this->emetteur = $mysoc;
137 if (empty($this->emetteur->country_code)) {
138 $this->emetteur->country_code = substr($langs->defaultlang, -2);
139 } // By default, if was not defined
140 }
141
142 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
154 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
155 {
156 // phpcs:enable
157 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
158
159 '@phan-var-force StockTransfer $object';
160
161 if (!is_object($outputlangs)) {
162 $outputlangs = $langs;
163 }
164 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
165 if (getDolGlobalString('MAIN_USE_FPDF')) {
166 $outputlangs->charset_output = 'ISO-8859-1';
167 }
168
169
170 // Load translation files required by page
171 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch", "stocks", "stocktransfer@stocktransfer"));
172
173 global $outputlangsbis;
174 $outputlangsbis = null;
175 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
176 $outputlangsbis = new Translate('', $conf);
177 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
178 $outputlangsbis->loadLangs(array("main", "bills", "orders", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
179 }
180
181 $nblines = is_array($object->lines) ? count($object->lines) : 0;
182
183 $hidetop = 0;
184 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
185 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
186 }
187
188 // Loop on each lines to detect if there is at least one image to show
189 $realpatharray = array();
190 $this->atleastonephoto = false;
191 if (getDolGlobalString('MAIN_GENERATE_STOCKTRANSFER_WITH_PICTURE')) {
192 $objphoto = new Product($this->db);
193
194 for ($i = 0; $i < $nblines; $i++) {
195 if (empty($object->lines[$i]->fk_product)) {
196 continue;
197 }
198
199 $objphoto->fetch($object->lines[$i]->fk_product);
200 //var_dump($objphoto->ref);exit;
201 $pdir = array();
202 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
203 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
204 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
205 } else {
206 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; // default
207 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
208 }
209
210 $arephoto = false;
211 foreach ($pdir as $midir) {
212 if (!$arephoto) {
213 $dir = $conf->product->dir_output.'/'.$midir;
214
215 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
216 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
217 if ($obj['photo_vignette']) {
218 $filename = $obj['photo_vignette'];
219 } else {
220 $filename = $obj['photo'];
221 }
222 } else {
223 $filename = $obj['photo'];
224 }
225
226 $realpath = $dir.$filename;
227 $arephoto = true;
228 $this->atleastonephoto = true;
229 }
230 }
231 }
232
233 if ($realpath && $arephoto) {
234 $realpatharray[$i] = $realpath;
235 }
236 }
237 }
238
239
240
241 if ($conf->stocktransfer->dir_output) {
242 $object->fetch_thirdparty();
243
244 $deja_regle = 0;
245
246 // Definition of $dir and $file
247 if ($object->specimen) {
248 $dir = $conf->stocktransfer->multidir_output[$conf->entity];
249 $file = $dir."/SPECIMEN.pdf";
250 } else {
251 $objectref = dol_sanitizeFileName($object->ref);
252 $dir = $conf->stocktransfer->multidir_output[$conf->entity]."/".$object->element."/".$objectref;
253 $file = $dir."/".$objectref."-proforma.pdf";
254 }
255
256 if (!file_exists($dir)) {
257 if (dol_mkdir($dir) < 0) {
258 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
259 return 0;
260 }
261 }
262
263 if (file_exists($dir)) {
264 // Add pdfgeneration hook
265 if (!is_object($hookmanager)) {
266 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
267 $hookmanager = new HookManager($this->db);
268 }
269 $hookmanager->initHooks(array('pdfgeneration'));
270 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
271 global $action;
272 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
273
274 // Set nblines with the new facture lines content after hook
275 $nblines = is_array($object->lines) ? count($object->lines) : 0;
276
277 // Create pdf instance
278 $pdf = pdf_getInstance($this->format);
279 $default_font_size = pdf_getPDFFontSize($outputlangs);
280 $pdf->SetAutoPageBreak(1, 0);
281
282 $heightforinfotot = 40; // Height reserved to output the info and total part
283 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
284 $heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
285 $pdf->SetAutoPageBreak(1, 0);
286
287 if (class_exists('TCPDF')) {
288 $pdf->setPrintHeader(false);
289 $pdf->setPrintFooter(false);
290 }
291 $pdf->SetFont(pdf_getPDFFont($outputlangs));
292 // Set path to the background PDF File
293 if (!getDolGlobalString('MAIN_DISABLE_FPDI') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
294 $logodir = $conf->mycompany->dir_output;
295 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
296 $logodir = $conf->mycompany->multidir_output[$object->entity];
297 }
298 $pagecount = $pdf->setSourceFile($logodir .'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
299 $tplidx = $pdf->importPage(1);
300 }
301
302 $pdf->Open();
303 $pagenb = 0;
304 $pdf->SetDrawColor(128, 128, 128);
305
306 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
307 $pdf->SetSubject($outputlangs->transnoentities("StockTransferSheetProforma"));
308 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
309 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
310 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("StockTransfer"));
311 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
312 $pdf->SetCompression(false);
313 }
314
315 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
316 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
317
319 if (is_array($object->lines)) {
320 foreach ($object->lines as $line) {
321 if ($line->remise_percent) {
322 $this->atleastonediscount = true;
323 break;
324 }
325 }
326 }
327
328 // New page
329 $pdf->AddPage();
330 if (!empty($tplidx)) {
331 $pdf->useTemplate($tplidx);
332 }
333 $pagenb++;
334 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
335 $pdf->SetFont('', '', $default_font_size - 1);
336 $pdf->MultiCell(0, 3, ''); // Set interline to 3
337 $pdf->SetTextColor(0, 0, 0);
338
339
340 $tab_top = 90 + $top_shift;
341 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
342 $tab_height = 130;
343
344 // Incoterm
345 $height_incoterms = 0;
346 if (isModEnabled('incoterm')) {
347 $desc_incoterms = $object->getIncotermsForPDF();
348 if ($desc_incoterms) {
349 $tab_top -= 2;
350
351 $pdf->SetFont('', '', $default_font_size - 1);
352 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
353 $nexY = $pdf->GetY();
354 $height_incoterms = $nexY - $tab_top;
355
356 // Rect takes a length in 3rd parameter
357 $pdf->SetDrawColor(192, 192, 192);
358 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
359
360 $tab_top = $nexY + 6;
361 $height_incoterms += 4;
362 }
363 }
364
365 // Displays notes
366 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
367 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
368 // Get first sale rep
369 if (is_object($object->thirdparty)) {
370 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
371 $salerepobj = new User($this->db);
372 $salerepobj->fetch($salereparray[0]['id']);
373 if (!empty($salerepobj->signature)) {
374 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
375 }
376 }
377 }
378
379 // Extrafields in note
380 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
381 if (!empty($extranote)) {
382 $notetoshow = dol_concatdesc($notetoshow, $extranote);
383 }
384
385 $pagenb = $pdf->getPage();
386 if ($notetoshow) {
387 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
388 $pageposbeforenote = $pagenb;
389
390 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
391 complete_substitutions_array($substitutionarray, $outputlangs, $object);
392 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
393 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
394
395 $tab_top -= 2;
396
397 $pdf->startTransaction();
398
399 $pdf->SetFont('', '', $default_font_size - 1);
400 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
401 // Description
402 $pageposafternote = $pdf->getPage();
403 $posyafter = $pdf->GetY();
404
405 if ($pageposafternote > $pageposbeforenote) {
406 $pdf->rollbackTransaction(true);
407
408 // prepare pages to receive notes
409 while ($pagenb < $pageposafternote) {
410 $pdf->AddPage();
411 $pagenb++;
412 if (!empty($tplidx)) {
413 $pdf->useTemplate($tplidx);
414 }
415 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
416 $this->_pagehead($pdf, $object, 0, $outputlangs);
417 }
418 // $this->_pagefoot($pdf,$object,$outputlangs,1);
419 $pdf->setTopMargin($tab_top_newpage);
420 // The only function to edit the bottom margin of current page to set it.
421 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
422 }
423
424 // back to start
425 $pdf->setPage($pageposbeforenote);
426 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
427 $pdf->SetFont('', '', $default_font_size - 1);
428 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
429 $pageposafternote = $pdf->getPage();
430
431 $posyafter = $pdf->GetY();
432
433 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
434 $pdf->AddPage('', '', true);
435 $pagenb++;
436 $pageposafternote++;
437 $pdf->setPage($pageposafternote);
438 $pdf->setTopMargin($tab_top_newpage);
439 // The only function to edit the bottom margin of current page to set it.
440 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
441 //$posyafter = $tab_top_newpage;
442 }
443
444
445 // apply note frame to previous pages
446 $i = $pageposbeforenote;
447 while ($i < $pageposafternote) {
448 $pdf->setPage($i);
449
450
451 $pdf->SetDrawColor(128, 128, 128);
452 // Draw note frame
453 if ($i > $pageposbeforenote) {
454 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
455 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
456 } else {
457 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
458 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
459 }
460
461 // Add footer
462 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
463 $this->_pagefoot($pdf, $object, $outputlangs, 1);
464
465 $i++;
466 }
467
468 // apply note frame to last page
469 $pdf->setPage($pageposafternote);
470 if (!empty($tplidx)) {
471 $pdf->useTemplate($tplidx);
472 }
473 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
474 $this->_pagehead($pdf, $object, 0, $outputlangs);
475 }
476 $height_note = $posyafter - $tab_top_newpage;
477 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
478 } else { // No pagebreak
479 $pdf->commitTransaction();
480 $posyafter = $pdf->GetY();
481 $height_note = $posyafter - $tab_top;
482 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
483
484
485 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
486 // not enough space, need to add page
487 $pdf->AddPage('', '', true);
488 $pagenb++;
489 $pageposafternote++;
490 $pdf->setPage($pageposafternote);
491 if (!empty($tplidx)) {
492 $pdf->useTemplate($tplidx);
493 }
494 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
495 $this->_pagehead($pdf, $object, 0, $outputlangs);
496 }
497
498 $posyafter = $tab_top_newpage;
499 }
500 }
501
502 $tab_height -= $height_note;
503 $tab_top = $posyafter + 6;
504 } else {
505 $height_note = 0;
506 }
507
508
509 // Use new auto column system
510 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
511
512 // tab simulation to know line height
513 $pdf->startTransaction();
514 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
515 $pdf->rollbackTransaction(true);
516
517 $nexY = $tab_top + $this->tabTitleHeight;
518
519 // Loop on each lines
520 $pageposbeforeprintlines = $pdf->getPage();
521 $pagenb = $pageposbeforeprintlines;
522 for ($i = 0; $i < $nblines; $i++) {
523 $curY = $nexY;
524 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
525 $pdf->SetTextColor(0, 0, 0);
526
527 // Define size of image if we need it
528 $imglinesize = array();
529 if (!empty($realpatharray[$i])) {
530 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
531 }
532
533 $pdf->setTopMargin($tab_top_newpage);
534 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
535 $pageposbefore = $pdf->getPage();
536
537
538 $showpricebeforepagebreak = 1;
539 $posYAfterImage = 0;
540
541 if ($this->getColumnStatus('photo')) {
542 // We start with Photo of product line
543 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
544 $pdf->AddPage('', '', true);
545 if (!empty($tplidx)) {
546 $pdf->useTemplate($tplidx);
547 }
548 $pdf->setPage($pageposbefore + 1);
549
550 $curY = $tab_top_newpage;
551
552 // Allows data in the first page if description is long enough to break in multiples pages
553 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
554 $showpricebeforepagebreak = 1;
555 } else {
556 $showpricebeforepagebreak = 0;
557 }
558 }
559
560 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
561 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
562 // $pdf->Image does not increase value return by getY, so we save it manually
563 $posYAfterImage = $curY + $imglinesize['height'];
564 }
565 }
566
567 if ($this->getColumnStatus('desc')) {
568 $pdf->startTransaction();
569
570 if (method_exists($object->lines[$i], 'fetch_product')) {
571 $object->lines[$i]->fetch_product();
572 $object->lines[$i]->label = $object->lines[$i]->product->label;
573 $object->lines[$i]->description = $object->lines[$i]->product->description;
574 $object->lines[$i]->fk_unit = $object->lines[$i]->product->fk_unit;
575 }
576
577 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
578
579 $pageposafter = $pdf->getPage();
580 if ($pageposafter > $pageposbefore) { // There is a pagebreak
581 $pdf->rollbackTransaction(true);
582 $pageposafter = $pageposbefore;
583 //print $pageposafter.'-'.$pageposbefore;exit;
584 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
585 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
586
587 $pageposafter = $pdf->getPage();
588 $posyafter = $pdf->GetY();
589 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
590 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
591 $pdf->AddPage('', '', true);
592 if (!empty($tplidx)) {
593 $pdf->useTemplate($tplidx);
594 }
595 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
596 $pdf->setPage($pageposafter + 1);
597 }
598 } else {
599 // We found a page break
600 // Allows data in the first page if description is long enough to break in multiples pages
601 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
602 $showpricebeforepagebreak = 1;
603 } else {
604 $showpricebeforepagebreak = 0;
605 }
606 }
607 } else { // No pagebreak
608 $pdf->commitTransaction();
609 }
610 }
611
612
613
614 $nexY = max($pdf->GetY(), $posYAfterImage);
615
616
617 $pageposafter = $pdf->getPage();
618
619 $pdf->setPage($pageposbefore);
620 $pdf->setTopMargin($this->marge_haute);
621 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
622
623 // We suppose that a too long description is moved completely on next page
624 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
625 $pdf->setPage($pageposafter);
626 $curY = $tab_top_newpage;
627 }
628
629 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
630
631 // VAT Rate
632 if ($this->getColumnStatus('vat')) {
633 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
634 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
635 $nexY = max($pdf->GetY(), $nexY);
636 }
637
638 // Unit price before discount
639 if ($this->getColumnStatus('subprice')) {
640 $pmp = $object->lines[$i]->pmp;
641 $this->printStdColumnContent($pdf, $curY, 'subprice', price($pmp));
642 $nexY = max($pdf->GetY(), $nexY);
643 }
644
645 // Quantity
646 // Enough for 6 chars
647 if ($this->getColumnStatus('qty')) {
648 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
649 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
650 $nexY = max($pdf->GetY(), $nexY);
651 }
652
653
654 // Unit
655 if ($this->getColumnStatus('unit')) {
656 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
657 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
658 $nexY = max($pdf->GetY(), $nexY);
659 }
660
661 // Discount on line
662 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
663 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
664 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
665 $nexY = max($pdf->GetY(), $nexY);
666 }
667
668 // Total HT line
669 if ($this->getColumnStatus('totalexcltax')) {
670 $pmp_qty = $pmp * $object->lines[$i]->qty;
671 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', price($pmp_qty));
672 $nexY = max($pdf->GetY(), $nexY);
673 }
674
675 // Extrafields
676 if (!empty($object->lines[$i]->array_options)) {
677 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
678 if ($this->getColumnStatus($extrafieldColKey)) {
679 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
680 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
681 $nexY = max($pdf->GetY(), $nexY);
682 }
683 }
684 }
685
686 $parameters = array(
687 'object' => $object,
688 'i' => $i,
689 'pdf' => & $pdf,
690 'curY' => & $curY,
691 'nexY' => & $nexY,
692 'outputlangs' => $outputlangs,
693 'hidedetails' => $hidedetails
694 );
695 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
696
697
698 // Collection of totals by value of vat in $this->tva["rate"] = total_tva
699 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
700 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
701 } else {
702 $tvaligne = $object->lines[$i]->total_tva;
703 }
704
705 /*
706 $localtax1ligne = $object->lines[$i]->total_localtax1;
707 $localtax2ligne = $object->lines[$i]->total_localtax2;
708 $localtax1_rate = $object->lines[$i]->localtax1_tx;
709 $localtax2_rate = $object->lines[$i]->localtax2_tx;
710 $localtax1_type = $object->lines[$i]->localtax1_type;
711 $localtax2_type = $object->lines[$i]->localtax2_type;
712
713 $vatrate = (string) $object->lines[$i]->tva_tx;
714
715 // Retrieve type from database for backward compatibility with old records
716 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
717 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
718 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
719 $localtax1_type = $localtaxtmp_array[0];
720 $localtax2_type = $localtaxtmp_array[2];
721 }
722
723 // retrieve global local tax
724 if ($localtax1_type && $localtax1ligne != 0) {
725 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
726 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
727 } else {
728 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
729 }
730 }
731 if ($localtax2_type && $localtax2ligne != 0) {
732 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
733 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
734 } else {
735 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
736 }
737 }
738
739 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
740 $vatrate .= '*';
741 }
742 if (!isset($this->tva[$vatrate])) {
743 $this->tva[$vatrate] = 0;
744 }
745 $this->tva[$vatrate] += $tvaligne;
746 */
747
748 // Add line
749 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
750 $pdf->setPage($pageposafter);
751 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
752 //$pdf->SetDrawColor(190,190,200);
753 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
754 $pdf->SetLineStyle(array('dash' => 0));
755 }
756
757
758 // Detect if some page were added automatically and output _tableau for past pages
759 while ($pagenb < $pageposafter) {
760 $pdf->setPage($pagenb);
761 if ($pagenb == $pageposbeforeprintlines) {
762 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
763 } else {
764 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
765 }
766 $this->_pagefoot($pdf, $object, $outputlangs, 1);
767 $pagenb++;
768 $pdf->setPage($pagenb);
769 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
770 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
771 $this->_pagehead($pdf, $object, 0, $outputlangs);
772 }
773 }
774 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
775 if ($pagenb == $pageposafter) {
776 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
777 } else {
778 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
779 }
780 $this->_pagefoot($pdf, $object, $outputlangs, 1);
781 // New page
782 $pdf->AddPage();
783 if (!empty($tplidx)) {
784 $pdf->useTemplate($tplidx);
785 }
786 $pagenb++;
787 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
788 $this->_pagehead($pdf, $object, 0, $outputlangs);
789 }
790 }
791 }
792
793 // Show square
794 if ($pagenb == $pageposbeforeprintlines) {
795 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
796 } else {
797 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
798 }
799 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
800
801 // Display total area
802 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
803
804 // Pagefoot
805 $this->_pagefoot($pdf, $object, $outputlangs);
806 if (method_exists($pdf, 'AliasNbPages')) {
807 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
808 }
809
810 $pdf->Close();
811
812 $pdf->Output($file, 'F');
813
814 // Add pdfgeneration hook
815 $hookmanager->initHooks(array('pdfgeneration'));
816 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
817 global $action;
818 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
819 if ($reshook < 0) {
820 $this->error = $hookmanager->error;
821 $this->errors = $hookmanager->errors;
822 }
823
824 dolChmod($file);
825
826 $this->result = array('fullpath' => $file);
827
828 return 1; // No error
829 } else {
830 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
831 return 0;
832 }
833 } else {
834 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "STOCKTRANSFER_OUTPUTDIR");
835 return 0;
836 }
837 }
838
848 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
849 {
850 global $conf, $mysoc;
851 '@phan-var-force Commande|Propal|Facture $object'; // availability_code,... does not exist on Facture.
852
853 $default_font_size = pdf_getPDFFontSize($outputlangs);
854
855 $pdf->SetFont('', '', $default_font_size - 1);
856
857 // If France, show VAT mention if not applicable
858 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
859 $pdf->SetFont('', 'B', $default_font_size - 2);
860 $pdf->SetXY($this->marge_gauche, $posy);
861 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
862
863 $posy = $pdf->GetY() + 4;
864 }
865
866 $posxval = 52;
867
868 // Show payments conditions
869 if ($object->cond_reglement_code || $object->cond_reglement) {
870 $pdf->SetFont('', 'B', $default_font_size - 2);
871 $pdf->SetXY($this->marge_gauche, $posy);
872 $titre = $outputlangs->transnoentities("PaymentConditions").':';
873 $pdf->MultiCell(43, 4, $titre, 0, 'L');
874
875 $pdf->SetFont('', '', $default_font_size - 2);
876 $pdf->SetXY($posxval, $posy);
877 $lib_condition_paiement = ($outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != 'PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc);
878 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
879 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
880
881 $posy = $pdf->GetY() + 3;
882 }
883
884 // Check a payment mode is defined
885 /* Not used with orders
886 if (empty($object->mode_reglement_code)
887 && ! $conf->global->FACTURE_CHQ_NUMBER
888 && ! $conf->global->FACTURE_RIB_NUMBER)
889 {
890 $pdf->SetXY($this->marge_gauche, $posy);
891 $pdf->SetTextColor(200,0,0);
892 $pdf->SetFont('','B', $default_font_size - 2);
893 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
894 $pdf->SetTextColor(0,0,0);
895
896 $posy=$pdf->GetY()+1;
897 }
898 */
899 /* TODO
900 else if (!empty($object->availability_code))
901 {
902 $pdf->SetXY($this->marge_gauche, $posy);
903 $pdf->SetTextColor(200,0,0);
904 $pdf->SetFont('','B', $default_font_size - 2);
905 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
906 $pdf->SetTextColor(0,0,0);
907
908 $posy=$pdf->GetY()+1;
909 }*/
910
911 // Show planned date of delivery
912 if (!empty($object->delivery_date)) {
913 $outputlangs->load("sendings");
914 $pdf->SetFont('', 'B', $default_font_size - 2);
915 $pdf->SetXY($this->marge_gauche, $posy);
916 $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
917 $pdf->MultiCell(80, 4, $titre, 0, 'L');
918 $pdf->SetFont('', '', $default_font_size - 2);
919 $pdf->SetXY($posxval, $posy);
920 $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
921 $pdf->MultiCell(80, 4, $dlp, 0, 'L');
922
923 $posy = $pdf->GetY() + 1;
924 } elseif (property_exists($object, 'availability_code')
925 && property_exists($object, 'availability')
926 && (
927 $object->availability_code
928 || $object->availability
929 )
930 ) {
931 // Show availability conditions
932
933 $pdf->SetFont('', 'B', $default_font_size - 2);
934 $pdf->SetXY($this->marge_gauche, $posy);
935 $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
936 $pdf->MultiCell(80, 4, $titre, 0, 'L');
937 $pdf->SetTextColor(0, 0, 0);
938 $pdf->SetFont('', '', $default_font_size - 2);
939 $pdf->SetXY($posxval, $posy);
940 $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != 'AvailabilityType'.$object->availability_code ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
941 $lib_availability = str_replace('\n', "\n", $lib_availability);
942 $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
943
944 $posy = $pdf->GetY() + 1;
945 }
946
947 // Show payment mode
948 if ($object->mode_reglement_code
949 && $object->mode_reglement_code != 'CHQ'
950 && $object->mode_reglement_code != 'VIR') {
951 $pdf->SetFont('', 'B', $default_font_size - 2);
952 $pdf->SetXY($this->marge_gauche, $posy);
953 $titre = $outputlangs->transnoentities("PaymentMode").':';
954 $pdf->MultiCell(80, 5, $titre, 0, 'L');
955
956 $pdf->SetFont('', '', $default_font_size - 2);
957 $pdf->SetXY($posxval, $posy);
958 $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != 'PaymentType'.$object->mode_reglement_code ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
959 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
960
961 $posy = $pdf->GetY() + 2;
962 }
963
964 // Show payment mode CHQ
965 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
966 // Si mode reglement non force ou si force a CHQ
967 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
968 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
969 $account = new Account($this->db);
970 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
971
972 $pdf->SetXY($this->marge_gauche, $posy);
973 $pdf->SetFont('', 'B', $default_font_size - 3);
974 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
975 $posy = $pdf->GetY() + 1;
976
977 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
978 $pdf->SetXY($this->marge_gauche, $posy);
979 $pdf->SetFont('', '', $default_font_size - 3);
980 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
981 $posy = $pdf->GetY() + 2;
982 }
983 }
984 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
985 $pdf->SetXY($this->marge_gauche, $posy);
986 $pdf->SetFont('', 'B', $default_font_size - 3);
987 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
988 $posy = $pdf->GetY() + 1;
989
990 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
991 $pdf->SetXY($this->marge_gauche, $posy);
992 $pdf->SetFont('', '', $default_font_size - 3);
993 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
994 $posy = $pdf->GetY() + 2;
995 }
996 }
997 }
998 }
999
1000 // If payment mode not forced or forced to VIR, show payment with BAN
1001 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1002 if (!empty($object->fk_account) || !empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1003 $bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1004 if (!empty($object->fk_bank)) {
1005 $bankid = $object->fk_bank;
1006 } // For backward compatibility when object->fk_account is forced with object->fk_bank
1007 $account = new Account($this->db);
1008 $account->fetch($bankid);
1009
1010 $curx = $this->marge_gauche;
1011 $cury = $posy;
1012
1013 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1014
1015 $posy += 2;
1016 }
1017 }
1018
1019 return $posy;
1020 }
1021
1022
1033 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1034 {
1035 global $conf, $mysoc;
1036
1037 $default_font_size = pdf_getPDFFontSize($outputlangs);
1038
1039 $tab2_top = $posy;
1040 $tab2_hl = 4;
1041 $pdf->SetFont('', '', $default_font_size - 1);
1042
1043 // Tableau total
1044 $col1x = 120;
1045 $col2x = 170;
1046 if ($this->page_largeur < 210) { // To work with US executive format
1047 $col2x -= 20;
1048 }
1049 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1050 $useborder = 0;
1051 $index = 0;
1052
1053 $outputlangsbis = null;
1054 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1055 $outputlangsbis = new Translate('', $conf);
1056 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1057 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1058 }
1059
1060 // Total HT
1061 /*$pdf->SetFillColor(255, 255, 255);
1062 $pdf->SetXY($col1x, $tab2_top);
1063 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
1064 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1065 $pdf->SetXY($col2x, $tab2_top);
1066 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);*/
1067
1068 // Show VAT by rates and total
1069 $pdf->SetFillColor(248, 248, 248);
1070
1071 $total_ttc = $object->getValorisationTotale();
1072
1073 $this->atleastoneratenotnull = 0;
1074
1075 // Total TTC
1076 $index++;
1077 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1078 $pdf->SetTextColor(0, 0, 60);
1079 $pdf->SetFillColor(224, 224, 224);
1080 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("Total", $mysoc->country_code) : ''), $useborder, 'L', 1);
1081
1082 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1083 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1084
1085 $pdf->SetTextColor(0, 0, 0);
1086
1087 $creditnoteamount = 0;
1088 $depositsamount = 0;
1089 //$creditnoteamount=$object->getSumCreditNotesUsed();
1090 //$depositsamount=$object->getSumDepositsUsed();
1091 //print "x".$creditnoteamount."-".$depositsamount;exit;
1092 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1093 if (!empty($object->paye)) {
1094 $resteapayer = 0;
1095 }
1096
1097 if ($deja_regle > 0) {
1098 // Already paid + Deposits
1099 $index++;
1100
1101 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1102 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1103 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1104 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1105
1106 $index++;
1107 $pdf->SetTextColor(0, 0, 60);
1108 $pdf->SetFillColor(224, 224, 224);
1109 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1110 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), $useborder, 'L', 1);
1111
1112 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1113 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1114
1115 $pdf->SetFont('', '', $default_font_size - 1);
1116 $pdf->SetTextColor(0, 0, 0);
1117 }
1118
1119 $index++;
1120 return ($tab2_top + ($tab2_hl * $index));
1121 }
1122
1123 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1137 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1138 {
1139 global $conf;
1140
1141 // Force to disable hidetop and hidebottom
1142 $hidebottom = 0;
1143 if ($hidetop) {
1144 $hidetop = -1;
1145 }
1146
1147 $currency = !empty($currency) ? $currency : $conf->currency;
1148 $default_font_size = pdf_getPDFFontSize($outputlangs);
1149
1150 // Amount in (at tab_top - 1)
1151 $pdf->SetTextColor(0, 0, 0);
1152 $pdf->SetFont('', '', $default_font_size - 2);
1153
1154 if (empty($hidetop)) {
1155 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1156 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1157 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1158
1159 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1160 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1161 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1162 }
1163 }
1164
1165 $pdf->SetDrawColor(128, 128, 128);
1166 $pdf->SetFont('', '', $default_font_size - 1);
1167
1168 // Output Rect
1169 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
1170
1171
1172 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1173
1174 if (empty($hidetop)) {
1175 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
1176 }
1177 }
1178
1179 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1180 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1191 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "StockTransferSheetProforma")
1192 {
1193 // phpcs:enable
1194 global $conf, $langs;
1195
1196 '@phan-var-force StockTransfer $object';
1197
1198 // Load traductions files required by page
1199 $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1200
1201 $default_font_size = pdf_getPDFFontSize($outputlangs);
1202
1203 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1204
1205 // Show Draft Watermark
1206 if ($object->statut == 0 && getDolGlobalString('STOCKTRANSFER_DRAFT_WATERMARK')) {
1207 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1208 }
1209
1210 $pdf->SetTextColor(0, 0, 60);
1211 $pdf->SetFont('', 'B', $default_font_size + 3);
1212
1213 $w = 110;
1214
1215 $posy = $this->marge_haute;
1216 $posx = $this->page_largeur - $this->marge_droite - $w;
1217
1218 $pdf->SetXY($this->marge_gauche, $posy);
1219
1220 // Logo
1221 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1222 if ($this->emetteur->logo) {
1223 $logodir = $conf->mycompany->dir_output;
1224 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1225 $logodir = $conf->mycompany->multidir_output[$object->entity];
1226 }
1227 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1228 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1229 } else {
1230 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1231 }
1232 if (is_readable($logo)) {
1233 $height = pdf_getHeightForLogo($logo);
1234 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1235 } else {
1236 $pdf->SetTextColor(200, 0, 0);
1237 $pdf->SetFont('', 'B', $default_font_size - 2);
1238 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1239 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1240 }
1241 } else {
1242 $text = $this->emetteur->name;
1243 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1244 }
1245 }
1246
1247 $pdf->SetDrawColor(128, 128, 128);
1248
1249 $posx = $this->page_largeur - $w - $this->marge_droite;
1250 $posy = $this->marge_haute;
1251
1252 $pdf->SetFont('', 'B', $default_font_size + 2);
1253 $pdf->SetXY($posx, $posy);
1254 $pdf->SetTextColor(0, 0, 60);
1255 $title = $outputlangs->transnoentities("StockTransferSheet").' '.$object->ref;
1256 $pdf->MultiCell($w, 4, $title, '', 'R');
1257
1258 $pdf->SetFont('', '', $default_font_size + 1);
1259
1260 // Date prévue depart
1261 if (!empty($object->date_prevue_depart)) {
1262 $posy += 4;
1263 $pdf->SetXY($posx, $posy);
1264 $pdf->SetTextColor(0, 0, 60);
1265 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueDepart")." : ".dol_print_date($object->date_prevue_depart, "day", false, $outputlangs, true), '', 'R');
1266 }
1267
1268 // Date prévue arrivée
1269 if (!empty($object->date_prevue_arrivee)) {
1270 $posy += 4;
1271 $pdf->SetXY($posx, $posy);
1272 $pdf->SetTextColor(0, 0, 60);
1273 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueArrivee")." : ".dol_print_date($object->date_prevue_arrivee, "day", false, $outputlangs, true), '', 'R');
1274 }
1275
1276 // Date reelle depart
1277 if (!empty($object->date_reelle_depart)) {
1278 $posy += 4;
1279 $pdf->SetXY($posx, $posy);
1280 $pdf->SetTextColor(0, 0, 60);
1281 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleDepart")." : ".dol_print_date($object->date_reelle_depart, "day", false, $outputlangs, true), '', 'R');
1282 }
1283
1284 // Date reelle arrivée
1285 if (!empty($object->date_reelle_arrivee)) {
1286 $posy += 4;
1287 $pdf->SetXY($posx, $posy);
1288 $pdf->SetTextColor(0, 0, 60);
1289 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
1290 }
1291
1292 if (!empty($object->thirdparty->code_client)) {
1293 $posy += 4;
1294 $pdf->SetXY($posx, $posy);
1295 $pdf->SetTextColor(0, 0, 60);
1296 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1297 }
1298
1299 if ($object->ref_client) {
1300 $posy += 5;
1301 $pdf->SetXY($posx, $posy);
1302 $pdf->SetTextColor(0, 0, 60);
1303 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1304 }
1305
1306 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1307 $object->fetchProject();
1308 if (!empty($object->project->ref)) {
1309 $posy += 3;
1310 $pdf->SetXY($posx, $posy);
1311 $pdf->SetTextColor(0, 0, 60);
1312 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1313 }
1314 }
1315
1316 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1317 $object->fetchProject();
1318 if (!empty($object->project->ref)) {
1319 $posy += 3;
1320 $pdf->SetXY($posx, $posy);
1321 $pdf->SetTextColor(0, 0, 60);
1322 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->projet->ref), '', 'R');
1323 }
1324 }
1325
1326 if (getDolGlobalString('DOC_SHOW_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
1327 $posy += 4;
1328 $pdf->SetXY($posx, $posy);
1329 $pdf->SetTextColor(0, 0, 60);
1330 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1331 }
1332
1333 // Get contact
1334 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1335 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1336 if (count($arrayidcontact) > 0) {
1337 $usertmp = new User($this->db);
1338 $usertmp->fetch($arrayidcontact[0]);
1339 $posy += 4;
1340 $pdf->SetXY($posx, $posy);
1341 $pdf->SetTextColor(0, 0, 60);
1342 $pdf->MultiCell(100, 3, $outputlangs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1343 }
1344 }
1345
1346 $posy += 2;
1347
1348 $top_shift = 0;
1349 // Show list of linked objects
1350 $current_y = $pdf->getY();
1351 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1352 if ($current_y < $pdf->getY()) {
1353 $top_shift = $pdf->getY() - $current_y;
1354 }
1355
1356 if ($showaddress) {
1357 // Sender properties
1358 $carac_emetteur = '';
1359 // Add internal contact of origin element if defined
1360 $arrayidcontact = array();
1361 $arrayidcontact = $object->getIdContact('external', 'STFROM');
1362
1363 $usecontact = false;
1364 if (count($arrayidcontact) > 0) {
1365 /*$object->fetch_user(reset($arrayidcontact));
1366 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
1367 $usecontact = true;
1368 $result = $object->fetch_contact($arrayidcontact[0]);
1369 }
1370
1371 if ($usecontact) {
1372 $thirdparty = $object->contact;
1373 } else {
1374 $thirdparty = $this->emetteur;
1375 }
1376
1377 if (!empty($thirdparty)) {
1378 $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1379 }
1380
1381 if ($usecontact) {
1382 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
1383 } else {
1384 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1385 }
1386
1387 // Show sender
1388 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1389 $posx = $this->marge_gauche;
1390 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1391 $posx = $this->page_largeur - $this->marge_droite - 80;
1392 }
1393
1394 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1395 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1396
1397 // Show sender frame
1398 $pdf->SetTextColor(0, 0, 0);
1399 $pdf->SetFont('', '', $default_font_size - 2);
1400 $pdf->SetXY($posx, $posy - 5);
1401 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1402 $pdf->SetXY($posx, $posy);
1403 $pdf->SetFillColor(230, 230, 230);
1404 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1405 $pdf->SetTextColor(0, 0, 60);
1406 $pdf->SetFillColor(255, 255, 255);
1407
1408 // Show sender name
1409 $pdf->SetXY($posx + 2, $posy + 3);
1410 $pdf->SetFont('', 'B', $default_font_size);
1411 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_emetteur_name), 0, 'L');
1412 $posy = $pdf->getY();
1413
1414 // Show sender information
1415 $pdf->SetXY($posx + 2, $posy);
1416 $pdf->SetFont('', '', $default_font_size - 1);
1417 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1418
1419
1420 // If SHIPPING contact defined, we use it
1421 $usecontact = false;
1422 $arrayidcontact = $object->getIdContact('external', 'STDEST');
1423 if (count($arrayidcontact) > 0) {
1424 $usecontact = true;
1425 $result = $object->fetch_contact($arrayidcontact[0]);
1426 }
1427
1428 //Recipient name
1429 // On peut utiliser le nom de la societe du contact
1430 if ($usecontact/* && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)*/) {
1431 $thirdparty = $object->contact;
1432 } else {
1433 $thirdparty = $object->thirdparty;
1434 }
1435
1436 $carac_client_name = '';
1437 if (!empty($thirdparty)) {
1438 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1439 }
1440
1441 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), ($usecontact ? 1 : 0), 'targetwithdetails', $object);
1442
1443 // Show recipient
1444 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1445 if ($this->page_largeur < 210) {
1446 $widthrecbox = 84; // To work with US executive format
1447 }
1448 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1449 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1450 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1451 $posx = $this->marge_gauche;
1452 }
1453
1454 // Show recipient frame
1455 $pdf->SetTextColor(0, 0, 0);
1456 $pdf->SetFont('', '', $default_font_size - 2);
1457 $pdf->SetXY($posx + 2, $posy - 5);
1458 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1459 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1460
1461 // Show recipient name
1462 $pdf->SetXY($posx + 2, $posy + 3);
1463 $pdf->SetFont('', 'B', $default_font_size);
1464 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1465
1466 $posy = $pdf->getY();
1467
1468 // Show recipient information
1469 $pdf->SetFont('', '', $default_font_size - 1);
1470 $pdf->SetXY($posx + 2, $posy);
1471 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1472 }
1473
1474 $pdf->SetTextColor(0, 0, 0);
1475
1476 return $top_shift;
1477 }
1478
1479 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1480 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1490 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1491 {
1492 // phpcs:enable
1493 '@phan-var-force StockTransfer $object';
1494
1495 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1496 return pdf_pagefoot($pdf, $outputlangs, 'STOCKTRANSFER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1497 }
1498
1499
1500
1511 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1512 {
1513 global $conf, $hookmanager;
1514 '@phan-var-force StockTransfer $object';
1517 // Default field style for content
1518 $this->defaultContentsFieldsStyle = array(
1519 'align' => 'R', // R,C,L
1520 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1521 );
1522
1523 // Default field style for content
1524 $this->defaultTitlesFieldsStyle = array(
1525 'align' => 'C', // R,C,L
1526 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1527 );
1528
1529 /*
1530 * For example
1531 $this->cols['theColKey'] = array(
1532 'rank' => $rank, // int : use for ordering columns
1533 'width' => 20, // the column width in mm
1534 'title' => array(
1535 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1536 'label' => ' ', // the final label : used fore final generated text
1537 'align' => 'L', // text alignment : R,C,L
1538 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1539 ),
1540 'content' => array(
1541 'align' => 'L', // text alignment : R,C,L
1542 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1543 ),
1544 );
1545 */
1546
1547 $rank = 0; // do not use negative rank
1548 $this->cols['desc'] = array(
1549 'rank' => $rank,
1550 'width' => false, // only for desc
1551 'status' => true,
1552 'title' => array(
1553 'textkey' => 'Designation', // use lang key is useful in somme case with module
1554 'align' => 'L',
1555 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1556 // 'label' => ' ', // the final label
1557 'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1558 ),
1559 'content' => array(
1560 'align' => 'L',
1561 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1562 ),
1563 );
1564
1565 $rank += 10;
1566 $this->cols['photo'] = array(
1567 'rank' => $rank,
1568 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
1569 'status' => false,
1570 'title' => array(
1571 'textkey' => 'Photo',
1572 'label' => ' '
1573 ),
1574 'content' => array(
1575 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1576 ),
1577 'border-left' => false, // remove left line separator
1578 );
1579
1580 if (getDolGlobalString('MAIN_GENERATE_ORDERS_WITH_PICTURE')) {
1581 $this->cols['photo']['status'] = true;
1582 }
1583
1584
1585 $rank += 10;
1586 $this->cols['vat'] = array(
1587 'rank' => $rank,
1588 'status' => false,
1589 'width' => 16, // in mm
1590 'title' => array(
1591 'textkey' => 'VAT'
1592 ),
1593 'border-left' => true, // add left line separator
1594 );
1595
1596 /*if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1597 {
1598 $this->cols['vat']['status'] = true;
1599 }*/
1600
1601 $rank += 10;
1602 $this->cols['subprice'] = array(
1603 'rank' => $rank,
1604 'width' => 19, // in mm
1605 'status' => true,
1606 'title' => array(
1607 'textkey' => 'PMPValueShort'
1608 ),
1609 'border-left' => true, // add left line separator
1610 );
1611
1612 // Adapt dynamically the width of subprice, if text is too long.
1613 $tmpwidth = 0;
1614 $nblines = is_array($object->lines) ? count($object->lines) : 0;
1615 for ($i = 0; $i < $nblines; $i++) {
1616 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
1617 $tmpwidth = max($tmpwidth, $tmpwidth2);
1618 }
1619 if ($tmpwidth > 10) {
1620 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
1621 }
1622
1623 $rank += 10;
1624 $this->cols['qty'] = array(
1625 'rank' => $rank,
1626 'width' => 16, // in mm
1627 'status' => true,
1628 'title' => array(
1629 'textkey' => 'Qty'
1630 ),
1631 'border-left' => true, // add left line separator
1632 );
1633
1634 $rank += 10;
1635 $this->cols['unit'] = array(
1636 'rank' => $rank,
1637 'width' => 11, // in mm
1638 'status' => false,
1639 'title' => array(
1640 'textkey' => 'Unit'
1641 ),
1642 'border-left' => true, // add left line separator
1643 );
1644 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1645 $this->cols['unit']['status'] = true;
1646 }
1647
1648 $rank += 10;
1649 $this->cols['discount'] = array(
1650 'rank' => $rank,
1651 'width' => 13, // in mm
1652 'status' => false,
1653 'title' => array(
1654 'textkey' => 'ReductionShort'
1655 ),
1656 'border-left' => true, // add left line separator
1657 );
1658 if ($this->atleastonediscount) {
1659 $this->cols['discount']['status'] = true;
1660 }
1661
1662 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1663 $this->cols['totalexcltax'] = array(
1664 'rank' => $rank,
1665 'width' => 26, // in mm
1666 'status' => true,
1667 'title' => array(
1668 'textkey' => 'TotalHTShort'
1669 ),
1670 'border-left' => true, // add left line separator
1671 );
1672
1673 // Add extrafields cols
1674 if (!empty($object->lines)) {
1675 $line = reset($object->lines);
1676 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1677 }
1678
1679 $parameters = array(
1680 'object' => $object,
1681 'outputlangs' => $outputlangs,
1682 'hidedetails' => $hidedetails,
1683 'hidedesc' => $hidedesc,
1684 'hideref' => $hideref
1685 );
1686
1687 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1688 if ($reshook < 0) {
1689 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1690 } elseif (empty($reshook)) {
1691 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1692 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1693 } else {
1694 $this->cols = $hookmanager->resArray;
1695 }
1696 }
1697}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage bank accounts.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field into $this->cols This method must be implemented by the module that generat...
Class to manage hooks.
Parent class for documents models.
Class to manage products or services.
Class to manage translations.
Class to manage Dolibarr users.
Class to generate PDF orders with template Eagle.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
drawInfoTable(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="StockTransferSheetProforma")
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:2705
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1031
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2054
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1992
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1409
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:854
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:438
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2299
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2342
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2139
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:769
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:390
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:789
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153