dolibarr  7.0.0-beta
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@capnetworks.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  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  * or see http://www.gnu.org/
27  */
28 
42 function pdf_getFormat(Translate $outputlangs = null)
43 {
44  global $conf,$db;
45 
46  // Default value if setup was not done and/or entry into c_paper_format not defined
47  $width=210; $height=297; $unit='mm';
48 
49  if (empty($conf->global->MAIN_PDF_FORMAT))
50  {
51  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
52  $pdfformat=dol_getDefaultFormat($outputlangs);
53  }
54  else $pdfformat=$conf->global->MAIN_PDF_FORMAT;
55 
56  $sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
57  $sql.=" WHERE code = '".$pdfformat."'";
58  $resql=$db->query($sql);
59  if ($resql)
60  {
61  $obj=$db->fetch_object($resql);
62  if ($obj)
63  {
64  $width=(int) $obj->width;
65  $height=(int) $obj->height;
66  $unit=$obj->unit;
67  }
68  }
69 
70  //print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
71  return array('width'=>$width,'height'=>$height,'unit'=>$unit);
72 }
73 
82 function pdf_getInstance($format='',$metric='mm',$pagetype='P')
83 {
84  global $conf;
85 
86  // Define constant for TCPDF
87  if (! defined('K_TCPDF_EXTERNAL_CONFIG'))
88  {
89  define('K_TCPDF_EXTERNAL_CONFIG',1); // this avoid using tcpdf_config file
90  define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
91  define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
92  dol_mkdir(K_PATH_CACHE);
93  define('K_BLANK_IMAGE', '_blank.png');
94  define('PDF_PAGE_FORMAT', 'A4');
95  define('PDF_PAGE_ORIENTATION', 'P');
96  define('PDF_CREATOR', 'TCPDF');
97  define('PDF_AUTHOR', 'TCPDF');
98  define('PDF_HEADER_TITLE', 'TCPDF Example');
99  define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
100  define('PDF_UNIT', 'mm');
101  define('PDF_MARGIN_HEADER', 5);
102  define('PDF_MARGIN_FOOTER', 10);
103  define('PDF_MARGIN_TOP', 27);
104  define('PDF_MARGIN_BOTTOM', 25);
105  define('PDF_MARGIN_LEFT', 15);
106  define('PDF_MARGIN_RIGHT', 15);
107  define('PDF_FONT_NAME_MAIN', 'helvetica');
108  define('PDF_FONT_SIZE_MAIN', 10);
109  define('PDF_FONT_NAME_DATA', 'helvetica');
110  define('PDF_FONT_SIZE_DATA', 8);
111  define('PDF_FONT_MONOSPACED', 'courier');
112  define('PDF_IMAGE_SCALE_RATIO', 1.25);
113  define('HEAD_MAGNIFICATION', 1.1);
114  define('K_CELL_HEIGHT_RATIO', 1.25);
115  define('K_TITLE_MAGNIFICATION', 1.3);
116  define('K_SMALL_RATIO', 2/3);
117  define('K_THAI_TOPCHARS', true);
118  define('K_TCPDF_CALLS_IN_HTML', true);
119  define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
120  }
121 
122  if (! empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->MAIN_DISABLE_FPDI))
123  return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together";
124 
125  // We use by default TCPDF else FPDF
126  if (empty($conf->global->MAIN_USE_FPDF)) require_once TCPDF_PATH.'tcpdf.php';
127  else require_once FPDF_PATH.'fpdf.php';
128 
129  // We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
130  if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php';
131  else if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once FPDI_PATH.'fpdi.php';
132 
133  //$arrayformat=pdf_getFormat();
134  //$format=array($arrayformat['width'],$arrayformat['height']);
135  //$metric=$arrayformat['unit'];
136 
137  // Protection and encryption of pdf
138  if (empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->PDF_SECURITY_ENCRYPTION))
139  {
140  /* Permission supported by TCPDF
141  - print : Print the document;
142  - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
143  - copy : Copy or otherwise extract text and graphics from the document;
144  - 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);
145  - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
146  - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
147  - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
148  - 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.
149  - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
150  */
151  if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format);
152  else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format);
153  else $pdf = new TCPDF($pagetype,$metric,$format);
154  // For TCPDF, we specify permission we want to block
155  $pdfrights = array('modify','copy');
156 
157  $pdfuserpass = ''; // Password for the end user
158  $pdfownerpass = NULL; // Password of the owner, created randomly if not defined
159  $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
160  }
161  else
162  {
163  if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format);
164  else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format);
165  else $pdf = new TCPDF($pagetype,$metric,$format);
166  }
167 
168  // If we use FPDF class, we may need to add method writeHTMLCell
169  if (! empty($conf->global->MAIN_USE_FPDF) && ! method_exists($pdf, 'writeHTMLCell'))
170  {
171  // Declare here a class to overwrite FPDI to add method writeHTMLCell
175  class FPDI_DolExtended extends FPDI
176  {
184  public function __call($method, $args)
185  {
186  if (isset($this->$method)) {
187  $func = $this->$method;
188  $func($args);
189  }
190  }
191 
208  public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
209  {
210  $this->SetXY($x,$y);
211  $val=str_replace('<br>',"\n",$html);
212  //$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
213  $val=dol_string_nohtmltag($val,false,'UTF-8');
214  $this->MultiCell($w,$h,$val,$border,$align,$fill);
215  }
216  }
217 
218  $pdf2=new FPDI_DolExtended($pagetype,$metric,$format);
219  unset($pdf);
220  $pdf=$pdf2;
221  }
222 
223  return $pdf;
224 }
225 
226 
233 function pdf_getPDFFont($outputlangs)
234 {
235  global $conf;
236 
237  if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
238 
239  $font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF
240  if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
241  {
242  if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
243  {
244  $font=$outputlangs->trans('FONTFORPDF');
245  }
246  }
247  return $font;
248 }
249 
256 function pdf_getPDFFontSize($outputlangs)
257 {
258  $size=10; // By default, for FPDI or ISO language on TCPDF
259  if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
260  {
261  if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
262  {
263  $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
264  }
265  }
266  return $size;
267 }
268 
269 
277 function pdf_getHeightForLogo($logo, $url = false)
278 {
279  global $conf;
280  $height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
281  $maxwidth=130;
282  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
283  $tmp=dol_getImageSize($logo, $url);
284  if ($tmp['height'])
285  {
286  $width=round($height*$tmp['width']/$tmp['height']);
287  if ($width > $maxwidth) $height=$height*$maxwidth/$width;
288  }
289  //print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
290  return $height;
291 }
292 
300 function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
301 {
302  // store current object
303  $pdf->startTransaction();
304  // store starting values
305  $start_y = $pdf->GetY();
306  //var_dump($start_y);
307  $start_page = $pdf->getPage();
308  // call printing functions with content
309  $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J',true);
310  // get the new Y
311  $end_y = $pdf->GetY();
312  $end_page = $pdf->getPage();
313  // calculate height
314  $height = 0;
315  if ($end_page == $start_page) {
316  $height = $end_y - $start_y;
317  }
318  else
319  {
320  for ($page=$start_page; $page <= $end_page; ++$page) {
321  $pdf->setPage($page);
322  $tmpm=$pdf->getMargins();
323  $tMargin = $tmpm['top'];
324  if ($page == $start_page) {
325  // first page
326  $height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
327  } elseif ($page == $end_page) {
328  // last page
329  $height = $end_y - $tMargin;
330  } else {
331  $height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
332  }
333  }
334  }
335  // restore previous object
336  $pdf = $pdf->rollbackTransaction();
337 
338  return $height;
339 }
340 
341 
350 function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
351 {
352  global $conf;
353 
354  // Recipient name
355  $socname = '';
356 
357  if ($thirdparty instanceof Societe) {
358  $socname .= $thirdparty->name;
359  if (($includealias || ! empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
360  $socname .= "\n".$thirdparty->name_alias;
361  }
362  } elseif ($thirdparty instanceof Contact) {
363  $socname = $thirdparty->socname;
364  } else {
365  throw new InvalidArgumentException('Parameter 1=$thirdparty is not a Societe nor Contact');
366  }
367 
368  return $outputlangs->convToOutputCharset($socname);
369 }
370 
371 
384 function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null)
385 {
386  global $conf, $hookmanager;
387 
388  if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
389  if ($mode == 'target' && ! is_object($targetcompany)) return -1;
390 
391  if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
392  if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
393  if (! empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id)) $sourcecompany->departement_id=getState($sourcecompany->state_id,'2');
394  if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
395  if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
396  if (! empty($targetcompany->state_id) && !isset($targetcompany->departement_id)) $targetcompany->departement_id=getState($targetcompany->state_id,'2');
397 
398  $reshook=0;
399  $stringaddress = '';
400  if (is_object($hookmanager))
401  {
402  $parameters = array('sourcecompany'=>&$sourcecompany,'targetcompany'=>&$targetcompany,'targetcontact'=>$targetcontact,'outputlangs'=>$outputlangs,'mode'=>$mode,'usecontact'=>$usecontact);
403  $action='';
404  $reshook = $hookmanager->executeHooks('pdf_build_address',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
405  $stringaddress.=$hookmanager->resPrint;
406  }
407  if (empty($reshook))
408  {
409  if ($mode == 'source')
410  {
411  $withCountry = 0;
412  if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;
413 
414  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
415 
416  if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
417  {
418  // Phone
419  if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
420  // Fax
421  if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
422  // EMail
423  if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
424  // Web
425  if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
426  }
427  }
428 
429  if ($mode == 'target' || preg_match('/targetwithdetails/',$mode))
430  {
431  if ($usecontact)
432  {
433  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
434 
435  if (!empty($targetcontact->address)) {
436  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
437  }else {
438  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
439  }
440  // Country
441  if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
442  $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
443  }
444  else if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
445  $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
446  }
447 
448  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
449  {
450  // Phone
451  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
452  {
453  if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
454  if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
455  if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
456  if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
457  }
458  // Fax
459  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
460  {
461  if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
462  }
463  // EMail
464  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
465  {
466  if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
467  }
468  // Web
469  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
470  {
471  if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
472  }
473  }
474  }
475  else
476  {
477  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
478  // Country
479  if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
480 
481  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
482  {
483  // Phone
484  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
485  {
486  if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
487  if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
488  if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
489  if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
490  }
491  // Fax
492  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
493  {
494  if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
495  }
496  // EMail
497  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
498  {
499  if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
500  }
501  // Web
502  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
503  {
504  if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
505  }
506  }
507  }
508 
509  // Intra VAT
510  if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS))
511  {
512  if ($targetcompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
513  }
514 
515  // Professionnal Ids
516  if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1))
517  {
518  $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code);
519  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
520  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
521  }
522  if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2))
523  {
524  $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code);
525  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
526  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
527  }
528  if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3))
529  {
530  $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code);
531  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
532  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
533  }
534  if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4))
535  {
536  $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code);
537  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
538  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
539  }
540  if (! empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && ! empty($targetcompany->idprof5))
541  {
542  $tmp=$outputlangs->transcountrynoentities("ProfId5",$targetcompany->country_code);
543  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
544  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
545  }
546  if (! empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && ! empty($targetcompany->idprof6))
547  {
548  $tmp=$outputlangs->transcountrynoentities("ProfId6",$targetcompany->country_code);
549  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
550  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
551  }
552 
553  // Public note
554  if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
555  {
556  if ($mode == 'source' && ! empty($sourcecompany->note_public))
557  {
558  $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($sourcecompany->note_public);
559  }
560  if (($mode == 'target' || preg_match('/targetwithdetails/',$mode)) && ! empty($targetcompany->note_public))
561  {
562  $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($targetcompany->note_public);
563  }
564  }
565  }
566  }
567 
568  return $stringaddress;
569 }
570 
571 
580 function pdf_pagehead(&$pdf,$outputlangs,$page_height)
581 {
582  global $conf;
583 
584  // Add a background image on document
585  if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF)) // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
586  {
587  $pdf->SetAutoPageBreak(0,0); // Disable auto pagebreak before adding image
588  $pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, (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);
589  $pdf->SetAutoPageBreak(1,0); // Restore pagebreak
590  }
591 }
592 
593 
603 function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
604 {
605  $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
606  $substitutionarray['__FROM_NAME__']='__FROM_NAME__';
607  $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
608  return $substitutionarray;
609 }
610 
611 
623 function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
624 {
625  global $langs, $mysoc, $user;
626 
627  // Print Draft Watermark
628  if ($unit=='pt') $k=1;
629  elseif ($unit=='mm') $k=72/25.4;
630  elseif ($unit=='cm') $k=72/2.54;
631  elseif ($unit=='in') $k=72;
632 
633  // Make substitution
634  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
635  complete_substitutions_array($substitutionarray, $outputlangs, null);
636  $text=make_substitutions($text, $substitutionarray, $outputlangs);
637  $text=$outputlangs->convToOutputCharset($text);
638 
639  $savx=$pdf->getX(); $savy=$pdf->getY();
640 
641  $watermark_angle=atan($h/$w)/2;
642  $watermark_x_pos=0;
643  $watermark_y_pos=$h/3;
644  $watermark_x=$w/2;
645  $watermark_y=$h/3;
646  $pdf->SetFont('','B',40);
647  $pdf->SetTextColor(255,192,203);
648  //rotate
649  $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));
650  //print watermark
651  $pdf->SetXY($watermark_x_pos,$watermark_y_pos);
652  $pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0);
653  //antirotate
654  $pdf->_out('Q');
655 
656  $pdf->SetXY($savx,$savy);
657 }
658 
659 
672 function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default_font_size=10)
673 {
674  global $mysoc, $conf;
675 
676  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
677 
678  $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
679  $diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT);
680  $pdf->SetXY($curx, $cury);
681 
682  if (empty($onlynumber))
683  {
684  $pdf->SetFont('','B',$default_font_size - $diffsizetitle);
685  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
686  $cury+=4;
687  }
688 
689  $outputlangs->load("banks");
690 
691  // Use correct name of bank id according to country
692  $bickey="BICNumber";
693  if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
694 
695  // Get format of bank account according to its country
696  $usedetailedbban=$account->useDetailedBBAN();
697 
698  //$onlynumber=0; $usedetailedbban=1; // For tests
699  if ($usedetailedbban)
700  {
701  $savcurx=$curx;
702 
703  if (empty($onlynumber))
704  {
705  $pdf->SetFont('','',$default_font_size - $diffsizecontent);
706  $pdf->SetXY($curx, $cury);
707  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
708  $cury+=3;
709  }
710 
711  if (empty($conf->global->PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN)) // Note that some countries still need bank number, BIC/IBAN not enought for them
712  {
713  // Note:
714  // bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
715  // desk = code guichet (FR), used only when $usedetailedbban = 1
716  // number = account number
717  // key = check control key used only when $usedetailedbban = 1
718  if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6);
719 
720 
721  foreach ($account->getFieldsToShow() as $val)
722  {
723  $pdf->SetXY($curx, $cury+4);
724  $pdf->SetFont('','',$default_font_size - 3);
725 
726  if ($val == 'BankCode') {
727  // Bank code
728  $tmplength = 18;
729  $content = $account->code_banque;
730  } elseif ($val == 'DeskCode') {
731  // Desk
732  $tmplength = 18;
733  $content = $account->code_guichet;
734  } elseif ($val == 'BankAccountNumber') {
735  // Number
736  $tmplength = 24;
737  $content = $account->number;
738  } elseif ($val == 'BankAccountNumberKey') {
739  // Key
740  $tmplength = 13;
741  $content = $account->cle_rib;
742  }elseif ($val == 'IBAN' || $val == 'BIC') {
743  // Key
744  $tmplength = 0;
745  $content = '';
746  } else {
747  dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
748  break;
749  }
750 
751  $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0);
752  $pdf->SetXY($curx, $cury + 1);
753  $curx += $tmplength;
754  $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
755  $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0);
756  if (empty($onlynumber)) {
757  $pdf->line($curx, $cury + 1, $curx, $cury + 7);
758  }
759  }
760 
761  $curx=$savcurx;
762  $cury+=8;
763  }
764  }
765  else
766  {
767  $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
768  $pdf->SetXY($curx, $cury);
769  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
770  $cury+=3;
771 
772  $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
773  $pdf->SetXY($curx, $cury);
774  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
775  $cury+=3;
776 
777  if ($diffsizecontent <= 2) $cury+=1;
778  }
779 
780  $pdf->SetFont('','',$default_font_size - $diffsizecontent);
781 
782  if (empty($onlynumber) && ! empty($account->domiciliation))
783  {
784  $pdf->SetXY($curx, $cury);
785  $val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
786  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
787  //$nboflines=dol_nboflines_bis($val,120);
788  //$cury+=($nboflines*3)+2;
789  $tmpy=$pdf->getStringHeight(100, $val);
790  $cury+=$tmpy;
791  }
792 
793  if (! empty($account->proprio))
794  {
795  $pdf->SetXY($curx, $cury);
796  $val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio);
797  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
798  $tmpy=$pdf->getStringHeight(100, $val);
799  $cury+=$tmpy;
800  $cur+=1;
801  }
802 
803  else if (! $usedetailedbban) $cury+=1;
804 
805  // Use correct name of bank id according to country
806  $ibankey = FormBank::getIBANLabel($account);
807 
808  if (! empty($account->iban))
809  {
810  //Remove whitespaces to ensure we are dealing with the format we expect
811  $ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
812  $ibanDisplay = "";
813 
814  $nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
815  for ($i = 0; $i < $nbIbanDisplay_temp; $i++)
816  {
817  $ibanDisplay .= $ibanDisplay_temp[$i];
818  if($i%4 == 3 && $i > 0) $ibanDisplay .= " ";
819  }
820 
821  $pdf->SetFont('','B',$default_font_size - 3);
822  $pdf->SetXY($curx, $cury);
823  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0);
824  $cury+=3;
825  }
826 
827  if (! empty($account->bic))
828  {
829  $pdf->SetFont('','B',$default_font_size - 3);
830  $pdf->SetXY($curx, $cury);
831  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
832  }
833 
834  return $pdf->getY();
835 }
836 
852 function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0,$hidefreetext=0)
853 {
854  global $conf,$user,$mysoc;
855 
856  $outputlangs->load("dict");
857  $line='';
858 
859  $dims=$pdf->getPageDimensions();
860 
861  // Line of free text
862  if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
863  {
864  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
865  // More substitution keys
866  $substitutionarray['__FROM_NAME__']=$fromcompany->name;
867  $substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
868  complete_substitutions_array($substitutionarray, $outputlangs, $object);
869  $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
870 
871  // Make a change into HTML code to allow to include images from medias directory.
872  // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
873  // become
874  // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
875  $newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
876 
877  $line.=$outputlangs->convToOutputCharset($newfreetext);
878  }
879 
880  // First line of company infos
881  $line1=""; $line2=""; $line3=""; $line4="";
882 
883  if ($showdetails == 1 || $showdetails == 3)
884  {
885  // Company name
886  if ($fromcompany->name)
887  {
888  $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
889  }
890  // Address
891  if ($fromcompany->address)
892  {
893  $line1.=($line1?" - ":"").str_replace("\n", ", ", $fromcompany->address);
894  }
895  // Zip code
896  if ($fromcompany->zip)
897  {
898  $line1.=($line1?" - ":"").$fromcompany->zip;
899  }
900  // Town
901  if ($fromcompany->town)
902  {
903  $line1.=($line1?" ":"").$fromcompany->town;
904  }
905  // Phone
906  if ($fromcompany->phone)
907  {
908  $line2.=($line2?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
909  }
910  // Fax
911  if ($fromcompany->fax)
912  {
913  $line2.=($line2?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
914  }
915 
916  // URL
917  if ($fromcompany->url)
918  {
919  $line2.=($line2?" - ":"").$fromcompany->url;
920  }
921  // Email
922  if ($fromcompany->email)
923  {
924  $line2.=($line2?" - ":"").$fromcompany->email;
925  }
926  }
927  if ($showdetails == 2 || $showdetails == 3 || ($fromcompany->country_code == 'DE'))
928  {
929  // Managers
930  if ($fromcompany->managers)
931  {
932  $line2.=($line2?" - ":"").$fromcompany->managers;
933  }
934  }
935 
936  // Line 3 of company infos
937  // Juridical status
938  if ($fromcompany->forme_juridique_code)
939  {
940  $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
941  }
942  // Capital
943  if ($fromcompany->capital)
944  {
945  $tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string
946  if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
947  else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$tmpamounttoshow,$outputlangs);
948  }
949  // Prof Id 1
950  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
951  {
952  $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
953  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
954  $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
955  }
956  // Prof Id 2
957  if ($fromcompany->idprof2)
958  {
959  $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
960  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
961  $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
962  }
963 
964  // Line 4 of company infos
965  // Prof Id 3
966  if ($fromcompany->idprof3)
967  {
968  $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
969  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
970  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
971  }
972  // Prof Id 4
973  if ($fromcompany->idprof4)
974  {
975  $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
976  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
977  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
978  }
979  // Prof Id 5
980  if ($fromcompany->idprof5)
981  {
982  $field=$outputlangs->transcountrynoentities("ProfId5",$fromcompany->country_code);
983  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
984  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
985  }
986  // Prof Id 6
987  if ($fromcompany->idprof6)
988  {
989  $field=$outputlangs->transcountrynoentities("ProfId6",$fromcompany->country_code);
990  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
991  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
992  }
993  // IntraCommunautary VAT
994  if ($fromcompany->tva_intra != '')
995  {
996  $line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
997  }
998 
999  $pdf->SetFont('','',7);
1000  $pdf->SetDrawColor(224,224,224);
1001 
1002  // The start of the bottom of this page footer is positioned according to # of lines
1003  $freetextheight=0;
1004  if ($line) // Free text
1005  {
1006  //$line="eee<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
1007  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
1008  {
1009  $width=20000; $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.
1010  if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
1011  $width=200; $align='C';
1012  }
1013  $freetextheight=$pdf->getStringHeight($width,$line);
1014  }
1015  else
1016  {
1017  $freetextheight=pdfGetHeightForHtmlContent($pdf,dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
1018  //print '<br>'.$freetextheight;exit;
1019  }
1020  }
1021 
1022  $marginwithfooter=$marge_basse + $freetextheight + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0);
1023  $posy=$marginwithfooter+0;
1024 
1025  if ($line) // Free text
1026  {
1027  $pdf->SetXY($dims['lm'],-$posy);
1028  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) // by default
1029  {
1030  $pdf->MultiCell(0, 3, $line, 0, $align, 0);
1031  }
1032  else
1033  {
1034  $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk']-$marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1035  }
1036  $posy-=$freetextheight;
1037  }
1038 
1039  $pdf->SetY(-$posy);
1040  $pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy);
1041  $posy--;
1042 
1043  if (! empty($line1))
1044  {
1045  $pdf->SetFont('','B',7);
1046  $pdf->SetXY($dims['lm'],-$posy);
1047  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line1, 0, 'C', 0);
1048  $posy-=3;
1049  $pdf->SetFont('','',7);
1050  }
1051 
1052  if (! empty($line2))
1053  {
1054  $pdf->SetFont('','B',7);
1055  $pdf->SetXY($dims['lm'],-$posy);
1056  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line2, 0, 'C', 0);
1057  $posy-=3;
1058  $pdf->SetFont('','',7);
1059  }
1060 
1061  if (! empty($line3))
1062  {
1063  $pdf->SetXY($dims['lm'],-$posy);
1064  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line3, 0, 'C', 0);
1065  }
1066 
1067  if (! empty($line4))
1068  {
1069  $posy-=3;
1070  $pdf->SetXY($dims['lm'],-$posy);
1071  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line4, 0, 'C', 0);
1072  }
1073 
1074  // Show page nb only on iso languages (so default Helvetica font)
1075  if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica')
1076  {
1077  $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy);
1078  //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
1079  if (empty($conf->global->MAIN_USE_FPDF)) $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
1080  else $pdf->MultiCell(15, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
1081  }
1082 
1083  return $marginwithfooter;
1084 }
1085 
1100 function pdf_writeLinkedObjects(&$pdf,$object,$outputlangs,$posx,$posy,$w,$h,$align,$default_font_size)
1101 {
1102  $linkedobjects = pdf_getLinkedObjects($object,$outputlangs);
1103  if (! empty($linkedobjects))
1104  {
1105  foreach($linkedobjects as $linkedobject)
1106  {
1107  $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
1108  if (! empty($linkedobject["date_value"]))
1109  {
1110  $reftoshow .= ' / '.$linkedobject["date_value"];
1111  }
1112 
1113  $posy+=3;
1114  $pdf->SetXY($posx,$posy);
1115  $pdf->SetFont('','', $default_font_size - 2);
1116  $pdf->MultiCell($w, $h, $reftoshow, '', $align);
1117  }
1118  }
1119 
1120  return $pdf->getY();
1121 }
1122 
1139 function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0)
1140 {
1141  global $db, $conf, $langs, $hookmanager;
1142 
1143  $reshook=0;
1144  $result='';
1145  //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) ) )
1146  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
1147  {
1148  $special_code = $object->lines[$i]->special_code;
1149  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1150  $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);
1151  $action='';
1152  $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1153 
1154  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1155  }
1156  if (empty($reshook))
1157  {
1158  $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
1159  // Description
1160  $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true);
1161  $result.=$labelproductservice;
1162  }
1163  return $result;
1164 }
1165 
1177 function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
1178 {
1179  global $db, $conf, $langs;
1180 
1181  $idprod=(! empty($object->lines[$i]->fk_product)?$object->lines[$i]->fk_product:false);
1182  $label=(! empty($object->lines[$i]->label)?$object->lines[$i]->label:(! empty($object->lines[$i]->product_label)?$object->lines[$i]->product_label:''));
1183  $desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:''));
1184  $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
1185  $note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:'');
1186  $dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false);
1187 
1188  if ($issupplierline) $prodser = new ProductFournisseur($db);
1189  else $prodser = new Product($db);
1190 
1191  if ($idprod)
1192  {
1193  $prodser->fetch($idprod);
1194  // If a predefined product and multilang and on other lang, we renamed label with label translated
1195  if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
1196  {
1197  $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)
1198 
1199  // 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
1200  // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
1201 
1202  // Set label
1203  // If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation.
1204  //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
1205  $textwasmodified=($label == $prodser->label);
1206  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
1207 
1208  // Set desc
1209  // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
1210  $textwasmodified=false;
1211  if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
1212  $textwasmodified=(strpos(dol_html_entity_decode($desc,ENT_QUOTES | ENT_HTML401),dol_html_entity_decode($prodser->description,ENT_QUOTES | ENT_HTML401))!==false);
1213  } else {
1214  $textwasmodified=($desc == $prodser->description);
1215  }
1216  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
1217 
1218  // Set note
1219  $textwasmodified=($note == $prodser->note);
1220  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
1221  }
1222  }
1223 
1224  // Description short of product line
1225  $libelleproduitservice=$label;
1226 
1227  // Description long of product line
1228  if (! empty($desc) && ($desc != $label))
1229  {
1230  if ($libelleproduitservice && empty($hidedesc))
1231  {
1232  $libelleproduitservice.='__N__';
1233  }
1234 
1235  if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
1236  {
1237  $discount=new DiscountAbsolute($db);
1238  $discount->fetch($object->lines[$i]->fk_remise_except);
1239  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
1240  }
1241  elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
1242  {
1243  $discount=new DiscountAbsolute($db);
1244  $discount->fetch($object->lines[$i]->fk_remise_except);
1245  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
1246  // Add date of deposit
1247  if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
1248  }
1249  if ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except)
1250  {
1251  $discount=new DiscountAbsolute($db);
1252  $discount->fetch($object->lines[$i]->fk_remise_except);
1253  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
1254  }
1255  else
1256  {
1257  if ($idprod)
1258  {
1259  if (empty($hidedesc)) $libelleproduitservice.=$desc;
1260  }
1261  else
1262  {
1263  $libelleproduitservice.=$desc;
1264  }
1265  }
1266  }
1267 
1268  // We add ref of product (and supplier ref if defined)
1269  $prefix_prodserv = "";
1270  $ref_prodserv = "";
1271  if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
1272  {
1273  if ($prodser->isService())
1274  {
1275  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
1276  }
1277  else
1278  {
1279  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
1280  }
1281  }
1282 
1283  if (empty($hideref))
1284  {
1285  if ($issupplierline)
1286  {
1287  if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1)
1288  $ref_prodserv = $ref_supplier;
1289  elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2)
1290  $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
1291  else // Common case
1292  {
1293  $ref_prodserv = $prodser->ref; // Show local ref
1294  if ($ref_supplier) $ref_prodserv.= ($prodser->ref?' (':'').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref?')':'');
1295  }
1296  }
1297  else
1298  {
1299  $ref_prodserv = $prodser->ref; // Show local ref only
1300  }
1301 
1302  if (! empty($libelleproduitservice) && ! empty($ref_prodserv)) $ref_prodserv .= " - ";
1303  }
1304 
1305  $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
1306 
1307  // Add an additional description for the category products
1308  if (! empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && ! empty($conf->categorie->enabled))
1309  {
1310  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1311  $categstatic=new Categorie($db);
1312  // recovering the list of all the categories linked to product
1313  $tblcateg=$categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
1314  foreach ($tblcateg as $cate)
1315  {
1316  // Adding the descriptions if they are filled
1317  $desccateg=$cate->add_description;
1318  if ($desccateg)
1319  $libelleproduitservice.='__N__'.$desccateg;
1320  }
1321  }
1322 
1323  if (! empty($object->lines[$i]->date_start) || ! empty($object->lines[$i]->date_end))
1324  {
1325  $format='day';
1326  // Show duration if exists
1327  if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
1328  {
1329  $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)).')';
1330  }
1331  if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
1332  {
1333  $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
1334  }
1335  if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
1336  {
1337  $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1338  }
1339  //print '>'.$outputlangs->charset_output.','.$period;
1340  $libelleproduitservice.="__N__".$period;
1341  //print $libelleproduitservice;
1342  }
1343 
1344  if ($dbatch)
1345  {
1346  $format='day';
1347  foreach ($dbatch as $detail)
1348  {
1349  $dte=array();
1350  if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
1351  if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
1352  if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
1353  $dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->dluo_qty);
1354  $libelleproduitservice.= "__N__ ".implode(" - ", $dte);
1355  }
1356  }
1357 
1358  // Now we convert \n into br
1359  if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice);
1360  else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice);
1361  $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
1362 
1363  return $libelleproduitservice;
1364 }
1365 
1375 function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0)
1376 {
1377  global $hookmanager;
1378 
1379  $reshook=0;
1380  $result='';
1381  //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) ) )
1382  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
1383  {
1384  $special_code = $object->lines[$i]->special_code;
1385  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1386  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1387  $action='';
1388  $reshook = $hookmanager->executeHooks('pdf_getlinenum',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1389  $result.=$hookmanager->resPrint;
1390  }
1391  if (empty($reshook))
1392  {
1393  $result.=dol_htmlentitiesbr($object->lines[$i]->num);
1394  }
1395  return $result;
1396 }
1397 
1398 
1408 function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0)
1409 {
1410  global $hookmanager;
1411 
1412  $reshook=0;
1413  $result='';
1414  //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) ) )
1415  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
1416  {
1417  $special_code = $object->lines[$i]->special_code;
1418  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1419  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1420  $action='';
1421  $reshook = $hookmanager->executeHooks('pdf_getlineref',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1422  $result.=$hookmanager->resPrint;
1423  }
1424  if (empty($reshook))
1425  {
1426  $result.=dol_htmlentitiesbr($object->lines[$i]->product_ref);
1427  }
1428  return $result;
1429 }
1430 
1440 function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0)
1441 {
1442  global $hookmanager;
1443 
1444  $reshook=0;
1445  $result='';
1446  //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) ) )
1447  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
1448  {
1449  $special_code = $object->lines[$i]->special_code;
1450  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1451  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1452  $action='';
1453  $reshook = $hookmanager->executeHooks('pdf_getlineref_supplier',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1454  $result.=$hookmanager->resPrint;
1455  }
1456  if (empty($reshook))
1457  {
1458  $result.=dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
1459  }
1460  return $result;
1461 }
1462 
1472 function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0)
1473 {
1474  global $conf, $hookmanager, $mysoc;
1475 
1476  $result='';
1477  $reshook=0;
1478  //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) ) )
1479  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
1480  {
1481  $special_code = $object->lines[$i]->special_code;
1482  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1483  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1484  $action='';
1485  $reshook = $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1486 
1487  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1488  }
1489  if (empty($reshook))
1490  {
1491  if (empty($hidedetails) || $hidedetails > 1)
1492  {
1493  $tmpresult='';
1494 
1495  $tmpresult.=vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
1496  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX))
1497  {
1498  if ($object->lines[$i]->total_localtax1 != 0)
1499  {
1500  if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1501  else $tmpresult='';
1502  $tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx), 0);
1503  }
1504  }
1505  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX))
1506  {
1507  if ($object->lines[$i]->total_localtax2 != 0)
1508  {
1509  if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1510  else $tmpresult='';
1511  $tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx), 0);
1512  }
1513  }
1514  $tmpresult.= '%';
1515 
1516  $result.=$tmpresult;
1517  }
1518  }
1519  return $result;
1520 }
1521 
1531 function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0)
1532 {
1533  global $conf, $hookmanager;
1534 
1535  $sign=1;
1536  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1537 
1538  $result='';
1539  $reshook=0;
1540  //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) ) )
1541  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
1542  {
1543  $special_code = $object->lines[$i]->special_code;
1544  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1545  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1546  $action='';
1547  $reshook = $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1548 
1549  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1550  }
1551  if (empty($reshook))
1552  {
1553  if (empty($hidedetails) || $hidedetails > 1)
1554  {
1555  $subprice = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
1556  $result.=price($sign * $subprice, 0, $outputlangs);
1557  }
1558  }
1559  return $result;
1560 }
1561 
1571 function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0)
1572 {
1573  global $hookmanager,$conf;
1574 
1575  $sign=1;
1576  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1577 
1578  $result='';
1579  $reshook=0;
1580  //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) ) )
1581  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
1582  {
1583  $special_code = $object->lines[$i]->special_code;
1584  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1585  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1586  $action='';
1587  $reshook = $hookmanager->executeHooks('pdf_getlineupwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1588 
1589  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1590  }
1591  if (empty($reshook))
1592  {
1593  if (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs);
1594  }
1595  return $result;
1596 }
1597 
1607 function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0)
1608 {
1609  global $hookmanager;
1610 
1611  $result='';
1612  $reshook=0;
1613  //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) ) )
1614  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
1615  {
1616  $special_code = $object->lines[$i]->special_code;
1617  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1618  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1619  $action='';
1620  $reshook = $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1621 
1622  if(!empty($hookmanager->resPrint)) $result=$hookmanager->resPrint;
1623  }
1624  if (empty($reshook))
1625  {
1626  if ($object->lines[$i]->special_code == 3) return '';
1627  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty;
1628  }
1629  return $result;
1630 }
1631 
1641 function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0)
1642 {
1643  global $hookmanager;
1644 
1645  $reshook=0;
1646  $result='';
1647  //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) ) )
1648  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
1649  {
1650  $special_code = $object->lines[$i]->special_code;
1651  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1652  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1653  $action='';
1654  $reshook = $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1655 
1656  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1657  }
1658  if (empty($reshook))
1659  {
1660  if ($object->lines[$i]->special_code == 3) return '';
1661  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_asked;
1662  }
1663  return $result;
1664 }
1665 
1675 function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0)
1676 {
1677  global $hookmanager;
1678 
1679  $reshook=0;
1680  $result='';
1681  //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) ) )
1682  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
1683  {
1684  $special_code = $object->lines[$i]->special_code;
1685  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1686  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1687  $action='';
1688  $reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1689 
1690  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1691  }
1692  if (empty($reshook))
1693  {
1694  if ($object->lines[$i]->special_code == 3) return '';
1695  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_shipped;
1696  }
1697  return $result;
1698 }
1699 
1709 function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
1710 {
1711  global $hookmanager;
1712 
1713  $reshook=0;
1714  $result='';
1715  //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) ) )
1716  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
1717  {
1718  $special_code = $object->lines[$i]->special_code;
1719  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1720  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1721  $action='';
1722  $reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1723 
1724  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1725  }
1726  if (empty($reshook))
1727  {
1728  if ($object->lines[$i]->special_code == 3) return '';
1729  if (empty($hidedetails) || $hidedetails > 1) $result.=($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
1730  }
1731  return $result;
1732 }
1733 
1744 function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false)
1745 {
1746  global $langs;
1747 
1748  $reshook=0;
1749  $result='';
1750  //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) ) )
1751  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
1752  {
1753  $special_code = $object->lines[$i]->special_code;
1754  if (!empty($object->lines[$i]->fk_parent_line)) {
1755  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1756  }
1757  $parameters = array(
1758  'i' => $i,
1759  'outputlangs' => $outputlangs,
1760  'hidedetails' => $hidedetails,
1761  'special_code' => $special_code
1762  );
1763  $action = '';
1764  $reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1765 
1766  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1767  }
1768  if (empty($reshook))
1769  {
1770  if ($object->lines[$i]->special_code == 3) return '';
1771  if (empty($hidedetails) || $hidedetails > 1) $result.=$langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
1772  }
1773  return $result;
1774 }
1775 
1776 
1786 function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
1787 {
1788  global $hookmanager;
1789 
1790  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1791 
1792  $reshook=0;
1793  $result='';
1794  //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) ) )
1795  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
1796  {
1797  $special_code = $object->lines[$i]->special_code;
1798  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1799  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1800  $action='';
1801  $reshook = $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1802 
1803  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1804  }
1805  if (empty($reshook))
1806  {
1807  if ($object->lines[$i]->special_code == 3) return '';
1808  if (empty($hidedetails) || $hidedetails > 1) $result.=dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
1809  }
1810  return $result;
1811 }
1812 
1823 function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null)
1824 {
1825  if (empty($hookmanager)) global $hookmanager;
1826 
1827  $reshook=0;
1828  $result='';
1829  //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) ) )
1830  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
1831  {
1832  $special_code = $object->lines[$i]->special_code;
1833  if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1834  $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
1835  $action = '';
1836  $reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1837 
1838  if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint;
1839  }
1840  if (empty($reshook))
1841  {
1842  if ($object->lines[$i]->special_code == 3) return '';
1843  if (empty($hidedetails) || $hidedetails > 1)
1844  {
1845  if ($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF)
1846  {
1847  $prev_progress = 0;
1848  if (method_exists($object, 'get_prev_progress'))
1849  {
1850  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1851  }
1852  $result = ($object->lines[$i]->situation_percent - $prev_progress) . '%';
1853  }
1854  else
1855  $result = $object->lines[$i]->situation_percent . '%';
1856  }
1857  }
1858  return $result;
1859 }
1860 
1870 function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0)
1871 {
1872  global $conf, $hookmanager;
1873 
1874  $sign=1;
1875  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1876 
1877  $reshook=0;
1878  $result='';
1879  //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) ) )
1880  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
1881  {
1882  $special_code = $object->lines[$i]->special_code;
1883  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1884  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code, 'sign'=>$sign);
1885  $action='';
1886  $reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1887 
1888  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1889  }
1890  if (empty($reshook))
1891  {
1892  if ($object->lines[$i]->special_code == 3)
1893  {
1894  return $outputlangs->transnoentities("Option");
1895  }
1896  if (empty($hidedetails) || $hidedetails > 1)
1897  {
1898  $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht);
1899  if ($object->lines[$i]->situation_percent > 0)
1900  {
1901  $prev_progress = 0;
1902  $progress = 1;
1903  if (method_exists($object, 'get_prev_progress'))
1904  {
1905  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1906  $progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
1907  }
1908  $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs);
1909  }
1910  else
1911  $result.=price($sign * $total_ht, 0, $outputlangs);
1912  }
1913  }
1914  return $result;
1915 }
1916 
1926 function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
1927 {
1928  global $hookmanager,$conf;
1929 
1930  $sign=1;
1931  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1932 
1933  $reshook=0;
1934  $result='';
1935  //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) ) )
1936  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
1937  {
1938  $special_code = $object->lines[$i]->special_code;
1939  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1940  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1941  $action='';
1942  $reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1943 
1944  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1945  }
1946  if (empty($reshook))
1947  {
1948  if ($object->lines[$i]->special_code == 3)
1949  {
1950  $result.=$outputlangs->transnoentities("Option");
1951  }
1952  elseif (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * ($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs);
1953  }
1954  return $result;
1955 }
1956 
1966 function pdf_getTotalQty($object,$type,$outputlangs)
1967 {
1968  global $hookmanager;
1969 
1970  $total=0;
1971  $nblignes=count($object->lines);
1972 
1973  // Loop on each lines
1974  for ($i = 0 ; $i < $nblignes ; $i++)
1975  {
1976  if ($object->lines[$i]->special_code != 3)
1977  {
1978  if ($type=='all')
1979  {
1980  $total += $object->lines[$i]->qty;
1981  }
1982  else if ($type==9 && is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line)))
1983  {
1984  $special_code = $object->lines[$i]->special_code;
1985  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1986  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1987  $action='';
1988  $reshook = $hookmanager->executeHooks('pdf_getTotalQty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1989  return $hookmanager->resPrint;
1990  }
1991  else if ($type==0 && $object->lines[$i]->product_type == 0)
1992  {
1993  $total += $object->lines[$i]->qty;
1994  }
1995  else if ($type==1 && $object->lines[$i]->product_type == 1)
1996  {
1997  $total += $object->lines[$i]->qty;
1998  }
1999  }
2000  }
2001 
2002  return $total;
2003 }
2004 
2013 function pdf_getLinkedObjects($object,$outputlangs)
2014 {
2015  global $hookmanager;
2016 
2017  $linkedobjects=array();
2018 
2019  $object->fetchObjectLinked();
2020 
2021  foreach($object->linkedObjects as $objecttype => $objects)
2022  {
2023  if ($objecttype == 'facture')
2024  {
2025  // 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.
2026  }
2027  elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal')
2028  {
2029  $outputlangs->load('propal');
2030 
2031  foreach($objects as $elementobject)
2032  {
2033  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
2034  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2035  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
2036  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2037  }
2038  }
2039  else if ($objecttype == 'commande' || $objecttype == 'supplier_order')
2040  {
2041  $outputlangs->load('orders');
2042  foreach($objects as $elementobject)
2043  {
2044  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
2045  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '') . ($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
2046  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
2047  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2048  }
2049  }
2050  else if ($objecttype == 'contrat')
2051  {
2052  $outputlangs->load('contracts');
2053  foreach($objects as $elementobject)
2054  {
2055  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
2056  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2057  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
2058  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat,'day','',$outputlangs);
2059  }
2060  }
2061  else if ($objecttype == 'shipping')
2062  {
2063  $outputlangs->load('orders');
2064  $outputlangs->load('sendings');
2065  foreach($objects as $x => $elementobject)
2066  {
2067  $order=null;
2068  // We concat this record info into fields xxx_value. title is overwrote.
2069  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
2070  {
2071  $elementobject->fetchObjectLinked();
2072  if (! empty($elementobject->linkedObjects['commande'])) $order = reset($elementobject->linkedObjects['commande']);
2073  }
2074  if (! is_object($order))
2075  {
2076  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
2077  if (! empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'].=' / ';
2078  $linkedobjects[$objecttype]['ref_value'].= $outputlangs->transnoentities($elementobject->ref);
2079  //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
2080  //if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
2081  //$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
2082  }
2083  else
2084  {
2085  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
2086  if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' ('.$order->ref_client.')' : '');
2087  $linkedobjects[$objecttype]['ref_value'].= ' / ' . $outputlangs->transnoentities($elementobject->ref);
2088  //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
2089  //if (empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs);
2090  //$linkedobjects[$objecttype]['date_value'].= ($elementobject->date_delivery ? ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs) : '');
2091  }
2092  }
2093  }
2094  }
2095 
2096  // For add external linked objects
2097  if (is_object($hookmanager))
2098  {
2099  $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs);
2100  $action='';
2101  $hookmanager->executeHooks('pdf_getLinkedObjects',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
2102  if (! empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray;
2103  }
2104 
2105  return $linkedobjects;
2106 }
2107 
2115 function pdf_getSizeForImage($realpath)
2116 {
2117  global $conf;
2118 
2119  $maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
2120  $maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
2121  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2122  $tmp=dol_getImageSize($realpath);
2123  if ($tmp['height'])
2124  {
2125  $width=(int) round($maxheight*$tmp['width']/$tmp['height']); // I try to use maxheight
2126  if ($width > $maxwidth) // Pb with maxheight, so i use maxwidth
2127  {
2128  $width=$maxwidth;
2129  $height=(int) round($maxwidth*$tmp['height']/$tmp['width']);
2130  }
2131  else // No pb with maxheight
2132  {
2133  $height=$maxheight;
2134  }
2135  }
2136  return array('width'=>$width,'height'=>$height);
2137 }
2138 
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:672
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:350
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:580
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:623
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png and bmp) ...
Definition: images.lib.php:75
getState($id, $withcode='', $dbtouse=0)
Return state translated from an id.
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:384
dol_print_reduction($reduction, $langs)
Returns formated reduction.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0)
Return a formated address (part address/zip/town/state) according to country rules.
Class to manage contact/addresses.
pdf_getLinkedObjects($object, $outputlangs)
Return linked objects to use for document generation.
Definition: pdf.lib.php:2013
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails=0)
Return line keep to ship quantity.
Definition: pdf.lib.php:1709
pdf_getTotalQty($object, $type, $outputlangs)
Return total quantity of products and/or services.
Definition: pdf.lib.php:1966
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:256
Class to manage products or services.
pdf_getlinenum($object, $i, $outputlangs, $hidedetails=0)
Return line num.
Definition: pdf.lib.php:1375
pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails=0)
Return line quantity asked.
Definition: pdf.lib.php:1641
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:233
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1744
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:1870
static getIBANLabel(Account $account)
Returns the name of the Iban label.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1472
Class to manage third parties objects (customers, suppliers, prospects...)
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1607
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Class to manage categories.
pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails=0)
Return line quantity shipped.
Definition: pdf.lib.php:1675
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:852
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1531
pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition: pdf.lib.php:300
convToOutputCharset($str, $pagecodefrom='UTF-8')
Convert a string into output charset (this->charset_output that should be defined to conf->file->char...
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:2115
dol_getDefaultFormat(Translate $outputlangs=null)
Try to guess default paper format according to language into $langs.
Class to manage translations.
pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price including tax.
Definition: pdf.lib.php:1571
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:1786
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:1823
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:277
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1100
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8')
Clean a string from all HTML tags and entities.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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:603
pdf_getlineref($object, $i, $outputlangs, $hidedetails=0)
Return line product ref.
Definition: pdf.lib.php:1408
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:1139
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
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...
Class to manage absolute discounts.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...
dol_html_entity_decode($a, $b, $c='UTF-8')
Replace html_entity_decode functions to manage errors.
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:1177
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Class to manage predefined suppliers products.
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...
pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails=0)
Return line ref_supplier.
Definition: pdf.lib.php:1440
dol_textishtml($msg, $option=0)
Return if a text is a html content.
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition: pdf.lib.php:1926