dolibarr 21.0.0-beta
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 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
295 $tplidx = $pdf->importPage(1);
296 }
297
298 $pdf->Open();
299 $pagenb = 0;
300 $pdf->SetDrawColor(128, 128, 128);
301
302 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
303 $pdf->SetSubject($outputlangs->transnoentities("StockTransferSheetProforma"));
304 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
305 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
306 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("StockTransfer"));
307 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
308 $pdf->SetCompression(false);
309 }
310
311 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
312 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
313
315 if (is_array($object->lines)) {
316 foreach ($object->lines as $line) {
317 if ($line->remise_percent) {
318 $this->atleastonediscount = true;
319 break;
320 }
321 }
322 }
323
324 // New page
325 $pdf->AddPage();
326 if (!empty($tplidx)) {
327 $pdf->useTemplate($tplidx);
328 }
329 $pagenb++;
330 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
331 $pdf->SetFont('', '', $default_font_size - 1);
332 $pdf->MultiCell(0, 3, ''); // Set interline to 3
333 $pdf->SetTextColor(0, 0, 0);
334
335
336 $tab_top = 90 + $top_shift;
337 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
338 $tab_height = 130;
339
340 // Incoterm
341 $height_incoterms = 0;
342 if (isModEnabled('incoterm')) {
343 $desc_incoterms = $object->getIncotermsForPDF();
344 if ($desc_incoterms) {
345 $tab_top -= 2;
346
347 $pdf->SetFont('', '', $default_font_size - 1);
348 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
349 $nexY = $pdf->GetY();
350 $height_incoterms = $nexY - $tab_top;
351
352 // Rect takes a length in 3rd parameter
353 $pdf->SetDrawColor(192, 192, 192);
354 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius, '1234', 'D');
355
356 $tab_top = $nexY + 6;
357 $height_incoterms += 4;
358 }
359 }
360
361 // Displays notes
362 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
363 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
364 // Get first sale rep
365 if (is_object($object->thirdparty)) {
366 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
367 $salerepobj = new User($this->db);
368 $salerepobj->fetch($salereparray[0]['id']);
369 if (!empty($salerepobj->signature)) {
370 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
371 }
372 }
373 }
374
375 // Extrafields in note
376 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
377 if (!empty($extranote)) {
378 $notetoshow = dol_concatdesc($notetoshow, $extranote);
379 }
380
381 $pagenb = $pdf->getPage();
382 if ($notetoshow) {
383 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
384 $pageposbeforenote = $pagenb;
385
386 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
387 complete_substitutions_array($substitutionarray, $outputlangs, $object);
388 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
389 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
390
391 $tab_top -= 2;
392
393 $pdf->startTransaction();
394
395 $pdf->SetFont('', '', $default_font_size - 1);
396 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
397 // Description
398 $pageposafternote = $pdf->getPage();
399 $posyafter = $pdf->GetY();
400
401 if ($pageposafternote > $pageposbeforenote) {
402 $pdf->rollbackTransaction(true);
403
404 // prepare pages to receive notes
405 while ($pagenb < $pageposafternote) {
406 $pdf->AddPage();
407 $pagenb++;
408 if (!empty($tplidx)) {
409 $pdf->useTemplate($tplidx);
410 }
411 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
412 $this->_pagehead($pdf, $object, 0, $outputlangs);
413 }
414 // $this->_pagefoot($pdf,$object,$outputlangs,1);
415 $pdf->setTopMargin($tab_top_newpage);
416 // The only function to edit the bottom margin of current page to set it.
417 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
418 }
419
420 // back to start
421 $pdf->setPage($pageposbeforenote);
422 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
423 $pdf->SetFont('', '', $default_font_size - 1);
424 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
425 $pageposafternote = $pdf->getPage();
426
427 $posyafter = $pdf->GetY();
428
429 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
430 $pdf->AddPage('', '', true);
431 $pagenb++;
432 $pageposafternote++;
433 $pdf->setPage($pageposafternote);
434 $pdf->setTopMargin($tab_top_newpage);
435 // The only function to edit the bottom margin of current page to set it.
436 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
437 //$posyafter = $tab_top_newpage;
438 }
439
440
441 // apply note frame to previous pages
442 $i = $pageposbeforenote;
443 while ($i < $pageposafternote) {
444 $pdf->setPage($i);
445
446
447 $pdf->SetDrawColor(128, 128, 128);
448 // Draw note frame
449 if ($i > $pageposbeforenote) {
450 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
451 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
452 } else {
453 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
454 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
455 }
456
457 // Add footer
458 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
459 $this->_pagefoot($pdf, $object, $outputlangs, 1);
460
461 $i++;
462 }
463
464 // apply note frame to last page
465 $pdf->setPage($pageposafternote);
466 if (!empty($tplidx)) {
467 $pdf->useTemplate($tplidx);
468 }
469 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
470 $this->_pagehead($pdf, $object, 0, $outputlangs);
471 }
472 $height_note = $posyafter - $tab_top_newpage;
473 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
474 } else { // No pagebreak
475 $pdf->commitTransaction();
476 $posyafter = $pdf->GetY();
477 $height_note = $posyafter - $tab_top;
478 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius, '1234', 'D');
479
480
481 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
482 // not enough space, need to add page
483 $pdf->AddPage('', '', true);
484 $pagenb++;
485 $pageposafternote++;
486 $pdf->setPage($pageposafternote);
487 if (!empty($tplidx)) {
488 $pdf->useTemplate($tplidx);
489 }
490 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
491 $this->_pagehead($pdf, $object, 0, $outputlangs);
492 }
493
494 $posyafter = $tab_top_newpage;
495 }
496 }
497
498 $tab_height -= $height_note;
499 $tab_top = $posyafter + 6;
500 } else {
501 $height_note = 0;
502 }
503
504
505 // Use new auto column system
506 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
507
508 // tab simulation to know line height
509 $pdf->startTransaction();
510 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
511 $pdf->rollbackTransaction(true);
512
513 $nexY = $tab_top + $this->tabTitleHeight;
514
515 // Loop on each lines
516 $pageposbeforeprintlines = $pdf->getPage();
517 $pagenb = $pageposbeforeprintlines;
518 for ($i = 0; $i < $nblines; $i++) {
519 $curY = $nexY;
520 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
521 $pdf->SetTextColor(0, 0, 0);
522
523 // Define size of image if we need it
524 $imglinesize = array();
525 if (!empty($realpatharray[$i])) {
526 $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
527 }
528
529 $pdf->setTopMargin($tab_top_newpage);
530 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
531 $pageposbefore = $pdf->getPage();
532
533
534 $showpricebeforepagebreak = 1;
535 $posYAfterImage = 0;
536
537 if ($this->getColumnStatus('photo')) {
538 // We start with Photo of product line
539 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
540 $pdf->AddPage('', '', true);
541 if (!empty($tplidx)) {
542 $pdf->useTemplate($tplidx);
543 }
544 $pdf->setPage($pageposbefore + 1);
545
546 $curY = $tab_top_newpage;
547
548 // Allows data in the first page if description is long enough to break in multiples pages
549 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
550 $showpricebeforepagebreak = 1;
551 } else {
552 $showpricebeforepagebreak = 0;
553 }
554 }
555
556 if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
557 $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
558 // $pdf->Image does not increase value return by getY, so we save it manually
559 $posYAfterImage = $curY + $imglinesize['height'];
560 }
561 }
562
563 if ($this->getColumnStatus('desc')) {
564 $pdf->startTransaction();
565
566 if (method_exists($object->lines[$i], 'fetch_product')) {
567 $object->lines[$i]->fetch_product();
568 $object->lines[$i]->label = $object->lines[$i]->product->label;
569 $object->lines[$i]->description = $object->lines[$i]->product->description;
570 $object->lines[$i]->fk_unit = $object->lines[$i]->product->fk_unit;
571 }
572
573 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
574
575 $pageposafter = $pdf->getPage();
576 if ($pageposafter > $pageposbefore) { // There is a pagebreak
577 $pdf->rollbackTransaction(true);
578 $pageposafter = $pageposbefore;
579 //print $pageposafter.'-'.$pageposbefore;exit;
580 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
581 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
582
583 $pageposafter = $pdf->getPage();
584 $posyafter = $pdf->GetY();
585 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
586 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
587 $pdf->AddPage('', '', true);
588 if (!empty($tplidx)) {
589 $pdf->useTemplate($tplidx);
590 }
591 //if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
592 $pdf->setPage($pageposafter + 1);
593 }
594 } else {
595 // We found a page break
596 // Allows data in the first page if description is long enough to break in multiples pages
597 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
598 $showpricebeforepagebreak = 1;
599 } else {
600 $showpricebeforepagebreak = 0;
601 }
602 }
603 } else { // No pagebreak
604 $pdf->commitTransaction();
605 }
606 }
607
608
609
610 $nexY = max($pdf->GetY(), $posYAfterImage);
611
612
613 $pageposafter = $pdf->getPage();
614
615 $pdf->setPage($pageposbefore);
616 $pdf->setTopMargin($this->marge_haute);
617 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
618
619 // We suppose that a too long description is moved completely on next page
620 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
621 $pdf->setPage($pageposafter);
622 $curY = $tab_top_newpage;
623 }
624
625 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
626
627 // VAT Rate
628 if ($this->getColumnStatus('vat')) {
629 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
630 $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
631 $nexY = max($pdf->GetY(), $nexY);
632 }
633
634 // Unit price before discount
635 if ($this->getColumnStatus('subprice')) {
636 $pmp = $object->lines[$i]->pmp;
637 $this->printStdColumnContent($pdf, $curY, 'subprice', price($pmp));
638 $nexY = max($pdf->GetY(), $nexY);
639 }
640
641 // Quantity
642 // Enough for 6 chars
643 if ($this->getColumnStatus('qty')) {
644 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
645 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
646 $nexY = max($pdf->GetY(), $nexY);
647 }
648
649
650 // Unit
651 if ($this->getColumnStatus('unit')) {
652 $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
653 $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
654 $nexY = max($pdf->GetY(), $nexY);
655 }
656
657 // Discount on line
658 if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
659 $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
660 $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
661 $nexY = max($pdf->GetY(), $nexY);
662 }
663
664 // Total HT line
665 if ($this->getColumnStatus('totalexcltax')) {
666 $pmp_qty = $pmp * $object->lines[$i]->qty;
667 $this->printStdColumnContent($pdf, $curY, 'totalexcltax', price($pmp_qty));
668 $nexY = max($pdf->GetY(), $nexY);
669 }
670
671 // Extrafields
672 if (!empty($object->lines[$i]->array_options)) {
673 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
674 if ($this->getColumnStatus($extrafieldColKey)) {
675 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey);
676 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
677 $nexY = max($pdf->GetY(), $nexY);
678 }
679 }
680 }
681
682 $parameters = array(
683 'object' => $object,
684 'i' => $i,
685 'pdf' => & $pdf,
686 'curY' => & $curY,
687 'nexY' => & $nexY,
688 'outputlangs' => $outputlangs,
689 'hidedetails' => $hidedetails
690 );
691 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
692
693
694 // Collection of totals by value of vat in $this->tva["rate"] = total_tva
695 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
696 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
697 } else {
698 $tvaligne = $object->lines[$i]->total_tva;
699 }
700
701 /*
702 $localtax1ligne = $object->lines[$i]->total_localtax1;
703 $localtax2ligne = $object->lines[$i]->total_localtax2;
704 $localtax1_rate = $object->lines[$i]->localtax1_tx;
705 $localtax2_rate = $object->lines[$i]->localtax2_tx;
706 $localtax1_type = $object->lines[$i]->localtax1_type;
707 $localtax2_type = $object->lines[$i]->localtax2_type;
708
709 $vatrate = (string) $object->lines[$i]->tva_tx;
710
711 // Retrieve type from database for backward compatibility with old records
712 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
713 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
714 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
715 $localtax1_type = $localtaxtmp_array[0];
716 $localtax2_type = $localtaxtmp_array[2];
717 }
718
719 // retrieve global local tax
720 if ($localtax1_type && $localtax1ligne != 0) {
721 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
722 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
723 } else {
724 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
725 }
726 }
727 if ($localtax2_type && $localtax2ligne != 0) {
728 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
729 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
730 } else {
731 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
732 }
733 }
734
735 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
736 $vatrate .= '*';
737 }
738 if (!isset($this->tva[$vatrate])) {
739 $this->tva[$vatrate] = 0;
740 }
741 $this->tva[$vatrate] += $tvaligne;
742 */
743
744 // Add line
745 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
746 $pdf->setPage($pageposafter);
747 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
748 //$pdf->SetDrawColor(190,190,200);
749 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
750 $pdf->SetLineStyle(array('dash' => 0));
751 }
752
753
754 // Detect if some page were added automatically and output _tableau for past pages
755 while ($pagenb < $pageposafter) {
756 $pdf->setPage($pagenb);
757 if ($pagenb == $pageposbeforeprintlines) {
758 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
759 } else {
760 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
761 }
762 $this->_pagefoot($pdf, $object, $outputlangs, 1);
763 $pagenb++;
764 $pdf->setPage($pagenb);
765 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
766 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
767 $this->_pagehead($pdf, $object, 0, $outputlangs);
768 }
769 }
770 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
771 if ($pagenb == $pageposafter) {
772 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
773 } else {
774 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
775 }
776 $this->_pagefoot($pdf, $object, $outputlangs, 1);
777 // New page
778 $pdf->AddPage();
779 if (!empty($tplidx)) {
780 $pdf->useTemplate($tplidx);
781 }
782 $pagenb++;
783 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
784 $this->_pagehead($pdf, $object, 0, $outputlangs);
785 }
786 }
787 }
788
789 // Show square
790 if ($pagenb == $pageposbeforeprintlines) {
791 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
792 } else {
793 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
794 }
795 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
796
797 // Display total area
798 $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
799
800 // Pagefoot
801 $this->_pagefoot($pdf, $object, $outputlangs);
802 if (method_exists($pdf, 'AliasNbPages')) {
803 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
804 }
805
806 $pdf->Close();
807
808 $pdf->Output($file, 'F');
809
810 // Add pdfgeneration hook
811 $hookmanager->initHooks(array('pdfgeneration'));
812 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
813 global $action;
814 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
815 if ($reshook < 0) {
816 $this->error = $hookmanager->error;
817 $this->errors = $hookmanager->errors;
818 }
819
820 dolChmod($file);
821
822 $this->result = array('fullpath' => $file);
823
824 return 1; // No error
825 } else {
826 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
827 return 0;
828 }
829 } else {
830 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "STOCKTRANSFER_OUTPUTDIR");
831 return 0;
832 }
833 }
834
844 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
845 {
846 global $conf, $mysoc;
847 '@phan-var-force Commande|Propal|Facture $object'; // availability_code,... does not exist on Facture.
848
849 $default_font_size = pdf_getPDFFontSize($outputlangs);
850
851 $pdf->SetFont('', '', $default_font_size - 1);
852
853 // If France, show VAT mention if not applicable
854 if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
855 $pdf->SetFont('', 'B', $default_font_size - 2);
856 $pdf->SetXY($this->marge_gauche, $posy);
857 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
858
859 $posy = $pdf->GetY() + 4;
860 }
861
862 $posxval = 52;
863
864 // Show payments conditions
865 if ($object->cond_reglement_code || $object->cond_reglement) {
866 $pdf->SetFont('', 'B', $default_font_size - 2);
867 $pdf->SetXY($this->marge_gauche, $posy);
868 $titre = $outputlangs->transnoentities("PaymentConditions").':';
869 $pdf->MultiCell(43, 4, $titre, 0, 'L');
870
871 $pdf->SetFont('', '', $default_font_size - 2);
872 $pdf->SetXY($posxval, $posy);
873 $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);
874 $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
875 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
876
877 $posy = $pdf->GetY() + 3;
878 }
879
880 // Check a payment mode is defined
881 /* Not used with orders
882 if (empty($object->mode_reglement_code)
883 && ! $conf->global->FACTURE_CHQ_NUMBER
884 && ! $conf->global->FACTURE_RIB_NUMBER)
885 {
886 $pdf->SetXY($this->marge_gauche, $posy);
887 $pdf->SetTextColor(200,0,0);
888 $pdf->SetFont('','B', $default_font_size - 2);
889 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
890 $pdf->SetTextColor(0,0,0);
891
892 $posy=$pdf->GetY()+1;
893 }
894 */
895 /* TODO
896 else if (!empty($object->availability_code))
897 {
898 $pdf->SetXY($this->marge_gauche, $posy);
899 $pdf->SetTextColor(200,0,0);
900 $pdf->SetFont('','B', $default_font_size - 2);
901 $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
902 $pdf->SetTextColor(0,0,0);
903
904 $posy=$pdf->GetY()+1;
905 }*/
906
907 // Show planned date of delivery
908 if (!empty($object->delivery_date)) {
909 $outputlangs->load("sendings");
910 $pdf->SetFont('', 'B', $default_font_size - 2);
911 $pdf->SetXY($this->marge_gauche, $posy);
912 $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
913 $pdf->MultiCell(80, 4, $titre, 0, 'L');
914 $pdf->SetFont('', '', $default_font_size - 2);
915 $pdf->SetXY($posxval, $posy);
916 $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
917 $pdf->MultiCell(80, 4, $dlp, 0, 'L');
918
919 $posy = $pdf->GetY() + 1;
920 } elseif (property_exists($object, 'availability_code')
921 && property_exists($object, 'availability')
922 && (
923 $object->availability_code
924 || $object->availability
925 )
926 ) {
927 // Show availability conditions
928
929 $pdf->SetFont('', 'B', $default_font_size - 2);
930 $pdf->SetXY($this->marge_gauche, $posy);
931 $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
932 $pdf->MultiCell(80, 4, $titre, 0, 'L');
933 $pdf->SetTextColor(0, 0, 0);
934 $pdf->SetFont('', '', $default_font_size - 2);
935 $pdf->SetXY($posxval, $posy);
936 $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 : '');
937 $lib_availability = str_replace('\n', "\n", $lib_availability);
938 $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
939
940 $posy = $pdf->GetY() + 1;
941 }
942
943 // Show payment mode
944 if ($object->mode_reglement_code
945 && $object->mode_reglement_code != 'CHQ'
946 && $object->mode_reglement_code != 'VIR') {
947 $pdf->SetFont('', 'B', $default_font_size - 2);
948 $pdf->SetXY($this->marge_gauche, $posy);
949 $titre = $outputlangs->transnoentities("PaymentMode").':';
950 $pdf->MultiCell(80, 5, $titre, 0, 'L');
951
952 $pdf->SetFont('', '', $default_font_size - 2);
953 $pdf->SetXY($posxval, $posy);
954 $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);
955 $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
956
957 $posy = $pdf->GetY() + 2;
958 }
959
960 // Show payment mode CHQ
961 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
962 // Si mode reglement non force ou si force a CHQ
963 if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
964 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) {
965 $account = new Account($this->db);
966 $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
967
968 $pdf->SetXY($this->marge_gauche, $posy);
969 $pdf->SetFont('', 'B', $default_font_size - 3);
970 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0);
971 $posy = $pdf->GetY() + 1;
972
973 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
974 $pdf->SetXY($this->marge_gauche, $posy);
975 $pdf->SetFont('', '', $default_font_size - 3);
976 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
977 $posy = $pdf->GetY() + 2;
978 }
979 }
980 if (getDolGlobalInt('FACTURE_CHQ_NUMBER') == -1) {
981 $pdf->SetXY($this->marge_gauche, $posy);
982 $pdf->SetFont('', 'B', $default_font_size - 3);
983 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
984 $posy = $pdf->GetY() + 1;
985
986 if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) {
987 $pdf->SetXY($this->marge_gauche, $posy);
988 $pdf->SetFont('', '', $default_font_size - 3);
989 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
990 $posy = $pdf->GetY() + 2;
991 }
992 }
993 }
994 }
995
996 // If payment mode not forced or forced to VIR, show payment with BAN
997 if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
998 if (!empty($object->fk_account) || !empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
999 $bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1000 if (!empty($object->fk_bank)) {
1001 $bankid = $object->fk_bank;
1002 } // For backward compatibility when object->fk_account is forced with object->fk_bank
1003 $account = new Account($this->db);
1004 $account->fetch($bankid);
1005
1006 $curx = $this->marge_gauche;
1007 $cury = $posy;
1008
1009 $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1010
1011 $posy += 2;
1012 }
1013 }
1014
1015 return $posy;
1016 }
1017
1018
1029 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1030 {
1031 global $conf, $mysoc;
1032
1033 $default_font_size = pdf_getPDFFontSize($outputlangs);
1034
1035 $tab2_top = $posy;
1036 $tab2_hl = 4;
1037 $pdf->SetFont('', '', $default_font_size - 1);
1038
1039 // Tableau total
1040 $col1x = 120;
1041 $col2x = 170;
1042 if ($this->page_largeur < 210) { // To work with US executive format
1043 $col2x -= 20;
1044 }
1045 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1046 $useborder = 0;
1047 $index = 0;
1048
1049 $outputlangsbis = null;
1050 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
1051 $outputlangsbis = new Translate('', $conf);
1052 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
1053 $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1054 }
1055
1056 // Total HT
1057 /*$pdf->SetFillColor(255, 255, 255);
1058 $pdf->SetXY($col1x, $tab2_top);
1059 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
1060 $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1061 $pdf->SetXY($col2x, $tab2_top);
1062 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);*/
1063
1064 // Show VAT by rates and total
1065 $pdf->SetFillColor(248, 248, 248);
1066
1067 $total_ttc = $object->getValorisationTotale();
1068
1069 $this->atleastoneratenotnull = 0;
1070
1071 // Total TTC
1072 $index++;
1073 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1074 $pdf->SetTextColor(0, 0, 60);
1075 $pdf->SetFillColor(224, 224, 224);
1076 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("Total", $mysoc->country_code) : ''), $useborder, 'L', 1);
1077
1078 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1079 $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1080
1081 $pdf->SetTextColor(0, 0, 0);
1082
1083 $creditnoteamount = 0;
1084 $depositsamount = 0;
1085 //$creditnoteamount=$object->getSumCreditNotesUsed();
1086 //$depositsamount=$object->getSumDepositsUsed();
1087 //print "x".$creditnoteamount."-".$depositsamount;exit;
1088 $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1089 if (!empty($object->paye)) {
1090 $resteapayer = 0;
1091 }
1092
1093 if ($deja_regle > 0) {
1094 // Already paid + Deposits
1095 $index++;
1096
1097 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1098 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1100 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1101
1102 $index++;
1103 $pdf->SetTextColor(0, 0, 60);
1104 $pdf->SetFillColor(224, 224, 224);
1105 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1106 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), $useborder, 'L', 1);
1107
1108 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1109 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1110
1111 $pdf->SetFont('', '', $default_font_size - 1);
1112 $pdf->SetTextColor(0, 0, 0);
1113 }
1114
1115 $index++;
1116 return ($tab2_top + ($tab2_hl * $index));
1117 }
1118
1119 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1133 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1134 {
1135 global $conf;
1136
1137 // Force to disable hidetop and hidebottom
1138 $hidebottom = 0;
1139 if ($hidetop) {
1140 $hidetop = -1;
1141 }
1142
1143 $currency = !empty($currency) ? $currency : $conf->currency;
1144 $default_font_size = pdf_getPDFFontSize($outputlangs);
1145
1146 // Amount in (at tab_top - 1)
1147 $pdf->SetTextColor(0, 0, 0);
1148 $pdf->SetFont('', '', $default_font_size - 2);
1149
1150 if (empty($hidetop)) {
1151 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1152 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1153 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1154
1155 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1156 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
1157 $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')));
1158 }
1159 }
1160
1161 $pdf->SetDrawColor(128, 128, 128);
1162 $pdf->SetFont('', '', $default_font_size - 1);
1163
1164 // Output Rect
1165 $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
1166
1167
1168 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1169
1170 if (empty($hidetop)) {
1171 $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
1172 }
1173 }
1174
1175 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1176 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1187 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "StockTransferSheetProforma")
1188 {
1189 // phpcs:enable
1190 global $conf, $langs;
1191
1192 '@phan-var-force StockTransfer $object';
1193
1194 // Load traductions files required by page
1195 $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1196
1197 $default_font_size = pdf_getPDFFontSize($outputlangs);
1198
1199 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1200
1201 // Show Draft Watermark
1202 if ($object->statut == 0 && getDolGlobalString('STOCKTRANSFER_DRAFT_WATERMARK')) {
1203 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
1204 }
1205
1206 $pdf->SetTextColor(0, 0, 60);
1207 $pdf->SetFont('', 'B', $default_font_size + 3);
1208
1209 $w = 110;
1210
1211 $posy = $this->marge_haute;
1212 $posx = $this->page_largeur - $this->marge_droite - $w;
1213
1214 $pdf->SetXY($this->marge_gauche, $posy);
1215
1216 // Logo
1217 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1218 if ($this->emetteur->logo) {
1219 $logodir = $conf->mycompany->dir_output;
1220 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1221 $logodir = $conf->mycompany->multidir_output[$object->entity];
1222 }
1223 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1224 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1225 } else {
1226 $logo = $logodir.'/logos/'.$this->emetteur->logo;
1227 }
1228 if (is_readable($logo)) {
1229 $height = pdf_getHeightForLogo($logo);
1230 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1231 } else {
1232 $pdf->SetTextColor(200, 0, 0);
1233 $pdf->SetFont('', 'B', $default_font_size - 2);
1234 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1235 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1236 }
1237 } else {
1238 $text = $this->emetteur->name;
1239 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1240 }
1241 }
1242
1243 $pdf->SetDrawColor(128, 128, 128);
1244
1245 $posx = $this->page_largeur - $w - $this->marge_droite;
1246 $posy = $this->marge_haute;
1247
1248 $pdf->SetFont('', 'B', $default_font_size + 2);
1249 $pdf->SetXY($posx, $posy);
1250 $pdf->SetTextColor(0, 0, 60);
1251 $title = $outputlangs->transnoentities("StockTransferSheet").' '.$object->ref;
1252 $pdf->MultiCell($w, 4, $title, '', 'R');
1253
1254 $pdf->SetFont('', '', $default_font_size + 1);
1255
1256 // Date prévue depart
1257 if (!empty($object->date_prevue_depart)) {
1258 $posy += 4;
1259 $pdf->SetXY($posx, $posy);
1260 $pdf->SetTextColor(0, 0, 60);
1261 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueDepart")." : ".dol_print_date($object->date_prevue_depart, "day", false, $outputlangs, true), '', 'R');
1262 }
1263
1264 // Date prévue arrivée
1265 if (!empty($object->date_prevue_arrivee)) {
1266 $posy += 4;
1267 $pdf->SetXY($posx, $posy);
1268 $pdf->SetTextColor(0, 0, 60);
1269 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DatePrevueArrivee")." : ".dol_print_date($object->date_prevue_arrivee, "day", false, $outputlangs, true), '', 'R');
1270 }
1271
1272 // Date reelle depart
1273 if (!empty($object->date_reelle_depart)) {
1274 $posy += 4;
1275 $pdf->SetXY($posx, $posy);
1276 $pdf->SetTextColor(0, 0, 60);
1277 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleDepart")." : ".dol_print_date($object->date_reelle_depart, "day", false, $outputlangs, true), '', 'R');
1278 }
1279
1280 // Date reelle arrivée
1281 if (!empty($object->date_reelle_arrivee)) {
1282 $posy += 4;
1283 $pdf->SetXY($posx, $posy);
1284 $pdf->SetTextColor(0, 0, 60);
1285 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
1286 }
1287
1288 if (!empty($object->thirdparty->code_client)) {
1289 $posy += 4;
1290 $pdf->SetXY($posx, $posy);
1291 $pdf->SetTextColor(0, 0, 60);
1292 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1293 }
1294
1295 if ($object->ref_client) {
1296 $posy += 5;
1297 $pdf->SetXY($posx, $posy);
1298 $pdf->SetTextColor(0, 0, 60);
1299 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1300 }
1301
1302 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
1303 $object->fetchProject();
1304 if (!empty($object->project->ref)) {
1305 $posy += 3;
1306 $pdf->SetXY($posx, $posy);
1307 $pdf->SetTextColor(0, 0, 60);
1308 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1309 }
1310 }
1311
1312 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
1313 $object->fetchProject();
1314 if (!empty($object->project->ref)) {
1315 $posy += 3;
1316 $pdf->SetXY($posx, $posy);
1317 $pdf->SetTextColor(0, 0, 60);
1318 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->projet->ref), '', 'R');
1319 }
1320 }
1321
1322 if (getDolGlobalString('DOC_SHOW_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
1323 $posy += 4;
1324 $pdf->SetXY($posx, $posy);
1325 $pdf->SetTextColor(0, 0, 60);
1326 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1327 }
1328
1329 // Get contact
1330 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
1331 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1332 if (count($arrayidcontact) > 0) {
1333 $usertmp = new User($this->db);
1334 $usertmp->fetch($arrayidcontact[0]);
1335 $posy += 4;
1336 $pdf->SetXY($posx, $posy);
1337 $pdf->SetTextColor(0, 0, 60);
1338 $pdf->MultiCell(100, 3, $outputlangs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1339 }
1340 }
1341
1342 $posy += 2;
1343
1344 $top_shift = 0;
1345 // Show list of linked objects
1346 $current_y = $pdf->getY();
1347 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1348 if ($current_y < $pdf->getY()) {
1349 $top_shift = $pdf->getY() - $current_y;
1350 }
1351
1352 if ($showaddress) {
1353 // Sender properties
1354 $carac_emetteur = '';
1355 // Add internal contact of origin element if defined
1356 $arrayidcontact = array();
1357 $arrayidcontact = $object->getIdContact('external', 'STFROM');
1358
1359 $usecontact = false;
1360 if (count($arrayidcontact) > 0) {
1361 /*$object->fetch_user(reset($arrayidcontact));
1362 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
1363 $usecontact = true;
1364 $result = $object->fetch_contact($arrayidcontact[0]);
1365 }
1366
1367 if ($usecontact) {
1368 $thirdparty = $object->contact;
1369 } else {
1370 $thirdparty = $this->emetteur;
1371 }
1372
1373 if (!empty($thirdparty)) {
1374 $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1375 }
1376
1377 if ($usecontact) {
1378 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
1379 } else {
1380 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1381 }
1382
1383 // Show sender
1384 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1385 $posx = $this->marge_gauche;
1386 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1387 $posx = $this->page_largeur - $this->marge_droite - 80;
1388 }
1389
1390 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1391 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1392
1393 // Show sender frame
1394 $pdf->SetTextColor(0, 0, 0);
1395 $pdf->SetFont('', '', $default_font_size - 2);
1396 $pdf->SetXY($posx, $posy - 5);
1397 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1398 $pdf->SetXY($posx, $posy);
1399 $pdf->SetFillColor(230, 230, 230);
1400 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'F');
1401 $pdf->SetTextColor(0, 0, 60);
1402 $pdf->SetFillColor(255, 255, 255);
1403
1404 // Show sender name
1405 $pdf->SetXY($posx + 2, $posy + 3);
1406 $pdf->SetFont('', 'B', $default_font_size);
1407 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_emetteur_name), 0, 'L');
1408 $posy = $pdf->getY();
1409
1410 // Show sender information
1411 $pdf->SetXY($posx + 2, $posy);
1412 $pdf->SetFont('', '', $default_font_size - 1);
1413 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1414
1415
1416 // If SHIPPING contact defined, we use it
1417 $usecontact = false;
1418 $arrayidcontact = $object->getIdContact('external', 'STDEST');
1419 if (count($arrayidcontact) > 0) {
1420 $usecontact = true;
1421 $result = $object->fetch_contact($arrayidcontact[0]);
1422 }
1423
1424 //Recipient name
1425 // On peut utiliser le nom de la societe du contact
1426 if ($usecontact/* && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)*/) {
1427 $thirdparty = $object->contact;
1428 } else {
1429 $thirdparty = $object->thirdparty;
1430 }
1431
1432 $carac_client_name = '';
1433 if (!empty($thirdparty)) {
1434 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1435 }
1436
1437 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), ($usecontact ? 1 : 0), 'targetwithdetails', $object);
1438
1439 // Show recipient
1440 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1441 if ($this->page_largeur < 210) {
1442 $widthrecbox = 84; // To work with US executive format
1443 }
1444 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1445 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1446 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1447 $posx = $this->marge_gauche;
1448 }
1449
1450 // Show recipient frame
1451 $pdf->SetTextColor(0, 0, 0);
1452 $pdf->SetFont('', '', $default_font_size - 2);
1453 $pdf->SetXY($posx + 2, $posy - 5);
1454 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1455 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1456
1457 // Show recipient name
1458 $pdf->SetXY($posx + 2, $posy + 3);
1459 $pdf->SetFont('', 'B', $default_font_size);
1460 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1461
1462 $posy = $pdf->getY();
1463
1464 // Show recipient information
1465 $pdf->SetFont('', '', $default_font_size - 1);
1466 $pdf->SetXY($posx + 2, $posy);
1467 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1468 }
1469
1470 $pdf->SetTextColor(0, 0, 0);
1471
1472 return $top_shift;
1473 }
1474
1475 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1476 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1486 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1487 {
1488 // phpcs:enable
1489 '@phan-var-force StockTransfer $object';
1490
1491 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1492 return pdf_pagefoot($pdf, $outputlangs, 'STOCKTRANSFER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1493 }
1494
1495
1496
1507 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1508 {
1509 global $conf, $hookmanager;
1510 '@phan-var-force StockTransfer $object';
1513 // Default field style for content
1514 $this->defaultContentsFieldsStyle = array(
1515 'align' => 'R', // R,C,L
1516 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1517 );
1518
1519 // Default field style for content
1520 $this->defaultTitlesFieldsStyle = array(
1521 'align' => 'C', // R,C,L
1522 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1523 );
1524
1525 /*
1526 * For example
1527 $this->cols['theColKey'] = array(
1528 'rank' => $rank, // int : use for ordering columns
1529 'width' => 20, // the column width in mm
1530 'title' => array(
1531 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1532 'label' => ' ', // the final label : used fore final generated text
1533 'align' => 'L', // text alignment : R,C,L
1534 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1535 ),
1536 'content' => array(
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 );
1541 */
1542
1543 $rank = 0; // do not use negative rank
1544 $this->cols['desc'] = array(
1545 'rank' => $rank,
1546 'width' => false, // only for desc
1547 'status' => true,
1548 'title' => array(
1549 'textkey' => 'Designation', // use lang key is useful in somme case with module
1550 'align' => 'L',
1551 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1552 // 'label' => ' ', // the final label
1553 'padding' => array(0.5, 1, 0.5, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1554 ),
1555 'content' => array(
1556 'align' => 'L',
1557 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1558 ),
1559 );
1560
1561 $rank += 10;
1562 $this->cols['photo'] = array(
1563 'rank' => $rank,
1564 'width' => getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20), // in mm
1565 'status' => false,
1566 'title' => array(
1567 'textkey' => 'Photo',
1568 'label' => ' '
1569 ),
1570 'content' => array(
1571 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1572 ),
1573 'border-left' => false, // remove left line separator
1574 );
1575
1576 if (getDolGlobalString('MAIN_GENERATE_ORDERS_WITH_PICTURE')) {
1577 $this->cols['photo']['status'] = true;
1578 }
1579
1580
1581 $rank += 10;
1582 $this->cols['vat'] = array(
1583 'rank' => $rank,
1584 'status' => false,
1585 'width' => 16, // in mm
1586 'title' => array(
1587 'textkey' => 'VAT'
1588 ),
1589 'border-left' => true, // add left line separator
1590 );
1591
1592 /*if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1593 {
1594 $this->cols['vat']['status'] = true;
1595 }*/
1596
1597 $rank += 10;
1598 $this->cols['subprice'] = array(
1599 'rank' => $rank,
1600 'width' => 19, // in mm
1601 'status' => true,
1602 'title' => array(
1603 'textkey' => 'PMPValueShort'
1604 ),
1605 'border-left' => true, // add left line separator
1606 );
1607
1608 // Adapt dynamically the width of subprice, if text is too long.
1609 $tmpwidth = 0;
1610 $nblines = is_array($object->lines) ? count($object->lines) : 0;
1611 for ($i = 0; $i < $nblines; $i++) {
1612 $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
1613 $tmpwidth = max($tmpwidth, $tmpwidth2);
1614 }
1615 if ($tmpwidth > 10) {
1616 $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
1617 }
1618
1619 $rank += 10;
1620 $this->cols['qty'] = array(
1621 'rank' => $rank,
1622 'width' => 16, // in mm
1623 'status' => true,
1624 'title' => array(
1625 'textkey' => 'Qty'
1626 ),
1627 'border-left' => true, // add left line separator
1628 );
1629
1630 $rank += 10;
1631 $this->cols['unit'] = array(
1632 'rank' => $rank,
1633 'width' => 11, // in mm
1634 'status' => false,
1635 'title' => array(
1636 'textkey' => 'Unit'
1637 ),
1638 'border-left' => true, // add left line separator
1639 );
1640 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1641 $this->cols['unit']['status'] = true;
1642 }
1643
1644 $rank += 10;
1645 $this->cols['discount'] = array(
1646 'rank' => $rank,
1647 'width' => 13, // in mm
1648 'status' => false,
1649 'title' => array(
1650 'textkey' => 'ReductionShort'
1651 ),
1652 'border-left' => true, // add left line separator
1653 );
1654 if ($this->atleastonediscount) {
1655 $this->cols['discount']['status'] = true;
1656 }
1657
1658 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1659 $this->cols['totalexcltax'] = array(
1660 'rank' => $rank,
1661 'width' => 26, // in mm
1662 'status' => true,
1663 'title' => array(
1664 'textkey' => 'TotalHTShort'
1665 ),
1666 'border-left' => true, // add left line separator
1667 );
1668
1669 // Add extrafields cols
1670 if (!empty($object->lines)) {
1671 $line = reset($object->lines);
1672 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1673 }
1674
1675 $parameters = array(
1676 'object' => $object,
1677 'outputlangs' => $outputlangs,
1678 'hidedetails' => $hidedetails,
1679 'hidedesc' => $hidedesc,
1680 'hideref' => $hideref
1681 );
1682
1683 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1684 if ($reshook < 0) {
1685 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1686 } elseif (empty($reshook)) {
1687 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1688 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1689 } else {
1690 $this->cols = $hookmanager->resArray;
1691 }
1692 }
1693}
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_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 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:2648
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:1027
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2000
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1938
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1405
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:850
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:434
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2245
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2288
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2085
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:765
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:386
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:785
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152