PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/lib/pdf.lib.php

https://github.com/asterix14/dolibarr
PHP | 1228 lines | 765 code | 112 blank | 351 comment | 289 complexity | 37f8daac6dd503ce5359d7583d688303 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2010 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-2011 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. * or see http://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/lib/pdf.lib.php
  24. * \brief Set of functions used for PDF generation
  25. * \ingroup core
  26. */
  27. /**
  28. * Return array with format properties of default PDF format
  29. *
  30. * @return array Array('width'=>w,'height'=>h,'unit'=>u);
  31. */
  32. function pdf_getFormat()
  33. {
  34. global $conf,$db;
  35. // Default value if setup was not done and/or entry into c_paper_format not defined
  36. $width=210; $height=297; $unit='mm';
  37. if (empty($conf->global->MAIN_PDF_FORMAT))
  38. {
  39. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  40. $pdfformat=dol_getDefaultFormat();
  41. }
  42. else $pdfformat=$conf->global->MAIN_PDF_FORMAT;
  43. $sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
  44. $sql.=" WHERE code = '".$pdfformat."'";
  45. $resql=$db->query($sql);
  46. if ($resql)
  47. {
  48. $obj=$db->fetch_object($resql);
  49. if ($obj)
  50. {
  51. $width=(int) $obj->width;
  52. $height=(int) $obj->height;
  53. $unit=$obj->unit;
  54. }
  55. }
  56. //print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
  57. return array('width'=>$width,'height'=>$height,'unit'=>$unit);
  58. }
  59. /**
  60. * Return a PDF instance object. We create a FPDI instance that instanciate TCPDF.
  61. *
  62. * @param format Array(width,height). Keep empty to use default setup.
  63. * @param metric Unit of format ('mm')
  64. * @param pagetype 'P' or 'l'
  65. * @return PDF object
  66. */
  67. function pdf_getInstance($format='',$metric='mm',$pagetype='P')
  68. {
  69. global $conf;
  70. require_once(TCPDF_PATH.'tcpdf.php');
  71. // We need to instantiate fpdi object (instead of tcpdf) to use merging features. But we can disable it.
  72. if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once(FPDFI_PATH.'fpdi.php');
  73. //$arrayformat=pdf_getFormat();
  74. //$format=array($arrayformat['width'],$arrayformat['height']);
  75. //$metric=$arrayformat['unit'];
  76. // Protection et encryption du pdf
  77. if ($conf->global->PDF_SECURITY_ENCRYPTION)
  78. {
  79. /* Permission supported by TCPDF
  80. - print : Print the document;
  81. - modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
  82. - copy : Copy or otherwise extract text and graphics from the document;
  83. - 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);
  84. - fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
  85. - extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
  86. - assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
  87. - 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.
  88. - owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
  89. */
  90. if (! empty($conf->global->MAIN_USE_FPDF))
  91. {
  92. require_once(FPDFI_PATH.'fpdi_protection.php');
  93. $pdf = new FPDI_Protection($pagetype,$metric,$format);
  94. // For FPDF, we specify permission we want to open
  95. $pdfrights = array('print');
  96. }
  97. else
  98. {
  99. if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format);
  100. else $pdf = new TCPDF($pagetype,$metric,$format);
  101. // For TCPDF, we specify permission we want to block
  102. $pdfrights = array('modify','copy');
  103. }
  104. $pdfuserpass = ''; // Mot de passe pour l'utilisateur final
  105. $pdfownerpass = NULL; // Mot de passe du proprietaire, cree aleatoirement si pas defini
  106. $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
  107. }
  108. else
  109. {
  110. if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format);
  111. else $pdf = new TCPDF($pagetype,$metric,$format);
  112. }
  113. return $pdf;
  114. }
  115. /**
  116. * Return font name to use for PDF generation
  117. *
  118. * @param outputlangs Output langs object
  119. * @return string Name of font to use
  120. */
  121. function pdf_getPDFFont($outputlangs)
  122. {
  123. $font='Helvetica'; // By default, for FPDI or ISO language on TCPDF
  124. if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
  125. {
  126. if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
  127. {
  128. $font=$outputlangs->trans('FONTFORPDF');
  129. }
  130. }
  131. return $font;
  132. }
  133. /**
  134. * Return font size to use for PDF generation
  135. *
  136. * @param outputlangs Output langs object
  137. * @return int Size of font to use
  138. */
  139. function pdf_getPDFFontSize($outputlangs)
  140. {
  141. $size=10; // By default, for FPDI or ISO language on TCPDF
  142. if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
  143. {
  144. if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
  145. {
  146. $size = (int) $outputlangs->trans('FONTSIZEFORPDF');
  147. }
  148. }
  149. return $size;
  150. }
  151. /**
  152. * Return a string with full address formated
  153. *
  154. * @param outputlangs Output langs object
  155. * @param sourcecompany Source company object
  156. * @param targetcompany Target company object
  157. * @param targetcontact Target contact object
  158. * @param usecontact Use contact instead of company
  159. * @param mode Address type
  160. * @param deliverycompany Delivery company object
  161. * @return string String with full address
  162. */
  163. function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$deliverycompany='')
  164. {
  165. global $conf;
  166. $stringaddress = '';
  167. if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
  168. if ($mode == 'target' && ! is_object($targetcompany)) return -1;
  169. if ($mode == 'delivery' && ! is_object($deliverycompany)) return -1;
  170. if ($sourcecompany->state_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id);
  171. if ($targetcompany->state_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id);
  172. if ($mode == 'source')
  173. {
  174. $stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$sourcecompany)."\n";
  175. // Tel
  176. if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
  177. // Fax
  178. if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->tel ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
  179. // EMail
  180. if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
  181. // Web
  182. if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
  183. }
  184. if ($mode == 'target')
  185. {
  186. if ($usecontact)
  187. {
  188. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
  189. $stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$targetcontact)."\n";
  190. // Country
  191. if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
  192. }
  193. else
  194. {
  195. $stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$targetcompany)."\n";
  196. // Country
  197. if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
  198. }
  199. // Intra VAT
  200. if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
  201. // Professionnal Ids
  202. if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
  203. {
  204. $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);
  205. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  206. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
  207. }
  208. if ($conf->global->MAIN_PROFID2_IN_ADDRESS)
  209. {
  210. $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->pays_code);
  211. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  212. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
  213. }
  214. if ($conf->global->MAIN_PROFID3_IN_ADDRESS)
  215. {
  216. $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->pays_code);
  217. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  218. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
  219. }
  220. if ($conf->global->MAIN_PROFID4_IN_ADDRESS)
  221. {
  222. $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->pays_code);
  223. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  224. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
  225. }
  226. }
  227. if ($mode == 'delivery') // for a delivery address (address + phone/fax)
  228. {
  229. $stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$deliverycompany)."\n";
  230. // Tel
  231. if ($deliverycompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($deliverycompany->phone);
  232. // Fax
  233. if ($deliverycompany->fax) $stringaddress .= ($stringaddress ? ($deliverycompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($deliverycompany->fax);
  234. }
  235. return $stringaddress;
  236. }
  237. /**
  238. * Show header of page for PDF generation
  239. *
  240. * @param PDF $pdf Object PDF
  241. * @param Translate $outputlangs Object lang for output
  242. * @param int $page_height Height of page
  243. */
  244. function pdf_pagehead(&$pdf,$outputlangs,$page_height)
  245. {
  246. global $conf;
  247. // Add a background image on document
  248. if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))
  249. {
  250. $pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, 0, 0, 0, $page_height);
  251. }
  252. }
  253. /**
  254. * Add a draft watermark on PDF files
  255. *
  256. * @param pdf Object PDF
  257. * @param outputlangs Object lang
  258. * @param h Height of PDF
  259. * @param w Width of PDF
  260. * @param unit Unit of height (mmn, pt, ...)
  261. * @param text Text to show
  262. */
  263. function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
  264. {
  265. // Print Draft Watermark
  266. if ($unit=='pt') $k=1;
  267. elseif ($unit=='mm') $k=72/25.4;
  268. elseif ($unit=='cm') $k=72/2.54;
  269. elseif ($unit=='in') $k=72;
  270. $watermark_angle=atan($h/$w);
  271. $watermark_x=5;
  272. $watermark_y=$h-25; //Set to $this->page_hauteur-50 or less if problems
  273. $watermark_width=$h;
  274. $pdf->SetFont('','B',50);
  275. $pdf->SetTextColor(255,192,203);
  276. //rotate
  277. $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));
  278. //print watermark
  279. $pdf->SetXY($watermark_x,$watermark_y);
  280. $pdf->Cell($watermark_width,25,$outputlangs->convToOutputCharset($text),0,2,"C",0);
  281. //antirotate
  282. $pdf->_out('Q');
  283. }
  284. /**
  285. * Show bank informations for PDF generation
  286. *
  287. * @param pdf Object PDF
  288. * @param outputlangs Object lang
  289. * @param curx X
  290. * @param cury Y
  291. * @param account Bank account object
  292. * @param onlynumber Output only number
  293. */
  294. function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0)
  295. {
  296. global $mysoc, $conf;
  297. $pdf->SetXY($curx, $cury);
  298. if (empty($onlynumber))
  299. {
  300. $pdf->SetFont('','B',8);
  301. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
  302. $cury+=4;
  303. }
  304. $outputlangs->load("banks");
  305. // Get format of bank account according to its country
  306. $usedetailedbban=$account->useDetailedBBAN();
  307. //$onlynumber=0; $usedetailedbban=0; // For tests
  308. if ($usedetailedbban)
  309. {
  310. $savcurx=$curx;
  311. if (empty($onlynumber))
  312. {
  313. $pdf->SetFont('','',6);
  314. $pdf->SetXY($curx, $cury);
  315. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  316. $cury+=3;
  317. }
  318. if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+8 );
  319. if ($usedetailedbban == 1)
  320. {
  321. $fieldstoshow=array('bank','desk','number','key');
  322. if ($conf->global->BANK_SHOW_ORDER_OPTION==1) $fieldstoshow=array('bank','desk','key','number');
  323. }
  324. else if ($usedetailedbban == 2)
  325. {
  326. $fieldstoshow=array('bank','number');
  327. }
  328. else dol_print_error('','Value returned by function useDetailedBBAN not managed');
  329. foreach ($fieldstoshow as $val)
  330. {
  331. if ($val == 'bank')
  332. {
  333. // Bank code
  334. $tmplength=18;
  335. $pdf->SetXY($curx, $cury+5);
  336. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_banque), 0, 'C', 0);
  337. $pdf->SetXY($curx, $cury+1);
  338. $curx+=$tmplength;
  339. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0);
  340. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  341. }
  342. if ($val == 'desk')
  343. {
  344. // Desk
  345. $tmplength=18;
  346. $pdf->SetXY($curx, $cury+5);
  347. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_guichet), 0, 'C', 0);
  348. $pdf->SetXY($curx, $cury+1);
  349. $curx+=$tmplength;
  350. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0);
  351. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  352. }
  353. if ($val == 'number')
  354. {
  355. // Number
  356. $tmplength=24;
  357. $pdf->SetXY($curx, $cury+5);
  358. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->number), 0, 'C', 0);
  359. $pdf->SetXY($curx, $cury+1);
  360. $curx+=$tmplength;
  361. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0);
  362. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  363. }
  364. if ($val == 'key')
  365. {
  366. // Key
  367. $tmplength=13;
  368. $pdf->SetXY($curx, $cury+5);
  369. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->cle_rib), 0, 'C', 0);
  370. $pdf->SetXY($curx, $cury+1);
  371. $curx+=$tmplength;
  372. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0);
  373. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  374. }
  375. }
  376. $curx=$savcurx;
  377. $cury+=10;
  378. }
  379. else
  380. {
  381. $pdf->SetFont('','B',6);
  382. $pdf->SetXY($curx, $cury);
  383. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  384. $cury+=3;
  385. $pdf->SetFont('','B',6);
  386. $pdf->SetXY($curx, $cury);
  387. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
  388. $cury+=3;
  389. }
  390. // Use correct name of bank id according to country
  391. $ibankey="IBANNumber";
  392. $bickey="BICNumber";
  393. if ($account->getCountryCode() == 'IN') $ibankey="IFSC";
  394. if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
  395. $pdf->SetFont('','',6);
  396. if (empty($onlynumber) && ! empty($account->domiciliation))
  397. {
  398. $pdf->SetXY($curx, $cury);
  399. $val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
  400. $pdf->MultiCell(90, 3, $val, 0, 'L', 0);
  401. $nboflines=dol_nboflines_bis($val,120);
  402. //print $nboflines;exit;
  403. $cury+=($nboflines*2)+2;
  404. }
  405. else if (! $usedetailedbban) $cury+=1;
  406. $pdf->SetXY($curx, $cury);
  407. $pdf->MultiCell(90, 3, $outputlangs->transnoentities($ibankey).': ' . $outputlangs->convToOutputCharset($account->iban), 0, 'L', 0);
  408. $pdf->SetXY($curx, $cury+3);
  409. $pdf->MultiCell(90, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
  410. return $pdf->getY();
  411. }
  412. /**
  413. * Show footer of page for PDF generation
  414. *
  415. * @param pdf The PDF factory
  416. * @param outputlangs Object lang for output
  417. * @param paramfreetext Constant name of free text
  418. * @param fromcompany Object company
  419. * @param marge_basse Margin bottom
  420. * @param marge_gauche Margin left
  421. * @param page_hauteur Page height
  422. * @param object Object shown in PDF
  423. * @param showdetails Show company details
  424. * @return void
  425. */
  426. function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0)
  427. {
  428. global $conf,$user;
  429. $outputlangs->load("dict");
  430. $line='';
  431. // Line of free text
  432. if (! empty($conf->global->$paramfreetext))
  433. {
  434. // Make substitution
  435. $substitutionarray=array(
  436. '__FROM_NAME__' => $fromcompany->nom,
  437. '__FROM_EMAIL__' => $fromcompany->email,
  438. '__TOTAL_TTC__' => $object->total_ttc,
  439. '__TOTAL_HT__' => $object->total_ht,
  440. '__TOTAL_VAT__' => $object->total_vat
  441. );
  442. complete_substitutions_array($substitutionarray,$outputlangs,$object);
  443. $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
  444. $line.=$outputlangs->convToOutputCharset($newfreetext);
  445. }
  446. // First line of company infos
  447. if ($showdetails)
  448. {
  449. $line1="";
  450. // Company name
  451. if ($fromcompany->name)
  452. {
  453. $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
  454. }
  455. // Address
  456. if ($fromcompany->address)
  457. {
  458. $line1.=($line1?" - ":"").$fromcompany->address;
  459. }
  460. // Zip code
  461. if ($fromcompany->zip)
  462. {
  463. $line1.=($line1?" - ":"").$fromcompany->zip;
  464. }
  465. // Town
  466. if ($fromcompany->town)
  467. {
  468. $line1.=($line1?" ":"").$fromcompany->town;
  469. }
  470. // Phone
  471. if ($fromcompany->phone)
  472. {
  473. $line1.=($line1?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
  474. }
  475. // Fax
  476. if ($fromcompany->fax)
  477. {
  478. $line1.=($line1?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
  479. }
  480. $line2="";
  481. // URL
  482. if ($fromcompany->url)
  483. {
  484. $line2.=($line2?" - ":"").$fromcompany->url;
  485. }
  486. // Email
  487. if ($fromcompany->email)
  488. {
  489. $line2.=($line2?" - ":"").$fromcompany->email;
  490. }
  491. }
  492. // Line 3 of company infos
  493. $line3="";
  494. // Juridical status
  495. if ($fromcompany->forme_juridique_code)
  496. {
  497. $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
  498. }
  499. // Capital
  500. if ($fromcompany->capital)
  501. {
  502. $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->monnaie);
  503. }
  504. // Prof Id 1
  505. if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
  506. {
  507. $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
  508. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  509. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
  510. }
  511. // Prof Id 2
  512. if ($fromcompany->idprof2)
  513. {
  514. $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
  515. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  516. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
  517. }
  518. // Line 4 of company infos
  519. $line4="";
  520. // Prof Id 3
  521. if ($fromcompany->idprof3)
  522. {
  523. $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
  524. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  525. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
  526. }
  527. // Prof Id 4
  528. if ($fromcompany->idprof4)
  529. {
  530. $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
  531. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  532. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
  533. }
  534. // IntraCommunautary VAT
  535. if ($fromcompany->tva_intra != '')
  536. {
  537. $line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
  538. }
  539. $pdf->SetFont('','',7);
  540. $pdf->SetDrawColor(224,224,224);
  541. // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
  542. $nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
  543. //print 'nbofline='.$nbofline; exit;
  544. //print 'e'.$line.'t'.dol_nboflines($line);exit;
  545. $posy=$marge_basse + ($nbofline*3) + ($line1?3:0) + ($line2?3:0) + ($line3?3:0) + ($line4?3:0);
  546. if ($line) // Free text
  547. {
  548. $pdf->SetXY($marge_gauche,-$posy);
  549. $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.
  550. if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) { $width=200; $align='C'; }
  551. $pdf->MultiCell($width, 3, $line, 0, $align, 0);
  552. $posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell
  553. }
  554. $pdf->SetY(-$posy);
  555. $pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
  556. $posy--;
  557. if ($line1)
  558. {
  559. $pdf->SetFont('','B',7);
  560. $pdf->SetXY($marge_gauche,-$posy);
  561. $pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
  562. $posy-=3;
  563. $pdf->SetFont('','',7);
  564. }
  565. if ($line2)
  566. {
  567. $pdf->SetFont('','B',7);
  568. $pdf->SetXY($marge_gauche,-$posy);
  569. $pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
  570. $posy-=3;
  571. $pdf->SetFont('','',7);
  572. }
  573. if ($line3)
  574. {
  575. $pdf->SetXY($marge_gauche,-$posy);
  576. $pdf->MultiCell(200, 2, $line3, 0, 'C', 0);
  577. }
  578. if ($line4)
  579. {
  580. $posy-=3;
  581. $pdf->SetXY($marge_gauche,-$posy);
  582. $pdf->MultiCell(200, 2, $line4, 0, 'C', 0);
  583. }
  584. // Show page nb only on iso languages (so default Helvetica font)
  585. if (pdf_getPDFFont($outputlangs) == 'Helvetica')
  586. {
  587. $pdf->SetXY(-20,-$posy);
  588. $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  589. //print 'xxx'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
  590. }
  591. }
  592. /**
  593. * Output line description into PDF
  594. *
  595. * @param PDF $pdf PDF object
  596. * @param Object $object Object
  597. * @param int $i Current line number
  598. * @param Translate $outputlangs Object lang for output
  599. * @param int $w Width
  600. * @param int $h Height
  601. * @param int $posx Pos x
  602. * @param int $posy Pos y
  603. * @param int $hideref Hide reference
  604. * @param int $hidedesc Hide description
  605. * @param int $issupplierline Is it a line for a supplier object ?
  606. * @param HookManager $hookmanager Instance of HookManager
  607. * @return void
  608. */
  609. function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0,$hookmanager=false)
  610. {
  611. global $db, $conf, $langs;
  612. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  613. {
  614. $special_code = $object->lines[$i]->special_code;
  615. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  616. $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);
  617. $action='';
  618. $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  619. }
  620. else
  621. {
  622. $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
  623. // Description
  624. $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1);
  625. return $labelproductservice;
  626. }
  627. }
  628. /**
  629. * Return line description translated in outputlangs and encoded in UTF8
  630. *
  631. * @param Object $object Object
  632. * @param int $i Current line number
  633. * @param Translate $outputlangs Object langs for output
  634. * @param int $hideref Hide reference
  635. * @param int $hidedesc Hide description
  636. * @param int $issupplierline Is it a line for a supplier object ?
  637. * @return string String with line
  638. */
  639. function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
  640. {
  641. global $db, $conf, $langs;
  642. $idprod=$object->lines[$i]->fk_product;
  643. $label=$object->lines[$i]->label; if (empty($label)) $label=$object->lines[$i]->libelle;
  644. $desc=$object->lines[$i]->desc; if (empty($desc)) $desc=$object->lines[$i]->description;
  645. $ref_supplier=$object->lines[$i]->ref_supplier; if (empty($ref_supplier)) $ref_supplier=$object->lines[$i]->ref_fourn; // TODO Not yeld saved for supplier invoices, only supplier orders
  646. $note=$object->lines[$i]->note;
  647. if ($issupplierline) $prodser = new ProductFournisseur($db);
  648. else $prodser = new Product($db);
  649. if ($idprod)
  650. {
  651. $prodser->fetch($idprod);
  652. // If a predefined product and multilang and on other lang, we renamed label with label translated
  653. if ($conf->global->MAIN_MULTILANGS && ($outputlangs->defaultlang != $langs->defaultlang))
  654. {
  655. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"])) $label=$prodser->multilangs[$outputlangs->defaultlang]["libelle"];
  656. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
  657. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"])) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
  658. }
  659. }
  660. // Description short of product line
  661. $libelleproduitservice=$label;
  662. // Description long of product line
  663. if ($desc && ($desc != $label))
  664. {
  665. if ( $libelleproduitservice && empty($hidedesc) ) $libelleproduitservice.="<br>";
  666. if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
  667. {
  668. $discount=new DiscountAbsolute($db);
  669. $discount->fetch($object->lines[$i]->fk_remise_except);
  670. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
  671. }
  672. elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
  673. {
  674. $discount=new DiscountAbsolute($db);
  675. $discount->fetch($object->lines[$i]->fk_remise_except);
  676. $libelleproduitservice=$outputlangs->transnoentities("DiscountFromDeposit",$discount->ref_facture_source);
  677. // Add date of deposit
  678. if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
  679. }
  680. else
  681. {
  682. if ($idprod)
  683. {
  684. if ( empty($hidedesc) ) $libelleproduitservice.=dol_htmlentitiesbr($desc,1);
  685. }
  686. else
  687. {
  688. $libelleproduitservice.=dol_htmlentitiesbr($desc,1);
  689. }
  690. }
  691. }
  692. // If line linked to a product
  693. if ($idprod)
  694. {
  695. // On ajoute la ref
  696. if ($prodser->ref)
  697. {
  698. $prefix_prodserv = "";
  699. $ref_prodserv = "";
  700. if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS) // In standard mode, we do not show this
  701. {
  702. if($prodser->isservice())
  703. {
  704. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  705. }
  706. else
  707. {
  708. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  709. }
  710. }
  711. if ( empty($hideref) )
  712. {
  713. if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
  714. else $ref_prodserv = $prodser->ref; // Show local ref only
  715. $ref_prodserv .= " - ";
  716. }
  717. $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
  718. }
  719. }
  720. $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
  721. if ($object->lines[$i]->date_start || $object->lines[$i]->date_end)
  722. {
  723. // Show duration if exists
  724. if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
  725. {
  726. $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)).')';
  727. }
  728. if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
  729. {
  730. $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
  731. }
  732. if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
  733. {
  734. $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
  735. }
  736. //print '>'.$outputlangs->charset_output.','.$period;
  737. $libelleproduitservice.="<br>".dol_htmlentitiesbr($period,1);
  738. //print $libelleproduitservice;
  739. }
  740. // Note that we used here current custom and origin country code.
  741. /* Fix, this must be done when saving line
  742. if (! empty($prodser->customcode) || ! empty($prodser->country_code))
  743. {
  744. //var_dump($prodser);exit;
  745. $tmptxt='(';
  746. if (! empty($prodser->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prodser->customcode;
  747. if (! empty($prodser->customcode) && ! empty($prodser->country_code)) $tmptxt.=' - ';
  748. if (! empty($prodser->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prodser->country_code,0,$db,$outputlangs,0);
  749. $tmptxt.=')';
  750. $libelleproduitservice.="<br>".$tmptxt;
  751. }*/
  752. return $libelleproduitservice;
  753. }
  754. /**
  755. * Return line num
  756. *
  757. * @param Object $object Object
  758. * @param int $i Current line number
  759. * @param Translate $outputlangs Object langs for output
  760. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  761. * @param HookManager $hookmanager Hook manager instance
  762. * @return void
  763. */
  764. function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  765. {
  766. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  767. {
  768. $special_code = $object->lines[$i]->special_code;
  769. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  770. // TODO add hook function
  771. }
  772. else
  773. {
  774. return dol_htmlentitiesbr($object->lines[$i]->num);
  775. }
  776. }
  777. /**
  778. * Return line product ref
  779. *
  780. * @param Object $object Object
  781. * @param int $i Current line number
  782. * @param Translate $outputlangs Object langs for output
  783. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  784. * @param HookManager $hookmanager Hook manager instance
  785. * @return void
  786. */
  787. function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  788. {
  789. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  790. {
  791. $special_code = $object->lines[$i]->special_code;
  792. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  793. // TODO add hook function
  794. }
  795. else
  796. {
  797. return dol_htmlentitiesbr($object->lines[$i]->product_ref);
  798. }
  799. }
  800. /**
  801. * Return line ref_supplier
  802. *
  803. * @param Object $object Object
  804. * @param int $i Current line number
  805. * @param Translate $outputlangs Object langs for output
  806. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  807. * @param HookManager $hookmanager Hook manager instance
  808. * @return void
  809. */
  810. function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  811. {
  812. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  813. {
  814. $special_code = $object->lines[$i]->special_code;
  815. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  816. // TODO add hook function
  817. }
  818. else
  819. {
  820. return dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
  821. }
  822. }
  823. /**
  824. * Return line vat rate
  825. *
  826. * @param Object $object Object
  827. * @param int $i Current line number
  828. * @param Translate $outputlangs Object langs for output
  829. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  830. * @param HookManager $hookmanager Hook manager instance
  831. * @return void
  832. */
  833. function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  834. {
  835. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  836. {
  837. $special_code = $object->lines[$i]->special_code;
  838. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  839. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  840. $action='';
  841. return $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  842. }
  843. else
  844. {
  845. if (empty($hidedetails) || $hidedetails > 1) return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits,1);
  846. }
  847. }
  848. /**
  849. * Return line unit price excluding tax
  850. *
  851. * @param Object $object Object
  852. * @param int $i Current line number
  853. * @param Translate $outputlangs Object langs for output
  854. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  855. * @param HookManager $hookmanager Hook manager instance
  856. * @return void
  857. */
  858. function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  859. {
  860. global $conf;
  861. $sign=1;
  862. if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  863. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  864. {
  865. $special_code = $object->lines[$i]->special_code;
  866. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  867. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  868. $action='';
  869. return $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  870. }
  871. else
  872. {
  873. if (empty($hidedetails) || $hidedetails > 1) return price($sign * $object->lines[$i]->subprice);
  874. }
  875. }
  876. /**
  877. * Return line quantity
  878. *
  879. * @param Object $object Object
  880. * @param int $i Current line number
  881. * @param Translate $outputlangs Object langs for output
  882. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  883. * @param HookManager $hookmanager Hook manager instance
  884. */
  885. function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  886. {
  887. if ($object->lines[$i]->special_code != 3)
  888. {
  889. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  890. {
  891. $special_code = $object->lines[$i]->special_code;
  892. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  893. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  894. $action='';
  895. return $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  896. }
  897. else
  898. {
  899. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty;
  900. }
  901. }
  902. }
  903. /**
  904. * Return line quantity asked
  905. *
  906. * @param Object $object Object
  907. * @param int $i Current line number
  908. * @param Translate $outputlangs Object langs for output
  909. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  910. * @param HookManager $hookmanager Hook manager instance
  911. * @return void
  912. */
  913. function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  914. {
  915. if ($object->lines[$i]->special_code != 3)
  916. {
  917. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  918. {
  919. $special_code = $object->lines[$i]->special_code;
  920. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  921. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  922. $action='';
  923. return $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  924. }
  925. else
  926. {
  927. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_asked;
  928. }
  929. }
  930. }
  931. /**
  932. * Return line quantity shipped
  933. *
  934. * @param Object $object Object
  935. * @param int $i Current line number
  936. * @param Translate $outputlangs Object langs for output
  937. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  938. * @param HookManager $hookmanager Hook manager instance
  939. * @return void
  940. */
  941. function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  942. {
  943. if ($object->lines[$i]->special_code != 3)
  944. {
  945. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  946. {
  947. $special_code = $object->lines[$i]->special_code;
  948. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  949. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  950. $action='';
  951. return $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  952. }
  953. else
  954. {
  955. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_shipped;
  956. }
  957. }
  958. }
  959. /**
  960. * Return line keep to ship quantity
  961. *
  962. * @param Object $object Object
  963. * @param int $i Current line number
  964. * @param Translate $outputlangs Object langs for output
  965. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  966. * @param HookManager $hookmanager Hook manager instance
  967. * @return void
  968. */
  969. function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  970. {
  971. if ($object->lines[$i]->special_code != 3)
  972. {
  973. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  974. {
  975. $special_code = $object->lines[$i]->special_code;
  976. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  977. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  978. $action='';
  979. return $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  980. }
  981. else
  982. {
  983. if (empty($hidedetails) || $hidedetails > 1) return ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
  984. }
  985. }
  986. }
  987. /**
  988. * Return line remise percent
  989. *
  990. * @param Object $object Object
  991. * @param int $i Current line number
  992. * @param Translate $outputlangs Object langs for output
  993. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  994. * @param HookManager $hookmanager Hook manager instance
  995. * @return void
  996. */
  997. function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  998. {
  999. include_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  1000. if ($object->lines[$i]->special_code != 3)
  1001. {
  1002. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  1003. {
  1004. $special_code = $object->lines[$i]->special_code;
  1005. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1006. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1007. $action='';
  1008. return $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1009. }
  1010. else
  1011. {
  1012. if (empty($hidedetails) || $hidedetails > 1) return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
  1013. }
  1014. }
  1015. }
  1016. /**
  1017. * Return line total excluding tax
  1018. *
  1019. * @param Object $object Object
  1020. * @param int $i Current line number
  1021. * @param Translate $outputlangs Object langs for output
  1022. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1023. * @param HookManager $hookmanager Hook manager instance
  1024. * @return void
  1025. */
  1026. function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  1027. {
  1028. global $conf;
  1029. $sign=1;
  1030. if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  1031. if ($object->lines[$i]->special_code == 3)
  1032. {
  1033. return $outputlangs->transnoentities("Option");
  1034. }
  1035. else
  1036. {
  1037. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  1038. {
  1039. $special_code = $object->lines[$i]->special_code;
  1040. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1041. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1042. $action='';
  1043. return $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1044. }
  1045. else
  1046. {
  1047. if (empty($hidedetails) || $hidedetails > 1) return price($sign * $object->lines[$i]->total_ht);
  1048. }
  1049. }
  1050. }
  1051. /**
  1052. * Return total quantity of products and/or services
  1053. *
  1054. * @param Object $object Object
  1055. * @param string $type Type
  1056. * @param Translate $outputlangs Object langs for output
  1057. * @param HookManager $hookmanager Hook manager instance
  1058. * @return void
  1059. */
  1060. function pdf_getTotalQty($object,$type='',$outputlangs,$hookmanager=false)
  1061. {
  1062. $total=0;
  1063. $nblignes=count($object->lines);
  1064. // Loop on each lines
  1065. for ($i = 0 ; $i < $nblignes ; $i++)
  1066. {
  1067. if ($object->lines[$i]->special_code != 3)
  1068. {
  1069. if ($type=='all')
  1070. {
  1071. $total += $object->lines[$i]->qty;
  1072. }
  1073. else if ($type==9 && ! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  1074. {
  1075. $special_code = $object->lines[$i]->special_code;
  1076. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1077. // TODO add hook function
  1078. }
  1079. else if ($type==0 && $object->lines[$i]->product_type == 0)
  1080. {
  1081. $total += $object->lines[$i]->qty;
  1082. }
  1083. else if ($type==1 && $object->lines[$i]->product_type == 1)
  1084. {
  1085. $total += $object->lines[$i]->qty;
  1086. }
  1087. }
  1088. }
  1089. return $total;
  1090. }
  1091. /**
  1092. * Convert a currency code into its symbol
  1093. *
  1094. * @param PDF $pdf PDF object
  1095. * @param string $currency_code Currency code
  1096. * @return string Currency symbol encoded into UTF8
  1097. */
  1098. function pdf_getCurrencySymbol(&$pdf, $currency_code)
  1099. {
  1100. switch ($currency_code) {
  1101. case "EUR":
  1102. $currency_sign = " ".$pdf->unichr(8364);
  1103. break;
  1104. case "USD":
  1105. $currency_sign = " ".utf8_encode('$');
  1106. break;
  1107. case "GBP":
  1108. $currency_sign = " ".utf8_encode('ÂŁ');
  1109. break;
  1110. default:
  1111. $currency_sign = " ".$currency;
  1112. break;
  1113. }
  1114. return $currency_sign;
  1115. }
  1116. ?>