dolibarr 25.0.0-alpha
pdf.lib.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
5 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
6 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
9 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
10 * Copyright (C) 2012-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
11 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
12 * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
13 * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
14 * Copyright (C) 2019 Lenin Rivas <lenin.rivas@servcom-it.com>
15 * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
16 * Copyright (C) 2021-2022 Anthony Berton <anthony.berton@bb2a.fr>
17 * Copyright (C) 2023-2026 Frédéric France <frederic.france@free.fr>
18 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 * or see https://www.gnu.org/
33 */
34
41include_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
42
43
50{
51 global $langs, $conf;
52
53 $h = 0;
54 $head = array();
55
56 $head[$h][0] = DOL_URL_ROOT.'/admin/pdf.php';
57 $head[$h][1] = $langs->trans("GlobalParameters");
58 $head[$h][2] = 'general';
59 $h++;
60
61 // Show more tabs from modules
62 // Entries must be declared in modules descriptor with line
63 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
64 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
65 complete_head_from_modules($conf, $langs, null, $head, $h, 'pdf_admin');
66
67 if (isModEnabled("propal") || isModEnabled('invoice') || isModEnabled('reception')) {
68 $head[$h][0] = DOL_URL_ROOT.'/admin/pdf_other.php';
69 $head[$h][1] = $langs->trans("SpecificParameters");
70 $head[$h][2] = 'other';
71 $h++;
72 }
73
74 complete_head_from_modules($conf, $langs, null, $head, $h, 'pdf_admin', 'remove');
75
76 return $head;
77}
78
79
87function pdf_getFormat($outputlangs = null, $mode = 'setup')
88{
89 global $conf, $db, $langs;
90
91 dol_syslog("pdf_getFormat Get paper format with mode=".$mode." MAIN_PDF_FORMAT=".getDolGlobalString('MAIN_PDF_FORMAT')." outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')." and langs->defaultlang=".(is_object($langs) ? $langs->defaultlang : 'null'));
92
93 // Default value if setup was not done and/or entry into c_paper_format not defined
94 $width = 210;
95 $height = 297;
96 $unit = 'mm';
97
98 if ($mode == 'auto' || !getDolGlobalString('MAIN_PDF_FORMAT') || getDolGlobalString('MAIN_PDF_FORMAT') == 'auto') {
99 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
100 $pdfformat = dol_getDefaultFormat($outputlangs);
101 } else {
102 $pdfformat = getDolGlobalString('MAIN_PDF_FORMAT');
103 }
104
105 $sql = "SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
106 $sql .= " WHERE code = '".$db->escape($pdfformat)."'";
107 $resql = $db->query($sql);
108 if ($resql) {
109 $obj = $db->fetch_object($resql);
110 if ($obj) {
111 $width = (int) $obj->width;
112 $height = (int) $obj->height;
113 $unit = $obj->unit;
114 }
115 }
116
117 //print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
118 return array('width' => $width, 'height' => $height, 'unit' => $unit);
119}
120
129function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
130{
131 global $conf;
132
133 // Define constant for TCPDF
134 if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
135 define('K_TCPDF_EXTERNAL_CONFIG', 1); // this avoid using tcpdf_config file
136 define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
137 define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
138 dol_mkdir(K_PATH_CACHE);
139 define('K_BLANK_IMAGE', '_blank.png');
140 define('PDF_PAGE_FORMAT', 'A4');
141 define('PDF_PAGE_ORIENTATION', 'P');
142 define('PDF_CREATOR', 'TCPDF');
143 define('PDF_AUTHOR', 'TCPDF');
144 define('PDF_HEADER_TITLE', 'TCPDF Example');
145 define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
146 define('PDF_UNIT', 'mm');
147 define('PDF_MARGIN_HEADER', 5);
148 define('PDF_MARGIN_FOOTER', 10);
149 define('PDF_MARGIN_TOP', 27);
150 define('PDF_MARGIN_BOTTOM', 25);
151 define('PDF_MARGIN_LEFT', 15);
152 define('PDF_MARGIN_RIGHT', 15);
153 define('PDF_FONT_NAME_MAIN', 'helvetica');
154 define('PDF_FONT_SIZE_MAIN', 10);
155 define('PDF_FONT_NAME_DATA', 'helvetica');
156 define('PDF_FONT_SIZE_DATA', 8);
157 define('PDF_FONT_MONOSPACED', 'courier');
158 define('PDF_IMAGE_SCALE_RATIO', 1.25);
159 define('HEAD_MAGNIFICATION', 1.1);
160 define('K_CELL_HEIGHT_RATIO', 1.25);
161 define('K_TITLE_MAGNIFICATION', 1.3);
162 define('K_SMALL_RATIO', 2 / 3);
163 define('K_THAI_TOPCHARS', true);
164 define('K_TCPDF_CALLS_IN_HTML', true);
165 // Default: throw exceptions on TCPDF/TCPDI errors instead of die().
166 // A die() in a PDF library produces white pages on web requests and kills
167 // batch jobs on the first bad PDF. Exceptions can be caught and surfaced as
168 // normal Dolibarr errors. Users can opt out by setting
169 // TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = 0 to restore the legacy die() behavior.
170 if (getDolGlobalString('TCPDF_THROW_ERRORS_INSTEAD_OF_DIE', '1')) {
171 define('K_TCPDF_THROW_EXCEPTION_ERROR', true);
172 } else {
173 define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
174 }
175 }
176
177 // Load TCPDF
178 require_once TCPDF_PATH.'tcpdf.php';
179
180 // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
181 if (!getDolGlobalString('MAIN_DISABLE_TCPDI')) {
182 require_once TCPDI_PATH.'tcpdi.php';
183 }
184
185 //$arrayformat=pdf_getFormat();
186 //$format=array($arrayformat['width'],$arrayformat['height']);
187 //$metric=$arrayformat['unit'];
188
189 //$pdfa = false; // PDF default version
190 $pdfa = getDolGlobalInt('PDF_USE_A', 0); // 0=PDF 1.7, 1=PDF 1.4/A-1b ou 3=PDF 1.7/A-3b
191
192 if (!getDolGlobalString('MAIN_DISABLE_TCPDI') && class_exists('TCPDI')) {
193 $pdf = new TCPDI($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
194 } else {
195 $pdf = new TCPDF($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
196 }
197 // Allow "file://..." image src values (used to embed local server paths translated from a public URL)
198 $pdf->setAllowLocalFiles(true);
199
200 // Protection and encryption of pdf
201 if (getDolGlobalString('PDF_SECURITY_ENCRYPTION')) {
202 /* Permission supported by TCPDF
203 - print : Print the document;
204 - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
205 - copy : Copy or otherwise extract text and graphics from the document;
206 - annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
207 - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
208 - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
209 - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
210 - print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
211 - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
212 */
213
214 // For TCPDF, we specify permission we want to block
215 $pdfrights = (getDolGlobalString('PDF_SECURITY_ENCRYPTION_RIGHTS') ? json_decode(getDolGlobalString('PDF_SECURITY_ENCRYPTION_RIGHTS'), true) : array('modify', 'copy')); // Json format in llx_const
216
217 // Password for the end user
218 $pdfuserpass = getDolGlobalString('PDF_SECURITY_ENCRYPTION_USERPASS');
219
220 // Password of the owner, created randomly if not defined
221 $pdfownerpass = (getDolGlobalString('PDF_SECURITY_ENCRYPTION_OWNERPASS') ? getDolGlobalString('PDF_SECURITY_ENCRYPTION_OWNERPASS') : null);
222
223 // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
224 $encstrength = getDolGlobalInt('PDF_SECURITY_ENCRYPTION_STRENGTH', 0);
225
226 // Array of recipients containing public-key certificates ('c') and permissions ('p').
227 // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
228 $pubkeys = (getDolGlobalString('PDF_SECURITY_ENCRYPTION_PUBKEYS') ? json_decode(getDolGlobalString('PDF_SECURITY_ENCRYPTION_PUBKEYS'), true) : null); // Json format in llx_const
229
230 $pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass, $encstrength, $pubkeys);
231 }
232
233 return $pdf;
234}
235
242function pdf_getEncryption($pathoffile)
243{
244 require_once TCPDF_PATH.'tcpdf_parser.php';
245
246 $isencrypted = false;
247
248 $content = file_get_contents($pathoffile);
249
250 //ob_start();
251 @($parser = new TCPDF_PARSER(ltrim($content)));
252 $tmp = $parser->getParsedData();
253 $xref = $tmp[0];
254 $data = $tmp[1] ?? null;
255 unset($parser);
256 //ob_end_clean();
257
258 if (isset($xref['trailer']['encrypt'])) {
259 $isencrypted = true; // Secured pdf file are currently not supported
260 }
261
262 if (empty($data)) {
263 $isencrypted = true; // Object list not found. Possible secured file
264 }
265
266 return $isencrypted;
267}
268
275function pdf_getPDFFont($outputlangs)
276{
277 if (getDolGlobalString('MAIN_PDF_FORCE_FONT')) {
278 return getDolGlobalString('MAIN_PDF_FORCE_FONT');
279 }
280
281 $font = 'Helvetica'; // By default, for FPDI, or ISO language on TCPDF
282 if (class_exists('TCPDF')) { // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
283 if ($outputlangs->trans('FONTFORPDF') != 'FONTFORPDF') {
284 $font = $outputlangs->trans('FONTFORPDF');
285 }
286 }
287 return $font;
288}
289
296function pdf_getPDFFontSize($outputlangs)
297{
298 $size = 10; // By default, for FPDI or ISO language on TCPDF
299 if (class_exists('TCPDF')) { // If TCPDF on, we can use an UTF8 font like DejaVuSans if required (slower)
300 if ($outputlangs->trans('FONTSIZEFORPDF') != 'FONTSIZEFORPDF') {
301 $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
302 }
303 }
304 if (getDolGlobalString('MAIN_PDF_FORCE_FONT_SIZE')) {
305 $size = getDolGlobalString('MAIN_PDF_FORCE_FONT_SIZE');
306 }
307
308 return $size;
309}
310
311
319function pdf_getHeightForLogo($logo, $url = false)
320{
321 $height = getDolGlobalFloat('MAIN_DOCUMENTS_LOGO_HEIGHT', 20);
322 $maxwidth = 130;
323 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
324 $tmp = dol_getImageSize($logo, $url);
325 if ($tmp['height']) {
326 $width = round($height * $tmp['width'] / $tmp['height']);
327 if ($width > $maxwidth) {
328 $height = $height * $maxwidth / $width;
329 }
330 }
331
332 return $height;
333}
334
351function pdf_writeLogoOrCompanyName($pdf, $outputlangs, $emetteur, $logodir, $posx, $posy, $w, $default_font_size, $align)
352{
353 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
354 if ($emetteur->logo) {
355 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
356 $logo = $logodir.'/logos/thumbs/'.$emetteur->logo_small;
357 } else {
358 $logo = $logodir.'/logos/'.$emetteur->logo;
359 }
360 if (is_readable($logo)) {
361 $height = pdf_getHeightForLogo($logo);
362 $pdf->Image($logo, $posx, $posy, 0, $height); // width=0 (auto)
363 } else {
364 $pdf->SetTextColor(200, 0, 0);
365 $pdf->SetFont('', 'B', $default_font_size - 2);
366 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
367 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
368 }
369 } else {
370 $text = (string) $emetteur->name;
371 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $align);
372 }
373 }
374}
375
385function pdfGetHeightForHtmlContent($pdf, $htmlcontent)
386{
387 // store current object
388 $pdf->startTransaction();
389 // To avoid pagebreak effect or strange behavior of writeHTMLCell when we are out of page, we imagine we are at the begin of page to test the height of the text
390 // Another solution would be to do the test on another PDF instance with samefont, width...
391 $pdf->setY(0);
392 // store starting values
393 $start_y = $pdf->GetY();
394 //var_dump($start_y);
395 $start_page = $pdf->getPage();
396 // call printing functions with content
397 $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J', true);
398 // get the new Y
399 $end_y = $pdf->GetY();
400 $end_page = $pdf->getPage();
401 // calculate height
402 $height = 0;
403 if ($end_page == $start_page) {
404 $height = $end_y - $start_y;
405 } else {
406 for ($page = $start_page; $page <= $end_page; ++$page) {
407 $pdf->setPage($page);
408 $tmpm = $pdf->getMargins();
409 $tMargin = $tmpm['top'];
410 if ($page == $start_page) {
411 // first page
412 $height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
413 } elseif ($page == $end_page) {
414 // last page
415 $height = $end_y - $tMargin;
416 } else {
417 $height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
418 }
419 }
420 }
421 // restore previous object state
422 $pdf->rollbackTransaction(true);
423
424 return $height;
425}
426
427
436function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias = 0)
437{
438 // Recipient name
439 $socname = '';
440
441 if ($thirdparty instanceof Societe) {
442 $socname = $thirdparty->name;
443 if (($includealias || getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME')) && !empty($thirdparty->name_alias)) {
444 if (getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME') == 2) {
445 $socname = $thirdparty->name_alias." - ".$thirdparty->name;
446 } else {
447 $socname = $thirdparty->name." - ".$thirdparty->name_alias;
448 }
449 }
450 } elseif ($thirdparty instanceof Contact) {
451 if ($thirdparty->socid > 0) {
452 $thirdparty->fetch_thirdparty();
453 $socname = $thirdparty->thirdparty->name;
454 if (($includealias || getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME')) && !empty($thirdparty->thirdparty->name_alias)) {
455 if (getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME') == 2) {
456 $socname = $thirdparty->thirdparty->name_alias." - ".$thirdparty->thirdparty->name;
457 } else {
458 $socname = $thirdparty->thirdparty->name." - ".$thirdparty->thirdparty->name_alias;
459 }
460 }
461 }
462 } else {
463 throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
464 }
465
466 return $outputlangs->convToOutputCharset((string) $socname);
467}
468
481function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source', $object = null)
482{
483 global $hookmanager;
484
485 if ($mode == 'source' && !is_object($sourcecompany)) {
486 return -1;
487 }
488 if (($mode == 'target' || $mode == 'targetshipping') && !is_object($targetcompany)) {
489 return -1;
490 }
491
492 if (!empty($sourcecompany->state_id) && empty($sourcecompany->state)) {
493 $sourcecompany->state = getState($sourcecompany->state_id);
494 }
495 if (!empty($targetcompany->state_id) && empty($targetcompany->state)) {
496 $targetcompany->state = getState($targetcompany->state_id);
497 }
498
499 $reshook = 0;
500 $stringaddress = '';
501 if (is_object($hookmanager)) {
502 $parameters = array('sourcecompany' => &$sourcecompany, 'targetcompany' => &$targetcompany, 'targetcontact' => &$targetcontact, 'outputlangs' => $outputlangs, 'mode' => $mode, 'usecontact' => $usecontact);
503 $action = '';
504 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
505 $reshook = $hookmanager->executeHooks('pdf_build_address', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
506 $stringaddress .= $hookmanager->resPrint;
507 }
508 if (empty($reshook)) {
509 if ($mode == 'source') {
510 $withCountry = 0;
511 if (isset($targetcompany->country_code) && !empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
512 $withCountry = 1;
513 }
514
515 $fulladdress = dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs);
516 if ($fulladdress) {
517 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($fulladdress)."\n";
518 }
519
520 if (!getDolGlobalString('MAIN_PDF_DISABLESOURCEDETAILS')) {
521 // Phone
522 if ($sourcecompany->phone) {
523 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
524 }
525 // Phone mobile
526 if ($sourcecompany->phone_mobile && getDolGlobalString('MAIN_PDF_SHOW_SOURCE_PHONE_MOBILE')) {
527 $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '').$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone_mobile);
528 }
529 // Fax
530 if ($sourcecompany->fax) {
531 $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
532 }
533 // EMail
534 if ($sourcecompany->email) {
535 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
536 }
537 // Web
538 if ($sourcecompany->url) {
539 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
540 }
541 }
542 // Intra VAT
543 if (getDolGlobalString('MAIN_TVAINTRA_IN_SOURCE_ADDRESS')) {
544 if ($sourcecompany->tva_intra) {
545 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
546 }
547 }
548 // Professional Ids
549 $reg = array();
550 if (getDolGlobalString('MAIN_PROFID1_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof1)) {
551 $tmp = $outputlangs->transcountrynoentities("ProfId1", $sourcecompany->country_code);
552 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
553 $tmp = $reg[1];
554 }
555 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
556 }
557 if (getDolGlobalString('MAIN_PROFID2_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof2)) {
558 $tmp = $outputlangs->transcountrynoentities("ProfId2", $sourcecompany->country_code);
559 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
560 $tmp = $reg[1];
561 }
562 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
563 }
564 if (getDolGlobalString('MAIN_PROFID3_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof3)) {
565 $tmp = $outputlangs->transcountrynoentities("ProfId3", $sourcecompany->country_code);
566 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
567 $tmp = $reg[1];
568 }
569 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
570 }
571 if (getDolGlobalString('MAIN_PROFID4_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof4)) {
572 $tmp = $outputlangs->transcountrynoentities("ProfId4", $sourcecompany->country_code);
573 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
574 $tmp = $reg[1];
575 }
576 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
577 }
578 if (getDolGlobalString('MAIN_PROFID5_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof5)) {
579 $tmp = $outputlangs->transcountrynoentities("ProfId5", $sourcecompany->country_code);
580 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
581 $tmp = $reg[1];
582 }
583 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
584 }
585 if (getDolGlobalString('MAIN_PROFID6_IN_SOURCE_ADDRESS') && !empty($sourcecompany->idprof6)) {
586 $tmp = $outputlangs->transcountrynoentities("ProfId6", $sourcecompany->country_code);
587 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
588 $tmp = $reg[1];
589 }
590 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
591 }
592 if (getDolGlobalString('PDF_ADD_MORE_AFTER_SOURCE_ADDRESS')) {
593 $stringaddress .= ($stringaddress ? "\n" : '') . getDolGlobalString('PDF_ADD_MORE_AFTER_SOURCE_ADDRESS');
594 }
595 }
596
597 if ($mode == 'target' || $mode == 'targetshipping' || preg_match('/targetwithdetails/', $mode)) {
598 if ($usecontact && (is_object($targetcontact))) {
599 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs, 1));
600
601 if (!empty($targetcontact->address)) {
602 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcontact))."\n";
603 } elseif (is_object($targetcompany)) {
604 $companytouseforaddress = $targetcompany;
605
606 // Contact on a thirdparty that is a different thirdparty than the thirdparty of object
607 if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id) {
608 $targetcontact->fetch_thirdparty();
609 $companytouseforaddress = $targetcontact->thirdparty;
610 }
611
612 if (is_object($companytouseforaddress)) {
613 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress))."\n";
614 }
615 }
616 // Country
617 if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
618 $stringaddress .= (($stringaddress && !getDolGlobalString('MAIN_PDF_REMOVE_BREAK_BEFORE_COUNTRY')) ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
619 } elseif (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
620 $stringaddress .= (($stringaddress && !getDolGlobalString('MAIN_PDF_REMOVE_BREAK_BEFORE_COUNTRY')) ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
621 }
622
623 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || preg_match('/targetwithdetails/', $mode)) {
624 // Phone
625 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode)) {
626 if (!empty($targetcontact->phone_pro) || !empty($targetcontact->phone_mobile)) {
627 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
628 }
629 if (!empty($targetcontact->phone_pro)) {
630 $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
631 }
632 if (!empty($targetcontact->phone_pro) && !empty($targetcontact->phone_mobile)) {
633 $stringaddress .= " / ";
634 }
635 if (!empty($targetcontact->phone_mobile)) {
636 $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
637 }
638 }
639 // Fax
640 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode)) {
641 if ($targetcontact->fax) {
642 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
643 }
644 }
645 // EMail
646 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode)) {
647 if ($targetcontact->email) {
648 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
649 }
650 }
651 // Web
652 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode)) {
653 if ($targetcontact->url) {
654 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset((string) $targetcontact->url);
655 }
656 }
657 }
658 } else {
659 if (is_object($targetcompany)) {
660 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
661 // Country
662 if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) {
663 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
664 } else {
665 $stringaddress .= ($stringaddress ? "\n" : '');
666 }
667
668 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || preg_match('/targetwithdetails/', $mode)) {
669 // Phone
670 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode)) {
671 if (!empty($targetcompany->phone) || !empty($targetcompany->phone_mobile)) {
672 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
673 }
674 if (!empty($targetcompany->phone)) {
675 $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
676 }
677 if (!empty($targetcompany->phone) && !empty($targetcompany->phone_mobile)) {
678 $stringaddress .= " / ";
679 }
680 if (!empty($targetcompany->phone_mobile)) {
681 $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
682 }
683 }
684 // Fax
685 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode)) {
686 if ($targetcompany->fax) {
687 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
688 }
689 }
690 // EMail
691 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode)) {
692 if ($targetcompany->email) {
693 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
694 }
695 }
696 // Web
697 if (getDolGlobalString('MAIN_PDF_ADDALSOTARGETDETAILS') || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode)) {
698 if ($targetcompany->url) {
699 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
700 }
701 }
702 }
703 }
704 }
705
706 // Intra VAT
707 if (!getDolGlobalString('MAIN_TVAINTRA_NOT_IN_ADDRESS')) {
708 if ($usecontact && is_object($targetcontact) && getDolGlobalInt('MAIN_USE_COMPANY_NAME_OF_CONTACT')) {
709 $targetcontact->fetch_thirdparty();
710 if (!empty($targetcontact->thirdparty->id) && $targetcontact->thirdparty->tva_intra) {
711 $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("VATIntraShort") . ': ' . $outputlangs->convToOutputCharset($targetcontact->thirdparty->tva_intra);
712 }
713 } elseif (!empty($targetcompany->tva_intra)) {
714 $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
715 }
716 }
717
718 // Legal form
719 if (getDolGlobalString('MAIN_LEGALFORM_IN_ADDRESS') && !empty($targetcompany->forme_juridique_code)) {
720 $tmp = getFormeJuridiqueLabel((string) $targetcompany->forme_juridique_code);
721 $stringaddress .= ($stringaddress ? "\n" : '').$tmp;
722 }
723
724 // Professional Ids
725 if (getDolGlobalString('MAIN_PROFID1_IN_ADDRESS') && !empty($targetcompany->idprof1)) {
726 $tmp = $outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code);
727 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
728 $tmp = $reg[1];
729 }
730 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
731 }
732 if (getDolGlobalString('MAIN_PROFID2_IN_ADDRESS') && !empty($targetcompany->idprof2)) {
733 $tmp = $outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code);
734 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
735 $tmp = $reg[1];
736 }
737 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
738 }
739 if (getDolGlobalString('MAIN_PROFID3_IN_ADDRESS') && !empty($targetcompany->idprof3)) {
740 $tmp = $outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code);
741 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
742 $tmp = $reg[1];
743 }
744 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
745 }
746 if (getDolGlobalString('MAIN_PROFID4_IN_ADDRESS') && !empty($targetcompany->idprof4)) {
747 $tmp = $outputlangs->transcountrynoentities("ProfId4", $targetcompany->country_code);
748 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
749 $tmp = $reg[1];
750 }
751 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
752 }
753 if (getDolGlobalString('MAIN_PROFID5_IN_ADDRESS') && !empty($targetcompany->idprof5)) {
754 $tmp = $outputlangs->transcountrynoentities("ProfId5", $targetcompany->country_code);
755 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
756 $tmp = $reg[1];
757 }
758 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
759 }
760 if (getDolGlobalString('MAIN_PROFID6_IN_ADDRESS') && !empty($targetcompany->idprof6)) {
761 $tmp = $outputlangs->transcountrynoentities("ProfId6", $targetcompany->country_code);
762 if (preg_match('/\‍((.+)\‍)/', $tmp, $reg)) {
763 $tmp = $reg[1];
764 }
765 $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
766 }
767
768 // Public note
769 if (getDolGlobalString('MAIN_PUBLIC_NOTE_IN_ADDRESS')) {
770 if ($mode == 'source' && !empty($sourcecompany->note_public)) {
771 $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($sourcecompany->note_public);
772 }
773 if (($mode == 'target' || $mode == 'targetshipping' || preg_match('/targetwithdetails/', $mode)) && !empty($targetcompany->note_public)) {
774 $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($targetcompany->note_public);
775 }
776 }
777 }
778 }
779
780 return $stringaddress;
781}
782
783
792function pdf_pagehead($pdf, $outputlangs, $page_height)
793{
794 global $conf;
795
796 // Add a background image on document only if good setup of const
797 if (getDolGlobalString('MAIN_USE_BACKGROUND_ON_PDF') && (getDolGlobalString('MAIN_USE_BACKGROUND_ON_PDF') != '-1')) { // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
798 $filepath = $conf->mycompany->dir_output.'/logos/' . getDolGlobalString('MAIN_USE_BACKGROUND_ON_PDF');
799 if (file_exists($filepath)) {
800 $pdf->setAutoPageBreak(false, 0); // Disable auto pagebreak before adding image
801 if (getDolGlobalString('MAIN_USE_BACKGROUND_ON_PDF_ALPHA')) {
802 $pdf->SetAlpha(getDolGlobalFloat('MAIN_USE_BACKGROUND_ON_PDF_ALPHA'));
803 } // Option for change opacity of background
804 $pdf->Image($filepath, getDolGlobalFloat('MAIN_USE_BACKGROUND_ON_PDF_X'), getDolGlobalFloat('MAIN_USE_BACKGROUND_ON_PDF_Y'), 0, $page_height);
805 if (getDolGlobalString('MAIN_USE_BACKGROUND_ON_PDF_ALPHA')) {
806 $pdf->SetAlpha(1);
807 }
808 $pdf->SetPageMark(); // This option avoid to have the images missing on some pages
809 $pdf->setAutoPageBreak(true, 0); // Restore pagebreak
810 }
811 }
812 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND') && getDolGlobalString('MAIN_ADD_PDF_BACKGROUND') != '-1') {
813 $pdf->SetPageMark(); // This option avoid to have the images missing on some pages
814 }
815}
816
817
830function pdfWriteAdditionnalTitle($pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
831{
832 // Transaction/Signature ID + Duplicate or Temporary info
833 include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
834
835 pdfWriteBlockedLogSignature($pdf, $outputlangs, $page_height, $object, $w, $posx, $posy);
836}
837
838
855function pdfWriteVATArray($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl)
856{
857 global $mysoc;
858
859 $tmpatleastoneratenotnull = 0;
860
861 // Local tax 1 before VAT
862 foreach ($docgenerator->localtax1 as $localtax_type => $localtax_rate) {
863 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
864 continue;
865 }
866
867 foreach ($localtax_rate as $tvakey => $tvaval) {
868 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
869 //$tmpatleastoneratenotnull++;
870
871 $index++;
872 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
873
874 $tvacompl = '';
875 if (preg_match('/\*/', (string) $tvakey)) {
876 $tvakey = str_replace('*', '', (string) $tvakey);
877 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
878 }
879
880 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
881 $totalvat .= ' ';
882
883 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
884 $totalvat .= $tvacompl;
885 } else {
886 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
887 }
888
889 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
890
891 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
892
893 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
894 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
895 }
896 }
897 }
898
899 // Local tax 2 before VAT
900 foreach ($docgenerator->localtax2 as $localtax_type => $localtax_rate) {
901 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
902 continue;
903 }
904
905 foreach ($localtax_rate as $tvakey => $tvaval) {
906 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
907 //$tmpatleastoneratenotnull++;
908
909 $index++;
910 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
911
912 $tvacompl = '';
913 if (preg_match('/\*/', (string) $tvakey)) {
914 $tvakey = str_replace('*', '', (string) $tvakey);
915 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
916 }
917 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
918 $totalvat .= ' ';
919
920 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
921 $totalvat .= $tvacompl;
922 } else {
923 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
924 }
925
926 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
927
928 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
929
930 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
931 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
932 }
933 }
934 }
935
936 // Situations totals might be wrong on huge amounts with old mode 1
937 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
938 $sum_pdf_tva = 0;
939 foreach ($docgenerator->tva as $tvakey => $tvaval) {
940 $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
941 }
942
943 if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
944 if (!empty($sum_pdf_tva)) {
945 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
946 } else {
947 $coef_fix_tva = 1;
948 }
949
950
951 foreach ($docgenerator->tva as $tvakey => $tvaval) {
952 $docgenerator->tva[$tvakey] = $tvaval * $coef_fix_tva;
953 }
954 foreach ($docgenerator->tva_array as $tvakey => $tvaval) {
955 $docgenerator->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
956 }
957 }
958 }
959
960 if (!getDolGlobalInt('PDF_INVOICE_SHOW_VAT_ANALYSIS')) { // by default, we show detail of vat here
961 // VAT
962 foreach ($docgenerator->tva_array as $tvakey => $tvaval) {
963 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_VAT_LINE_IF_ZERO')) {
964 $tmpatleastoneratenotnull++;
965
966 $index++;
967 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
968
969 $tvacompl = '';
970 if (preg_match('/\*/', $tvakey)) {
971 $tvakey = str_replace('*', '', $tvakey);
972 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
973 }
974 $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
975 $totalvat .= ' ';
976 if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
977 $totalvat .= vatrate((string) $tvaval['vatrate'], true).$tvacompl;
978 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
979 $totalvat .= $tvaval['vatcode'].$tvacompl;
980 } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
981 $totalvat .= $tvacompl;
982 } else {
983 $totalvat .= vatrate((string) $tvaval['vatrate'], true).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
984 }
985
986 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
987
988 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
989
990 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', true);
991 }
992 }
993 }
994
995 // Local tax 1 after VAT
996 foreach ($docgenerator->localtax1 as $localtax_type => $localtax_rate) {
997 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
998 continue;
999 }
1000
1001 foreach ($localtax_rate as $tvakey => $tvaval) {
1002 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1003 //$tmpatleastoneratenotnull++;
1004
1005 $index++;
1006 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1007
1008 $tvacompl = '';
1009 if (preg_match('/\*/', (string) $tvakey)) {
1010 $tvakey = str_replace('*', '', (string) $tvakey);
1011 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1012 }
1013 $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1014 $totalvat .= ' ';
1015
1016 if (getDolGlobalString('PDF_LOCALTAX1_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1017 $totalvat .= $tvacompl;
1018 } else {
1019 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1020 }
1021
1022 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1023
1024 $total_localtax = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1025
1026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1027 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1028 }
1029 }
1030 }
1031
1032 // Local tax 2 after VAT
1033 foreach ($docgenerator->localtax2 as $localtax_type => $localtax_rate) {
1034 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1035 continue;
1036 }
1037
1038 foreach ($localtax_rate as $tvakey => $tvaval) {
1039 // retrieve global local tax
1040 if ($tvakey != 0 || getDolGlobalString('INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1041 //$tmpatleastoneratenotnull++;
1042
1043 $index++;
1044 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1045
1046 $tvacompl = '';
1047 if (preg_match('/\*/', (string) $tvakey)) {
1048 $tvakey = str_replace('*', '', (string) $tvakey);
1049 $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1050 }
1051 $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1052 $totalvat .= ' ';
1053
1054 if (getDolGlobalString('PDF_LOCALTAX2_LABEL_IS_CODE_OR_RATE') == 'nocodenorate') {
1055 $totalvat .= $tvacompl;
1056 } else {
1057 $totalvat .= vatrate((string) abs((float) $tvakey), true).$tvacompl;
1058 }
1059
1060 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', true);
1061
1062 $total_localtax = ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? price2num($tvaval * $object->multicurrency_tx, 'MT') : $tvaval);
1063
1064 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1065 $pdf->MultiCell($largcol2, $tab2_hl, price($total_localtax, 0, $outputlangs), 0, 'R', true);
1066 }
1067 }
1068 }
1069
1070 $docgenerator->atleastoneratenotnull = $tmpatleastoneratenotnull;
1071}
1072
1073
1095function pdfWriteAlreadyPaid($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin)
1096{
1097 global $mysoc;
1098
1099 $useborder = 0;
1100
1101 if ((($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS'))
1102 || isALNERunningVersion()) {
1103 // Already paid + Deposits
1104 $index++;
1105 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1106 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', false);
1107 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1108 //if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1109 $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
1110 //} else {
1111 // $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', false);
1112 //
1113 // $index++;
1114 // $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1115 // $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
1116
1117 // $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1118 // $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle_origin + $depositsamount_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
1119 //}
1120
1121 // Credit note
1122 if ($creditnoteamount) {
1123 $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1124 $labeltouse .= (is_object($outputlangsbis) ? (' / '.(($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes"))) : '');
1125 $index++;
1126 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1127 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', false);
1128 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1129 $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', false);
1130 }
1131
1132 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1133 $index++;
1134 $pdf->SetFillColor(255, 255, 255);
1135
1136 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1137 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', true);
1138 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1139 $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'), 0, $outputlangs), $useborder, 'R', true);
1140
1141 $resteapayer = 0;
1142 $resteapayer_origin = 0;
1143 }
1144
1145 $index++;
1146 $pdf->SetTextColor(0, 0, 60);
1147 $pdf->SetFillColor(224, 224, 224);
1148 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1149 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', true);
1150 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1151 if (!isModEnabled("multicurrency") || $object->multicurrency_tx == 1 || getDolGlobalInt('MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1152 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
1153 } else {
1154 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', true);
1155
1156 //$pdf->MultiCell($largcol2, $tab2_hl, '('.price($resteapayer_origin, 0, $outputlangs, 1, -1, 'MT', $mysoc->currency_code).') '.price($resteapayer, 0, $outputlangs), 0, 'R', true);
1157 $index++;
1158 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1159 $pdf->SetTextColor(0, 0, 60);
1160 $pdf->SetFillColor(224, 224, 224);
1161 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : '').' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).')', $useborder, 'L', true);
1162
1163 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1164 $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder, 'L', true);
1165 }
1166 }
1167}
1168
1169
1180function pdf_getSubstitutionArray($outputlangs, $exclude = null, $object = null, $onlykey = 0, $include = null)
1181{
1182 $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object, $include);
1183 $substitutionarray['__FROM_NAME__'] = '__FROM_NAME__';
1184 $substitutionarray['__FROM_EMAIL__'] = '__FROM_EMAIL__';
1185 return $substitutionarray;
1186}
1187
1188
1200function pdf_watermark($pdf, $outputlangs, $h, $w, $unit, $text)
1201{
1202 // Print Draft Watermark
1203 if ($unit == 'pt') {
1204 $k = 1;
1205 } elseif ($unit == 'mm') {
1206 $k = 72 / 25.4;
1207 } elseif ($unit == 'cm') {
1208 $k = 72 / 2.54;
1209 } elseif ($unit == 'in') {
1210 $k = 72;
1211 } else {
1212 $k = 1;
1213 dol_print_error(null, 'Unexpected unit "'.$unit.'" for pdf_watermark');
1214 }
1215
1216 // Make substitution
1217 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, null);
1218 complete_substitutions_array($substitutionarray, $outputlangs, null);
1219 $text = make_substitutions($text, $substitutionarray, $outputlangs);
1220 $text = $outputlangs->convToOutputCharset($text);
1221
1222 $savx = $pdf->getX();
1223 $savy = $pdf->getY();
1224
1225 $watermark_angle = atan($h / $w) / 2;
1226 $watermark_x_pos = 0;
1227 $watermark_y_pos = $h / 3;
1228 $watermark_x = $w / 2;
1229 $watermark_y = $h / 3;
1230 $pdf->SetFont('', 'B', 40);
1231 $pdf->SetTextColor(255, 0, 0);
1232
1233 // rotate
1234 $pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', cos($watermark_angle), sin($watermark_angle), -sin($watermark_angle), cos($watermark_angle), $watermark_x * $k, ($h - $watermark_y) * $k, -$watermark_x * $k, -($h - $watermark_y) * $k));
1235 // print watermark
1236 $pdf->SetAlpha(0.5);
1237 $pdf->SetXY($watermark_x_pos, $watermark_y_pos);
1238
1239 // set alpha to semi-transparency
1240 $pdf->SetAlpha(0.3);
1241 $pdf->Cell($w - 20, 25, $outputlangs->convToOutputCharset($text), "", 2, "C", false);
1242
1243 // antirotate
1244 $pdf->_out('Q');
1245
1246 $pdf->SetXY($savx, $savy);
1247
1248 // Restore alpha
1249 $pdf->SetAlpha(1);
1250}
1251
1252
1264function pdfCertifMention($pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
1265{
1266 include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
1267
1268 return pdfCertifMentionblockedLog($pdf, $outputlangs, $seller, $default_font_size, $posy, $pdftemplate);
1269}
1270
1271
1286function pdf_bank($pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0, $default_font_size = 10)
1287{
1288 global $hookmanager;
1289
1290 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
1291
1292 if (is_object($hookmanager)) {
1293 $parameters = array('pdf' => $pdf, 'outputlangs' => $outputlangs, 'curx' => $curx, 'cury' => $cury, 'onlynumber' => $onlynumber, 'default_font_size' => $default_font_size);
1294 $action = '';
1295 $reshook = $hookmanager->executeHooks('pdf_bank', $parameters, $account, $action); // Note that $action and $account may have been modified by some hooks
1296 if ($reshook > 0) {
1297 return isset($hookmanager->resArray['posy']) ? (float) $hookmanager->resArray['posy'] : $cury;
1298 }
1299 }
1300
1301 $diffsizetitle = getDolGlobalInt('PDF_DIFFSIZE_TITLE', 3);
1302 $diffsizecontent = getDolGlobalInt('PDF_DIFFSIZE_CONTENT', 4);
1303 $pdf->SetXY($curx, $cury);
1304
1305 if (empty($onlynumber)) {
1306 $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1307 $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', false);
1308 $cury += 4;
1309 }
1310
1311 $outputlangs->load("banks");
1312
1313 // Use correct name of bank id according to country
1314 $bickey = "BICNumber";
1315 if ($account->getCountryCode() == 'IN') {
1316 $bickey = "SWIFT";
1317 }
1318
1319 // Get format of bank account according to its country
1320 $usedetailedbban = $account->useDetailedBBAN();
1321
1322 //$onlynumber=0; $usedetailedbban=1; // For tests
1323 if ($usedetailedbban) {
1324 $savcurx = $curx;
1325
1326 if (empty($onlynumber)) {
1327 $pdf->SetFont('', '', $default_font_size - $diffsizecontent);
1328 $pdf->SetXY($curx, $cury);
1329 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', false);
1330 $cury += 3;
1331 }
1332
1333 if (!getDolGlobalString('PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN')) { // Note that some countries still need bank number, BIC/IBAN not enough for them
1334 // Note:
1335 // bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
1336 // desk = code guichet (FR), used only when $usedetailedbban = 1
1337 // number = account number
1338 // key = check control key used only when $usedetailedbban = 1
1339 if (empty($onlynumber)) {
1340 $pdf->line($curx + 1, $cury + 1, $curx + 1, $cury + 6);
1341 }
1342
1343 $bank_number_length = 0;
1344 foreach ($account->getFieldsToShow() as $val) {
1345 $pdf->SetXY($curx, $cury + 4);
1346 $pdf->SetFont('', '', $default_font_size - 3);
1347
1348 if ($val == 'BankCode') {
1349 // Bank code
1350 $tmplength = 18;
1351 $content = $account->code_banque;
1352 } elseif ($val == 'DeskCode') {
1353 // Desk
1354 $tmplength = 18;
1355 $content = $account->code_guichet;
1356 } elseif ($val == 'BankAccountNumber') {
1357 // Number
1358 $tmplength = 24;
1359 $content = $account->number;
1360 } elseif ($val == 'BankAccountNumberKey') {
1361 // Key
1362 $tmplength = 15;
1363 $content = $account->cle_rib;
1364 } elseif ($val == 'IBAN' || $val == 'BIC') {
1365 // Key
1366 $tmplength = 0;
1367 $content = '';
1368 } else {
1369 dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
1370 break;
1371 }
1372
1373 if ($content == '') {
1374 continue;
1375 }
1376
1377 $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', false);
1378 $pdf->SetXY($curx, $cury + 1);
1379 $curx += $tmplength;
1380 $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
1381 $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($account->getBankFieldLabel($val)), 0, 'C', false);
1382 if (empty($onlynumber)) {
1383 $pdf->line($curx, $cury + 1, $curx, $cury + 7);
1384 }
1385
1386 // Only set this variable when table was printed
1387 $bank_number_length = 8;
1388 }
1389
1390 $curx = $savcurx;
1391 $cury += $bank_number_length;
1392 }
1393 } elseif (!empty($account->number)) {
1394 $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
1395 $pdf->SetXY($curx, $cury);
1396 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', false);
1397 $cury += 3;
1398
1399 $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
1400 $pdf->SetXY($curx, $cury);
1401 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': '.$outputlangs->convToOutputCharset($account->number), 0, 'L', false);
1402 $cury += 3;
1403
1404 if ($diffsizecontent <= 2) {
1405 $cury += 1;
1406 }
1407 }
1408
1409 $pdf->SetFont('', '', $default_font_size - $diffsizecontent);
1410
1411 if (empty($onlynumber) && !empty($account->address)) {
1412 $pdf->SetXY($curx, $cury);
1413 $val = $outputlangs->transnoentities("Residence").': '.$outputlangs->convToOutputCharset($account->address);
1414 $pdf->MultiCell(100, 3, $val, 0, 'L', false);
1415 //$nboflines=dol_nboflines_bis($val,120);
1416 //$cury+=($nboflines*3)+2;
1417 $tmpy = $pdf->getStringHeight(100, $val);
1418 $cury += $tmpy;
1419 }
1420
1421 if (!empty($account->owner_name)) {
1422 $pdf->SetXY($curx, $cury);
1423 $val = $outputlangs->transnoentities("BankAccountOwner").': '.$outputlangs->convToOutputCharset($account->owner_name);
1424 $pdf->MultiCell(100, 3, $val, 0, 'L', false);
1425 $tmpy = $pdf->getStringHeight(100, $val);
1426 $cury += $tmpy;
1427 } elseif (!$usedetailedbban) {
1428 $cury += 1;
1429 }
1430
1431 // Use correct name of bank id according to country
1432 $ibankey = FormBank::getIBANLabel($account);
1433
1434 if (!empty($account->iban)) {
1435 //Remove whitespaces to ensure we are dealing with the format we expect
1436 $ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
1437 $ibanDisplay = "";
1438
1439 $nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
1440 for ($i = 0; $i < $nbIbanDisplay_temp; $i++) {
1441 $ibanDisplay .= $ibanDisplay_temp[$i];
1442 if ($i % 4 == 3 && $i > 0) {
1443 $ibanDisplay .= " ";
1444 }
1445 }
1446
1447 $pdf->SetFont('', 'B', $default_font_size - 3);
1448 $pdf->SetXY($curx, $cury);
1449 $pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': '.$ibanDisplay, 0, 'L', false);
1450 $cury += 3;
1451 }
1452
1453 if (!empty($account->bic)) {
1454 $pdf->SetFont('', 'B', $default_font_size - 3);
1455 $pdf->SetXY($curx, $cury);
1456 $pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': '.$outputlangs->convToOutputCharset($account->bic), 0, 'L', false);
1457 }
1458
1459 return $pdf->getY();
1460}
1461
1479function pdf_pagefoot($pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0, $hidefreetext = 0, $page_largeur = 0, $watermark = '')
1480{
1481 global $conf, $hookmanager;
1482
1483 $outputlangs->load("dict");
1484 $line = '';
1485 $reg = array();
1486 $marginwithfooter = 0; // Return value
1487
1488 $dims = $pdf->getPageDimensions();
1489
1490 // Line of free text
1491 if (empty($hidefreetext) && getDolGlobalString($paramfreetext)) {
1492 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
1493 // More substitution keys
1494 if (is_object($fromcompany)) {
1495 $substitutionarray['__FROM_NAME__'] = $fromcompany->name;
1496 $substitutionarray['__FROM_EMAIL__'] = $fromcompany->email;
1497 }
1498 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1499 $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray, $outputlangs);
1500
1501 // Make a change into HTML code to allow to include images from medias directory.
1502 // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
1503 // become
1504 // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
1505 $newfreetext = preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1file:/'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
1506
1507 $line .= $outputlangs->convToOutputCharset($newfreetext);
1508 }
1509
1510 // First line of company infos
1511 $line1 = "";
1512 $line2 = "";
1513 $line3 = "";
1514 $line4 = "";
1515
1516 if (is_object($fromcompany) && in_array($showdetails, array(1, 3))) {
1517 // Company name
1518 if ($fromcompany->name) {
1519 $line1 .= ($line1 ? " - " : "").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
1520 }
1521 // Address
1522 if ($fromcompany->address) {
1523 $line1 .= ($line1 ? " - " : "").str_replace("\n", ", ", $fromcompany->address);
1524 }
1525 // Zip code
1526 if ($fromcompany->zip) {
1527 $line1 .= ($line1 ? " - " : "").$fromcompany->zip;
1528 }
1529 // Town
1530 if ($fromcompany->town) {
1531 $line1 .= ($line1 ? " " : "").$fromcompany->town;
1532 }
1533 // Country
1534 if ($fromcompany->country) {
1535 $line1 .= ($line1 ? ", " : "").$fromcompany->country;
1536 }
1537 // Phone
1538 if ($fromcompany->phone) {
1539 $line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
1540 }
1541 // Fax
1542 if ($fromcompany->fax) {
1543 $line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
1544 }
1545
1546 // URL
1547 if ($fromcompany->url) {
1548 $line2 .= ($line2 ? " - " : "").$fromcompany->url;
1549 }
1550 // Email
1551 if ($fromcompany->email) {
1552 $line2 .= ($line2 ? " - " : "").$fromcompany->email;
1553 }
1554 }
1555 if ($showdetails == 2 || $showdetails == 3 || (!empty($fromcompany->country_code) && $fromcompany->country_code == 'DE')) {
1556 // Managers
1557 if ($fromcompany->managers) {
1558 $line2 .= ($line2 ? " - " : "").$fromcompany->managers;
1559 }
1560 }
1561
1562 // Line 3 of company infos
1563 // Juridical status
1564 if (!empty($fromcompany->forme_juridique_code)) {
1565 $line3 .= ($line3 ? " - " : "").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel((string) $fromcompany->forme_juridique_code));
1566 }
1567 // Capital
1568 if (!empty($fromcompany->capital)) {
1569 $tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string or a float
1570 if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) {
1571 $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, getDolCurrency()));
1572 } elseif (!empty($fromcompany->capital)) {
1573 $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", (string) $fromcompany->capital);
1574 }
1575 }
1576 // Prof Id 1
1577 if (!empty($fromcompany->idprof1) && ($fromcompany->country_code != 'FR' || (empty($fromcompany->idprof2) || strpos($fromcompany->idprof2, $fromcompany->idprof1) !== 0))) {
1578 $field = $outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
1579 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1580 $field = $reg[1];
1581 }
1582 $line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
1583 }
1584 // Prof Id 2
1585 if (!empty($fromcompany->idprof2)) {
1586 $field = $outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
1587 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1588 $field = $reg[1];
1589 }
1590 $line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
1591 }
1592
1593 // Line 4 of company infos
1594 // Prof Id 3
1595 if (!empty($fromcompany->idprof3)) {
1596 $field = $outputlangs->transcountrynoentities("ProfId3", $fromcompany->country_code);
1597 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1598 $field = $reg[1];
1599 }
1600 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
1601 }
1602 // Prof Id 4
1603 if (!empty($fromcompany->idprof4)) {
1604 $field = $outputlangs->transcountrynoentities("ProfId4", $fromcompany->country_code);
1605 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1606 $field = $reg[1];
1607 }
1608 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
1609 }
1610 // Prof Id 5
1611 if (!empty($fromcompany->idprof5)) {
1612 $field = $outputlangs->transcountrynoentities("ProfId5", $fromcompany->country_code);
1613 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1614 $field = $reg[1];
1615 }
1616 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
1617 }
1618 // Prof Id 6
1619 if (!empty($fromcompany->idprof6)) {
1620 $field = $outputlangs->transcountrynoentities("ProfId6", $fromcompany->country_code);
1621 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1622 $field = $reg[1];
1623 }
1624 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
1625 }
1626 // Prof Id 7
1627 if (!empty($fromcompany->idprof7)) {
1628 $field = $outputlangs->transcountrynoentities("ProfId7", $fromcompany->country_code);
1629 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1630 $field = $reg[1];
1631 }
1632 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof7);
1633 }
1634 // Prof Id 8
1635 if (!empty($fromcompany->idprof8)) {
1636 $field = $outputlangs->transcountrynoentities("ProfId8", $fromcompany->country_code);
1637 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1638 $field = $reg[1];
1639 }
1640 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof8);
1641 }
1642 // Prof Id 9
1643 if (!empty($fromcompany->idprof9)) {
1644 $field = $outputlangs->transcountrynoentities("ProfId9", $fromcompany->country_code);
1645 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1646 $field = $reg[1];
1647 }
1648 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof9);
1649 }
1650 // Prof Id 10
1651 if (!empty($fromcompany->idprof10)) {
1652 $field = $outputlangs->transcountrynoentities("ProfId10", $fromcompany->country_code);
1653 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
1654 $field = $reg[1];
1655 }
1656 $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof10);
1657 }
1658 // IntraCommunautary VAT
1659 if (!empty($fromcompany->tva_intra) && $fromcompany->tva_intra != '') {
1660 $line4 .= ($line4 ? " - " : "").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
1661 }
1662
1663 $pdf->SetFont('', '', 7);
1664 $pdf->SetDrawColor(224, 224, 224);
1665 // Option for footer text color
1666 if (getDolGlobalString('PDF_FOOTER_TEXT_COLOR')) {
1667 $tmparray = sscanf(getDolGlobalString('PDF_FOOTER_TEXT_COLOR'), '%d, %d, %d');
1668 $r = $tmparray[0];
1669 $g = $tmparray[1];
1670 $b = $tmparray[2];
1671 $pdf->SetTextColor($r, $g, $b);
1672 }
1673
1674 // The start of the bottom of this page footer is positioned according to # of lines
1675 $freetextheight = 0;
1676 $align = '';
1677 if ($line) { // Free text
1678 //$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
1679 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
1680 $width = 20000;
1681 $align = 'L'; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
1682 if (getDolGlobalString('MAIN_USE_AUTOWRAP_ON_FREETEXT')) {
1683 $width = 200;
1684 $align = 'C';
1685 }
1686 $freetextheight = $pdf->getStringHeight($width, $line);
1687 } else {
1688 $freetextheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
1689 //print '<br>'.$freetextheight;
1690 }
1691 }
1692
1693 $posy = 0;
1694 // For customized footer
1695 if (is_object($hookmanager)) {
1696 $parameters = array('line1' => $line1, 'line2' => $line2, 'line3' => $line3, 'line4' => $line4, 'outputlangs' => $outputlangs, 'hidefreetext' => $hidefreetext, 'pdf' => $pdf, 'pagenb' => $pdf->PageNo());
1697 $action = '';
1698 $hookmanager->executeHooks('pdf_pagefoot', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1699 // The footer returned by a hook replaces the default footer on the last page only (the one that shows the free text), unless
1700 // the hook also returns $this->results['footeronallpages'] = 1 to replace it on all pages.
1701 if (!empty($hookmanager->resPrint) && ($hidefreetext == 0 || !empty($hookmanager->resArray['footeronallpages']))) {
1702 $mycustomfooter = $hookmanager->resPrint;
1703 $mycustomfooterheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($mycustomfooter, 1, 'UTF-8', 0));
1704
1705 $marginwithfooter = $marge_basse + $freetextheight + $mycustomfooterheight;
1706 $posy = (float) $marginwithfooter;
1707
1708 // Option for footer background color (without freetext zone)
1709 if (getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1710 $tmparray = sscanf(getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR'), '%d, %d, %d');
1711 $r = $tmparray[0];
1712 $g = $tmparray[1];
1713 $b = $tmparray[2];
1714 $pdf->setAutoPageBreak(false, 0); // Disable auto pagebreak
1715 $pdf->Rect(0, $dims['hk'] - $posy + $freetextheight, $dims['wk'] + 1, $marginwithfooter + 1, 'F', array(), $fill_color = array($r, $g, $b));
1716 $pdf->setAutoPageBreak(true, 0); // Restore pagebreak
1717 }
1718
1719 if (getDolGlobalInt('PDF_FREETEXT_DISABLE_PAGEBREAK') === 1) {
1720 $pdf->setAutoPageBreak(false, 0);
1721 } // Option for disable auto pagebreak
1722 if ($line) { // Free text
1723 $pdf->SetXY($dims['lm'], -$posy);
1724 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) { // by default
1725 $pdf->MultiCell(0, 3, $line, 0, $align, false);
1726 } else {
1727 $pdf->writeHTMLCell($dims['wk'] - $dims['lm'] - $dims['rm'], $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1728 }
1729 $posy -= $freetextheight;
1730 }
1731 if (getDolGlobalInt('PDF_FREETEXT_DISABLE_PAGEBREAK') === 1) {
1732 $pdf->setAutoPageBreak(true, 0);
1733 } // Restore pagebreak
1734
1735 $pdf->SetY(-$posy);
1736
1737 // Hide footer line if footer background color is set
1738 if (!getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1739 $pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
1740 }
1741
1742 // Option for set top margin height of footer after freetext
1743 if (getDolGlobalString('PDF_FOOTER_TOP_MARGIN') || getDolGlobalInt('PDF_FOOTER_TOP_MARGIN') === 0) {
1744 $posy -= (float) getDolGlobalString('PDF_FOOTER_TOP_MARGIN');
1745 } else {
1746 $posy--;
1747 }
1748
1749 if (getDolGlobalInt('PDF_FOOTER_DISABLE_PAGEBREAK') === 1) {
1750 $pdf->setAutoPageBreak(false, 0);
1751 } // Option for disable auto pagebreak
1752 $pdf->writeHTMLCell($dims['wk'] - $dims['lm'] - $dims['rm'], $mycustomfooterheight, $dims['lm'], $dims['hk'] - $posy, dol_htmlentitiesbr($mycustomfooter, 1, 'UTF-8', 0));
1753 if (getDolGlobalInt('PDF_FOOTER_DISABLE_PAGEBREAK') === 1) {
1754 $pdf->setAutoPageBreak(true, 0);
1755 } // Restore pagebreak
1756
1757 $posy -= $mycustomfooterheight - 3;
1758 } else {
1759 // Else default footer
1760 $marginwithfooter = $marge_basse + $freetextheight + (!empty($line1) ? 3 : 0) + (!empty($line2) ? 3 : 0) + (!empty($line3) ? 3 : 0) + (!empty($line4) ? 3 : 0);
1761 $posy = (float) $marginwithfooter;
1762
1763 // Option for footer background color (without freetext zone)
1764 if (getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1765 $tmparray = sscanf(getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR'), '%d, %d, %d');
1766 $r = $tmparray[0];
1767 $g = $tmparray[1];
1768 $b = $tmparray[2];
1769 $pdf->setAutoPageBreak(false, 0); // Disable auto pagebreak
1770 $pdf->Rect(0, $dims['hk'] - $posy + $freetextheight, $dims['wk'] + 1, $marginwithfooter + 1, 'F', array(), $fill_color = array($r, $g, $b));
1771 $pdf->setAutoPageBreak(true, 0); // Restore pagebreak
1772 }
1773
1774 if (getDolGlobalInt('PDF_FREETEXT_DISABLE_PAGEBREAK') === 1) {
1775 $pdf->setAutoPageBreak(false, 0);
1776 } // Option for disable auto pagebreak
1777 if ($line) { // Free text
1778 $pdf->SetXY($dims['lm'], -$posy);
1779 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) { // by default
1780 $pdf->MultiCell(0, 3, $line, 0, $align, false);
1781 } else {
1782 $pdf->writeHTMLCell($dims['wk'] - $dims['lm'] - $dims['rm'], $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1783 }
1784 $posy -= $freetextheight;
1785 }
1786 if (getDolGlobalInt('PDF_FREETEXT_DISABLE_PAGEBREAK') === 1) {
1787 $pdf->setAutoPageBreak(true, 0);
1788 } // Restore pagebreak
1789
1790 $pdf->SetY(-$posy);
1791
1792 // Option for hide all footer (page number will no hidden)
1793 if (!getDolGlobalInt('PDF_FOOTER_HIDDEN')) {
1794 // Hide footer line if footer background color is set
1795 if (!getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1796 $pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
1797 }
1798
1799 // Option for set top margin height of footer after freetext
1800 if (getDolGlobalString('PDF_FOOTER_TOP_MARGIN') || getDolGlobalInt('PDF_FOOTER_TOP_MARGIN') === 0) {
1801 $posy -= (float) getDolGlobalString('PDF_FOOTER_TOP_MARGIN');
1802 } else {
1803 $posy--;
1804 }
1805
1806 if (!empty($line1)) {
1807 $pdf->SetFont('', 'B', 7);
1808 $pdf->SetXY($dims['lm'], -$posy);
1809 $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line1, 0, 'C', false);
1810 $posy -= 3;
1811 $pdf->SetFont('', '', 7);
1812 }
1813
1814 if (!empty($line2)) {
1815 $pdf->SetFont('', 'B', 7);
1816 $pdf->SetXY($dims['lm'], -$posy);
1817 $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line2, 0, 'C', false);
1818 $posy -= 3;
1819 $pdf->SetFont('', '', 7);
1820 }
1821
1822 if (!empty($line3)) {
1823 $pdf->SetXY($dims['lm'], -$posy);
1824 $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line3, 0, 'C', false);
1825 }
1826
1827 if (!empty($line4)) {
1828 $posy -= 3;
1829 $pdf->SetXY($dims['lm'], -$posy);
1830 $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line4, 0, 'C', false);
1831 }
1832 }
1833 }
1834 }
1835
1836 // Show page nb and apply correction for some font.
1837 $pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));
1838
1839 $pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages();
1840 $fontRenderCorrection = 0;
1841 if (in_array(pdf_getPDFFont($outputlangs), array('freemono', 'DejaVuSans'))) {
1842 $fontRenderCorrection = 10;
1843 }
1844 $pdf->MultiCell(18 + $fontRenderCorrection, 2, $pagination, 0, 'R', false);
1845
1846 // Show Draft Watermark
1847 if (!empty($watermark)) {
1848 pdf_watermark($pdf, $outputlangs, $page_hauteur, $page_largeur, 'mm', $watermark);
1849 }
1850
1851 return $marginwithfooter;
1852}
1853
1870function pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
1871{
1872 global $hookmanager;
1873
1874 if (is_object($hookmanager)) {
1875 $parameters = array('pdf' => $pdf, 'outputlangs' => $outputlangs, 'posx' => $posx, 'posy' => $posy, 'w' => $w, 'h' => $h, 'align' => $align, 'default_font_size' => $default_font_size);
1876 $action = '';
1877 $reshook = $hookmanager->executeHooks('pdf_writeLinkedObjects', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1878 if ($reshook > 0) {
1879 return isset($hookmanager->resArray['posy']) ? (float) $hookmanager->resArray['posy'] : $pdf->getY();
1880 }
1881 }
1882
1883 $linkedobjects = pdf_getLinkedObjects($object, $outputlangs); // May update $object->note_public
1884
1885 if (!empty($linkedobjects)) {
1886 foreach ($linkedobjects as $linkedobject) {
1887 $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
1888 if (!empty($linkedobject["date_value"])) {
1889 $reftoshow .= ' / '.$linkedobject["date_value"];
1890 }
1891
1892 $posy += 3;
1893 $pdf->SetXY($posx, $posy);
1894 $pdf->SetFont('', '', (float) $default_font_size - 2);
1895 $pdf->MultiCell($w, $h, $reftoshow, '', $align);
1896 }
1897 }
1898
1899 return $pdf->getY();
1900}
1901
1919function pdf_writelinedesc($pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref = 0, $hidedesc = 0, $issupplierline = 0, $align = 'J')
1920{
1921 global $hookmanager;
1922
1923 $reshook = 0;
1924 $result = '';
1925 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
1926 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
1927 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
1928 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1929 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1930 }
1931 $parameters = array('pdf' => $pdf, 'i' => $i, 'outputlangs' => $outputlangs, 'w' => $w, 'h' => $h, 'posx' => $posx, 'posy' => $posy, 'hideref' => $hideref, 'hidedesc' => $hidedesc, 'issupplierline' => $issupplierline, 'special_code' => $special_code);
1932 $action = '';
1933 // WARNING: A hook must not close/open the PDF transaction. Doing this generates a lot of trouble.
1934 // Test to know if content added by the hooks is already done by the main caller of pdf_writelinedesc
1935 $reshook = $hookmanager->executeHooks('pdf_writelinedesc', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1936
1937 if (!empty($hookmanager->resPrint)) {
1938 $result .= $hookmanager->resPrint;
1939 }
1940 }
1941 if (empty($reshook)) {
1942 $labelproductservice = pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1943 $labelproductservice = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)/', '\1file:/'.DOL_DATA_ROOT.'/medias/\2\3', $labelproductservice, -1, $nbrep);
1944
1945 //var_dump($labelproductservice);exit;
1946
1947 // Fix bug of some HTML editors that replace links <img src="http://localhostgit/viewimage.php?modulepart=medias&file=image/efd.png" into <img src="http://localhostgit/viewimage.php?modulepart=medias&amp;file=image/efd.png"
1948 // We make the reverse, so PDF generation has the real URL.
1949 $nbrep = 0;
1950 $labelproductservice = preg_replace('/(<img[^>]*src=")([^"]*)(&amp;)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep);
1951
1952 if (getDolGlobalString('MARGIN_TOP_ZERO_UL')) {
1953 $pdf->setListIndentWidth(5);
1954 $TMarginList = ['ul' => [['h' => 0.1, ],['h' => 0.1, ]], 'li' => [['h' => 0.1, ],],];
1955 $pdf->setHtmlVSpace($TMarginList);
1956 }
1957
1958 // Description
1959 $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, $align, true);
1960 $result .= $labelproductservice;
1961 }
1962 return $result;
1963}
1964
1976function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1977{
1978 global $db, $conf, $langs;
1979
1980 $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false);
1981 $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : ''));
1982 $product_barcode = (!empty($object->lines[$i]->product_barcode) ? $object->lines[$i]->product_barcode : "");
1983 $desc = (!empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : ''));
1984 $ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders
1985 $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : '');
1986 $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false);
1987
1988 $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS');
1989
1990 if ($issupplierline) {
1991 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
1992 $prodser = new ProductFournisseur($db);
1993 } else {
1994 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1995 $prodser = new Product($db);
1996
1997 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
1998 include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
1999 }
2000 }
2001
2002 //id
2003 $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false);
2004 if ($idprod) {
2005 $prodser->fetch($idprod);
2006 //load multilangs
2007 if ($multilangsactive) {
2008 $prodser->getMultiLangs();
2009 $object->lines[$i]->multilangs = $prodser->multilangs;
2010 }
2011 }
2012 //label
2013 if (!empty($object->lines[$i]->label)) {
2014 $label = $object->lines[$i]->label;
2015 } else {
2016 if (!empty($object->lines[$i]->multilangs[$outputlangs->defaultlang]['label']) && $multilangsactive) {
2017 $label = $object->lines[$i]->multilangs[$outputlangs->defaultlang]['label'];
2018 } else {
2019 if (!empty($object->lines[$i]->product_label)) {
2020 $label = $object->lines[$i]->product_label;
2021 } else {
2022 $label = '';
2023 }
2024 }
2025 }
2026 //description
2027 if (!empty($object->lines[$i]->desc)) {
2028 $desc = $object->lines[$i]->desc;
2029 } else {
2030 if (!empty($object->lines[$i]->multilangs[$outputlangs->defaultlang]['description']) && $multilangsactive) {
2031 $desc = $object->lines[$i]->multilangs[$outputlangs->defaultlang]['description'];
2032 } else {
2033 if (!empty($object->lines[$i]->description)) {
2034 $desc = $object->lines[$i]->description;
2035 } else {
2036 $desc = '';
2037 }
2038 }
2039 }
2040 //ref supplier
2041 $ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders
2042 //note
2043 $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : '');
2044 //dbatch
2045 $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false);
2046
2047 if ($idprod) {
2048 // If a predefined product and multilang and on other lang, we renamed label with label translated
2049 if ($multilangsactive && ($outputlangs->defaultlang != $langs->defaultlang)) {
2050 $translatealsoifmodified = getDolGlobalString('MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED'); // By default if value was modified manually, we keep it (no translation because we don't have it)
2051
2052 // TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation
2053 // ($textwasnotmodified is replaced with $textwasmodifiedorcompleted and we add completion).
2054
2055 // Set label
2056 // If we want another language, and if label is same than default language (we did not force it to a specific value), we can use translation.
2057 //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
2058 $textwasnotmodified = ($label == $prodser->label);
2059 if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasnotmodified || $translatealsoifmodified)) {
2060 $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
2061 }
2062
2063 // Set desc
2064 // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
2065 $textwasnotmodified = false;
2066 $textdiffersonlybymarkup = false;
2067 if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
2068 $textwasnotmodified = (strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML5), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML5)) !== false);
2069 } elseif (!empty($desc) && !empty($prodser->description) && dol_textishtml($desc) != dol_textishtml($prodser->description)) {
2070 // One side is HTML and the other is not. This happens as soon as a line is saved while the
2071 // WYSIWYG editor is enabled on line details: the plain product description becomes "<p>...</p>".
2072 // Comparing the raw strings would then report a manual change and silently drop the translation,
2073 // so compare the text content instead.
2074 $desctextonly = trim(dol_html_entity_decode(dol_string_nohtmltag($desc, 1), ENT_QUOTES | ENT_HTML5));
2075 $prodtextonly = trim(dol_html_entity_decode(dol_string_nohtmltag($prodser->description, 1), ENT_QUOTES | ENT_HTML5));
2076 $textwasnotmodified = ($prodtextonly !== '' && strpos($desctextonly, $prodtextonly) !== false);
2077 $textdiffersonlybymarkup = ($textwasnotmodified && $desctextonly === $prodtextonly);
2078 } else {
2079 $textwasnotmodified = ($desc == $prodser->description);
2080 }
2081 if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) {
2082 if ($textwasnotmodified) {
2083 if ($textdiffersonlybymarkup && strpos($desc, $prodser->description) === false) {
2084 // Same text, but wrapped in tags or written with HTML entities: the product description
2085 // is not present verbatim, so the str_replace below would find nothing to replace.
2086 $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
2087 } else {
2088 $desc = str_replace($prodser->description, $prodser->multilangs[$outputlangs->defaultlang]["description"], $desc);
2089 }
2090 } elseif ($translatealsoifmodified) {
2091 $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
2092 }
2093 }
2094
2095 // Set note
2096 $textwasnotmodified = ($note == $prodser->note_public);
2097 if (!empty($prodser->multilangs[$outputlangs->defaultlang]["other"]) && ($textwasnotmodified || $translatealsoifmodified)) {
2098 $note = $prodser->multilangs[$outputlangs->defaultlang]["other"];
2099 }
2100 }
2101 } elseif (($object->element == 'facture' || $object->element == 'facturefourn') && preg_match('/^\‍(DEPOSIT\‍).+/', $desc)) { // We must not replace '(DEPOSIT)' when it is alone, it will be translated and detailed later
2102 $desc = str_replace('(DEPOSIT)', $outputlangs->trans('Deposit'), $desc);
2103 }
2104
2105 $labelproductservice = ''; // Default value
2106 if (!getDolGlobalString('PDF_HIDE_PRODUCT_LABEL_IN_SUPPLIER_LINES')) {
2107 // Description short of product line
2108 $labelproductservice = $label;
2109 if (!empty($labelproductservice) && getDolGlobalString('PDF_BOLD_PRODUCT_LABEL')) {
2110 // Adding <b> may convert the original string into a HTML string. So we have to first
2111 // convert \n into <br> we text is not already HTML.
2112 if (!dol_textishtml($labelproductservice)) {
2113 $labelproductservice = str_replace("\n", '<br>', $labelproductservice);
2114 }
2115 $labelproductservice = '<b>'.$labelproductservice.'</b>';
2116 }
2117 }
2118
2119
2120 // Add ref of subproducts
2121 if (getDolGlobalString('SHOW_SUBPRODUCT_REF_IN_PDF')) {
2122 $prodser->get_sousproduits_arbo();
2123 if (!empty($prodser->sousprods) && is_array($prodser->sousprods) && count($prodser->sousprods)) {
2124 $outputlangs->load('mrp');
2125 $tmparrayofsubproducts = reset($prodser->sousprods);
2126
2127 $qtyText = null;
2128 if (isset($object->lines[$i]->qty) && !empty($object->lines[$i]->qty)) {
2129 $qtyText = $object->lines[$i]->qty;
2130 } elseif (isset($object->lines[$i]->qty_shipped) && !empty($object->lines[$i]->qty_shipped)) {
2131 $qtyText = $object->lines[$i]->qty;
2132 }
2133
2134 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF')) {
2135 foreach ($tmparrayofsubproducts as $subprodval) {
2136 $labelproductservice = dol_concatdesc(
2137 dol_concatdesc($labelproductservice, " * ".$subprodval[3]),
2138 (!empty($qtyText) ?
2139 $outputlangs->trans('Qty').':'.$qtyText.' x '.$outputlangs->trans('AssociatedProducts').':'.$subprodval[1].'= '.$outputlangs->trans('QtyTot').':'.$subprodval[1] * $qtyText :
2140 $outputlangs->trans('Qty').' '.$outputlangs->trans('AssociatedProducts').':'.$subprodval[1])
2141 );
2142 }
2143 } else {
2144 foreach ($tmparrayofsubproducts as $subprodval) {
2145 $labelproductservice = dol_concatdesc(
2146 dol_concatdesc($labelproductservice, " * ".$subprodval[5].(($subprodval[5] && $subprodval[3]) ? ' - ' : '').$subprodval[3]),
2147 (!empty($qtyText) ?
2148 $outputlangs->trans('Qty').':'.$qtyText.' x '.$outputlangs->trans('AssociatedProducts').':'.$subprodval[1].'= '.$outputlangs->trans('QtyTot').':'.$subprodval[1] * $qtyText :
2149 $outputlangs->trans('Qty').' '.$outputlangs->trans('AssociatedProducts').':'.$subprodval[1])
2150 );
2151 }
2152 }
2153 }
2154 }
2155
2156 if (isModEnabled('barcode') && getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_PRODUCT_BARCODE') && !empty($product_barcode)) {
2157 $labelproductservice = dol_concatdesc($labelproductservice, $outputlangs->trans("BarCode")." ".$product_barcode);
2158 }
2159
2160 // Description long of product line
2161 if (!empty($desc) && ($desc != $label)) {
2162 if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) {
2163 $discount = new DiscountAbsolute($db);
2164 $discount->fetch($object->lines[$i]->fk_remise_except);
2165 $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
2166 $labelproductservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
2167 } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) {
2168 $discount = new DiscountAbsolute($db);
2169 $discount->fetch($object->lines[$i]->fk_remise_except);
2170 $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
2171 $labelproductservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
2172 // Add date of deposit
2173 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
2174 $labelproductservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
2175 }
2176 } elseif ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except) {
2177 $discount = new DiscountAbsolute($db);
2178 $discount->fetch($object->lines[$i]->fk_remise_except);
2179 $labelproductservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
2180 } elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except) {
2181 $discount = new DiscountAbsolute($db);
2182 $discount->fetch($object->lines[$i]->fk_remise_except);
2183 $labelproductservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
2184 } else {
2185 if ($idprod) {
2186 // Check if description must be output
2187 if (!empty($object->element)) {
2188 $tmpkey = 'MAIN_DOCUMENTS_HIDE_DESCRIPTION_FOR_'.strtoupper($object->element);
2189 if (getDolGlobalString($tmpkey)) {
2190 $hidedesc = 1;
2191 }
2192 }
2193 if (empty($hidedesc)) {
2194 if (getDolGlobalString('MAIN_DOCUMENTS_DESCRIPTION_FIRST')) {
2195 $labelproductservice = dol_concatdesc($desc, $labelproductservice);
2196 } else {
2197 if (getDolGlobalString('HIDE_LABEL_VARIANT_PDF') && $prodser->isVariant()) {
2198 $labelproductservice = $desc;
2199 } else {
2200 $labelproductservice = dol_concatdesc($labelproductservice, $desc);
2201 }
2202 }
2203 }
2204 } else {
2205 $labelproductservice = dol_concatdesc($labelproductservice, $desc);
2206 }
2207 }
2208 }
2209
2210 // We add ref of product (and supplier ref if defined)
2211 $prefix_prodserv = "";
2212 $ref_prodserv = "";
2213 if (getDolGlobalString('PRODUCT_ADD_TYPE_IN_DOCUMENTS')) { // In standard mode, we do not show this
2214 if ($prodser->isService()) {
2215 $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
2216 } else {
2217 $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
2218 }
2219 }
2220
2221 if (empty($hideref)) {
2222 if ($issupplierline) {
2223 if (!getDolGlobalString('PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES')) { // Common case
2224 $ref_prodserv = $prodser->ref; // Show local ref
2225 if ($ref_supplier) {
2226 $ref_prodserv .= ($prodser->ref ? ' (' : '').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref ? ')' : '');
2227 }
2228 } elseif (getDolGlobalInt('PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES') == 1) {
2229 $ref_prodserv = $ref_supplier;
2230 } elseif (getDolGlobalInt('PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES') == 2) {
2231 $ref_prodserv = $ref_supplier.' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
2232 }
2233 } else {
2234 $ref_prodserv = $prodser->ref; // Show local ref only
2235
2236 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
2237 $productCustomerPriceStatic = new ProductCustomerPrice($db);
2238 $filter = array('fk_product' => (string) $idprod, 'fk_soc' => (string) $object->socid);
2239
2240 $nbCustomerPrices = $productCustomerPriceStatic->fetchAll('', '', 1, 0, $filter);
2241
2242 if ($nbCustomerPrices > 0) {
2243 $productCustomerPrice = null;
2244 if (count($productCustomerPriceStatic->lines) > 0) {
2245 $date_now = (int) floor(dol_now() / 86400) * 86400; // date without hours
2246 foreach ($productCustomerPriceStatic->lines as $k => $custprice_line) {
2247 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
2248 $productCustomerPrice = $custprice_line;
2249 break;
2250 }
2251 }
2252 }
2253
2254 if (isset($productCustomerPrice) && !empty($productCustomerPrice->ref_customer)) {
2255 $idcustprice = getDolGlobalInt('PRODUIT_CUSTOMER_PRICES_PDF_REF_MODE');
2256 switch ($idcustprice) {
2257 case 1:
2258 $ref_prodserv = $productCustomerPrice->ref_customer;
2259 break;
2260
2261 case 2:
2262 $ref_prodserv = $productCustomerPrice->ref_customer . ' (' . $outputlangs->transnoentitiesnoconv('InternalRef') . ' ' . $ref_prodserv . ')';
2263 break;
2264
2265 default:
2266 $ref_prodserv = $ref_prodserv . ' (' . $outputlangs->transnoentitiesnoconv('RefCustomer') . ' ' . $productCustomerPrice->ref_customer . ')';
2267 }
2268 }
2269 }
2270 }
2271 }
2272
2273 if (!empty($labelproductservice) && !empty($ref_prodserv)) {
2274 $ref_prodserv .= " - ";
2275 }
2276 }
2277
2278 if (!empty($ref_prodserv) && getDolGlobalString('PDF_BOLD_PRODUCT_REF_AND_PERIOD')) {
2279 if (!dol_textishtml($labelproductservice)) {
2280 $labelproductservice = str_replace("\n", '<br>', $labelproductservice);
2281 }
2282 $ref_prodserv = '<b>'.$ref_prodserv.'</b>';
2283 // $prefix_prodserv and $ref_prodser are not HTML var
2284 }
2285 $labelproductservice = $prefix_prodserv.$ref_prodserv.$labelproductservice;
2286
2287 // Add an additional description for the category products
2288 if (getDolGlobalString('CATEGORY_ADD_DESC_INTO_DOC') && $idprod && isModEnabled('category')) {
2289 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2290 $categstatic = new Categorie($db);
2291 // recovering the list of all the categories linked to product
2292 $tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
2293 foreach ($tblcateg as $cate) {
2294 // Adding the descriptions if they are filled
2295 $desccateg = $cate->description;
2296 if ($desccateg) {
2297 $labelproductservice = dol_concatdesc($labelproductservice, $desccateg);
2298 }
2299 }
2300 }
2301
2302 if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) {
2303 $format = 'day';
2304 $period = '';
2305 // Show duration if exists
2306 if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
2307 $period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
2308 }
2309 if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) {
2310 $period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
2311 }
2312 if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) {
2313 $period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
2314 }
2315 //print '>'.$outputlangs->charset_output.','.$period;
2316 if (getDolGlobalString('PDF_BOLD_PRODUCT_REF_AND_PERIOD')) {
2317 if (!dol_textishtml($labelproductservice)) {
2318 $labelproductservice = str_replace("\n", '<br>', $labelproductservice);
2319 }
2320 $labelproductservice .= '<br><b style="color:#333666;" ><em>'.$period.'</em></b>';
2321 } else {
2322 $labelproductservice = dol_concatdesc($labelproductservice, $period);
2323 }
2324 //print $labelproductservice;
2325 }
2326
2327 // Show information for lot
2328 if (!empty($dbatch)) {
2329 // $object is a shipment.
2330 //var_dump($object->lines[$i]->details_entrepot); // array from llx_expeditiondet (we can have several lines for one fk_origin_line)
2331 //var_dump($object->lines[$i]->detail_batch); // array from llx_expeditiondet_batch (each line with a lot is linked to llx_expeditiondet)
2332
2333 include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
2334 include_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
2335 $tmpwarehouse = new Entrepot($db);
2336 $tmpproductbatch = new Productbatch($db);
2337
2338 $format = 'day';
2339 foreach ($dbatch as $detail) {
2340 $dte = array();
2341 if ($detail->eatby) {
2342 $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs));
2343 }
2344 if ($detail->sellby) {
2345 $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs));
2346 }
2347 if ($detail->batch) {
2348 $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch);
2349 }
2350 if ($detail->qty) {
2351 $dte[] = $outputlangs->transnoentitiesnoconv('printQty', (string) $detail->qty);
2352 }
2353
2354 // Add also info of planned warehouse for lot
2355 if ($object->element == 'shipping' && $detail->fk_origin_stock > 0 && getDolGlobalInt('PRODUCTBATCH_SHOW_WAREHOUSE_ON_SHIPMENT')) {
2356 $resproductbatch = $tmpproductbatch->fetch($detail->fk_origin_stock);
2357 if ($resproductbatch > 0) {
2358 $reswarehouse = $tmpwarehouse->fetch($tmpproductbatch->warehouseid);
2359 if ($reswarehouse > 0) {
2360 $dte[] = $tmpwarehouse->ref;
2361 }
2362 }
2363 }
2364
2365 $labelproductservice .= "__N__ ".implode(" - ", $dte);
2366 }
2367 } else {
2368 if (getDolGlobalInt('PRODUCTBATCH_SHOW_WAREHOUSE_ON_SHIPMENT')) {
2369 // TODO Show warehouse for shipment line without batch
2370 }
2371 }
2372
2373 // Now we convert \n into br
2374 if (dol_textishtml($labelproductservice)) {
2375 $labelproductservice = preg_replace('/__N__/', '<br>', $labelproductservice);
2376 } else {
2377 $labelproductservice = preg_replace('/__N__/', "\n", $labelproductservice);
2378 }
2379 $labelproductservice = dol_htmlentitiesbr($labelproductservice, 1);
2380
2381 return $labelproductservice;
2382}
2383
2393function pdf_getlinenum($object, $i, $outputlangs, $hidedetails = 0)
2394{
2395 global $hookmanager;
2396
2397 $reshook = 0;
2398 $result = '';
2399 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2400 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2401 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2402 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2403 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2404 }
2405 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2406 $action = '';
2407 $reshook = $hookmanager->executeHooks('pdf_getlinenum', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2408 $result .= $hookmanager->resPrint;
2409 }
2410 if (empty($reshook)) {
2411 $result .= dol_htmlentitiesbr($object->lines[$i]->num);
2412 }
2413 return $result;
2414}
2415
2416
2426function pdf_getlineref($object, $i, $outputlangs, $hidedetails = 0)
2427{
2428 global $hookmanager;
2429
2430 $reshook = 0;
2431 $result = '';
2432 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2433 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2434 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2435 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2436 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2437 }
2438 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2439 $action = '';
2440 $reshook = $hookmanager->executeHooks('pdf_getlineref', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2441 $result .= $hookmanager->resPrint;
2442 }
2443 if (empty($reshook)) {
2444 $result .= dol_htmlentitiesbr($object->lines[$i]->product_ref);
2445 }
2446 return $result;
2447}
2448
2449
2459function pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails = 0)
2460{
2461 global $hookmanager;
2462
2463 $reshook = 0;
2464 $result = '';
2465 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2466 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2467 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2468 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2469 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2470 }
2471 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2472 $action = '';
2473 $reshook = $hookmanager->executeHooks('pdf_getlineref_supplier', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2474 $result .= $hookmanager->resPrint;
2475 }
2476 if (empty($reshook)) {
2477 $result .= dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
2478 }
2479 return $result;
2480}
2481
2491function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails = 0)
2492{
2493 global $conf, $hookmanager, $mysoc;
2494
2495 $result = '';
2496 $reshook = 0;
2497 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2498 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2499 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2500 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2501 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2502 }
2503 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2504 $action = '';
2505 $reshook = $hookmanager->executeHooks('pdf_getlinevatrate', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2506
2507 if (!empty($hookmanager->resPrint)) {
2508 $result .= $hookmanager->resPrint;
2509 }
2510 }
2511 if (empty($reshook)) {
2512 if (empty($hidedetails) || $hidedetails > 1) {
2513 $tmpresult = '';
2514
2515 $tmpresult .= vatrate($object->lines[$i]->tva_tx, false, $object->lines[$i]->info_bits, -1);
2516 if (!getDolGlobalString('MAIN_PDF_MAIN_HIDE_SECOND_TAX')) {
2517 if (price2num($object->lines[$i]->localtax1_tx)) {
2518 if (preg_replace('/[\s0%]/', '', $tmpresult)) {
2519 $tmpresult .= '/';
2520 } else {
2521 $tmpresult = '';
2522 }
2523 $tmpresult .= vatrate((string) abs($object->lines[$i]->localtax1_tx), false);
2524 }
2525 }
2526 if (!getDolGlobalString('MAIN_PDF_MAIN_HIDE_THIRD_TAX')) {
2527 if (price2num($object->lines[$i]->localtax2_tx)) {
2528 if (preg_replace('/[\s0%]/', '', $tmpresult)) {
2529 $tmpresult .= '/';
2530 } else {
2531 $tmpresult = '';
2532 }
2533 $tmpresult .= vatrate((string) abs($object->lines[$i]->localtax2_tx), false);
2534 }
2535 }
2536 $tmpresult .= '%';
2537
2538 $result .= $tmpresult;
2539 }
2540 }
2541 return $result;
2542}
2543
2553function pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails = 0)
2554{
2555 global $hookmanager;
2556
2557 $sign = 1;
2558 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
2559 $sign = -1;
2560 }
2561
2562 $result = '';
2563 $reshook = 0;
2564 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2565 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2566 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2567 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2568 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2569 }
2570 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2571 $action = '';
2572 $reshook = $hookmanager->executeHooks('pdf_getlineupexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2573
2574 if (!empty($hookmanager->resPrint)) {
2575 $result .= $hookmanager->resPrint;
2576 }
2577 }
2578 if (empty($reshook)) {
2579 if (empty($hidedetails) || $hidedetails > 1) {
2580 $subprice = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
2581 $result .= price($sign * $subprice, 0, $outputlangs);
2582 }
2583 }
2584 return $result;
2585}
2586
2596function pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails = 0)
2597{
2598 global $hookmanager;
2599
2600 $sign = 1;
2601 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
2602 $sign = -1;
2603 }
2604
2605 $result = '';
2606 $reshook = 0;
2607 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2608 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2609 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2610 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2611 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2612 }
2613 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2614 $action = '';
2615 $reshook = $hookmanager->executeHooks('pdf_getlineupwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2616
2617 if (!empty($hookmanager->resPrint)) {
2618 $result .= $hookmanager->resPrint;
2619 }
2620 }
2621 if (empty($reshook)) {
2622 if (empty($hidedetails) || $hidedetails > 1) {
2623 $result .= price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice) * ($object->lines[$i]->tva_tx) / 100), 0, $outputlangs);
2624 }
2625 }
2626 return $result;
2627}
2628
2638function pdf_getlineqty($object, $i, $outputlangs, $hidedetails = 0)
2639{
2640 global $hookmanager;
2641
2642 $result = '';
2643 $reshook = 0;
2644 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2645 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2646 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2647 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2648 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2649 }
2650 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2651 $action = '';
2652 $reshook = $hookmanager->executeHooks('pdf_getlineqty', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2653
2654 if (!empty($hookmanager->resPrint)) {
2655 $result = $hookmanager->resPrint;
2656 }
2657 }
2658 if (empty($reshook)) {
2659 if ($object->lines[$i]->special_code == 3) {
2660 return '';
2661 }
2662 if (empty($hidedetails) || $hidedetails > 1) {
2663 $result .= $object->lines[$i]->qty;
2664 }
2665 }
2666 return $result;
2667}
2668
2678function pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails = 0)
2679{
2680 global $hookmanager;
2681
2682 $reshook = 0;
2683 $result = '';
2684 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2685 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2686 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2687 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2688 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2689 }
2690 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2691 $action = '';
2692 $reshook = $hookmanager->executeHooks('pdf_getlineqty_asked', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2693
2694 if (!empty($hookmanager->resPrint)) {
2695 $result .= $hookmanager->resPrint;
2696 }
2697 }
2698 if (empty($reshook)) {
2699 if ($object->lines[$i]->special_code == 3) {
2700 return '';
2701 }
2702 if (empty($hidedetails) || $hidedetails > 1) {
2703 $result .= $object->lines[$i]->qty_asked;
2704 }
2705 }
2706 return $result;
2707}
2708
2718function pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails = 0)
2719{
2720 global $hookmanager;
2721
2722 $reshook = 0;
2723 $result = '';
2724 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2725 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2726 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2727 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2728 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2729 }
2730 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2731 $action = '';
2732 $reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2733
2734 if (!empty($hookmanager->resPrint)) {
2735 $result .= $hookmanager->resPrint;
2736 }
2737 }
2738 if (empty($reshook)) {
2739 if ($object->lines[$i]->special_code == 3) {
2740 return '';
2741 }
2742 if (empty($hidedetails) || $hidedetails > 1) {
2743 $result .= $object->lines[$i]->qty_shipped;
2744 }
2745 }
2746 return $result;
2747}
2748
2758function pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails = 0)
2759{
2760 global $hookmanager;
2761
2762 $reshook = 0;
2763 $result = '';
2764 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2765 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2766 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2767 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) { // @phan-suppress-current-line PhanUndeclaredProperty
2768 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2769 }
2770 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2771 $action = '';
2772 $reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2773
2774 if (!empty($hookmanager->resPrint)) {
2775 $result .= $hookmanager->resPrint;
2776 }
2777 }
2778 if (empty($reshook)) {
2779 if ($object->lines[$i]->special_code == 3) {
2780 return '';
2781 }
2782 if (empty($hidedetails) || $hidedetails > 1) {
2783 $result .= ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
2784 }
2785 }
2786 return $result;
2787}
2788
2798function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0)
2799{
2800 global $hookmanager;
2801
2802 $reshook = 0;
2803 $result = '';
2804 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2805 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2806 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2807 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2808 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2809 }
2810 $parameters = array(
2811 'i' => $i,
2812 'outputlangs' => $outputlangs,
2813 'hidedetails' => $hidedetails,
2814 'special_code' => $special_code
2815 );
2816 $action = '';
2817 $reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2818
2819 if (!empty($hookmanager->resPrint)) {
2820 $result .= $hookmanager->resPrint;
2821 }
2822 }
2823 if (empty($reshook)) {
2824 if (empty($hidedetails) || $hidedetails > 1) {
2825 $result .= $object->lines[$i]->getLabelOfUnit('short', $outputlangs, 1);
2826 }
2827 }
2828 return $result;
2829}
2830
2831
2841function pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails = 0)
2842{
2843 global $hookmanager;
2844
2845 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2846
2847 $reshook = 0;
2848 $result = '';
2849 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2850 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2851 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2852 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2853 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2854 }
2855 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2856 $action = '';
2857 $reshook = $hookmanager->executeHooks('pdf_getlineremisepercent', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2858
2859 if (!empty($hookmanager->resPrint)) {
2860 $result .= $hookmanager->resPrint;
2861 }
2862 }
2863 if (empty($reshook)) {
2864 if ($object->lines[$i]->special_code == 3) {
2865 return '';
2866 }
2867 if (empty($hidedetails) || $hidedetails > 1) {
2868 $result .= dol_print_reduction($object->lines[$i]->remise_percent, $outputlangs);
2869 }
2870 }
2871 return $result;
2872}
2873
2884function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null)
2885{
2886 if (empty($hookmanager)) {
2887 global $hookmanager;
2888 }
2889
2890 $reshook = 0;
2891 $result = '';
2892 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2893 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2894 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2895 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2896 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2897 }
2898 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2899 $action = '';
2900 $reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2901
2902 if (!empty($hookmanager->resPrint)) {
2903 return $hookmanager->resPrint;
2904 }
2905 }
2906 if (empty($reshook)) {
2907 if ($object->lines[$i]->special_code == 3) {
2908 return '';
2909 }
2910 if (empty($hidedetails) || $hidedetails > 1) {
2911 // 2 = situation_percent is non-cumulative (delta of current situation)
2912 // 1 = (old mode): situation_percent is cumulative (state at situation)
2913 $isCumulative = getDolGlobalInt('INVOICE_USE_SITUATION') === 1;
2914 $showDelta = (bool) getDolGlobalInt('SITUATION_DISPLAY_DIFF_ON_PDF');
2915
2916 if ($isCumulative xor $showDelta) {
2917 // Either:
2918 // - old mode and we want to show a total or
2919 // - new mode and we want to show a delta
2920 $result = $object->lines[$i]->situation_percent;
2921 } else {
2922 // Either:
2923 // - old mode but we want to show a delta or
2924 // - new mode but we want to show a total
2925 $prev_progress = 0;
2926 if ($isCumulative) {
2927 // old mode: the previous line already holds the running total
2928 if (method_exists($object->lines[$i], 'get_prev_progress')) {
2929 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
2930 }
2931 } else {
2932 // new mode: each line holds its own delta, so we must sum every previous one.
2933 // get_prev_progress() only reads the line pointed by fk_prev_id, which is the last
2934 // delta and not the accumulated progress, so it under-reports from the third
2935 // situation on. getAllPrevProgress() walks the whole fk_prev_id chain, and it is
2936 // what the screen uses to compute the same value.
2937 if (method_exists($object->lines[$i], 'getAllPrevProgress')) {
2938 $prev_progress = $object->lines[$i]->getAllPrevProgress($object->id);
2939 } elseif (method_exists($object->lines[$i], 'get_prev_progress')) {
2940 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
2941 }
2942 }
2943 $result = $isCumulative ?
2944 // old mode: we need to compute the delta (total - sum of previous)
2945 $object->lines[$i]->situation_percent - $prev_progress :
2946 // new mode: we need to compute the total (sum of previous + delta)
2947 $prev_progress + $object->lines[$i]->situation_percent;
2948 }
2949 $result = round($result, getDolGlobalInt('INVOICE_SITUATION_PROGRESS_DECIMALS', 2)).'%';
2950 }
2951 }
2952 return $result;
2953}
2954
2964function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0)
2965{
2966 global $hookmanager;
2967
2968 $sign = 1;
2969 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
2970 $sign = -1;
2971 }
2972
2973 $reshook = 0;
2974 $result = '';
2975 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
2976 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
2977 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
2978 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2979 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2980 }
2981 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code, 'sign' => $sign);
2982 $action = '';
2983 $reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2984
2985 if (!empty($hookmanager->resPrint)) {
2986 $result .= $hookmanager->resPrint;
2987 }
2988 }
2989 if (empty($reshook)) {
2990 if (!empty($object->lines[$i]) && $object->lines[$i]->special_code == 3) {
2991 $result .= $outputlangs->transnoentities("Option");
2992 } elseif (empty($hidedetails) || $hidedetails > 1) {
2993 $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht);
2994 if (!empty($object->lines[$i]->situation_percent) && $object->lines[$i]->situation_percent > 0) {
2995 if (method_exists($object->lines[$i], 'getSituationRatio')) {
2996 $total_ht *= $object->lines[$i]->getSituationRatio();
2997 }
2998 }
2999 $result .= price($sign * $total_ht, 0, $outputlangs);
3000 }
3001 }
3002 return $result;
3003}
3004
3014function pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails = 0)
3015{
3016 global $hookmanager;
3017
3018 $sign = 1;
3019 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3020 $sign = -1;
3021 }
3022
3023 $reshook = 0;
3024 $result = '';
3025 //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line) ) )
3026 if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
3027 $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
3028 if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
3029 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
3030 }
3031 $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
3032 $action = '';
3033 $reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
3034
3035 if (!empty($hookmanager->resPrint)) {
3036 $result .= $hookmanager->resPrint;
3037 }
3038 }
3039 if (empty($reshook)) {
3040 if ($object->lines[$i]->special_code == 3) {
3041 $result .= $outputlangs->transnoentities("Option");
3042 } elseif (empty($hidedetails) || $hidedetails > 1) {
3043 $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ttc : $object->lines[$i]->total_ttc);
3044 if (isset($object->lines[$i]->situation_percent) && $object->lines[$i]->situation_percent > 0) {
3045 $total_ttc *= $object->lines[$i]->getSituationRatio();
3046 }
3047 $result .= price($sign * $total_ttc, 0, $outputlangs);
3048 }
3049 }
3050 return $result;
3051}
3052
3063function canDisplayLinkedObjectInPDF($object, $elementobject)
3064{
3065 $objectSocId = getObjectSocId($object);
3066 $elementSocId = getObjectSocId($elementobject);
3067
3068 if (getDolGlobalBool("PDF_ALLOW_DISPLAY_LINKED_OBJECT_FOR_OTHER_SOC")) {
3069 return true;
3070 }
3071
3072 if (!empty($objectSocId) && !empty($elementSocId) && $objectSocId != $elementSocId) {
3073 return false;
3074 }
3075
3076 return true;
3077}
3078
3087function pdf_getLinkedObjects($object, $outputlangs)
3088{
3089 global $db, $hookmanager;
3090
3091 $linkedobjects = array();
3092
3093 $object->fetchObjectLinked();
3094
3095 foreach ($object->linkedObjects as $objecttype => $objects) {
3096 if ($objecttype == 'facture') {
3097 // For invoice, we don't want to have a reference line on document. Image we are using recurring invoice, we will have a line longer than document width.
3098 } elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal') {
3099 '@phan-var-force array<Propal|SupplierProposal> $objects';
3101 $outputlangs->load('propal');
3102
3103 foreach ($objects as $elementobject) {
3104 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
3105 $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
3106 $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
3107 $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
3108 }
3109 } elseif ($objecttype == 'commande' || $objecttype == 'supplier_order' || $objecttype == 'order_supplier') {
3110 $optiontohidelinkedorders = "PDF_HIDE_LINKED_ORDERS_ON_SAME_THIRDPARTY";
3111 if ($objecttype == 'supplier_order' || $objecttype == 'order_supplier') {
3112 $optiontohidelinkedorders = "PDF_HIDE_LINKED_PURCHASE_ORDERS_ON_SAME_THIRDPARTY";
3113 }
3114 '@phan-var-force array<Commande|CommandeFournisseur> $objects';
3115 $outputlangs->load('orders');
3116
3117 if (count($objects) > 1 && count($objects) <= getDolGlobalInt("MAXREFONDOC", 10) && !getDolGlobalString($optiontohidelinkedorders)) {
3118 if (empty($object->context['DolPublicNoteAppendedGetLinkedObjects'])) { // Check if already appended before add to avoid repeat data
3119 $outputList = '';
3120 foreach ($objects as $elementobject) {
3121 if (canDisplayLinkedObjectInPDF($object, $elementobject)) {
3122 $outputList = dol_concatdesc($outputList, $outputlangs->transnoentities($elementobject->ref) . (empty($elementobject->ref_client) ? '' : ' (' . $elementobject->ref_client . ')') . (empty($elementobject->ref_supplier) ? '' : ' (' . $elementobject->ref_supplier . ')') . ' ');
3123 $outputList = dol_concatdesc($outputList, $outputlangs->transnoentities("OrderDate") . ' : ' . dol_print_date($elementobject->date, 'day', '', $outputlangs));
3124 }
3125 }
3126
3127 if (!empty($outputList)) {
3128 $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities("RefOrder").' :');
3129 $object->note_public = dol_concatdesc($object->note_public, $outputList);
3130 }
3131 }
3132 } elseif (count($objects) == 1 && !getDolGlobalString($optiontohidelinkedorders)) {
3133 $elementobject = array_shift($objects);
3134 if (canDisplayLinkedObjectInPDF($object, $elementobject)) {
3135 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
3136 $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref).(!empty($elementobject->ref_client) ? ' ('.$elementobject->ref_client.')' : '').(!empty($elementobject->ref_supplier) ? ' ('.$elementobject->ref_supplier.')' : '');
3137 $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
3138 $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
3139 }
3140 }
3141 } elseif ($objecttype == 'contrat') {
3142 '@phan-var-force Contrat[] $objects';
3143 $outputlangs->load('contracts');
3144 foreach ($objects as $elementobject) {
3145 if (canDisplayLinkedObjectInPDF($object, $elementobject)) {
3146 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
3147 $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
3148 $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
3149 $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat, 'day', '', $outputlangs);
3150 }
3151 }
3152 } elseif ($objecttype == 'fichinter') {
3153 '@phan-var-force Fichinter[] $objects';
3154 $outputlangs->load('interventions');
3155 foreach ($objects as $elementobject) {
3156 if (canDisplayLinkedObjectInPDF($object, $elementobject)) {
3157 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("InterRef");
3158 $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
3159 $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("InterDate");
3160 $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->datec, 'day', '', $outputlangs);
3161 }
3162 }
3163 } elseif ($objecttype == 'shipping') {
3164 '@phan-var-force Expedition[] $objects';
3165 $outputlangs->loadLangs(array("orders", "sendings"));
3166
3167 if (count($objects) > 1) {
3168 $order = null;
3169
3170 $refListsTxt = '';
3171 if (empty($object->linkedObjects['commande']) && $object->element != 'commande') {
3172 $refListsTxt .= $outputlangs->transnoentities("RefOrder").' / '.$outputlangs->transnoentities("RefSending").' :';
3173 } else {
3174 $refListsTxt .= $outputlangs->transnoentities("RefSending").' :';
3175 }
3176 // We concat this record info into fields xxx_value. title is overwrote.
3177 foreach ($objects as $elementobject) {
3178 if (empty($object->linkedObjects['commande']) && $object->element != 'commande') { // There is not already a link to order and object is not the order, so we show also info with order
3179 $elementobject->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
3180 if (!empty($elementobject->linkedObjectsIds['commande'])) {
3181 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
3182 $order = new Commande($db);
3183 $ret = $order->fetch(reset($elementobject->linkedObjectsIds['commande']));
3184 if ($ret < 1) {
3185 $order = null;
3186 }
3187 }
3188 }
3189 $refListsTxt .= (!empty($refListsTxt) ? ' ' : '');
3190 if (! is_object($order)) {
3191 $refListsTxt .= $outputlangs->transnoentities($elementobject->ref);
3192 } else {
3193 $refListsTxt .= $outputlangs->convToOutputCharset($order->ref).($order->ref_client ? ' ('.$order->ref_client.')' : '');
3194 $refListsTxt .= ' / '.$outputlangs->transnoentities($elementobject->ref);
3195 }
3196 }
3197
3198 if (empty($object->context['DolPublicNoteAppendedGetLinkedObjects']) && !getDolGlobalString("PDF_HIDE_LINKED_OBJECT_IN_PUBLIC_NOTE")) { // Check if already appended before add to avoid repeat data
3199 $object->note_public = dol_concatdesc($object->note_public, $refListsTxt);
3200 }
3201 } elseif (count($objects) == 1) {
3202 $elementobject = array_shift($objects);
3203 $order = null;
3204 // We concat this record info into fields xxx_value. title is overwrote.
3205 if (empty($object->linkedObjects['commande']) && $object->element != 'commande') { // There is not already a link to order and object is not the order, so we show also info with order
3206 $elementobject->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
3207 if (!empty($elementobject->linkedObjectsIds['commande'])) {
3208 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
3209 $order = new Commande($db);
3210 $ret = $order->fetch(reset($elementobject->linkedObjectsIds['commande']));
3211 if ($ret < 1) {
3212 $order = null;
3213 }
3214 }
3215 }
3216
3217 if (! is_object($order)) {
3218 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
3219 if (empty($linkedobjects[$objecttype]['ref_value'])) {
3220 $linkedobjects[$objecttype]['ref_value'] = '';
3221 } else {
3222 $linkedobjects[$objecttype]['ref_value'] .= ' / ';
3223 }
3224 $linkedobjects[$objecttype]['ref_value'] .= $outputlangs->transnoentities($elementobject->ref);
3225 $linkedobjects[$objecttype]['date_value'] = dol_print_date(empty($elementobject->date_shipping) ? $elementobject->date_delivery : $elementobject->date_shipping, 'day', '', $outputlangs);
3226 } else {
3227 $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder").' / '.$outputlangs->transnoentities("RefSending");
3228 if (empty($linkedobjects[$objecttype]['ref_value'])) {
3229 $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref).($order->ref_client ? ' ('.$order->ref_client.')' : '');
3230 }
3231 $linkedobjects[$objecttype]['ref_value'] .= ' / '.$outputlangs->transnoentities($elementobject->ref);
3232 $linkedobjects[$objecttype]['date_value'] = dol_print_date(empty($elementobject->date_shipping) ? $elementobject->date_delivery : $elementobject->date_shipping, 'day', '', $outputlangs);
3233 }
3234 }
3235 }
3236 }
3237
3238 $object->context['DolPublicNoteAppendedGetLinkedObjects'] = 1;
3239
3240 // For add external linked objects
3241 if (is_object($hookmanager)) {
3242 $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs' => $outputlangs);
3243 $action = '';
3244 $reshook = $hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
3245 if (empty($reshook)) {
3246 $linkedobjects = array_replace($linkedobjects, $hookmanager->resArray); // array_replace is used to preserve keys
3247 } elseif ($reshook > 0) {
3248 // The array must be reinserted even if it is empty because clearing the array could be one of the actions performed by the hook.
3249 $linkedobjects = $hookmanager->resArray;
3250 }
3251 }
3252
3253 return $linkedobjects;
3254}
3255
3263function pdf_getSizeForImage($realpath)
3264{
3265 $maxwidth = getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20);
3266 $maxheight = getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT', 32);
3267
3268 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
3269 $tmp = dol_getImageSize($realpath);
3270 $width = 0;
3271 $height = 0;
3272 if ($tmp['height']) {
3273 $width = (int) round($maxheight * $tmp['width'] / $tmp['height']); // I try to use maxheight
3274 if ($width > $maxwidth) { // Pb with maxheight, so i use maxwidth
3275 $width = $maxwidth;
3276 $height = (int) round($maxwidth * $tmp['height'] / $tmp['width']);
3277 } else { // No pb with maxheight
3278 $height = $maxheight;
3279 }
3280 }
3281 return array('width' => $width, 'height' => $height);
3282}
3283
3295function pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails = 0, $multicurrency = 0)
3296{
3297 global $hookmanager;
3298
3299 $sign = 1;
3300 if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) {
3301 $sign = -1;
3302 }
3303 if ($object->lines[$i]->special_code == 3) {
3304 // If option
3305 return $outputlangs->transnoentities("Option");
3306 } else {
3307 if (is_object($hookmanager)) {
3308 $special_code = $object->lines[$i]->special_code;
3309 if (!empty($object->lines[$i]->fk_parent_line)) {
3310 $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
3311 }
3312
3313 $parameters = array(
3314 'i' => $i,
3315 'outputlangs' => $outputlangs,
3316 'hidedetails' => $hidedetails,
3317 'special_code' => $special_code,
3318 'multicurrency' => $multicurrency
3319 );
3320
3321 $action = '';
3322
3323 if ($hookmanager->executeHooks('getlinetotalremise', $parameters, $object, $action) > 0) { // Note that $action and $object may have been modified by some hooks
3324 if (isset($hookmanager->resArray['linetotalremise'])) {
3325 return (float) $hookmanager->resArray['linetotalremise'];
3326 } else {
3327 return (float) $hookmanager->resPrint; // For backward compatibility
3328 }
3329 }
3330 }
3331
3332 if (empty($hidedetails) || $hidedetails > 1) {
3333 if (empty($multicurrency)) {
3334 $diff = (float) price2num($sign * $object->lines[$i]->subprice * (float) $object->lines[$i]->qty, 'MT', 1) - $object->lines[$i]->total_ht;
3335 return (float) price2num($diff, 'MT', 1);
3336 } else {
3337 $diff = (float) price2num($sign * $object->lines[$i]->multicurrency_subprice * (float) $object->lines[$i]->qty, 'MT', 1) - $object->lines[$i]->multicurrency_total_ht;
3338 return (float) price2num($diff, 'MT', 1);
3339 }
3340 }
3341 }
3342 return 0;
3343}
3344
3352function pdfExtractMetadata($file, $field = 'Keywords')
3353{
3354 if (!dol_is_file($file)) {
3355 return "ERROR: FILE NOT FOUND OR NOT VALID";
3356 }
3357
3358 // Get content of PDF file
3359 $content = file_get_contents(dol_osencode($file));
3360
3361 // Use a regex to capture the metadata
3362 if ($content) {
3363 $matches = array();
3364
3365 // Remove non printablecaracters
3366 $content = preg_replace('/[^(\x20-\x7F)]*/', '', $content);
3367 if (preg_match('/\/' . preg_quote($field, '/') . '\s*\‍((.*?)\‍)/', $content, $matches)) {
3368 return trim($matches[1]);
3369 }
3370 return "ERROR: NOT FOUND";
3371 } else {
3372 return "ERROR: FAILED TO READ PDF";
3373 }
3374}
3375
3396 TCPDF $pdf,
3397 CommonDocGenerator $generator,
3398 float $curY,
3400 int $i,
3401 Translate $outputlangs,
3402 int $hideref,
3403 int $hidedesc,
3404 array $bgColor,
3405 bool $isSubtotal = false,
3406 bool $applySubtotalLogic = true
3407) {
3408 global $hookmanager;
3409
3410 if (is_object($hookmanager)) {
3411 $parameters = array('pdf' => $pdf, 'generator' => $generator, 'curY' => $curY, 'i' => $i, 'outputlangs' => $outputlangs, 'hideref' => $hideref, 'hidedesc' => $hidedesc, 'bgColor' => $bgColor, 'isSubtotal' => $isSubtotal, 'applySubtotalLogic' => $applySubtotalLogic);
3412 $action = '';
3413 $reshook = $hookmanager->executeHooks('pdf_render_subtotals', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
3414 if ($reshook > 0) {
3415 return;
3416 }
3417 }
3418
3419 $savePage = $pdf->getPage();
3420 $saveX = $pdf->GetX();
3421 $prevAlign = $generator->cols['desc']['content']['align'];
3422 $prevDesc = $object->lines[$i]->desc;
3423
3424 if ($isSubtotal && $applySubtotalLogic && $object->lines[$i]->qty < 0) {
3425 $outputlangs->load("subtotals");
3426 $object->lines[$i]->desc = getDolGlobalString("SUBTOTAL_LINE_TEXT_DOES_NOT_INCLUDE_TITLE_TEXT") ? $outputlangs->trans("SubTotal") : $outputlangs->trans("SubtotalOf", $object->lines[$i]->desc);
3427 $generator->cols['desc']['content']['align'] = ($prevAlign === 'L') ? 'R' : 'L';
3428 }
3429
3430 $pdf->startTransaction();
3431 $pdf->SetXY($saveX, $curY);
3432 $generator->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
3433 $pageAfter = $pdf->getPage();
3434 $yAfter = $pdf->GetY();
3435 $pdf->rollbackTransaction(true);
3436
3437 $pdf->SetFillColor($bgColor[0], $bgColor[1], $bgColor[2]);
3438 $width = $generator->page_largeur - $generator->marge_droite - $generator->marge_gauche;
3439
3440 $pdf->SetXY($generator->marge_gauche, $curY);
3441 if ($pageAfter === $savePage) {
3442 $pdf->MultiCell($width, max(0, $yAfter - $curY), '', 0, '', true);
3443 } else {
3444 $pdf->MultiCell($width, $pdf->getPageHeight() - $pdf->getBreakMargin() - $curY, '', 0, '', true);
3445
3446 // The page reached by the measuring pass above was discarded along with
3447 // the transaction, and the MultiCell only recreates it when some room was
3448 // left to fill. A line starting below the break margin leaves none, so
3449 // the page must be added before it can be selected.
3450 while ($pdf->getNumPages() < $pageAfter) {
3451 $pdf->AddPage();
3452 }
3453 $pdf->setPage($pageAfter);
3454 $pdf->SetXY($generator->marge_gauche, $pdf->getMargins()['top']);
3455 $pdf->MultiCell($width, max(0, $yAfter - $pdf->getMargins()['top']), '', 0, '', true);
3456
3457 $pdf->setPage($savePage);
3458 }
3459
3460 // Dark text on a light background, white text on a dark one (a single argument of SetTextColor() is a gray level 0-255)
3461 $textGray = (colorIsLight(implode(',', $bgColor)) === 0) ? 255 : 0;
3462 $pdf->SetTextColor($textGray);
3463 $pdf->SetXY($saveX, $curY);
3464 $generator->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
3465 $generator->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
3466
3467 $generator->cols['desc']['content']['align'] = $prevAlign;
3468 // The text "Subtotal of ..." must not stay in the line: a second generation of the document would prefix it again
3469 $object->lines[$i]->desc = $prevDesc;
3470}
3471
3472
3483function pdf_truncate_text($pdf, $text, $max_width, $ellipsis_pos = 1, $ellipsis = "\u{2026}")
3484{
3485 if ($ellipsis_pos == 0) {
3486 $ellipsis = '';
3487 }
3488 if ($ellipsis_pos == 'left') {
3489 // Keep left part of the string
3490 $ellipsis_pos = 1;
3491 }
3492 if ($ellipsis_pos == 'right') {
3493 // Keep right part of the string
3494 $ellipsis_pos = 0;
3495 }
3496
3497 $ellipsis_width = $pdf->GetStringWidth($ellipsis);
3498 $available_width = $max_width - $ellipsis_width;
3499
3500 if ($available_width <= 0) {
3501 return ($ellipsis_pos <= 0) ? $ellipsis : '';
3502 }
3503
3504 $text_width = $pdf->GetStringWidth($text);
3505 if ($text_width <= $max_width) {
3506 return $text;
3507 }
3508
3509 if ($ellipsis_pos < 0) {
3510 // Ellipsis at start: truncate from the beginning
3511 $low = 0;
3512 $high = dol_strlen($text, 'UTF-8');
3513 $best = $high;
3514
3515 while ($low <= $high) {
3516 $mid = (int) (($low + $high) / 2);
3517 $substring = dol_substr($text, $mid, null, 'UTF-8');
3518 $substring_width = $pdf->GetStringWidth($substring);
3519
3520 if ($substring_width <= $available_width) {
3521 $best = $mid;
3522 $high = $mid - 1;
3523 } else {
3524 $low = $mid + 1;
3525 }
3526 }
3527
3528 return $ellipsis . dol_substr($text, $best, null, 'UTF-8');
3529 } else {
3530 // Ellipsis at end (default)
3531 $low = 0;
3532 $high = dol_strlen($text, 'UTF-8');
3533 $best = 0;
3534
3535 while ($low <= $high) {
3536 $mid = (int) (($low + $high) / 2);
3537 $substring = dol_substr($text, 0, $mid, 'UTF-8');
3538 $substring_width = $pdf->GetStringWidth($substring);
3539
3540 if ($substring_width <= $available_width) {
3541 $best = $mid;
3542 $low = $mid + 1;
3543 } else {
3544 $high = $mid - 1;
3545 }
3546 }
3547
3548 return dol_substr($text, 0, $best, 'UTF-8') . $ellipsis;
3549 }
3550}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
pdfWriteBlockedLogSignature(&$pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
pdfCertifMentionblockedLog(&$pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal mention.
isALNERunningVersion($blockedlogusagealreadychecked=0, $blockedlogmoduleonalreadychecked=0)
Return if the application is executed with the LNE requirements on.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage categories.
Class to manage customers orders.
Parent class for documents (PDF, ODT, ...) generators.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
Used for to set afterColsLinePositions var in a pdf draw line loop.
Class to manage contact/addresses.
Class to manage absolute discounts.
Class to manage warehouses.
static getIBANLabel(Account $account)
Returns the name of the Iban label.
File of class to manage predefined price products or services by customer.
Class to manage predefined suppliers products.
Class to manage products or services.
Manage record for batch number management.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
global $mysoc
dol_is_file($pathoffile)
Return if path is a file.
dol_print_reduction($reduction, $langs)
Returns formatted reduction.
dol_getDefaultFormat($outputlangs=null)
Try to guess default paper format according to language into $langs.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode='gmt')
Return date for now.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getObjectSocId($obj)
Get the socid of an object, supporting legacy attribute names.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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...
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
colorIsLight($stringcolor)
Return true if the color is light.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
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.
isModEnabled($module)
Is Dolibarr module enabled.
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)
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
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:3263
pdf_watermark($pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:1200
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition pdf.lib.php:2964
pdfCertifMention($pdf, $outputlangs, $seller, $default_font_size, &$posy, $pdftemplate)
Add legal certificate mention.
Definition pdf.lib.php:1264
pdf_getlinedesc($object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
Return line description translated in outputlangs and encoded into htmlentities and with
Definition pdf.lib.php:1976
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0, $multicurrency=0)
Return line total amount discount.
Definition pdf.lib.php:3295
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation The hook 'pdf_writeLinkedObjects' can replace this block (retu...
Definition pdf.lib.php:1870
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:296
pdfExtractMetadata($file, $field='Keywords')
Function to extract metadata from a PDF file by doing a binary parsing of the PDF file.
Definition pdf.lib.php:3352
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation The hook 'pdf_bank' can replace this block (return > 0).
Definition pdf.lib.php:1286
pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails=0)
Return line quantity shipped.
Definition pdf.lib.php:2718
pdf_getlinenum($object, $i, $outputlangs, $hidedetails=0)
Return line num.
Definition pdf.lib.php:2393
pdf_getEncryption($pathoffile)
Return if pdf file is protected/encrypted.
Definition pdf.lib.php:242
pdf_writelinedesc($pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0, $align='J')
Output line description into PDF.
Definition pdf.lib.php:1919
pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price including tax.
Definition pdf.lib.php:2596
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:319
pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails=0)
Return line ref_supplier.
Definition pdf.lib.php:2459
pdfWriteVATArray($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl)
Add some information from the blockedlog module.
Definition pdf.lib.php:855
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition pdf.lib.php:3014
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition pdf.lib.php:2553
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition pdf.lib.php:2884
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:2491
pdf_admin_prepare_head()
Return array head with list of tabs to view object information.
Definition pdf.lib.php:49
canDisplayLinkedObjectInPDF($object, $elementobject)
Check if a linked object can be displayed based on third-party privacy rules.
Definition pdf.lib.php:3063
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:792
pdfGetHeightForHtmlContent($pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition pdf.lib.php:385
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:1479
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:275
pdf_render_subtotals(TCPDF $pdf, CommonDocGenerator $generator, float $curY, CommonObject $object, int $i, Translate $outputlangs, int $hideref, int $hidedesc, array $bgColor, bool $isSubtotal=false, bool $applySubtotalLogic=true)
Render subtotals line with a colored background and adapted text color .
Definition pdf.lib.php:3395
pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails=0)
Return line keep to ship quantity.
Definition pdf.lib.php:2758
pdf_truncate_text($pdf, $text, $max_width, $ellipsis_pos=1, $ellipsis="\u{2026}")
Truncates text to fit a specified width in TCPDF, with configurable ellipsis position.
Definition pdf.lib.php:3483
pdf_getlineref($object, $i, $outputlangs, $hidedetails=0)
Return line product ref.
Definition pdf.lib.php:2426
pdfWriteAdditionnalTitle($pdf, $outputlangs, $page_height, $object, &$w, &$posx, &$posy)
Add some information from the blockedlog module.
Definition pdf.lib.php:830
pdfWriteAlreadyPaid($docgenerator, &$index, $pdf, $outputlangs, $outputlangsbis, $object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin)
Add some information from the blockedlog module.
Definition pdf.lib.php:1095
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:481
pdf_writeLogoOrCompanyName($pdf, $outputlangs, $emetteur, $logodir, $posx, $posy, $w, $default_font_size, $align)
Output company logo on top-left of a PDF page header, or the company name as fallback text if no logo...
Definition pdf.lib.php:351
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0)
Return line unit.
Definition pdf.lib.php:2798
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition pdf.lib.php:2841
pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails=0)
Return line quantity asked.
Definition pdf.lib.php:2678
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2638
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:1180
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:436