dolibarr  9.0.0
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  *
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  // Load TCPDF
123  require_once TCPDF_PATH.'tcpdf.php';
124 
125  // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
126  if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php';
127 
128  //$arrayformat=pdf_getFormat();
129  //$format=array($arrayformat['width'],$arrayformat['height']);
130  //$metric=$arrayformat['unit'];
131 
132  $pdfa=false; // PDF-1.3
133  if (! empty($conf->global->PDF_USE_1A)) $pdfa=true; // PDF1/A
134 
135  if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
136  else $pdf = new TCPDF($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
137 
138  // Protection and encryption of pdf
139  if (! empty($conf->global->PDF_SECURITY_ENCRYPTION))
140  {
141  /* Permission supported by TCPDF
142  - print : Print the document;
143  - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
144  - copy : Copy or otherwise extract text and graphics from the document;
145  - 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);
146  - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
147  - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
148  - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
149  - 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.
150  - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
151  */
152 
153  // For TCPDF, we specify permission we want to block
154  $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
155 
156  // Password for the end user
157  $pdfuserpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_USERPASS:'');
158 
159  // Password of the owner, created randomly if not defined
160  $pdfownerpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS:null);
161 
162  // For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
163  $encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0);
164 
165  // Array of recipients containing public-key certificates ('c') and permissions ('p').
166  // For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
167  $pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const
168 
169  $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass,$encstrength,$pubkeys);
170  }
171 
172  return $pdf;
173 }
174 
182 function pdf_getEncryption(&$pdf, $pathoffile)
183 {
184  $isencrypted = false;
185 
186  $pdfparser = $pdf->_getPdfParser($pathoffile);
187  $data = $pdfparser->getParsedData();
188  if (isset($data[0]['trailer'][1]['/Encrypt'])) {
189  $isencrypted = true;
190  }
191 
192  return $isencrypted;
193 }
194 
201 function pdf_getPDFFont($outputlangs)
202 {
203  global $conf;
204 
205  if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
206 
207  $font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF
208  if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
209  {
210  if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
211  {
212  $font=$outputlangs->trans('FONTFORPDF');
213  }
214  }
215  return $font;
216 }
217 
224 function pdf_getPDFFontSize($outputlangs)
225 {
226  $size=10; // By default, for FPDI or ISO language on TCPDF
227  if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
228  {
229  if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
230  {
231  $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
232  }
233  }
234  return $size;
235 }
236 
237 
245 function pdf_getHeightForLogo($logo, $url = false)
246 {
247  global $conf;
248  $height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
249  $maxwidth=130;
250  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
251  $tmp=dol_getImageSize($logo, $url);
252  if ($tmp['height'])
253  {
254  $width=round($height*$tmp['width']/$tmp['height']);
255  if ($width > $maxwidth) $height=$height*$maxwidth/$width;
256  }
257  //print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
258  return $height;
259 }
260 
269 function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
270 {
271  // store current object
272  $pdf->startTransaction();
273  // store starting values
274  $start_y = $pdf->GetY();
275  //var_dump($start_y);
276  $start_page = $pdf->getPage();
277  // call printing functions with content
278  $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J',true);
279  // get the new Y
280  $end_y = $pdf->GetY();
281  $end_page = $pdf->getPage();
282  // calculate height
283  $height = 0;
284  if ($end_page == $start_page) {
285  $height = $end_y - $start_y;
286  }
287  else
288  {
289  for ($page=$start_page; $page <= $end_page; ++$page) {
290  $pdf->setPage($page);
291  $tmpm=$pdf->getMargins();
292  $tMargin = $tmpm['top'];
293  if ($page == $start_page) {
294  // first page
295  $height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
296  } elseif ($page == $end_page) {
297  // last page
298  $height = $end_y - $tMargin;
299  } else {
300  $height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
301  }
302  }
303  }
304  // restore previous object
305  $pdf = $pdf->rollbackTransaction();
306 
307  return $height;
308 }
309 
310 
319 function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
320 {
321  global $conf;
322 
323  // Recipient name
324  $socname = '';
325 
326  if ($thirdparty instanceof Societe) {
327  $socname .= $thirdparty->name;
328  if (($includealias || ! empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
329  $socname .= "\n".$thirdparty->name_alias;
330  }
331  } elseif ($thirdparty instanceof Contact) {
332  $socname = $thirdparty->socname;
333  } else {
334  throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
335  }
336 
337  return $outputlangs->convToOutputCharset($socname);
338 }
339 
340 
353 function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null)
354 {
355  global $conf, $hookmanager;
356 
357  if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
358  if ($mode == 'target' && ! is_object($targetcompany)) return -1;
359 
360  if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
361  if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
362  if (! empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id)) $sourcecompany->departement_id=getState($sourcecompany->state_id,'2');
363  if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
364  if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
365  if (! empty($targetcompany->state_id) && !isset($targetcompany->departement_id)) $targetcompany->departement_id=getState($targetcompany->state_id,'2');
366 
367  $reshook=0;
368  $stringaddress = '';
369  if (is_object($hookmanager))
370  {
371  $parameters = array('sourcecompany'=>&$sourcecompany,'targetcompany'=>&$targetcompany,'targetcontact'=>$targetcontact,'outputlangs'=>$outputlangs,'mode'=>$mode,'usecontact'=>$usecontact);
372  $action='';
373  $reshook = $hookmanager->executeHooks('pdf_build_address',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
374  $stringaddress.=$hookmanager->resPrint;
375  }
376  if (empty($reshook))
377  {
378  if ($mode == 'source')
379  {
380  $withCountry = 0;
381  if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;
382 
383  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
384 
385  if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
386  {
387  // Phone
388  if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
389  // Fax
390  if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
391  // EMail
392  if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
393  // Web
394  if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
395  }
396  // Intra VAT
397  if (! empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
398  {
399  if ($sourcecompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
400  }
401  // Professionnal Ids
402  if (! empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof1))
403  {
404  $tmp=$outputlangs->transcountrynoentities("ProfId1",$sourcecompany->country_code);
405  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
406  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
407  }
408  if (! empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof2))
409  {
410  $tmp=$outputlangs->transcountrynoentities("ProfId2",$sourcecompany->country_code);
411  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
412  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
413  }
414  if (! empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof3))
415  {
416  $tmp=$outputlangs->transcountrynoentities("ProfId3",$sourcecompany->country_code);
417  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
418  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
419  }
420  if (! empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof4))
421  {
422  $tmp=$outputlangs->transcountrynoentities("ProfId4",$sourcecompany->country_code);
423  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
424  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
425  }
426  if (! empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof5))
427  {
428  $tmp=$outputlangs->transcountrynoentities("ProfId5",$sourcecompany->country_code);
429  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
430  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
431  }
432  if (! empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof6))
433  {
434  $tmp=$outputlangs->transcountrynoentities("ProfId6",$sourcecompany->country_code);
435  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
436  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
437  }
438  }
439 
440  if ($mode == 'target' || preg_match('/targetwithdetails/',$mode))
441  {
442  if ($usecontact)
443  {
444  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
445 
446  if (!empty($targetcontact->address)) {
447  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
448  } else {
449  $companytouseforaddress = $targetcompany;
450 
451  // Contact on a thirdparty that is a different thirdparty than the thirdparty of object
452  if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id)
453  {
454  $targetcontact->fetch_thirdparty();
455  $companytouseforaddress = $targetcontact->thirdparty;
456  }
457 
458  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
459  }
460  // Country
461  if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
462  $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
463  }
464  else if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
465  $stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
466  }
467 
468  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
469  {
470  // Phone
471  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
472  {
473  if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
474  if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
475  if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
476  if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
477  }
478  // Fax
479  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
480  {
481  if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
482  }
483  // EMail
484  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
485  {
486  if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
487  }
488  // Web
489  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
490  {
491  if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
492  }
493  }
494  }
495  else
496  {
497  $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
498  // Country
499  if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
500 
501  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
502  {
503  // Phone
504  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
505  {
506  if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
507  if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
508  if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
509  if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
510  }
511  // Fax
512  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
513  {
514  if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
515  }
516  // EMail
517  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
518  {
519  if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
520  }
521  // Web
522  if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
523  {
524  if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
525  }
526  }
527  }
528 
529  // Intra VAT
530  if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS))
531  {
532  if ($targetcompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
533  }
534 
535  // Professionnal Ids
536  if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1))
537  {
538  $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code);
539  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
540  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
541  }
542  if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2))
543  {
544  $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code);
545  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
546  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
547  }
548  if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3))
549  {
550  $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code);
551  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
552  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
553  }
554  if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4))
555  {
556  $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code);
557  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
558  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
559  }
560  if (! empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && ! empty($targetcompany->idprof5))
561  {
562  $tmp=$outputlangs->transcountrynoentities("ProfId5",$targetcompany->country_code);
563  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
564  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
565  }
566  if (! empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && ! empty($targetcompany->idprof6))
567  {
568  $tmp=$outputlangs->transcountrynoentities("ProfId6",$targetcompany->country_code);
569  if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
570  $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
571  }
572 
573  // Public note
574  if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
575  {
576  if ($mode == 'source' && ! empty($sourcecompany->note_public))
577  {
578  $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($sourcecompany->note_public);
579  }
580  if (($mode == 'target' || preg_match('/targetwithdetails/',$mode)) && ! empty($targetcompany->note_public))
581  {
582  $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($targetcompany->note_public);
583  }
584  }
585  }
586  }
587 
588  return $stringaddress;
589 }
590 
591 
600 function pdf_pagehead(&$pdf,$outputlangs,$page_height)
601 {
602  global $conf;
603 
604  // Add a background image on document
605  if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF)) // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
606  {
607  $pdf->SetAutoPageBreak(0,0); // Disable auto pagebreak before adding image
608  $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);
609  $pdf->SetAutoPageBreak(1,0); // Restore pagebreak
610  }
611 }
612 
613 
623 function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
624 {
625  $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
626  $substitutionarray['__FROM_NAME__']='__FROM_NAME__';
627  $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
628  return $substitutionarray;
629 }
630 
631 
643 function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
644 {
645  global $langs, $mysoc, $user;
646 
647  // Print Draft Watermark
648  if ($unit=='pt') $k=1;
649  elseif ($unit=='mm') $k=72/25.4;
650  elseif ($unit=='cm') $k=72/2.54;
651  elseif ($unit=='in') $k=72;
652 
653  // Make substitution
654  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
655  complete_substitutions_array($substitutionarray, $outputlangs, null);
656  $text=make_substitutions($text, $substitutionarray, $outputlangs);
657  $text=$outputlangs->convToOutputCharset($text);
658 
659  $savx=$pdf->getX(); $savy=$pdf->getY();
660 
661  $watermark_angle=atan($h/$w)/2;
662  $watermark_x_pos=0;
663  $watermark_y_pos=$h/3;
664  $watermark_x=$w/2;
665  $watermark_y=$h/3;
666  $pdf->SetFont('','B',40);
667  $pdf->SetTextColor(255,192,203);
668  //rotate
669  $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));
670  //print watermark
671  $pdf->SetXY($watermark_x_pos,$watermark_y_pos);
672  $pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0);
673  //antirotate
674  $pdf->_out('Q');
675 
676  $pdf->SetXY($savx,$savy);
677 }
678 
679 
692 function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default_font_size=10)
693 {
694  global $mysoc, $conf;
695 
696  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
697 
698  $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
699  $diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT);
700  $pdf->SetXY($curx, $cury);
701 
702  if (empty($onlynumber))
703  {
704  $pdf->SetFont('','B',$default_font_size - $diffsizetitle);
705  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
706  $cury+=4;
707  }
708 
709  $outputlangs->load("banks");
710 
711  // Use correct name of bank id according to country
712  $bickey="BICNumber";
713  if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
714 
715  // Get format of bank account according to its country
716  $usedetailedbban=$account->useDetailedBBAN();
717 
718  //$onlynumber=0; $usedetailedbban=1; // For tests
719  if ($usedetailedbban)
720  {
721  $savcurx=$curx;
722 
723  if (empty($onlynumber))
724  {
725  $pdf->SetFont('','',$default_font_size - $diffsizecontent);
726  $pdf->SetXY($curx, $cury);
727  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
728  $cury+=3;
729  }
730 
731  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
732  {
733  // Note:
734  // bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
735  // desk = code guichet (FR), used only when $usedetailedbban = 1
736  // number = account number
737  // key = check control key used only when $usedetailedbban = 1
738  if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6);
739 
740 
741  foreach ($account->getFieldsToShow() as $val)
742  {
743  $pdf->SetXY($curx, $cury+4);
744  $pdf->SetFont('','',$default_font_size - 3);
745 
746  if ($val == 'BankCode') {
747  // Bank code
748  $tmplength = 18;
749  $content = $account->code_banque;
750  } elseif ($val == 'DeskCode') {
751  // Desk
752  $tmplength = 18;
753  $content = $account->code_guichet;
754  } elseif ($val == 'BankAccountNumber') {
755  // Number
756  $tmplength = 24;
757  $content = $account->number;
758  } elseif ($val == 'BankAccountNumberKey') {
759  // Key
760  $tmplength = 15;
761  $content = $account->cle_rib;
762  }elseif ($val == 'IBAN' || $val == 'BIC') {
763  // Key
764  $tmplength = 0;
765  $content = '';
766  } else {
767  dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
768  break;
769  }
770 
771  $pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0);
772  $pdf->SetXY($curx, $cury + 1);
773  $curx += $tmplength;
774  $pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
775  $pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0);
776  if (empty($onlynumber)) {
777  $pdf->line($curx, $cury + 1, $curx, $cury + 7);
778  }
779  }
780 
781  $curx=$savcurx;
782  $cury+=8;
783  }
784  }
785  else
786  {
787  $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
788  $pdf->SetXY($curx, $cury);
789  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
790  $cury+=3;
791 
792  $pdf->SetFont('','B',$default_font_size - $diffsizecontent);
793  $pdf->SetXY($curx, $cury);
794  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
795  $cury+=3;
796 
797  if ($diffsizecontent <= 2) $cury+=1;
798  }
799 
800  $pdf->SetFont('','',$default_font_size - $diffsizecontent);
801 
802  if (empty($onlynumber) && ! empty($account->domiciliation))
803  {
804  $pdf->SetXY($curx, $cury);
805  $val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
806  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
807  //$nboflines=dol_nboflines_bis($val,120);
808  //$cury+=($nboflines*3)+2;
809  $tmpy=$pdf->getStringHeight(100, $val);
810  $cury+=$tmpy;
811  }
812 
813  if (! empty($account->proprio))
814  {
815  $pdf->SetXY($curx, $cury);
816  $val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio);
817  $pdf->MultiCell(100, 3, $val, 0, 'L', 0);
818  $tmpy=$pdf->getStringHeight(100, $val);
819  $cury+=$tmpy;
820  $cur+=1;
821  }
822 
823  else if (! $usedetailedbban) $cury+=1;
824 
825  // Use correct name of bank id according to country
826  $ibankey = FormBank::getIBANLabel($account);
827 
828  if (! empty($account->iban))
829  {
830  //Remove whitespaces to ensure we are dealing with the format we expect
831  $ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
832  $ibanDisplay = "";
833 
834  $nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
835  for ($i = 0; $i < $nbIbanDisplay_temp; $i++)
836  {
837  $ibanDisplay .= $ibanDisplay_temp[$i];
838  if($i%4 == 3 && $i > 0) $ibanDisplay .= " ";
839  }
840 
841  $pdf->SetFont('','B',$default_font_size - 3);
842  $pdf->SetXY($curx, $cury);
843  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0);
844  $cury+=3;
845  }
846 
847  if (! empty($account->bic))
848  {
849  $pdf->SetFont('','B',$default_font_size - 3);
850  $pdf->SetXY($curx, $cury);
851  $pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
852  }
853 
854  return $pdf->getY();
855 }
856 
872 function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0,$hidefreetext=0)
873 {
874  global $conf,$user,$mysoc;
875 
876  $outputlangs->load("dict");
877  $line='';
878 
879  $dims=$pdf->getPageDimensions();
880 
881  // Line of free text
882  if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
883  {
884  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
885  // More substitution keys
886  $substitutionarray['__FROM_NAME__']=$fromcompany->name;
887  $substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
888  complete_substitutions_array($substitutionarray, $outputlangs, $object);
889  $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
890 
891  // Make a change into HTML code to allow to include images from medias directory.
892  // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
893  // become
894  // <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
895  $newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
896 
897  $line.=$outputlangs->convToOutputCharset($newfreetext);
898  }
899 
900  // First line of company infos
901  $line1=""; $line2=""; $line3=""; $line4="";
902 
903  if ($showdetails == 1 || $showdetails == 3)
904  {
905  // Company name
906  if ($fromcompany->name)
907  {
908  $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
909  }
910  // Address
911  if ($fromcompany->address)
912  {
913  $line1.=($line1?" - ":"").str_replace("\n", ", ", $fromcompany->address);
914  }
915  // Zip code
916  if ($fromcompany->zip)
917  {
918  $line1.=($line1?" - ":"").$fromcompany->zip;
919  }
920  // Town
921  if ($fromcompany->town)
922  {
923  $line1.=($line1?" ":"").$fromcompany->town;
924  }
925  // Phone
926  if ($fromcompany->phone)
927  {
928  $line2.=($line2?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
929  }
930  // Fax
931  if ($fromcompany->fax)
932  {
933  $line2.=($line2?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
934  }
935 
936  // URL
937  if ($fromcompany->url)
938  {
939  $line2.=($line2?" - ":"").$fromcompany->url;
940  }
941  // Email
942  if ($fromcompany->email)
943  {
944  $line2.=($line2?" - ":"").$fromcompany->email;
945  }
946  }
947  if ($showdetails == 2 || $showdetails == 3 || ($fromcompany->country_code == 'DE'))
948  {
949  // Managers
950  if ($fromcompany->managers)
951  {
952  $line2.=($line2?" - ":"").$fromcompany->managers;
953  }
954  }
955 
956  // Line 3 of company infos
957  // Juridical status
958  if ($fromcompany->forme_juridique_code)
959  {
960  $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
961  }
962  // Capital
963  if ($fromcompany->capital)
964  {
965  $tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string
966  if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
967  else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$tmpamounttoshow,$outputlangs);
968  }
969  // Prof Id 1
970  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
971  {
972  $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
973  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
974  $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
975  }
976  // Prof Id 2
977  if ($fromcompany->idprof2)
978  {
979  $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
980  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
981  $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
982  }
983 
984  // Line 4 of company infos
985  // Prof Id 3
986  if ($fromcompany->idprof3)
987  {
988  $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
989  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
990  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
991  }
992  // Prof Id 4
993  if ($fromcompany->idprof4)
994  {
995  $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
996  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
997  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
998  }
999  // Prof Id 5
1000  if ($fromcompany->idprof5)
1001  {
1002  $field=$outputlangs->transcountrynoentities("ProfId5",$fromcompany->country_code);
1003  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
1004  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
1005  }
1006  // Prof Id 6
1007  if ($fromcompany->idprof6)
1008  {
1009  $field=$outputlangs->transcountrynoentities("ProfId6",$fromcompany->country_code);
1010  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
1011  $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
1012  }
1013  // IntraCommunautary VAT
1014  if ($fromcompany->tva_intra != '')
1015  {
1016  $line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
1017  }
1018 
1019  $pdf->SetFont('','',7);
1020  $pdf->SetDrawColor(224,224,224);
1021 
1022  // The start of the bottom of this page footer is positioned according to # of lines
1023  $freetextheight=0;
1024  if ($line) // Free text
1025  {
1026  //$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
1027  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
1028  {
1029  $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.
1030  if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
1031  $width=200; $align='C';
1032  }
1033  $freetextheight=$pdf->getStringHeight($width,$line);
1034  }
1035  else
1036  {
1037  $freetextheight=pdfGetHeightForHtmlContent($pdf,dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
1038  //print '<br>'.$freetextheight;exit;
1039  }
1040  }
1041 
1042  $marginwithfooter=$marge_basse + $freetextheight + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0);
1043  $posy=$marginwithfooter+0;
1044 
1045  if ($line) // Free text
1046  {
1047  $pdf->SetXY($dims['lm'],-$posy);
1048  if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) // by default
1049  {
1050  $pdf->MultiCell(0, 3, $line, 0, $align, 0);
1051  }
1052  else
1053  {
1054  $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk']-$marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1055  }
1056  $posy-=$freetextheight;
1057  }
1058 
1059  $pdf->SetY(-$posy);
1060  $pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy);
1061  $posy--;
1062 
1063  if (! empty($line1))
1064  {
1065  $pdf->SetFont('','B',7);
1066  $pdf->SetXY($dims['lm'],-$posy);
1067  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line1, 0, 'C', 0);
1068  $posy-=3;
1069  $pdf->SetFont('','',7);
1070  }
1071 
1072  if (! empty($line2))
1073  {
1074  $pdf->SetFont('','B',7);
1075  $pdf->SetXY($dims['lm'],-$posy);
1076  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line2, 0, 'C', 0);
1077  $posy-=3;
1078  $pdf->SetFont('','',7);
1079  }
1080 
1081  if (! empty($line3))
1082  {
1083  $pdf->SetXY($dims['lm'],-$posy);
1084  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line3, 0, 'C', 0);
1085  }
1086 
1087  if (! empty($line4))
1088  {
1089  $posy-=3;
1090  $pdf->SetXY($dims['lm'],-$posy);
1091  $pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line4, 0, 'C', 0);
1092  }
1093 
1094  // Show page nb only on iso languages (so default Helvetica font)
1095  if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica')
1096  {
1097  $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy);
1098  //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
1099  $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
1100  }
1101 
1102  return $marginwithfooter;
1103 }
1104 
1119 function pdf_writeLinkedObjects(&$pdf,$object,$outputlangs,$posx,$posy,$w,$h,$align,$default_font_size)
1120 {
1121  $linkedobjects = pdf_getLinkedObjects($object,$outputlangs);
1122  if (! empty($linkedobjects))
1123  {
1124  foreach($linkedobjects as $linkedobject)
1125  {
1126  $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
1127  if (! empty($linkedobject["date_value"]))
1128  {
1129  $reftoshow .= ' / '.$linkedobject["date_value"];
1130  }
1131 
1132  $posy+=3;
1133  $pdf->SetXY($posx,$posy);
1134  $pdf->SetFont('','', $default_font_size - 2);
1135  $pdf->MultiCell($w, $h, $reftoshow, '', $align);
1136  }
1137  }
1138 
1139  return $pdf->getY();
1140 }
1141 
1158 function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0)
1159 {
1160  global $db, $conf, $langs, $hookmanager;
1161 
1162  $reshook=0;
1163  $result='';
1164  //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) ) )
1165  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
1166  {
1167  $special_code = $object->lines[$i]->special_code;
1168  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1169  $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);
1170  $action='';
1171  $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1172 
1173  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1174  }
1175  if (empty($reshook))
1176  {
1177  $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
1178 
1179  //var_dump($labelproductservice);exit;
1180 
1181  // 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"
1182  // We make the reverse, so PDF generation has the real URL.
1183  $labelproductservice = preg_replace('/(<img[^>]*src=")([^"]*)(&amp;)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep);
1184 
1185  //var_dump($labelproductservice);exit;
1186 
1187  // Description
1188  $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true);
1189  $result.=$labelproductservice;
1190  }
1191  return $result;
1192 }
1193 
1205 function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
1206 {
1207  global $db, $conf, $langs;
1208 
1209  $idprod=(! empty($object->lines[$i]->fk_product)?$object->lines[$i]->fk_product:false);
1210  $label=(! empty($object->lines[$i]->label)?$object->lines[$i]->label:(! empty($object->lines[$i]->product_label)?$object->lines[$i]->product_label:''));
1211  $desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:''));
1212  $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
1213  $note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:'');
1214  $dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false);
1215 
1216  if ($issupplierline)
1217  {
1218  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
1219  $prodser = new ProductFournisseur($db);
1220  }
1221  else
1222  {
1223  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1224  $prodser = new Product($db);
1225  }
1226 
1227  if ($idprod)
1228  {
1229  $prodser->fetch($idprod);
1230  // If a predefined product and multilang and on other lang, we renamed label with label translated
1231  if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
1232  {
1233  $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)
1234 
1235  // 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
1236  // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
1237 
1238  // Set label
1239  // 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.
1240  //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
1241  $textwasmodified=($label == $prodser->label);
1242  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
1243 
1244  // Set desc
1245  // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
1246  $textwasmodified=false;
1247  if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
1248  $textwasmodified=(strpos(dol_html_entity_decode($desc,ENT_QUOTES | ENT_HTML401),dol_html_entity_decode($prodser->description,ENT_QUOTES | ENT_HTML401))!==false);
1249  } else {
1250  $textwasmodified=($desc == $prodser->description);
1251  }
1252  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
1253 
1254  // Set note
1255  $textwasmodified=($note == $prodser->note);
1256  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
1257  }
1258  }
1259 
1260  // Description short of product line
1261  $libelleproduitservice=$label;
1262 
1263  // Description long of product line
1264  if (! empty($desc) && ($desc != $label))
1265  {
1266  if ($libelleproduitservice && empty($hidedesc))
1267  {
1268  $libelleproduitservice.='__N__';
1269  }
1270 
1271  if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
1272  {
1273  $discount=new DiscountAbsolute($db);
1274  $discount->fetch($object->lines[$i]->fk_remise_except);
1275  $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
1276  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
1277  }
1278  elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
1279  {
1280  $discount=new DiscountAbsolute($db);
1281  $discount->fetch($object->lines[$i]->fk_remise_except);
1282  $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
1283  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
1284  // Add date of deposit
1285  if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
1286  }
1287  if ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except)
1288  {
1289  $discount=new DiscountAbsolute($db);
1290  $discount->fetch($object->lines[$i]->fk_remise_except);
1291  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
1292  }
1293  elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except)
1294  {
1295  $discount=new DiscountAbsolute($db);
1296  $discount->fetch($object->lines[$i]->fk_remise_except);
1297  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
1298  }
1299  else
1300  {
1301  if ($idprod)
1302  {
1303  if (empty($hidedesc))
1304  {
1305  if (!empty($conf->global->MAIN_DOCUMENTS_DESCRIPTION_FIRST))
1306  {
1307  $libelleproduitservice=$desc."\n".$libelleproduitservice;
1308  }
1309  else
1310  {
1311  $libelleproduitservice.=$desc;
1312  }
1313  }
1314  }
1315  else
1316  {
1317  $libelleproduitservice.=$desc;
1318  }
1319  }
1320  }
1321 
1322  // We add ref of product (and supplier ref if defined)
1323  $prefix_prodserv = "";
1324  $ref_prodserv = "";
1325  if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
1326  {
1327  if ($prodser->isService())
1328  {
1329  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
1330  }
1331  else
1332  {
1333  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
1334  }
1335  }
1336 
1337  if (empty($hideref))
1338  {
1339  if ($issupplierline)
1340  {
1341  if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1)
1342  $ref_prodserv = $ref_supplier;
1343  elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2)
1344  $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
1345  else // Common case
1346  {
1347  $ref_prodserv = $prodser->ref; // Show local ref
1348  if ($ref_supplier) $ref_prodserv.= ($prodser->ref?' (':'').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref?')':'');
1349  }
1350  }
1351  else
1352  {
1353  $ref_prodserv = $prodser->ref; // Show local ref only
1354  }
1355 
1356  if (! empty($libelleproduitservice) && ! empty($ref_prodserv)) $ref_prodserv .= " - ";
1357  }
1358 
1359  $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
1360 
1361  // Add an additional description for the category products
1362  if (! empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && ! empty($conf->categorie->enabled))
1363  {
1364  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1365  $categstatic=new Categorie($db);
1366  // recovering the list of all the categories linked to product
1367  $tblcateg=$categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
1368  foreach ($tblcateg as $cate)
1369  {
1370  // Adding the descriptions if they are filled
1371  $desccateg=$cate->add_description;
1372  if ($desccateg)
1373  $libelleproduitservice.='__N__'.$desccateg;
1374  }
1375  }
1376 
1377  if (! empty($object->lines[$i]->date_start) || ! empty($object->lines[$i]->date_end))
1378  {
1379  $format='day';
1380  // Show duration if exists
1381  if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
1382  {
1383  $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)).')';
1384  }
1385  if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
1386  {
1387  $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
1388  }
1389  if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
1390  {
1391  $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1392  }
1393  //print '>'.$outputlangs->charset_output.','.$period;
1394  $libelleproduitservice.="__N__".$period;
1395  //print $libelleproduitservice;
1396  }
1397 
1398  if ($dbatch)
1399  {
1400  $format='day';
1401  foreach ($dbatch as $detail)
1402  {
1403  $dte=array();
1404  if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
1405  if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
1406  if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
1407  $dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->qty);
1408  $libelleproduitservice.= "__N__ ".implode(" - ", $dte);
1409  }
1410  }
1411 
1412  // Now we convert \n into br
1413  if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice);
1414  else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice);
1415  $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
1416 
1417  return $libelleproduitservice;
1418 }
1419 
1429 function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0)
1430 {
1431  global $hookmanager;
1432 
1433  $reshook=0;
1434  $result='';
1435  //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) ) )
1436  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
1437  {
1438  $special_code = $object->lines[$i]->special_code;
1439  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1440  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1441  $action='';
1442  $reshook = $hookmanager->executeHooks('pdf_getlinenum',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1443  $result.=$hookmanager->resPrint;
1444  }
1445  if (empty($reshook))
1446  {
1447  $result.=dol_htmlentitiesbr($object->lines[$i]->num);
1448  }
1449  return $result;
1450 }
1451 
1452 
1462 function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0)
1463 {
1464  global $hookmanager;
1465 
1466  $reshook=0;
1467  $result='';
1468  //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) ) )
1469  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
1470  {
1471  $special_code = $object->lines[$i]->special_code;
1472  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1473  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1474  $action='';
1475  $reshook = $hookmanager->executeHooks('pdf_getlineref',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1476  $result.=$hookmanager->resPrint;
1477  }
1478  if (empty($reshook))
1479  {
1480  $result.=dol_htmlentitiesbr($object->lines[$i]->product_ref);
1481  }
1482  return $result;
1483 }
1484 
1494 function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0)
1495 {
1496  global $hookmanager;
1497 
1498  $reshook=0;
1499  $result='';
1500  //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) ) )
1501  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
1502  {
1503  $special_code = $object->lines[$i]->special_code;
1504  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1505  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1506  $action='';
1507  $reshook = $hookmanager->executeHooks('pdf_getlineref_supplier',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1508  $result.=$hookmanager->resPrint;
1509  }
1510  if (empty($reshook))
1511  {
1512  $result.=dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
1513  }
1514  return $result;
1515 }
1516 
1526 function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
1527 {
1528  global $conf, $hookmanager, $mysoc;
1529 
1530  $result='';
1531  $reshook=0;
1532  //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) ) )
1533  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
1534  {
1535  $special_code = $object->lines[$i]->special_code;
1536  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1537  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1538  $action='';
1539  $reshook = $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1540 
1541  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1542  }
1543  if (empty($reshook))
1544  {
1545  if (empty($hidedetails) || $hidedetails > 1)
1546  {
1547  $tmpresult='';
1548 
1549  $tmpresult.=vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
1550  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX))
1551  {
1552  if ($object->lines[$i]->total_localtax1 != 0)
1553  {
1554  if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1555  else $tmpresult='';
1556  $tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx), 0);
1557  }
1558  }
1559  if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX))
1560  {
1561  if ($object->lines[$i]->total_localtax2 != 0)
1562  {
1563  if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1564  else $tmpresult='';
1565  $tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx), 0);
1566  }
1567  }
1568  $tmpresult.= '%';
1569 
1570  $result.=$tmpresult;
1571  }
1572  }
1573  return $result;
1574 }
1575 
1585 function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0)
1586 {
1587  global $conf, $hookmanager;
1588 
1589  $sign=1;
1590  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1591 
1592  $result='';
1593  $reshook=0;
1594  //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) ) )
1595  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
1596  {
1597  $special_code = $object->lines[$i]->special_code;
1598  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1599  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1600  $action='';
1601  $reshook = $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1602 
1603  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1604  }
1605  if (empty($reshook))
1606  {
1607  if (empty($hidedetails) || $hidedetails > 1)
1608  {
1609  $subprice = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
1610  $result.=price($sign * $subprice, 0, $outputlangs);
1611  }
1612  }
1613  return $result;
1614 }
1615 
1625 function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0)
1626 {
1627  global $hookmanager,$conf;
1628 
1629  $sign=1;
1630  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1631 
1632  $result='';
1633  $reshook=0;
1634  //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) ) )
1635  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
1636  {
1637  $special_code = $object->lines[$i]->special_code;
1638  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1639  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1640  $action='';
1641  $reshook = $hookmanager->executeHooks('pdf_getlineupwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1642 
1643  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1644  }
1645  if (empty($reshook))
1646  {
1647  if (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs);
1648  }
1649  return $result;
1650 }
1651 
1661 function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0)
1662 {
1663  global $hookmanager;
1664 
1665  $result='';
1666  $reshook=0;
1667  //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) ) )
1668  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
1669  {
1670  $special_code = $object->lines[$i]->special_code;
1671  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1672  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1673  $action='';
1674  $reshook = $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1675 
1676  if(!empty($hookmanager->resPrint)) $result=$hookmanager->resPrint;
1677  }
1678  if (empty($reshook))
1679  {
1680  if ($object->lines[$i]->special_code == 3) return '';
1681  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty;
1682  }
1683  return $result;
1684 }
1685 
1695 function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0)
1696 {
1697  global $hookmanager;
1698 
1699  $reshook=0;
1700  $result='';
1701  //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) ) )
1702  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
1703  {
1704  $special_code = $object->lines[$i]->special_code;
1705  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1706  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1707  $action='';
1708  $reshook = $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1709 
1710  if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1711  }
1712  if (empty($reshook))
1713  {
1714  if ($object->lines[$i]->special_code == 3) return '';
1715  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_asked;
1716  }
1717  return $result;
1718 }
1719 
1729 function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0)
1730 {
1731  global $hookmanager;
1732 
1733  $reshook=0;
1734  $result='';
1735  //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) ) )
1736  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
1737  {
1738  $special_code = $object->lines[$i]->special_code;
1739  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1740  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1741  $action='';
1742  $reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1743 
1744  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1745  }
1746  if (empty($reshook))
1747  {
1748  if ($object->lines[$i]->special_code == 3) return '';
1749  if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_shipped;
1750  }
1751  return $result;
1752 }
1753 
1763 function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
1764 {
1765  global $hookmanager;
1766 
1767  $reshook=0;
1768  $result='';
1769  //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) ) )
1770  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
1771  {
1772  $special_code = $object->lines[$i]->special_code;
1773  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1774  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1775  $action='';
1776  $reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1777 
1778  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1779  }
1780  if (empty($reshook))
1781  {
1782  if ($object->lines[$i]->special_code == 3) return '';
1783  if (empty($hidedetails) || $hidedetails > 1) $result.=($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
1784  }
1785  return $result;
1786 }
1787 
1798 function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false)
1799 {
1800  global $langs;
1801 
1802  $reshook=0;
1803  $result='';
1804  //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) ) )
1805  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
1806  {
1807  $special_code = $object->lines[$i]->special_code;
1808  if (!empty($object->lines[$i]->fk_parent_line)) {
1809  $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1810  }
1811  $parameters = array(
1812  'i' => $i,
1813  'outputlangs' => $outputlangs,
1814  'hidedetails' => $hidedetails,
1815  'special_code' => $special_code
1816  );
1817  $action = '';
1818  $reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1819 
1820  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1821  }
1822  if (empty($reshook))
1823  {
1824  if ($object->lines[$i]->special_code == 3) return '';
1825  if (empty($hidedetails) || $hidedetails > 1) $result.=$langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
1826  }
1827  return $result;
1828 }
1829 
1830 
1840 function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
1841 {
1842  global $hookmanager;
1843 
1844  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1845 
1846  $reshook=0;
1847  $result='';
1848  //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) ) )
1849  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
1850  {
1851  $special_code = $object->lines[$i]->special_code;
1852  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1853  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1854  $action='';
1855  $reshook = $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1856 
1857  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1858  }
1859  if (empty($reshook))
1860  {
1861  if ($object->lines[$i]->special_code == 3) return '';
1862  if (empty($hidedetails) || $hidedetails > 1) $result.=dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
1863  }
1864  return $result;
1865 }
1866 
1877 function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = null)
1878 {
1879  if (empty($hookmanager)) global $hookmanager;
1880  global $conf;
1881 
1882  $reshook=0;
1883  $result='';
1884  //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) ) )
1885  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
1886  {
1887  $special_code = $object->lines[$i]->special_code;
1888  if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1889  $parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
1890  $action = '';
1891  $reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1892 
1893  if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint;
1894  }
1895  if (empty($reshook))
1896  {
1897  if ($object->lines[$i]->special_code == 3) return '';
1898  if (empty($hidedetails) || $hidedetails > 1)
1899  {
1900  if ($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF)
1901  {
1902  $prev_progress = 0;
1903  if (method_exists($object, 'get_prev_progress'))
1904  {
1905  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1906  }
1907  $result = ($object->lines[$i]->situation_percent - $prev_progress) . '%';
1908  }
1909  else
1910  $result = $object->lines[$i]->situation_percent . '%';
1911  }
1912  }
1913  return $result;
1914 }
1915 
1925 function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0)
1926 {
1927  global $conf, $hookmanager;
1928 
1929  $sign=1;
1930  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1931 
1932  $reshook=0;
1933  $result='';
1934  //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) ) )
1935  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
1936  {
1937  $special_code = $object->lines[$i]->special_code;
1938  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1939  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code, 'sign'=>$sign);
1940  $action='';
1941  $reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1942 
1943  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1944  }
1945  if (empty($reshook))
1946  {
1947  if ($object->lines[$i]->special_code == 3)
1948  {
1949  return $outputlangs->transnoentities("Option");
1950  }
1951  if (empty($hidedetails) || $hidedetails > 1)
1952  {
1953  $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht);
1954  if ($object->lines[$i]->situation_percent > 0)
1955  {
1956  $prev_progress = 0;
1957  $progress = 1;
1958  if (method_exists($object->lines[$i], 'get_prev_progress'))
1959  {
1960  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1961  $progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
1962  }
1963  $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs);
1964  }
1965  else
1966  $result.=price($sign * $total_ht, 0, $outputlangs);
1967  }
1968  }
1969  return $result;
1970 }
1971 
1981 function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
1982 {
1983  global $hookmanager,$conf;
1984 
1985  $sign=1;
1986  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1987 
1988  $reshook=0;
1989  $result='';
1990  //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) ) )
1991  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
1992  {
1993  $special_code = $object->lines[$i]->special_code;
1994  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1995  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1996  $action='';
1997  $reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
1998 
1999  if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
2000  }
2001  if (empty($reshook))
2002  {
2003  if ($object->lines[$i]->special_code == 3)
2004  {
2005  $result.=$outputlangs->transnoentities("Option");
2006  }
2007  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);
2008  }
2009  return $result;
2010 }
2011 
2021 function pdf_getTotalQty($object,$type,$outputlangs)
2022 {
2023  global $hookmanager;
2024 
2025  $total=0;
2026  $nblignes=count($object->lines);
2027 
2028  // Loop on each lines
2029  for ($i = 0 ; $i < $nblignes ; $i++)
2030  {
2031  if ($object->lines[$i]->special_code != 3)
2032  {
2033  if ($type=='all')
2034  {
2035  $total += $object->lines[$i]->qty;
2036  }
2037  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)))
2038  {
2039  $special_code = $object->lines[$i]->special_code;
2040  if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2041  $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
2042  $action='';
2043  $reshook = $hookmanager->executeHooks('pdf_getTotalQty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
2044  return $hookmanager->resPrint;
2045  }
2046  else if ($type==0 && $object->lines[$i]->product_type == 0)
2047  {
2048  $total += $object->lines[$i]->qty;
2049  }
2050  else if ($type==1 && $object->lines[$i]->product_type == 1)
2051  {
2052  $total += $object->lines[$i]->qty;
2053  }
2054  }
2055  }
2056 
2057  return $total;
2058 }
2059 
2068 function pdf_getLinkedObjects($object,$outputlangs)
2069 {
2070  global $hookmanager;
2071 
2072  $linkedobjects=array();
2073 
2074  $object->fetchObjectLinked();
2075 
2076  foreach($object->linkedObjects as $objecttype => $objects)
2077  {
2078  if ($objecttype == 'facture')
2079  {
2080  // 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.
2081  }
2082  elseif ($objecttype == 'propal' || $objecttype == 'supplier_proposal')
2083  {
2084  $outputlangs->load('propal');
2085 
2086  foreach($objects as $elementobject)
2087  {
2088  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
2089  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2090  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
2091  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2092  }
2093  }
2094  else if ($objecttype == 'commande' || $objecttype == 'supplier_order')
2095  {
2096  $outputlangs->load('orders');
2097  foreach($objects as $elementobject)
2098  {
2099  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
2100  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '') . ($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
2101  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
2102  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2103  }
2104  }
2105  else if ($objecttype == 'contrat')
2106  {
2107  $outputlangs->load('contracts');
2108  foreach($objects as $elementobject)
2109  {
2110  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
2111  $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2112  $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
2113  $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat,'day','',$outputlangs);
2114  }
2115  }
2116  else if ($objecttype == 'shipping')
2117  {
2118  $outputlangs->loadLangs(array("orders", "sendings"));
2119 
2120  foreach($objects as $x => $elementobject)
2121  {
2122  $order=null;
2123  // We concat this record info into fields xxx_value. title is overwrote.
2124  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
2125  {
2126  $elementobject->fetchObjectLinked();
2127  if (! empty($elementobject->linkedObjects['commande'])) $order = reset($elementobject->linkedObjects['commande']);
2128  }
2129  if (! is_object($order))
2130  {
2131  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
2132  if (! empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'].=' / ';
2133  $linkedobjects[$objecttype]['ref_value'].= $outputlangs->transnoentities($elementobject->ref);
2134  //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
2135  //if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
2136  //$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
2137  }
2138  else
2139  {
2140  $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
2141  if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' ('.$order->ref_client.')' : '');
2142  $linkedobjects[$objecttype]['ref_value'].= ' / ' . $outputlangs->transnoentities($elementobject->ref);
2143  //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
2144  //if (empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs);
2145  //$linkedobjects[$objecttype]['date_value'].= ($elementobject->date_delivery ? ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs) : '');
2146  }
2147  }
2148  }
2149  }
2150 
2151  // For add external linked objects
2152  if (is_object($hookmanager))
2153  {
2154  $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs);
2155  $action='';
2156  $hookmanager->executeHooks('pdf_getLinkedObjects',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
2157  if (! empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray;
2158  }
2159 
2160  return $linkedobjects;
2161 }
2162 
2170 function pdf_getSizeForImage($realpath)
2171 {
2172  global $conf;
2173 
2174  $maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
2175  $maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
2176  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2177  $tmp=dol_getImageSize($realpath);
2178  if ($tmp['height'])
2179  {
2180  $width=(int) round($maxheight*$tmp['width']/$tmp['height']); // I try to use maxheight
2181  if ($width > $maxwidth) // Pb with maxheight, so i use maxwidth
2182  {
2183  $width=$maxwidth;
2184  $height=(int) round($maxwidth*$tmp['height']/$tmp['width']);
2185  }
2186  else // No pb with maxheight
2187  {
2188  $height=$maxheight;
2189  }
2190  }
2191  return array('width'=>$width,'height'=>$height);
2192 }
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:692
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:319
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:600
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:1053
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:643
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
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:353
dol_print_reduction($reduction, $langs)
Returns formated reduction.
Class to manage contact/addresses.
pdf_getLinkedObjects($object, $outputlangs)
Return linked objects to use for document generation.
Definition: pdf.lib.php:2068
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:1763
pdf_getTotalQty($object, $type, $outputlangs)
Return total quantity of products and/or services.
Definition: pdf.lib.php:2021
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
Class to manage products or services.
pdf_getlinenum($object, $i, $outputlangs, $hidedetails=0)
Return line num.
Definition: pdf.lib.php:1429
pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails=0)
Return line quantity asked.
Definition: pdf.lib.php:1695
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
pdf_getEncryption(&$pdf, $pathoffile)
Return if pdf file is protected/encrypted.
Definition: pdf.lib.php:182
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:201
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1798
dol_format_address($object, $withcountry=0, $sep="\, $outputlangs='', $mode=0)
Return a formated address (part address/zip/town/state) according to country rules.
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:1925
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:1526
Class to manage third parties objects (customers, suppliers, prospects...)
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1661
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:1729
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:872
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1585
pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
Function to try to calculate height of a HTML Content.
Definition: pdf.lib.php:269
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:2170
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:1625
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:1840
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:1877
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:245
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
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:1119
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:623
pdf_getlineref($object, $i, $outputlangs, $hidedetails=0)
Return line product ref.
Definition: pdf.lib.php:1462
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:1158
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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 substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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:1205
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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:1494
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:1981