dolibarr  16.0.5
pdf.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
8  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
9  * Copyright (C) 2012-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
10  * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
11  * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
12  * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
13  * Copyright (C) 2019 Lenin Rivas <lenin.rivas@servcom-it.com>
14  * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
15  * Copyright (C) 2021-2022 Anthony Berton <bertonanthony@gmail.com>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <https://www.gnu.org/licenses/>.
29  * or see https://www.gnu.org/
30  */
31 
38 include_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
39 
40 
47 {
48  global $langs, $conf, $user;
49 
50  $h = 0;
51  $head = array();
52 
53  $head[$h][0] = DOL_URL_ROOT.'/admin/pdf.php';
54  $head[$h][1] = $langs->trans("Parameters");
55  $head[$h][2] = 'general';
56  $h++;
57 
58  // Show more tabs from modules
59  // Entries must be declared in modules descriptor with line
60  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
61  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
62  complete_head_from_modules($conf, $langs, null, $head, $h, 'pdf_admin');
63 
64  if (!empty($conf->propal->enabled)) {
65  $head[$h][0] = DOL_URL_ROOT.'/admin/pdf_other.php';
66  $head[$h][1] = $langs->trans("Other");
67  $head[$h][2] = 'other';
68  $h++;
69  }
70 
71  complete_head_from_modules($conf, $langs, null, $head, $h, 'pdf_admin', 'remove');
72 
73  return $head;
74 }
75 
76 
84 function pdf_getFormat(Translate $outputlangs = null, $mode = 'setup')
85 {
86  global $conf, $db, $langs;
87 
88  dol_syslog("pdf_getFormat Get paper format with mode=".$mode." MAIN_PDF_FORMAT=".(empty($conf->global->MAIN_PDF_FORMAT) ? 'null' : $conf->global->MAIN_PDF_FORMAT)." outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')." and langs->defaultlang=".(is_object($langs) ? $langs->defaultlang : 'null'));
89 
90  // Default value if setup was not done and/or entry into c_paper_format not defined
91  $width = 210;
92  $height = 297;
93  $unit = 'mm';
94 
95  if ($mode == 'auto' || empty($conf->global->MAIN_PDF_FORMAT) || $conf->global->MAIN_PDF_FORMAT == 'auto') {
96  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
97  $pdfformat = dol_getDefaultFormat($outputlangs);
98  } else {
99  $pdfformat = $conf->global->MAIN_PDF_FORMAT;
100  }
101 
102  $sql = "SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
103  $sql .= " WHERE code = '".$db->escape($pdfformat)."'";
104  $resql = $db->query($sql);
105  if ($resql) {
106  $obj = $db->fetch_object($resql);
107  if ($obj) {
108  $width = (int) $obj->width;
109  $height = (int) $obj->height;
110  $unit = $obj->unit;
111  }
112  }
113 
114  //print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
115  return array('width'=>$width, 'height'=>$height, 'unit'=>$unit);
116 }
117 
126 function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
127 {
128  global $conf;
129 
130  // Define constant for TCPDF
131  if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
132  define('K_TCPDF_EXTERNAL_CONFIG', 1); // this avoid using tcpdf_config file
133  define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
134  define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
135  dol_mkdir(K_PATH_CACHE);
136  define('K_BLANK_IMAGE', '_blank.png');
137  define('PDF_PAGE_FORMAT', 'A4');
138  define('PDF_PAGE_ORIENTATION', 'P');
139  define('PDF_CREATOR', 'TCPDF');
140  define('PDF_AUTHOR', 'TCPDF');
141  define('PDF_HEADER_TITLE', 'TCPDF Example');
142  define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
143  define('PDF_UNIT', 'mm');
144  define('PDF_MARGIN_HEADER', 5);
145  define('PDF_MARGIN_FOOTER', 10);
146  define('PDF_MARGIN_TOP', 27);
147  define('PDF_MARGIN_BOTTOM', 25);
148  define('PDF_MARGIN_LEFT', 15);
149  define('PDF_MARGIN_RIGHT', 15);
150  define('PDF_FONT_NAME_MAIN', 'helvetica');
151  define('PDF_FONT_SIZE_MAIN', 10);
152  define('PDF_FONT_NAME_DATA', 'helvetica');
153  define('PDF_FONT_SIZE_DATA', 8);
154  define('PDF_FONT_MONOSPACED', 'courier');
155  define('PDF_IMAGE_SCALE_RATIO', 1.25);
156  define('HEAD_MAGNIFICATION', 1.1);
157  define('K_CELL_HEIGHT_RATIO', 1.25);
158  define('K_TITLE_MAGNIFICATION', 1.3);
159  define('K_SMALL_RATIO', 2 / 3);
160  define('K_THAI_TOPCHARS', true);
161  define('K_TCPDF_CALLS_IN_HTML', true);
162  if (!empty($conf->global->TCPDF_THROW_ERRORS_INSTEAD_OF_DIE)) {
163  define('K_TCPDF_THROW_EXCEPTION_ERROR', true);
164  } else {
165  define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
166  }
167  }
168 
169  // Load TCPDF
170  require_once TCPDF_PATH.'tcpdf.php';
171 
172  // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
173  if (empty($conf->global->MAIN_DISABLE_TCPDI)) {
174  require_once TCPDI_PATH.'tcpdi.php';
175  }
176 
177  //$arrayformat=pdf_getFormat();
178  //$format=array($arrayformat['width'],$arrayformat['height']);
179  //$metric=$arrayformat['unit'];
180 
181  $pdfa = false; // PDF-1.3
182  if (!empty($conf->global->PDF_USE_A)) {
183  $pdfa = $conf->global->PDF_USE_A; // PDF/A-1 ou PDF/A-3
184  }
185 
186  if (class_exists('TCPDI')) {
187  $pdf = new TCPDI($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
188  } else {
189  $pdf = new TCPDF($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
190  }
191 
192  // Protection and encryption of pdf
193  if (!empty($conf->global->PDF_SECURITY_ENCRYPTION)) {
194  /* Permission supported by TCPDF
195  - print : Print the document;
196  - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
197  - copy : Copy or otherwise extract text and graphics from the document;
198  - 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);
199  - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
200  - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
201  - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
202  - 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.
203  - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
204  */
205 
206  // For TCPDF, we specify permission we want to block
207  $pdfrights = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS) ?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true) : array('modify', 'copy')); // Json format in llx_const
208 
209  // Password for the end user
210  $pdfuserpass = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS) ? $conf->global->PDF_SECURITY_ENCRYPTION_USERPASS : '');
211 
212  // Password of the owner, created randomly if not defined
213  $pdfownerpass = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS) ? $conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS : null);
214 
215  // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
216  $encstrength = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH) ? $conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH : 0);
217 
218  // Array of recipients containing public-key certificates ('c') and permissions ('p').
219  // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
220  $pubkeys = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS) ?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true) : null); // Json format in llx_const
221 
222  $pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass, $encstrength, $pubkeys);
223  }
224 
225  return $pdf;
226 }
227 
234 function pdf_getEncryption($pathoffile)
235 {
236  require_once TCPDF_PATH.'tcpdf_parser.php';
237 
238  $isencrypted = false;
239 
240  $content = file_get_contents($pathoffile);
241 
242  //ob_start();
243  @($parser = new \TCPDF_PARSER(ltrim($content)));
244  list($xref, $data) = $parser->getParsedData();
245  unset($parser);
246  //ob_end_clean();
247 
248  if (isset($xref['trailer']['encrypt'])) {
249  $isencrypted = true; // Secured pdf file are currently not supported
250  }
251 
252  if (empty($data)) {
253  $isencrypted = true; // Object list not found. Possible secured file
254  }
255 
256  return $isencrypted;
257 }
258 
265 function pdf_getPDFFont($outputlangs)
266 {
267  global $conf;
268 
269  if (!empty($conf->global->MAIN_PDF_FORCE_FONT)) {
270  return $conf->global->MAIN_PDF_FORCE_FONT;
271  }
272 
273  $font = 'Helvetica'; // By default, for FPDI, or ISO language on TCPDF
274  if (class_exists('TCPDF')) { // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
275  if ($outputlangs->trans('FONTFORPDF') != 'FONTFORPDF') {
276  $font = $outputlangs->trans('FONTFORPDF');
277  }
278  }
279  return $font;
280 }
281 
288 function pdf_getPDFFontSize($outputlangs)
289 {
290  global $conf;
291 
292  $size = 10; // By default, for FPDI or ISO language on TCPDF
293  if (class_exists('TCPDF')) { // If TCPDF on, we can use an UTF8 font like DejaVuSans if required (slower)
294  if ($outputlangs->trans('FONTSIZEFORPDF') != 'FONTSIZEFORPDF') {
295  $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
296  }
297  }
298  if (!empty($conf->global->MAIN_PDF_FORCE_FONT_SIZE)) {
299  $size = $conf->global->MAIN_PDF_FORCE_FONT_SIZE;
300  }
301 
302  return $size;
303 }
304 
305 
313 function pdf_getHeightForLogo($logo, $url = false)
314 {
315  global $conf;
316  $height = (empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT) ? 20 : $conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
317  $maxwidth = 130;
318  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
319  $tmp = dol_getImageSize($logo, $url);
320  if ($tmp['height']) {
321  $width = round($height * $tmp['width'] / $tmp['height']);
322  if ($width > $maxwidth) {
323  $height = $height * $maxwidth / $width;
324  }
325  }
326  //print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
327  return $height;
328 }
329 
338 function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
339 {
340  // store current object
341  $pdf->startTransaction();
342  // store starting values
343  $start_y = $pdf->GetY();
344  //var_dump($start_y);
345  $start_page = $pdf->getPage();
346  // call printing functions with content
347  $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J', true);
348  // get the new Y
349  $end_y = $pdf->GetY();
350  $end_page = $pdf->getPage();
351  // calculate height
352  $height = 0;
353  if ($end_page == $start_page) {
354  $height = $end_y - $start_y;
355  } else {
356  for ($page = $start_page; $page <= $end_page; ++$page) {
357  $pdf->setPage($page);
358  $tmpm = $pdf->getMargins();
359  $tMargin = $tmpm['top'];
360  if ($page == $start_page) {
361  // first page
362  $height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
363  } elseif ($page == $end_page) {
364  // last page
365  $height = $end_y - $tMargin;
366  } else {
367  $height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
368  }
369  }
370  }
371  // restore previous object
372  $pdf = $pdf->rollbackTransaction();
373 
374  return $height;
375 }
376 
377 
386 function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias = 0)
387 {
388  global $conf;
389 
390  // Recipient name
391  $socname = '';
392 
393  if ($thirdparty instanceof Societe) {
394  $socname = $thirdparty->name;
395  if (($includealias || getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME')) && !empty($thirdparty->name_alias)) {
396  if (getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME') == 2) {
397  $socname = $thirdparty->name_alias." - ".$thirdparty->name;
398  } else {
399  $socname = $thirdparty->name." - ".$thirdparty->name_alias;
400  }
401  }
402  } elseif ($thirdparty instanceof Contact) {
403  $socname = $thirdparty->socname;
404  if (($includealias || getDolGlobalInt('PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME')) && !empty($thirdparty->name_alias)) {
405  // TODO PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME not completely implemented
406  }
407  } else {
408  throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
409  }
410 
411  return $outputlangs->convToOutputCharset($socname);
412 }
413 
414 
427 function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source', $object = null)
428 {
429  global $conf, $hookmanager;
430 
431  if ($mode == 'source' && !is_object($sourcecompany)) {
432  return -1;
433  }
434  if ($mode == 'target' && !is_object($targetcompany)) {
435  return -1;
436  }
437 
438  if (!empty($sourcecompany->state_id) && empty($sourcecompany->state)) {
439  $sourcecompany->state = getState($sourcecompany->state_id);
440  }
441  if (!empty($targetcompany->state_id) && empty($targetcompany->state)) {
442  $targetcompany->state = getState($targetcompany->state_id);
443  }
444 
445  $reshook = 0;
446  $stringaddress = '';
447  if (is_object($hookmanager)) {
448  $parameters = array('sourcecompany' => &$sourcecompany, 'targetcompany' => &$targetcompany, 'targetcontact' => &$targetcontact, 'outputlangs' => $outputlangs, 'mode' => $mode, 'usecontact' => $usecontact);
449  $action = '';
450  $reshook = $hookmanager->executeHooks('pdf_build_address', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
451  $stringaddress .= $hookmanager->resPrint;
452  }
453  if (empty($reshook)) {
454  if ($mode == 'source') {
455  $withCountry = 0;
456  if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
457  $withCountry = 1;
458  }
459 
460  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
461 
462  if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS)) {
463  // Phone
464  if ($sourcecompany->phone) {
465  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
466  }
467  // Fax
468  if ($sourcecompany->fax) {
469  $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
470  }
471  // EMail
472  if ($sourcecompany->email) {
473  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
474  }
475  // Web
476  if ($sourcecompany->url) {
477  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
478  }
479  }
480  // Intra VAT
481  if (!empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS)) {
482  if ($sourcecompany->tva_intra) {
483  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
484  }
485  }
486  // Professionnal Ids
487  $reg = array();
488  if (!empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof1)) {
489  $tmp = $outputlangs->transcountrynoentities("ProfId1", $sourcecompany->country_code);
490  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
491  $tmp = $reg[1];
492  }
493  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
494  }
495  if (!empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof2)) {
496  $tmp = $outputlangs->transcountrynoentities("ProfId2", $sourcecompany->country_code);
497  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
498  $tmp = $reg[1];
499  }
500  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
501  }
502  if (!empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof3)) {
503  $tmp = $outputlangs->transcountrynoentities("ProfId3", $sourcecompany->country_code);
504  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
505  $tmp = $reg[1];
506  }
507  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
508  }
509  if (!empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof4)) {
510  $tmp = $outputlangs->transcountrynoentities("ProfId4", $sourcecompany->country_code);
511  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
512  $tmp = $reg[1];
513  }
514  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
515  }
516  if (!empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof5)) {
517  $tmp = $outputlangs->transcountrynoentities("ProfId5", $sourcecompany->country_code);
518  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
519  $tmp = $reg[1];
520  }
521  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
522  }
523  if (!empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof6)) {
524  $tmp = $outputlangs->transcountrynoentities("ProfId6", $sourcecompany->country_code);
525  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
526  $tmp = $reg[1];
527  }
528  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
529  }
530  if (!empty($conf->global->PDF_ADD_MORE_AFTER_SOURCE_ADDRESS)) {
531  $stringaddress .= ($stringaddress ? "\n" : '').$conf->global->PDF_ADD_MORE_AFTER_SOURCE_ADDRESS;
532  }
533  }
534 
535  if ($mode == 'target' || preg_match('/targetwithdetails/', $mode)) {
536  if ($usecontact) {
537  if (is_object($targetcontact)) {
538  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs, 1));
539 
540  if (!empty($targetcontact->address)) {
541  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
542  } else {
543  $companytouseforaddress = $targetcompany;
544 
545  // Contact on a thirdparty that is a different thirdparty than the thirdparty of object
546  if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id) {
547  $targetcontact->fetch_thirdparty();
548  $companytouseforaddress = $targetcontact->thirdparty;
549  }
550 
551  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
552  }
553  // Country
554  if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
555  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
556  } elseif (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
557  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
558  }
559 
560  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode)) {
561  // Phone
562  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode)) {
563  if (!empty($targetcontact->phone_pro) || !empty($targetcontact->phone_mobile)) {
564  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
565  }
566  if (!empty($targetcontact->phone_pro)) {
567  $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
568  }
569  if (!empty($targetcontact->phone_pro) && !empty($targetcontact->phone_mobile)) {
570  $stringaddress .= " / ";
571  }
572  if (!empty($targetcontact->phone_mobile)) {
573  $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
574  }
575  }
576  // Fax
577  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode)) {
578  if ($targetcontact->fax) {
579  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
580  }
581  }
582  // EMail
583  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode)) {
584  if ($targetcontact->email) {
585  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
586  }
587  }
588  // Web
589  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode)) {
590  if ($targetcontact->url) {
591  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
592  }
593  }
594  }
595  }
596  } else {
597  if (is_object($targetcompany)) {
598  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
599  // Country
600  if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) {
601  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
602  }
603 
604  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode)) {
605  // Phone
606  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode)) {
607  if (!empty($targetcompany->phone)) {
608  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
609  }
610  if (!empty($targetcompany->phone)) {
611  $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
612  }
613  }
614  // Fax
615  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode)) {
616  if ($targetcompany->fax) {
617  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
618  }
619  }
620  // EMail
621  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode)) {
622  if ($targetcompany->email) {
623  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
624  }
625  }
626  // Web
627  if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode)) {
628  if ($targetcompany->url) {
629  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
630  }
631  }
632  }
633  }
634  }
635 
636  // Intra VAT
637  if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS)) {
638  if ($targetcompany->tva_intra) {
639  $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
640  }
641  }
642 
643  // Professionnal Ids
644  if (!empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && !empty($targetcompany->idprof1)) {
645  $tmp = $outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code);
646  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
647  $tmp = $reg[1];
648  }
649  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
650  }
651  if (!empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && !empty($targetcompany->idprof2)) {
652  $tmp = $outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code);
653  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
654  $tmp = $reg[1];
655  }
656  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
657  }
658  if (!empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && !empty($targetcompany->idprof3)) {
659  $tmp = $outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code);
660  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
661  $tmp = $reg[1];
662  }
663  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
664  }
665  if (!empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && !empty($targetcompany->idprof4)) {
666  $tmp = $outputlangs->transcountrynoentities("ProfId4", $targetcompany->country_code);
667  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
668  $tmp = $reg[1];
669  }
670  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
671  }
672  if (!empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && !empty($targetcompany->idprof5)) {
673  $tmp = $outputlangs->transcountrynoentities("ProfId5", $targetcompany->country_code);
674  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
675  $tmp = $reg[1];
676  }
677  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
678  }
679  if (!empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && !empty($targetcompany->idprof6)) {
680  $tmp = $outputlangs->transcountrynoentities("ProfId6", $targetcompany->country_code);
681  if (preg_match('/\((.+)\)/', $tmp, $reg)) {
682  $tmp = $reg[1];
683  }
684  $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
685  }
686 
687  // Public note
688  if (!empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS)) {
689  if ($mode == 'source' && !empty($sourcecompany->note_public)) {
690  $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($sourcecompany->note_public);
691  }
692  if (($mode == 'target' || preg_match('/targetwithdetails/', $mode)) && !empty($targetcompany->note_public)) {
693  $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($targetcompany->note_public);
694  }
695  }
696  }
697  }
698 
699  return $stringaddress;
700 }
701 
702 
711 function pdf_pagehead(&$pdf, $outputlangs, $page_height)
712 {
713  global $conf;
714 
715  // Add a background image on document only if good setup of const
716  if (!empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF) && ($conf->global->MAIN_USE_BACKGROUND_ON_PDF != '-1')) { // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
717  $filepath = $conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF;
718  if (file_exists($filepath)) {
719  $pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak before adding image
720  $pdf->Image($filepath, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_X : 0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y : 0), 0, $page_height);
721  $pdf->SetPageMark(); // This option avoid to have the images missing on some pages
722  $pdf->SetAutoPageBreak(1, 0); // Restore pagebreak
723  }
724  }
725 }
726 
727 
737 function pdf_getSubstitutionArray($outputlangs, $exclude = null, $object = null, $onlykey = 0)
738 {
739  $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
740  $substitutionarray['__FROM_NAME__'] = '__FROM_NAME__';
741  $substitutionarray['__FROM_EMAIL__'] = '__FROM_EMAIL__';
742  return $substitutionarray;
743 }
744 
745 
757 function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
758 {
759  global $langs, $mysoc, $user;
760 
761  // Print Draft Watermark
762  if ($unit == 'pt') {
763  $k = 1;
764  } elseif ($unit == 'mm') {
765  $k = 72 / 25.4;
766  } elseif ($unit == 'cm') {
767  $k = 72 / 2.54;
768  } elseif ($unit == 'in') {
769  $k = 72;
770  }
771 
772  // Make substitution
773  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, null);
774  complete_substitutions_array($substitutionarray, $outputlangs, null);
775  $text = make_substitutions($text, $substitutionarray, $outputlangs);
776  $text = $outputlangs->convToOutputCharset($text);
777 
778  $savx = $pdf->getX();
779  $savy = $pdf->getY();
780 
781  $watermark_angle = atan($h / $w) / 2;
782  $watermark_x_pos = 0;
783  $watermark_y_pos = $h / 3;
784  $watermark_x = $w / 2;
785  $watermark_y = $h / 3;
786  $pdf->SetFont('', 'B', 40);
787  $pdf->SetTextColor(255, 192, 203);
788  //rotate
789  $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));
790  //print watermark
791  $pdf->SetXY($watermark_x_pos, $watermark_y_pos);
792  $pdf->Cell($w - 20, 25, $outputlangs->convToOutputCharset($text), "", 2, "C", 0);
793  //antirotate
794  $pdf->_out('Q');
795 
796  $pdf->SetXY($savx, $savy);
797 }
798 
799 
812 function pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0, $default_font_size = 10)
813 {
814  global $mysoc, $conf;
815 
816  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
817 
818  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
819  $diffsizecontent = (empty($conf->global->PDF_DIFFSIZE_CONTENT) ? 4 : $conf->global->PDF_DIFFSIZE_CONTENT);
820  $pdf->SetXY($curx, $cury);
821 
822  if (empty($onlynumber)) {
823  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
824  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
825  $cury += 4;
826  }
827 
828  $outputlangs->load("banks");
829 
830  // Use correct name of bank id according to country
831  $bickey = "BICNumber";
832  if ($account->getCountryCode() == 'IN') {
833  $bickey = "SWIFT";
834  }
835 
836  // Get format of bank account according to its country
837  $usedetailedbban = $account->useDetailedBBAN();
838 
839  //$onlynumber=0; $usedetailedbban=1; // For tests
840  if ($usedetailedbban) {
841  $savcurx = $curx;
842 
843  if (empty($onlynumber)) {
844  $pdf->SetFont('', '', $default_font_size - $diffsizecontent);
845  $pdf->SetXY($curx, $cury);
846  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
847  $cury += 3;
848  }
849 
850  if (empty($conf->global->PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN)) { // Note that some countries still need bank number, BIC/IBAN not enougth for them
851  // Note:
852  // bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
853  // desk = code guichet (FR), used only when $usedetailedbban = 1
854  // number = account number
855  // key = check control key used only when $usedetailedbban = 1
856  if (empty($onlynumber)) {
857  $pdf->line($curx + 1, $cury + 1, $curx + 1, $cury + 6);
858  }
859 
860 
861  foreach ($account->getFieldsToShow() as $val) {
862  $pdf->SetXY($curx, $cury + 4);
863  $pdf->SetFont('', '', $default_font_size - 3);
864 
865  if ($val == 'BankCode') {
866  // Bank code
867  $tmplength = 18;
868  $content = $account->code_banque;
869  } elseif ($val == 'DeskCode') {
870  // Desk
871  $tmplength = 18;
872  $content = $account->code_guichet;
873  } elseif ($val == 'BankAccountNumber') {
874  // Number
875  $tmplength = 24;
876  $content = $account->number;
877  } elseif ($val == 'BankAccountNumberKey') {
878  // Key
879  $tmplength = 15;
880  $content = $account->cle_rib;
881  } elseif ($val == 'IBAN' || $val == 'BIC') {
882  // Key
883  $tmplength = 0;
884  $content = '';
885  } else {
886  dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
887  break;
888  }
889 
890  $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0);
891  $pdf->SetXY($curx, $cury + 1);
892  $curx += $tmplength;
893  $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
894  $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0);
895  if (empty($onlynumber)) {
896  $pdf->line($curx, $cury + 1, $curx, $cury + 7);
897  }
898  }
899 
900  $curx = $savcurx;
901  $cury += 8;
902  }
903  } else {
904  $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
905  $pdf->SetXY($curx, $cury);
906  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
907  $cury += 3;
908 
909  $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
910  $pdf->SetXY($curx, $cury);
911  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': '.$outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
912  $cury += 3;
913 
914  if ($diffsizecontent <= 2) {
915  $cury += 1;
916  }
917  }
918 
919  $pdf->SetFont('', '', $default_font_size - $diffsizecontent);
920 
921  if (empty($onlynumber) && !empty($account->domiciliation)) {
922  $pdf->SetXY($curx, $cury);
923  $val = $outputlangs->transnoentities("Residence").': '.$outputlangs->convToOutputCharset($account->domiciliation);
924  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
925  //$nboflines=dol_nboflines_bis($val,120);
926  //$cury+=($nboflines*3)+2;
927  $tmpy = $pdf->getStringHeight(100, $val);
928  $cury += $tmpy;
929  }
930 
931  if (!empty($account->proprio)) {
932  $pdf->SetXY($curx, $cury);
933  $val = $outputlangs->transnoentities("BankAccountOwner").': '.$outputlangs->convToOutputCharset($account->proprio);
934  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
935  $tmpy = $pdf->getStringHeight(100, $val);
936  $cury += $tmpy;
937  } elseif (!$usedetailedbban) {
938  $cury += 1;
939  }
940 
941  // Use correct name of bank id according to country
942  $ibankey = FormBank::getIBANLabel($account);
943 
944  if (!empty($account->iban)) {
945  //Remove whitespaces to ensure we are dealing with the format we expect
946  $ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
947  $ibanDisplay = "";
948 
949  $nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
950  for ($i = 0; $i < $nbIbanDisplay_temp; $i++) {
951  $ibanDisplay .= $ibanDisplay_temp[$i];
952  if ($i % 4 == 3 && $i > 0) {
953  $ibanDisplay .= " ";
954  }
955  }
956 
957  $pdf->SetFont('', 'B', $default_font_size - 3);
958  $pdf->SetXY($curx, $cury);
959  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': '.$ibanDisplay, 0, 'L', 0);
960  $cury += 3;
961  }
962 
963  if (!empty($account->bic)) {
964  $pdf->SetFont('', 'B', $default_font_size - 3);
965  $pdf->SetXY($curx, $cury);
966  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': '.$outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
967  }
968 
969  return $pdf->getY();
970 }
971 
989 function pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0, $hidefreetext = 0, $page_largeur = 0, $watermark = '')
990 {
991  global $conf, $user, $mysoc, $hookmanager;
992 
993  $outputlangs->load("dict");
994  $line = '';
995  $reg = array();
996 
997  $dims = $pdf->getPageDimensions();
998 
999  // Line of free text
1000  if (empty($hidefreetext) && !empty($conf->global->$paramfreetext)) {
1001  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
1002  // More substitution keys
1003  $substitutionarray['__FROM_NAME__'] = $fromcompany->name;
1004  $substitutionarray['__FROM_EMAIL__'] = $fromcompany->email;
1005  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1006  $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
1007 
1008  // Make a change into HTML code to allow to include images from medias directory.
1009  // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
1010  // become
1011  // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
1012  $newfreetext = preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1file:/'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
1013 
1014  $line .= $outputlangs->convToOutputCharset($newfreetext);
1015  }
1016 
1017  // First line of company infos
1018  $line1 = "";
1019  $line2 = "";
1020  $line3 = "";
1021  $line4 = "";
1022 
1023  if ($showdetails == 1 || $showdetails == 3) {
1024  // Company name
1025  if ($fromcompany->name) {
1026  $line1 .= ($line1 ? " - " : "").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
1027  }
1028  // Address
1029  if ($fromcompany->address) {
1030  $line1 .= ($line1 ? " - " : "").str_replace("\n", ", ", $fromcompany->address);
1031  }
1032  // Zip code
1033  if ($fromcompany->zip) {
1034  $line1 .= ($line1 ? " - " : "").$fromcompany->zip;
1035  }
1036  // Town
1037  if ($fromcompany->town) {
1038  $line1 .= ($line1 ? " " : "").$fromcompany->town;
1039  }
1040  // Country
1041  if ($fromcompany->country) {
1042  $line1 .= ($line1 ? ", " : "").$fromcompany->country;
1043  }
1044  // Phone
1045  if ($fromcompany->phone) {
1046  $line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
1047  }
1048  // Fax
1049  if ($fromcompany->fax) {
1050  $line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
1051  }
1052 
1053  // URL
1054  if ($fromcompany->url) {
1055  $line2 .= ($line2 ? " - " : "").$fromcompany->url;
1056  }
1057  // Email
1058  if ($fromcompany->email) {
1059  $line2 .= ($line2 ? " - " : "").$fromcompany->email;
1060  }
1061  }
1062  if ($showdetails == 2 || $showdetails == 3 || (!empty($fromcompany->country_code) && $fromcompany->country_code == 'DE')) {
1063  // Managers
1064  if ($fromcompany->managers) {
1065  $line2 .= ($line2 ? " - " : "").$fromcompany->managers;
1066  }
1067  }
1068 
1069  // Line 3 of company infos
1070  // Juridical status
1071  if (!empty($fromcompany->forme_juridique_code) && $fromcompany->forme_juridique_code) {
1072  $line3 .= ($line3 ? " - " : "").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
1073  }
1074  // Capital
1075  if (!empty($fromcompany->capital)) {
1076  $tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string or a float
1077  if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) {
1078  $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
1079  } elseif (!empty($fromcompany->capital)) {
1080  $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", $fromcompany->capital, $outputlangs);
1081  }
1082  }
1083  // Prof Id 1
1084  if (!empty($fromcompany->idprof1) && $fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
1085  $field = $outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
1086  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1087  $field = $reg[1];
1088  }
1089  $line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
1090  }
1091  // Prof Id 2
1092  if (!empty($fromcompany->idprof2) && $fromcompany->idprof2) {
1093  $field = $outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
1094  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1095  $field = $reg[1];
1096  }
1097  $line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
1098  }
1099 
1100  // Line 4 of company infos
1101  // Prof Id 3
1102  if (!empty($fromcompany->idprof3) && $fromcompany->idprof3) {
1103  $field = $outputlangs->transcountrynoentities("ProfId3", $fromcompany->country_code);
1104  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1105  $field = $reg[1];
1106  }
1107  $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
1108  }
1109  // Prof Id 4
1110  if (!empty($fromcompany->idprof4) && $fromcompany->idprof4) {
1111  $field = $outputlangs->transcountrynoentities("ProfId4", $fromcompany->country_code);
1112  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1113  $field = $reg[1];
1114  }
1115  $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
1116  }
1117  // Prof Id 5
1118  if (!empty($fromcompany->idprof5) && $fromcompany->idprof5) {
1119  $field = $outputlangs->transcountrynoentities("ProfId5", $fromcompany->country_code);
1120  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1121  $field = $reg[1];
1122  }
1123  $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
1124  }
1125  // Prof Id 6
1126  if (!empty($fromcompany->idprof6) && $fromcompany->idprof6) {
1127  $field = $outputlangs->transcountrynoentities("ProfId6", $fromcompany->country_code);
1128  if (preg_match('/\((.*)\)/i', $field, $reg)) {
1129  $field = $reg[1];
1130  }
1131  $line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
1132  }
1133  // IntraCommunautary VAT
1134  if (!empty($fromcompany->tva_intra) && $fromcompany->tva_intra != '') {
1135  $line4 .= ($line4 ? " - " : "").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
1136  }
1137 
1138  $pdf->SetFont('', '', 7);
1139  $pdf->SetDrawColor(224, 224, 224);
1140  // Option for footer text color
1141  if (!empty($conf->global->PDF_FOOTER_TEXT_COLOR)) {
1142  list($r, $g, $b) = sscanf($conf->global->PDF_FOOTER_TEXT_COLOR, '%d, %d, %d');
1143  $pdf->SetTextColor($r, $g, $b);
1144  }
1145 
1146  // The start of the bottom of this page footer is positioned according to # of lines
1147  $freetextheight = 0;
1148  if ($line) { // Free text
1149  //$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
1150  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
1151  $width = 20000;
1152  $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.
1153  if (!empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
1154  $width = 200;
1155  $align = 'C';
1156  }
1157  $freetextheight = $pdf->getStringHeight($width, $line);
1158  } else {
1159  $freetextheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
1160  //print '<br>'.$freetextheight;exit;
1161  }
1162  }
1163 
1164  // For customize footer
1165  if (is_object($hookmanager)) {
1166  $parameters = array('line1' => $line1, 'line2' => $line2, 'line3' => $line3, 'line4' => $line4, 'outputlangs'=>$outputlangs);
1167  $action = '';
1168  $hookmanager->executeHooks('pdf_pagefoot', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1169  if (!empty($hookmanager->resPrint) && $hidefreetext == 0) {
1170  $mycustomfooter = $hookmanager->resPrint;
1171  $mycustomfooterheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($mycustomfooter, 1, 'UTF-8', 0));
1172 
1173  $marginwithfooter = $marge_basse + $freetextheight + $mycustomfooterheight;
1174  $posy = $marginwithfooter + 0;
1175 
1176  // Option for footer background color (without freetext zone)
1177  if (getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1178  list($r, $g, $b) = sscanf($conf->global->PDF_FOOTER_BACKGROUND_COLOR, '%d, %d, %d');
1179  $pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak
1180  $pdf->Rect(0, $dims['hk'] - $posy + $freetextheight, $dims['wk'] + 1, $marginwithfooter + 1, 'F', '', $fill_color = array($r, $g, $b));
1181  $pdf->SetAutoPageBreak(1, 0); // Restore pagebreak
1182  }
1183 
1184  if ($line) { // Free text
1185  $pdf->SetXY($dims['lm'], -$posy);
1186  if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) { // by default
1187  $pdf->MultiCell(0, 3, $line, 0, $align, 0);
1188  } else {
1189  $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1190  }
1191  $posy -= $freetextheight;
1192  }
1193 
1194  $pdf->SetY(-$posy);
1195 
1196  // Hide footer line if footer background color is set
1197  if (!getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1198  $pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
1199  }
1200 
1201  // Option for set top margin height of footer after freetext
1202  if (getDolGlobalString('PDF_FOOTER_TOP_MARGIN') || getDolGlobalString('PDF_FOOTER_TOP_MARGIN') === '0') {
1203  // TODO Remove this case. Height should be good automatically, only $posy-- should be required.
1204  $posy -= getDolGlobalInt('PDF_FOOTER_TOP_MARGIN');
1205  } else {
1206  $posy--;
1207  }
1208 
1209  if (getDolGlobalString('PDF_FOOTER_DISABLE_PAGEBREAK') === '1') { $pdf->SetAutoPageBreak(0, 0); } // Option for disable auto pagebreak
1210  $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $mycustomfooterheight, $dims['lm'], $dims['hk'] - $posy, dol_htmlentitiesbr($mycustomfooter, 1, 'UTF-8', 0));
1211  if (getDolGlobalString('PDF_FOOTER_DISABLE_PAGEBREAK') === '1') { $pdf->SetAutoPageBreak(1, 0); } // Restore pagebreak
1212 
1213  $posy -= $mycustomfooterheight - 3;
1214  } else {
1215  // Else default footer
1216  $marginwithfooter = $marge_basse + $freetextheight + (!empty($line1) ? 3 : 0) + (!empty($line2) ? 3 : 0) + (!empty($line3) ? 3 : 0) + (!empty($line4) ? 3 : 0);
1217  $posy = $marginwithfooter + 0;
1218 
1219  // Option for footer background color (without freetext zone)
1220  if (getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1221  list($r, $g, $b) = sscanf($conf->global->PDF_FOOTER_BACKGROUND_COLOR, '%d, %d, %d');
1222  $pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak
1223  $pdf->Rect(0, $dims['hk'] - $posy + $freetextheight, $dims['wk'] + 1, $marginwithfooter + 1, 'F', '', $fill_color = array($r, $g, $b));
1224  $pdf->SetAutoPageBreak(1, 0); // Restore pagebreak
1225  }
1226 
1227  if ($line) { // Free text
1228  $pdf->SetXY($dims['lm'], -$posy);
1229  if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) { // by default
1230  $pdf->MultiCell(0, 3, $line, 0, $align, 0);
1231  } else {
1232  $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1233  }
1234  $posy -= $freetextheight;
1235  }
1236 
1237  $pdf->SetY(-$posy);
1238 
1239  // Hide footer line if footer background color is set
1240  if (!getDolGlobalString('PDF_FOOTER_BACKGROUND_COLOR')) {
1241  $pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
1242  }
1243 
1244  // Option for set top margin height of footer after freetext
1245  if (getDolGlobalString('PDF_FOOTER_TOP_MARGIN') || getDolGlobalString('PDF_FOOTER_TOP_MARGIN') === '0') {
1246  // TODO Remove this case. Height should be good automatically, only $posy-- should be required.
1247  $posy -= getDolGlobalString('PDF_FOOTER_TOP_MARGIN');
1248  } else {
1249  $posy--;
1250  }
1251 
1252  if (!empty($line1)) {
1253  $pdf->SetFont('', 'B', 7);
1254  $pdf->SetXY($dims['lm'], -$posy);
1255  $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line1, 0, 'C', 0);
1256  $posy -= 3;
1257  $pdf->SetFont('', '', 7);
1258  }
1259 
1260  if (!empty($line2)) {
1261  $pdf->SetFont('', 'B', 7);
1262  $pdf->SetXY($dims['lm'], -$posy);
1263  $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line2, 0, 'C', 0);
1264  $posy -= 3;
1265  $pdf->SetFont('', '', 7);
1266  }
1267 
1268  if (!empty($line3)) {
1269  $pdf->SetXY($dims['lm'], -$posy);
1270  $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line3, 0, 'C', 0);
1271  }
1272 
1273  if (!empty($line4)) {
1274  $posy -= 3;
1275  $pdf->SetXY($dims['lm'], -$posy);
1276  $pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line4, 0, 'C', 0);
1277  }
1278  }
1279  }
1280  // Show page nb only on iso languages (so default Helvetica font)
1281  if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica') {
1282  $pdf->SetXY($dims['wk'] - $dims['rm'] - 15, -$posy);
1283  //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
1284  $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
1285  }
1286 
1287  // Show Draft Watermark
1288  if (!empty($watermark)) {
1289  pdf_watermark($pdf, $outputlangs, $page_hauteur, $page_largeur, 'mm', $watermark);
1290  }
1291 
1292  return $marginwithfooter;
1293 }
1294 
1309 function pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
1310 {
1311  $linkedobjects = pdf_getLinkedObjects($object, $outputlangs);
1312  if (!empty($linkedobjects)) {
1313  foreach ($linkedobjects as $linkedobject) {
1314  $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
1315  if (!empty($linkedobject["date_value"])) {
1316  $reftoshow .= ' / '.$linkedobject["date_value"];
1317  }
1318 
1319  $posy += 3;
1320  $pdf->SetXY($posx, $posy);
1321  $pdf->SetFont('', '', $default_font_size - 2);
1322  $pdf->MultiCell($w, $h, $reftoshow, '', $align);
1323  }
1324  }
1325 
1326  return $pdf->getY();
1327 }
1328 
1345 function pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1346 {
1347  global $db, $conf, $langs, $hookmanager;
1348 
1349  $reshook = 0;
1350  $result = '';
1351  //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) ) )
1352  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1353  $special_code = empty($object->lines[$i]->special_code) ? '' : $object->lines[$i]->special_code;
1354  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1355  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1356  }
1357  $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);
1358  $action = '';
1359  $reshook = $hookmanager->executeHooks('pdf_writelinedesc', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1360 
1361  if (!empty($hookmanager->resPrint)) {
1362  $result .= $hookmanager->resPrint;
1363  }
1364  }
1365  if (empty($reshook)) {
1366  $labelproductservice = pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1367 
1368  //var_dump($labelproductservice);exit;
1369 
1370  // 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"
1371  // We make the reverse, so PDF generation has the real URL.
1372  $nbrep = 0;
1373  $labelproductservice = preg_replace('/(<img[^>]*src=")([^"]*)(&amp;)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep);
1374 
1375  //var_dump($labelproductservice);exit;
1376 
1377  // Description
1378  $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true);
1379  $result .= $labelproductservice;
1380  }
1381  return $result;
1382 }
1383 
1395 function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1396 {
1397  global $db, $conf, $langs;
1398 
1399  $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false);
1400  $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : ''));
1401  $desc = (!empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : ''));
1402  $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
1403  $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : '');
1404  $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false);
1405 
1406  if ($issupplierline) {
1407  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
1408  $prodser = new ProductFournisseur($db);
1409  } else {
1410  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1411  $prodser = new Product($db);
1412 
1413  if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1414  include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
1415  }
1416  }
1417 
1418  if ($idprod) {
1419  $prodser->fetch($idprod);
1420  // If a predefined product and multilang and on other lang, we renamed label with label translated
1421  if (!empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) {
1422  $translatealsoifmodified = (!empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED)); // By default if value was modified manually, we keep it (no translation because we don't have it)
1423 
1424  // 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
1425  // ($textwasnotmodified is replaced with $textwasmodifiedorcompleted and we add completion).
1426 
1427  // Set label
1428  // 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.
1429  //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
1430  $textwasnotmodified = ($label == $prodser->label);
1431  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasnotmodified || $translatealsoifmodified)) {
1432  $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
1433  }
1434 
1435  // Set desc
1436  // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
1437  $textwasnotmodified = false;
1438  if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
1439  $textwasnotmodified = (strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML5), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML5)) !== false);
1440  } else {
1441  $textwasnotmodified = ($desc == $prodser->description);
1442  }
1443  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) {
1444  if ($textwasnotmodified) {
1445  $desc = str_replace($prodser->description, $prodser->multilangs[$outputlangs->defaultlang]["description"], $desc);
1446  } elseif ($translatealsoifmodified) {
1447  $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
1448  }
1449  }
1450 
1451  // Set note
1452  $textwasnotmodified = ($note == $prodser->note_public);
1453  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["other"]) && ($textwasnotmodified || $translatealsoifmodified)) {
1454  $note = $prodser->multilangs[$outputlangs->defaultlang]["other"];
1455  }
1456  }
1457  } 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
1458  $desc = str_replace('(DEPOSIT)', $outputlangs->trans('Deposit'), $desc);
1459  }
1460 
1461  if (empty($conf->global->PDF_HIDE_PRODUCT_LABEL_IN_SUPPLIER_LINES)) {
1462  // Description short of product line
1463  $libelleproduitservice = $label;
1464  if (!empty($libelleproduitservice) && !empty($conf->global->PDF_BOLD_PRODUCT_LABEL)) {
1465  // Adding <b> may convert the original string into a HTML string. Sowe have to first
1466  // convert \n into <br> we text is not already HTML.
1467  if (!dol_textishtml($libelleproduitservice)) {
1468  $libelleproduitservice = str_replace("\n", '<br>', $libelleproduitservice);
1469  }
1470  $libelleproduitservice = '<b>'.$libelleproduitservice.'</b>';
1471  }
1472  }
1473 
1474 
1475  // Add ref of subproducts
1476  if (!empty($conf->global->SHOW_SUBPRODUCT_REF_IN_PDF)) {
1477  $prodser->get_sousproduits_arbo();
1478  if (!empty($prodser->sousprods) && is_array($prodser->sousprods) && count($prodser->sousprods)) {
1479  $tmparrayofsubproducts = reset($prodser->sousprods);
1480  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF)) {
1481  foreach ($tmparrayofsubproducts as $subprodval) {
1482  $libelleproduitservice = dol_concatdesc($libelleproduitservice, " * ".$subprodval[3].' ('.$subprodval[1].')');
1483  }
1484  } else {
1485  foreach ($tmparrayofsubproducts as $subprodval) {
1486  $libelleproduitservice = dol_concatdesc($libelleproduitservice, " * ".$subprodval[5].(($subprodval[5] && $subprodval[3]) ? ' - ' : '').$subprodval[3].' ('.$subprodval[1].')');
1487  }
1488  }
1489  }
1490  }
1491 
1492  // Description long of product line
1493  if (!empty($desc) && ($desc != $label)) {
1494  if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) {
1495  $discount = new DiscountAbsolute($db);
1496  $discount->fetch($object->lines[$i]->fk_remise_except);
1497  $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
1498  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
1499  } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) {
1500  $discount = new DiscountAbsolute($db);
1501  $discount->fetch($object->lines[$i]->fk_remise_except);
1502  $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
1503  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
1504  // Add date of deposit
1505  if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
1506  $libelleproduitservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
1507  }
1508  } elseif ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except) {
1509  $discount = new DiscountAbsolute($db);
1510  $discount->fetch($object->lines[$i]->fk_remise_except);
1511  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
1512  } elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except) {
1513  $discount = new DiscountAbsolute($db);
1514  $discount->fetch($object->lines[$i]->fk_remise_except);
1515  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
1516  } else {
1517  if ($idprod) {
1518  // Check if description must be output
1519  if (!empty($object->element)) {
1520  $tmpkey = 'MAIN_DOCUMENTS_HIDE_DESCRIPTION_FOR_'.strtoupper($object->element);
1521  if (!empty($conf->global->$tmpkey)) {
1522  $hidedesc = 1;
1523  }
1524  }
1525  if (empty($hidedesc)) {
1526  if (!empty($conf->global->MAIN_DOCUMENTS_DESCRIPTION_FIRST)) {
1527  $libelleproduitservice = dol_concatdesc($desc, $libelleproduitservice);
1528  } else {
1529  if (!empty($conf->global->HIDE_LABEL_VARIANT_PDF) && $prodser->isVariant()) {
1530  $libelleproduitservice = $desc;
1531  } else {
1532  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
1533  }
1534  }
1535  }
1536  } else {
1537  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
1538  }
1539  }
1540  }
1541 
1542  // We add ref of product (and supplier ref if defined)
1543  $prefix_prodserv = "";
1544  $ref_prodserv = "";
1545  if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) { // In standard mode, we do not show this
1546  if ($prodser->isService()) {
1547  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
1548  } else {
1549  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
1550  }
1551  }
1552 
1553  if (empty($hideref)) {
1554  if ($issupplierline) {
1555  if (empty($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES)) { // Common case
1556  $ref_prodserv = $prodser->ref; // Show local ref
1557  if ($ref_supplier) {
1558  $ref_prodserv .= ($prodser->ref ? ' (' : '').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref ? ')' : '');
1559  }
1560  } elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1) {
1561  $ref_prodserv = $ref_supplier;
1562  } elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2) {
1563  $ref_prodserv = $ref_supplier.' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
1564  }
1565  } else {
1566  $ref_prodserv = $prodser->ref; // Show local ref only
1567 
1568  if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1569  $productCustomerPriceStatic = new Productcustomerprice($db);
1570  $filter = array('fk_product' => $idprod, 'fk_soc' => $object->socid);
1571 
1572  $nbCustomerPrices = $productCustomerPriceStatic->fetch_all('', '', 1, 0, $filter);
1573 
1574  if ($nbCustomerPrices > 0) {
1575  $productCustomerPrice = $productCustomerPriceStatic->lines[0];
1576 
1577  if (! empty($productCustomerPrice->ref_customer)) {
1578  switch ($conf->global->PRODUIT_CUSTOMER_PRICES_PDF_REF_MODE) {
1579  case 1:
1580  $ref_prodserv = $productCustomerPrice->ref_customer;
1581  break;
1582 
1583  case 2:
1584  $ref_prodserv = $productCustomerPrice->ref_customer . ' (' . $outputlangs->transnoentitiesnoconv('InternalRef') . ' ' . $ref_prodserv . ')';
1585  break;
1586 
1587  default:
1588  $ref_prodserv = $ref_prodserv . ' (' . $outputlangs->transnoentitiesnoconv('RefCustomer') . ' ' . $productCustomerPrice->ref_customer . ')';
1589  }
1590  }
1591  }
1592  }
1593  }
1594 
1595  if (!empty($libelleproduitservice) && !empty($ref_prodserv)) {
1596  $ref_prodserv .= " - ";
1597  }
1598  }
1599 
1600  if (!empty($ref_prodserv) && !empty($conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD)) {
1601  if (!dol_textishtml($libelleproduitservice)) {
1602  $libelleproduitservice = str_replace("\n", '<br>', $libelleproduitservice);
1603  }
1604  $ref_prodserv = '<b>'.$ref_prodserv.'</b>';
1605  // $prefix_prodserv and $ref_prodser are not HTML var
1606  }
1607  $libelleproduitservice = $prefix_prodserv.$ref_prodserv.$libelleproduitservice;
1608 
1609  // Add an additional description for the category products
1610  if (!empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && !empty($conf->categorie->enabled)) {
1611  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1612  $categstatic = new Categorie($db);
1613  // recovering the list of all the categories linked to product
1614  $tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
1615  foreach ($tblcateg as $cate) {
1616  // Adding the descriptions if they are filled
1617  $desccateg = $cate->description;
1618  if ($desccateg) {
1619  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desccateg);
1620  }
1621  }
1622  }
1623 
1624  if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) {
1625  $format = 'day';
1626  $period = '';
1627  // Show duration if exists
1628  if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
1629  $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)).')';
1630  }
1631  if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) {
1632  $period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
1633  }
1634  if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) {
1635  $period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1636  }
1637  //print '>'.$outputlangs->charset_output.','.$period;
1638  if (!empty($conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD)) {
1639  if (!dol_textishtml($libelleproduitservice)) {
1640  $libelleproduitservice = str_replace("\n", '<br>', $libelleproduitservice);
1641  }
1642  $libelleproduitservice .= '<br><b style="color:#333666;" ><em>'.$period.'</em></b>';
1643  } else {
1644  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $period);
1645  }
1646  //print $libelleproduitservice;
1647  }
1648 
1649  if ($dbatch) {
1650  $format = 'day';
1651  foreach ($dbatch as $detail) {
1652  $dte = array();
1653  if ($detail->eatby) {
1654  $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs));
1655  }
1656  if ($detail->sellby) {
1657  $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs));
1658  }
1659  if ($detail->batch) {
1660  $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch);
1661  }
1662  $dte[] = $outputlangs->transnoentitiesnoconv('printQty', $detail->qty);
1663  $libelleproduitservice .= "__N__ ".implode(" - ", $dte);
1664  }
1665  }
1666 
1667  // Now we convert \n into br
1668  if (dol_textishtml($libelleproduitservice)) {
1669  $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice);
1670  } else {
1671  $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice);
1672  }
1673  $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1);
1674 
1675  return $libelleproduitservice;
1676 }
1677 
1687 function pdf_getlinenum($object, $i, $outputlangs, $hidedetails = 0)
1688 {
1689  global $hookmanager;
1690 
1691  $reshook = 0;
1692  $result = '';
1693  //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) ) )
1694  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1695  $special_code = $object->lines[$i]->special_code;
1696  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1697  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1698  }
1699  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1700  $action = '';
1701  $reshook = $hookmanager->executeHooks('pdf_getlinenum', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1702  $result .= $hookmanager->resPrint;
1703  }
1704  if (empty($reshook)) {
1705  $result .= dol_htmlentitiesbr($object->lines[$i]->num);
1706  }
1707  return $result;
1708 }
1709 
1710 
1720 function pdf_getlineref($object, $i, $outputlangs, $hidedetails = 0)
1721 {
1722  global $hookmanager;
1723 
1724  $reshook = 0;
1725  $result = '';
1726  //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) ) )
1727  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1728  $special_code = $object->lines[$i]->special_code;
1729  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1730  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1731  }
1732  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1733  $action = '';
1734  $reshook = $hookmanager->executeHooks('pdf_getlineref', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1735  $result .= $hookmanager->resPrint;
1736  }
1737  if (empty($reshook)) {
1738  $result .= dol_htmlentitiesbr($object->lines[$i]->product_ref);
1739  }
1740  return $result;
1741 }
1742 
1752 function pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails = 0)
1753 {
1754  global $hookmanager;
1755 
1756  $reshook = 0;
1757  $result = '';
1758  //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) ) )
1759  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1760  $special_code = $object->lines[$i]->special_code;
1761  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1762  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1763  }
1764  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1765  $action = '';
1766  $reshook = $hookmanager->executeHooks('pdf_getlineref_supplier', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1767  $result .= $hookmanager->resPrint;
1768  }
1769  if (empty($reshook)) {
1770  $result .= dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
1771  }
1772  return $result;
1773 }
1774 
1784 function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails = 0)
1785 {
1786  global $conf, $hookmanager, $mysoc;
1787 
1788  $result = '';
1789  $reshook = 0;
1790  //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) ) )
1791  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
1792  $special_code = empty($object->lines[$i]) ? '' : $object->lines[$i]->special_code;
1793  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1794  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1795  }
1796  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1797  $action = '';
1798  $reshook = $hookmanager->executeHooks('pdf_getlinevatrate', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1799 
1800  if (!empty($hookmanager->resPrint)) {
1801  $result .= $hookmanager->resPrint;
1802  }
1803  }
1804  if (empty($reshook)) {
1805  if (empty($hidedetails) || $hidedetails > 1) {
1806  $tmpresult = '';
1807 
1808  $tmpresult .= vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
1809  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX)) {
1810  if ($object->lines[$i]->total_localtax1 != 0) {
1811  if (preg_replace('/[\s0%]/', '', $tmpresult)) {
1812  $tmpresult .= '/';
1813  } else {
1814  $tmpresult = '';
1815  }
1816  $tmpresult .= vatrate(abs($object->lines[$i]->localtax1_tx), 0);
1817  }
1818  }
1819  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX)) {
1820  if ($object->lines[$i]->total_localtax2 != 0) {
1821  if (preg_replace('/[\s0%]/', '', $tmpresult)) {
1822  $tmpresult .= '/';
1823  } else {
1824  $tmpresult = '';
1825  }
1826  $tmpresult .= vatrate(abs($object->lines[$i]->localtax2_tx), 0);
1827  }
1828  }
1829  $tmpresult .= '%';
1830 
1831  $result .= $tmpresult;
1832  }
1833  }
1834  return $result;
1835 }
1836 
1846 function pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails = 0)
1847 {
1848  global $conf, $hookmanager;
1849 
1850  $sign = 1;
1851  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1852  $sign = -1;
1853  }
1854 
1855  $result = '';
1856  $reshook = 0;
1857  //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) ) )
1858  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1859  $special_code = empty($object->lines[$i]) ? '' : $object->lines[$i]->special_code;
1860  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1861  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1862  }
1863  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1864  $action = '';
1865  $reshook = $hookmanager->executeHooks('pdf_getlineupexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1866 
1867  if (!empty($hookmanager->resPrint)) {
1868  $result .= $hookmanager->resPrint;
1869  }
1870  }
1871  if (empty($reshook)) {
1872  if (empty($hidedetails) || $hidedetails > 1) {
1873  $subprice = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
1874  $result .= price($sign * $subprice, 0, $outputlangs);
1875  }
1876  }
1877  return $result;
1878 }
1879 
1889 function pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails = 0)
1890 {
1891  global $hookmanager, $conf;
1892 
1893  $sign = 1;
1894  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1895  $sign = -1;
1896  }
1897 
1898  $result = '';
1899  $reshook = 0;
1900  //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) ) )
1901  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1902  $special_code = $object->lines[$i]->special_code;
1903  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1904  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1905  }
1906  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1907  $action = '';
1908  $reshook = $hookmanager->executeHooks('pdf_getlineupwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1909 
1910  if (!empty($hookmanager->resPrint)) {
1911  $result .= $hookmanager->resPrint;
1912  }
1913  }
1914  if (empty($reshook)) {
1915  if (empty($hidedetails) || $hidedetails > 1) {
1916  $result .= price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice) * ($object->lines[$i]->tva_tx) / 100), 0, $outputlangs);
1917  }
1918  }
1919  return $result;
1920 }
1921 
1931 function pdf_getlineqty($object, $i, $outputlangs, $hidedetails = 0)
1932 {
1933  global $hookmanager;
1934 
1935  $result = '';
1936  $reshook = 0;
1937  //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) ) )
1938  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1939  $special_code = empty($object->lines[$i]) ? '' : $object->lines[$i]->special_code;
1940  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1941  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1942  }
1943  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1944  $action = '';
1945  $reshook = $hookmanager->executeHooks('pdf_getlineqty', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1946 
1947  if (!empty($hookmanager->resPrint)) {
1948  $result = $hookmanager->resPrint;
1949  }
1950  }
1951  if (empty($reshook)) {
1952  if ($object->lines[$i]->special_code == 3) {
1953  return '';
1954  }
1955  if (empty($hidedetails) || $hidedetails > 1) {
1956  $result .= $object->lines[$i]->qty;
1957  }
1958  }
1959  return $result;
1960 }
1961 
1971 function pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails = 0)
1972 {
1973  global $hookmanager;
1974 
1975  $reshook = 0;
1976  $result = '';
1977  //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) ) )
1978  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1979  $special_code = $object->lines[$i]->special_code;
1980  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
1981  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1982  }
1983  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1984  $action = '';
1985  $reshook = $hookmanager->executeHooks('pdf_getlineqty_asked', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1986 
1987  if (!empty($hookmanager->resPrint)) {
1988  $result .= $hookmanager->resPrint;
1989  }
1990  }
1991  if (empty($reshook)) {
1992  if ($object->lines[$i]->special_code == 3) {
1993  return '';
1994  }
1995  if (empty($hidedetails) || $hidedetails > 1) {
1996  $result .= $object->lines[$i]->qty_asked;
1997  }
1998  }
1999  return $result;
2000 }
2001 
2011 function pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails = 0)
2012 {
2013  global $hookmanager;
2014 
2015  $reshook = 0;
2016  $result = '';
2017  //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) ) )
2018  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2019  $special_code = $object->lines[$i]->special_code;
2020  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2021  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2022  }
2023  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
2024  $action = '';
2025  $reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2026 
2027  if (!empty($hookmanager->resPrint)) {
2028  $result .= $hookmanager->resPrint;
2029  }
2030  }
2031  if (empty($reshook)) {
2032  if ($object->lines[$i]->special_code == 3) {
2033  return '';
2034  }
2035  if (empty($hidedetails) || $hidedetails > 1) {
2036  $result .= $object->lines[$i]->qty_shipped;
2037  }
2038  }
2039  return $result;
2040 }
2041 
2051 function pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails = 0)
2052 {
2053  global $hookmanager;
2054 
2055  $reshook = 0;
2056  $result = '';
2057  //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) ) )
2058  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2059  $special_code = $object->lines[$i]->special_code;
2060  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2061  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2062  }
2063  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
2064  $action = '';
2065  $reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2066 
2067  if (!empty($hookmanager->resPrint)) {
2068  $result .= $hookmanager->resPrint;
2069  }
2070  }
2071  if (empty($reshook)) {
2072  if ($object->lines[$i]->special_code == 3) {
2073  return '';
2074  }
2075  if (empty($hidedetails) || $hidedetails > 1) {
2076  $result .= ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
2077  }
2078  }
2079  return $result;
2080 }
2081 
2092 function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false)
2093 {
2094  global $langs;
2095 
2096  $reshook = 0;
2097  $result = '';
2098  //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) ) )
2099  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2100  $special_code = $object->lines[$i]->special_code;
2101  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2102  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2103  }
2104  $parameters = array(
2105  'i' => $i,
2106  'outputlangs' => $outputlangs,
2107  'hidedetails' => $hidedetails,
2108  'special_code' => $special_code
2109  );
2110  $action = '';
2111  $reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2112 
2113  if (!empty($hookmanager->resPrint)) {
2114  $result .= $hookmanager->resPrint;
2115  }
2116  }
2117  if (empty($reshook)) {
2118  if (empty($hidedetails) || $hidedetails > 1) {
2119  $result .= $langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
2120  }
2121  }
2122  return $result;
2123 }
2124 
2125 
2135 function pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails = 0)
2136 {
2137  global $hookmanager;
2138 
2139  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2140 
2141  $reshook = 0;
2142  $result = '';
2143  //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) ) )
2144  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2145  $special_code = $object->lines[$i]->special_code;
2146  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2147  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2148  }
2149  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
2150  $action = '';
2151  $reshook = $hookmanager->executeHooks('pdf_getlineremisepercent', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2152 
2153  if (!empty($hookmanager->resPrint)) {
2154  $result .= $hookmanager->resPrint;
2155  }
2156  }
2157  if (empty($reshook)) {
2158  if ($object->lines[$i]->special_code == 3) {
2159  return '';
2160  }
2161  if (empty($hidedetails) || $hidedetails > 1) {
2162  $result .= dol_print_reduction($object->lines[$i]->remise_percent, $outputlangs);
2163  }
2164  }
2165  return $result;
2166 }
2167 
2178 function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null)
2179 {
2180  if (empty($hookmanager)) {
2181  global $hookmanager;
2182  }
2183  global $conf;
2184 
2185  $reshook = 0;
2186  $result = '';
2187  //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) ) )
2188  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2189  $special_code = $object->lines[$i]->special_code;
2190  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2191  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2192  }
2193  $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
2194  $action = '';
2195  $reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2196 
2197  if (!empty($hookmanager->resPrint)) {
2198  return $hookmanager->resPrint;
2199  }
2200  }
2201  if (empty($reshook)) {
2202  if ($object->lines[$i]->special_code == 3) {
2203  return '';
2204  }
2205  if (empty($hidedetails) || $hidedetails > 1) {
2206  if (!empty($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF)) {
2207  $prev_progress = 0;
2208  if (method_exists($object->lines[$i], 'get_prev_progress')) {
2209  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
2210  }
2211  $result = round($object->lines[$i]->situation_percent - $prev_progress, 1).'%';
2212  } else {
2213  $result = round($object->lines[$i]->situation_percent, 1).'%';
2214  }
2215  }
2216  }
2217  return $result;
2218 }
2219 
2229 function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0)
2230 {
2231  global $conf, $hookmanager;
2232 
2233  $sign = 1;
2234  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
2235  $sign = -1;
2236  }
2237 
2238  $reshook = 0;
2239  $result = '';
2240  //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) ) )
2241  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2242  $special_code = empty($object->lines[$i]) ? '' : $object->lines[$i]->special_code;
2243  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2244  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2245  }
2246  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code, 'sign'=>$sign);
2247  $action = '';
2248  $reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2249 
2250  if (!empty($hookmanager->resPrint)) {
2251  $result .= $hookmanager->resPrint;
2252  }
2253  }
2254  if (empty($reshook)) {
2255  if (!empty($object->lines[$i]) && $object->lines[$i]->special_code == 3) {
2256  $result .= $outputlangs->transnoentities("Option");
2257  } elseif (empty($hidedetails) || $hidedetails > 1) {
2258  $total_ht = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht);
2259  if (!empty($object->lines[$i]->situation_percent) && $object->lines[$i]->situation_percent > 0) {
2260  // TODO Remove this. The total should be saved correctly in database instead of being modified here.
2261  $prev_progress = 0;
2262  $progress = 1;
2263  if (method_exists($object->lines[$i], 'get_prev_progress')) {
2264  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
2265  $progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
2266  }
2267  $result .= price($sign * ($total_ht / ($object->lines[$i]->situation_percent / 100)) * $progress, 0, $outputlangs);
2268  } else {
2269  $result .= price($sign * $total_ht, 0, $outputlangs);
2270  }
2271  }
2272  }
2273  return $result;
2274 }
2275 
2285 function pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails = 0)
2286 {
2287  global $hookmanager, $conf;
2288 
2289  $sign = 1;
2290  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
2291  $sign = -1;
2292  }
2293 
2294  $reshook = 0;
2295  $result = '';
2296  //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) ) )
2297  if (is_object($hookmanager)) { // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
2298  $special_code = $object->lines[$i]->special_code;
2299  if (!empty($object->lines[$i]->fk_parent_line) && $object->lines[$i]->fk_parent_line > 0) {
2300  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2301  }
2302  $parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
2303  $action = '';
2304  $reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2305 
2306  if (!empty($hookmanager->resPrint)) {
2307  $result .= $hookmanager->resPrint;
2308  }
2309  }
2310  if (empty($reshook)) {
2311  if ($object->lines[$i]->special_code == 3) {
2312  $result .= $outputlangs->transnoentities("Option");
2313  } elseif (empty($hidedetails) || $hidedetails > 1) {
2314  $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ttc : $object->lines[$i]->total_ttc);
2315  if ($object->lines[$i]->situation_percent > 0) {
2316  // TODO Remove this. The total should be saved correctly in database instead of being modified here.
2317  $prev_progress = 0;
2318  $progress = 1;
2319  if (method_exists($object->lines[$i], 'get_prev_progress')) {
2320  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
2321  $progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
2322  }
2323  $result .= price($sign * ($total_ttc / ($object->lines[$i]->situation_percent / 100)) * $progress, 0, $outputlangs);
2324  } else {
2325  $result .= price($sign * $total_ttc, 0, $outputlangs);
2326  }
2327  }
2328  }
2329  return $result;
2330 }
2331 
2340 function pdf_getLinkedObjects(&$object, $outputlangs)
2341 {
2342  global $db, $hookmanager;
2343 
2344  $linkedobjects = array();
2345 
2346  $object->fetchObjectLinked();
2347 
2348  foreach ($object->linkedObjects as $objecttype => $objects) {
2349  if ($objecttype == 'facture') {
2350  // For invoice, we don't want to have a reference line on document. Image we are using recuring invoice, we will have a line longer than document width.
2351  } elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal') {
2352  $outputlangs->load('propal');
2353 
2354  foreach ($objects as $elementobject) {
2355  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
2356  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2357  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
2358  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
2359  }
2360  } elseif ($objecttype == 'commande' || $objecttype == 'supplier_order') {
2361  $outputlangs->load('orders');
2362 
2363  if (count($objects) > 1 && count($objects) <= (getDolGlobalInt("MAXREFONDOC") ? getDolGlobalInt("MAXREFONDOC") : 10)) {
2364  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities("RefOrder").' :');
2365  foreach ($objects as $elementobject) {
2366  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities($elementobject->ref).(empty($elementobject->ref_client) ?'' : ' ('.$elementobject->ref_client.')').(empty($elementobject->ref_supplier) ? '' : ' ('.$elementobject->ref_supplier.')').' ');
2367  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities("OrderDate").' : '.dol_print_date($elementobject->date, 'day', '', $outputlangs));
2368  }
2369  } elseif (count($objects) == 1) {
2370  $elementobject = array_shift($objects);
2371  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
2372  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref).(!empty($elementobject->ref_client) ? ' ('.$elementobject->ref_client.')' : '').(!empty($elementobject->ref_supplier) ? ' ('.$elementobject->ref_supplier.')' : '');
2373  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
2374  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
2375  }
2376  } elseif ($objecttype == 'contrat') {
2377  $outputlangs->load('contracts');
2378  foreach ($objects as $elementobject) {
2379  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
2380  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2381  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
2382  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat, 'day', '', $outputlangs);
2383  }
2384  } elseif ($objecttype == 'fichinter') {
2385  $outputlangs->load('interventions');
2386  foreach ($objects as $elementobject) {
2387  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("InterRef");
2388  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2389  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("InterDate");
2390  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->datec, 'day', '', $outputlangs);
2391  }
2392  } elseif ($objecttype == 'shipping') {
2393  $outputlangs->loadLangs(array("orders", "sendings"));
2394 
2395  if (count($objects) > 1) {
2396  $order = null;
2397  if (empty($object->linkedObjects['commande']) && $object->element != 'commande') {
2398  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities("RefOrder").' / '.$outputlangs->transnoentities("RefSending").' :');
2399  } else {
2400  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities("RefSending").' :');
2401  }
2402  // We concat this record info into fields xxx_value. title is overwrote.
2403  foreach ($objects as $elementobject) {
2404  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
2405  $elementobject->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
2406  if (! empty($elementobject->linkedObjectsIds['commande'])) {
2407  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
2408  $order = new Commande($db);
2409  $ret = $order->fetch(reset($elementobject->linkedObjectsIds['commande']));
2410  if ($ret < 1) {
2411  $order = null;
2412  }
2413  }
2414  }
2415 
2416  if (! is_object($order)) {
2417  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->transnoentities($elementobject->ref));
2418  } else {
2419  $object->note_public = dol_concatdesc($object->note_public, $outputlangs->convToOutputCharset($order->ref).($order->ref_client ? ' ('.$order->ref_client.')' : ''));
2420  $object->note_public = dol_concatdesc($object->note_public, ' / '.$outputlangs->transnoentities($elementobject->ref));
2421  }
2422  }
2423  } elseif (count($objects) == 1) {
2424  $elementobject = array_shift($objects);
2425  $order = null;
2426  // We concat this record info into fields xxx_value. title is overwrote.
2427  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
2428  $elementobject->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
2429  if (! empty($elementobject->linkedObjectsIds['commande'])) {
2430  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
2431  $order = new Commande($db);
2432  $ret = $order->fetch(reset($elementobject->linkedObjectsIds['commande']));
2433  if ($ret < 1) {
2434  $order = null;
2435  }
2436  }
2437  }
2438 
2439  if (! is_object($order)) {
2440  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
2441  if (! empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] .= ' / ';
2442  $linkedobjects[$objecttype]['ref_value'] .= $outputlangs->transnoentities($elementobject->ref);
2443  $linkedobjects[$objecttype]['date_value'] = dol_print_date(empty($elementobject->date_shipping) ? $elementobject->date_delivery : $elementobject->date_shipping, 'day', '', $outputlangs);
2444  } else {
2445  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder").' / '.$outputlangs->transnoentities("RefSending");
2446  if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref).($order->ref_client ? ' ('.$order->ref_client.')' : '');
2447  $linkedobjects[$objecttype]['ref_value'] .= ' / '.$outputlangs->transnoentities($elementobject->ref);
2448  $linkedobjects[$objecttype]['date_value'] = dol_print_date(empty($elementobject->date_shipping) ? $elementobject->date_delivery : $elementobject->date_shipping, 'day', '', $outputlangs);
2449  }
2450  }
2451  }
2452  }
2453 
2454  // For add external linked objects
2455  if (is_object($hookmanager)) {
2456  $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs);
2457  $action = '';
2458  $hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2459  if (!empty($hookmanager->resArray)) {
2460  $linkedobjects = $hookmanager->resArray;
2461  }
2462  }
2463 
2464  return $linkedobjects;
2465 }
2466 
2474 function pdf_getSizeForImage($realpath)
2475 {
2476  global $conf;
2477 
2478  $maxwidth = (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
2479  $maxheight = (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT) ? 32 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
2480  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2481  $tmp = dol_getImageSize($realpath);
2482  if ($tmp['height']) {
2483  $width = (int) round($maxheight * $tmp['width'] / $tmp['height']); // I try to use maxheight
2484  if ($width > $maxwidth) { // Pb with maxheight, so i use maxwidth
2485  $width = $maxwidth;
2486  $height = (int) round($maxwidth * $tmp['height'] / $tmp['width']);
2487  } else // No pb with maxheight
2488  {
2489  $height = $maxheight;
2490  }
2491  }
2492  return array('width'=>$width, 'height'=>$height);
2493 }
2494 
2504 function pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails = 0)
2505 {
2506  global $conf, $hookmanager;
2507  $sign = 1;
2508  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
2509  $sign = -1;
2510  }
2511  if ($object->lines[$i]->special_code == 3) {
2512  return $outputlangs->transnoentities("Option");
2513  } else {
2514  if (is_object($hookmanager)) {
2515  $special_code = $object->lines[$i]->special_code;
2516  if (!empty($object->lines[$i]->fk_parent_line)) {
2517  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2518  }
2519 
2520  $parameters = array(
2521  'i'=>$i,
2522  'outputlangs'=>$outputlangs,
2523  'hidedetails'=>$hidedetails,
2524  'special_code'=>$special_code
2525  );
2526 
2527  $action = '';
2528 
2529  if ($hookmanager->executeHooks('getlinetotalremise', $parameters, $object, $action) > 0) {
2530  return $hookmanager->resPrint; // Note that $action and $object may have been modified by some hooks
2531  }
2532  }
2533 
2534  if (empty($hidedetails) || $hidedetails > 1) {
2535  return $sign * (($object->lines[$i]->subprice * $object->lines[$i]->qty) - $object->lines[$i]->total_ht);
2536  }
2537  }
2538  return '';
2539 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1784
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
pdf_getSizeForImage
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:2474
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1931
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1846
pdf_writelinedesc
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1345
pdf_getlineremisepercent
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2135
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdfGetHeightForHtmlContent
pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition: pdf.lib.php:338
Productcustomerprice
File of class to manage predefined price products or services by customer.
Definition: productcustomerprice.class.php:29
ProductFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.product.class.php:41
pdf_getlineupwithtax
pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price including tax.
Definition: pdf.lib.php:1889
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
pdf_getlineref
pdf_getlineref($object, $i, $outputlangs, $hidedetails=0)
Return line product ref.
Definition: pdf.lib.php:1720
Translate\convToOutputCharset
convToOutputCharset($str, $pagecodefrom='UTF-8')
Convert a string into output charset (this->charset_output that should be defined to conf->file->char...
Definition: translate.class.php:778
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
Translate
Class to manage translations.
Definition: translate.class.php:30
pdf_getlineunit
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2092
dol_getImageSize
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
Definition: images.lib.php:140
dol_print_reduction
dol_print_reduction($reduction, $langs)
Returns formated reduction.
Definition: functions2.lib.php:1850
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
Categorie
Class to manage categories.
Definition: categorie.class.php:47
pdf_getlinedesc
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:1395
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
pdf_admin_prepare_head
pdf_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: pdf.lib.php:46
dol_concatdesc
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...
Definition: functions.lib.php:7248
getState
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
Definition: company.lib.php:569
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:711
pdf_bank
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:812
pdf_getlineqty_keeptoship
pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails=0)
Return line keep to ship quantity.
Definition: pdf.lib.php:2051
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:757
pdf_getlineqty_asked
pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails=0)
Return line quantity asked.
Definition: pdf.lib.php:1971
Commande
Class to manage customers orders.
Definition: commande.class.php:46
pdf_getlineprogress
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:2178
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
pdf_getlinetotalwithtax
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition: pdf.lib.php:2285
pdf_getLinkedObjects
pdf_getLinkedObjects(&$object, $outputlangs)
Return linked objects to use for document generation.
Definition: pdf.lib.php:2340
pdf_writeLinkedObjects
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1309
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
DiscountAbsolute
Class to manage absolute discounts.
Definition: discount.class.php:29
pdf_build_address
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:427
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_format_address
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
Definition: functions.lib.php:2393
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:683
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
pdf_getEncryption
pdf_getEncryption($pathoffile)
Return if pdf file is protected/encrypted.
Definition: pdf.lib.php:234
pdf_getlineref_supplier
pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails=0)
Return line ref_supplier.
Definition: pdf.lib.php:1752
dol_html_entity_decode
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
Definition: functions.lib.php:7052
dol_getDefaultFormat
dol_getDefaultFormat(Translate $outputlangs=null)
Try to guess default paper format according to language into $langs.
Definition: functions2.lib.php:119
Product
Class to manage products or services.
Definition: product.class.php:46
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:737
price
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.
Definition: functions.lib.php:5541
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7185
FormBank\getIBANLabel
static getIBANLabel(Account $account)
Returns the name of the Iban label.
Definition: html.formbank.class.php:75
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2229
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
pdf_getlineqty_shipped
pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails=0)
Return line quantity shipped.
Definition: pdf.lib.php:2011
complete_substitutions_array
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...
Definition: functions.lib.php:7961
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5492
pdf_pagefoot
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:989
pdf_getlinenum
pdf_getlinenum($object, $i, $outputlangs, $hidedetails=0)
Return line num.
Definition: pdf.lib.php:1687
pdfGetLineTotalDiscountAmount
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0)
Return line total amount discount.
Definition: pdf.lib.php:2504