pdf.lib.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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/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.'/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 formated address (part address/zip/town/state) according to country rules
  153. *
  154. * @param outputlangs Output langs object
  155. * @param object A company or contact object
  156. * @return string Formated string
  157. */
  158. function pdf_format_address($outputlangs,$object)
  159. {
  160. $ret='';
  161. $countriesusingstate=array('US','IN');
  162. // Address
  163. $ret .= $outputlangs->convToOutputCharset($object->address);
  164. // Zip/Town/State
  165. if (in_array($object->pays_code,array('US'))) // US: town, state, zip
  166. {
  167. $ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->town);
  168. if ($object->departement && in_array($object->pays_code,$countriesusingstate))
  169. {
  170. $ret.=", ".$outputlangs->convToOutputCharset($object->departement);
  171. }
  172. if ($object->cp) $ret .= ', '.$outputlangs->convToOutputCharset($object->zip);
  173. }
  174. else // Other: zip town, state
  175. {
  176. $ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->zip);
  177. $ret .= ' '.$outputlangs->convToOutputCharset($object->town);
  178. if ($object->departement && in_array($object->pays_code,$countriesusingstate))
  179. {
  180. $ret.=", ".$outputlangs->convToOutputCharset($object->departement);
  181. }
  182. }
  183. return $ret;
  184. }
  185. /**
  186. * Return a string with full address formated
  187. *
  188. * @param outputlangs Output langs object
  189. * @param sourcecompany Source company object
  190. * @param targetcompany Target company object
  191. * @param targetcontact Target contact object
  192. * @param usecontact Use contact instead of company
  193. * @param mode Address type
  194. * @param deliverycompany Delivery company object
  195. * @return string String with full address
  196. */
  197. function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$deliverycompany='')
  198. {
  199. global $conf;
  200. $stringaddress = '';
  201. if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
  202. if ($mode == 'target' && ! is_object($targetcompany)) return -1;
  203. if ($mode == 'delivery' && ! is_object($deliverycompany)) return -1;
  204. if ($sourcecompany->state_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id);
  205. if ($targetcompany->state_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id);
  206. if ($mode == 'source')
  207. {
  208. $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$sourcecompany)."\n";
  209. // Tel
  210. if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
  211. // Fax
  212. if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->tel ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
  213. // EMail
  214. if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
  215. // Web
  216. if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
  217. }
  218. if ($mode == 'target')
  219. {
  220. if ($usecontact)
  221. {
  222. $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
  223. $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcontact)."\n";
  224. // Country
  225. if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
  226. }
  227. else
  228. {
  229. $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcompany)."\n";
  230. // Country
  231. if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
  232. }
  233. // Intra VAT
  234. if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
  235. // Professionnal Ids
  236. if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
  237. {
  238. $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);
  239. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  240. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
  241. }
  242. if ($conf->global->MAIN_PROFID2_IN_ADDRESS)
  243. {
  244. $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->pays_code);
  245. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  246. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
  247. }
  248. if ($conf->global->MAIN_PROFID3_IN_ADDRESS)
  249. {
  250. $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->pays_code);
  251. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  252. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
  253. }
  254. if ($conf->global->MAIN_PROFID4_IN_ADDRESS)
  255. {
  256. $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->pays_code);
  257. if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
  258. $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
  259. }
  260. }
  261. if ($mode == 'delivery') // for a delivery address (address + phone/fax)
  262. {
  263. $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$deliverycompany)."\n";
  264. // Tel
  265. if ($deliverycompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($deliverycompany->phone);
  266. // Fax
  267. if ($deliverycompany->fax) $stringaddress .= ($stringaddress ? ($deliverycompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($deliverycompany->fax);
  268. }
  269. return $stringaddress;
  270. }
  271. /**
  272. * Show header of page for PDF generation
  273. *
  274. * @param PDF $pdf Object PDF
  275. * @param Translate $outputlangs Object lang for output
  276. * @param int $page_height Height of page
  277. */
  278. function pdf_pagehead(&$pdf,$outputlangs,$page_height)
  279. {
  280. global $conf;
  281. // Add a background image on document
  282. if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))
  283. {
  284. $pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, 0, 0, 0, $page_height);
  285. }
  286. }
  287. /**
  288. * Add a draft watermark on PDF files
  289. *
  290. * @param pdf Object PDF
  291. * @param outputlangs Object lang
  292. * @param h Height of PDF
  293. * @param w Width of PDF
  294. * @param unit Unit of height (mmn, pt, ...)
  295. * @param text Text to show
  296. */
  297. function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
  298. {
  299. // Print Draft Watermark
  300. if ($unit=='pt') $k=1;
  301. elseif ($unit=='mm') $k=72/25.4;
  302. elseif ($unit=='cm') $k=72/2.54;
  303. elseif ($unit=='in') $k=72;
  304. $watermark_angle=atan($h/$w);
  305. $watermark_x=5;
  306. $watermark_y=$h-25; //Set to $this->page_hauteur-50 or less if problems
  307. $watermark_width=$h;
  308. $pdf->SetFont('','B',50);
  309. $pdf->SetTextColor(255,192,203);
  310. //rotate
  311. $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));
  312. //print watermark
  313. $pdf->SetXY($watermark_x,$watermark_y);
  314. $pdf->Cell($watermark_width,25,$outputlangs->convToOutputCharset($text),0,2,"C",0);
  315. //antirotate
  316. $pdf->_out('Q');
  317. }
  318. /**
  319. * Show bank informations for PDF generation
  320. *
  321. * @param pdf Object PDF
  322. * @param outputlangs Object lang
  323. * @param curx X
  324. * @param cury Y
  325. * @param account Bank account object
  326. * @param onlynumber Output only number
  327. */
  328. function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0)
  329. {
  330. global $mysoc, $conf;
  331. $pdf->SetXY($curx, $cury);
  332. if (empty($onlynumber))
  333. {
  334. $pdf->SetFont('','B',8);
  335. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
  336. $cury+=4;
  337. }
  338. $outputlangs->load("banks");
  339. // Get format of bank account according to its country
  340. $usedetailedbban=$account->useDetailedBBAN();
  341. //$onlynumber=0; $usedetailedbban=0; // For tests
  342. if ($usedetailedbban)
  343. {
  344. $savcurx=$curx;
  345. if (empty($onlynumber))
  346. {
  347. $pdf->SetFont('','',6);
  348. $pdf->SetXY($curx, $cury);
  349. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  350. $cury+=3;
  351. }
  352. if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+8 );
  353. if ($usedetailedbban == 1)
  354. {
  355. $fieldstoshow=array('bank','desk','number','key');
  356. if ($conf->global->BANK_SHOW_ORDER_OPTION==1) $fieldstoshow=array('bank','desk','key','number');
  357. }
  358. else if ($usedetailedbban == 2)
  359. {
  360. $fieldstoshow=array('bank','number');
  361. }
  362. else dol_print_error('','Value returned by function useDetailedBBAN not managed');
  363. foreach ($fieldstoshow as $val)
  364. {
  365. if ($val == 'bank')
  366. {
  367. // Bank code
  368. $tmplength=18;
  369. $pdf->SetXY($curx, $cury+5);
  370. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_banque), 0, 'C', 0);
  371. $pdf->SetXY($curx, $cury+1);
  372. $curx+=$tmplength;
  373. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0);
  374. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  375. }
  376. if ($val == 'desk')
  377. {
  378. // Desk
  379. $tmplength=18;
  380. $pdf->SetXY($curx, $cury+5);
  381. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_guichet), 0, 'C', 0);
  382. $pdf->SetXY($curx, $cury+1);
  383. $curx+=$tmplength;
  384. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0);
  385. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  386. }
  387. if ($val == 'number')
  388. {
  389. // Number
  390. $tmplength=24;
  391. $pdf->SetXY($curx, $cury+5);
  392. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->number), 0, 'C', 0);
  393. $pdf->SetXY($curx, $cury+1);
  394. $curx+=$tmplength;
  395. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0);
  396. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  397. }
  398. if ($val == 'key')
  399. {
  400. // Key
  401. $tmplength=13;
  402. $pdf->SetXY($curx, $cury+5);
  403. $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->cle_rib), 0, 'C', 0);
  404. $pdf->SetXY($curx, $cury+1);
  405. $curx+=$tmplength;
  406. $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0);
  407. if (empty($onlynumber)) $pdf->line($curx, $cury+1, $curx, $cury+8 );
  408. }
  409. }
  410. $curx=$savcurx;
  411. $cury+=10;
  412. }
  413. else
  414. {
  415. $pdf->SetFont('','B',6);
  416. $pdf->SetXY($curx, $cury);
  417. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
  418. $cury+=3;
  419. $pdf->SetFont('','B',6);
  420. $pdf->SetXY($curx, $cury);
  421. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
  422. $cury+=3;
  423. }
  424. // Use correct name of bank id according to country
  425. $ibankey="IBANNumber";
  426. $bickey="BICNumber";
  427. if ($account->getCountryCode() == 'IN') $ibankey="IFSC";
  428. if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
  429. $pdf->SetFont('','',6);
  430. if (empty($onlynumber) && ! empty($account->domiciliation))
  431. {
  432. $pdf->SetXY($curx, $cury);
  433. $val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
  434. $pdf->MultiCell(90, 3, $val, 0, 'L', 0);
  435. $nboflines=dol_nboflines_bis($val,120);
  436. //print $nboflines;exit;
  437. $cury+=($nboflines*2)+2;
  438. }
  439. else if (! $usedetailedbban) $cury+=1;
  440. $pdf->SetXY($curx, $cury);
  441. $pdf->MultiCell(90, 3, $outputlangs->transnoentities($ibankey).': ' . $outputlangs->convToOutputCharset($account->iban), 0, 'L', 0);
  442. $pdf->SetXY($curx, $cury+3);
  443. $pdf->MultiCell(90, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
  444. return $pdf->getY();
  445. }
  446. /**
  447. * Show footer of page for PDF generation
  448. *
  449. * @param pdf The PDF factory
  450. * @param outputlangs Object lang for output
  451. * @param paramfreetext Constant name of free text
  452. * @param fromcompany Object company
  453. * @param marge_basse Margin bottom
  454. * @param marge_gauche Margin left
  455. * @param page_hauteur Page height
  456. * @param object Object shown in PDF
  457. * @param showdetails Show company details
  458. * @return void
  459. */
  460. function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0)
  461. {
  462. global $conf,$user;
  463. $outputlangs->load("dict");
  464. $line='';
  465. // Line of free text
  466. if (! empty($conf->global->$paramfreetext))
  467. {
  468. // Make substitution
  469. $substitutionarray=array(
  470. '__FROM_NAME__' => $fromcompany->nom,
  471. '__FROM_EMAIL__' => $fromcompany->email,
  472. '__TOTAL_TTC__' => $object->total_ttc,
  473. '__TOTAL_HT__' => $object->total_ht,
  474. '__TOTAL_VAT__' => $object->total_vat
  475. );
  476. complete_substitutions_array($substitutionarray,$outputlangs,$object);
  477. $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
  478. $line.=$outputlangs->convToOutputCharset($newfreetext);
  479. }
  480. // First line of company infos
  481. if ($showdetails)
  482. {
  483. $line1="";
  484. // Company name
  485. if ($fromcompany->name)
  486. {
  487. $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
  488. }
  489. // Address
  490. if ($fromcompany->address)
  491. {
  492. $line1.=($line1?" - ":"").$fromcompany->address;
  493. }
  494. // Zip code
  495. if ($fromcompany->zip)
  496. {
  497. $line1.=($line1?" - ":"").$fromcompany->zip;
  498. }
  499. // Town
  500. if ($fromcompany->town)
  501. {
  502. $line1.=($line1?" ":"").$fromcompany->town;
  503. }
  504. // Phone
  505. if ($fromcompany->phone)
  506. {
  507. $line1.=($line1?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
  508. }
  509. // Fax
  510. if ($fromcompany->fax)
  511. {
  512. $line1.=($line1?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
  513. }
  514. $line2="";
  515. // URL
  516. if ($fromcompany->url)
  517. {
  518. $line2.=($line2?" - ":"").$fromcompany->url;
  519. }
  520. // Email
  521. if ($fromcompany->email)
  522. {
  523. $line2.=($line2?" - ":"").$fromcompany->email;
  524. }
  525. }
  526. // Line 3 of company infos
  527. $line3="";
  528. // Juridical status
  529. if ($fromcompany->forme_juridique_code)
  530. {
  531. $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
  532. }
  533. // Capital
  534. if ($fromcompany->capital)
  535. {
  536. $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->monnaie);
  537. }
  538. // Prof Id 1
  539. if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
  540. {
  541. $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
  542. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  543. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
  544. }
  545. // Prof Id 2
  546. if ($fromcompany->idprof2)
  547. {
  548. $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
  549. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  550. $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
  551. }
  552. // Line 4 of company infos
  553. $line4="";
  554. // Prof Id 3
  555. if ($fromcompany->idprof3)
  556. {
  557. $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
  558. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  559. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
  560. }
  561. // Prof Id 4
  562. if ($fromcompany->idprof4)
  563. {
  564. $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
  565. if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
  566. $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
  567. }
  568. // IntraCommunautary VAT
  569. if ($fromcompany->tva_intra != '')
  570. {
  571. $line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
  572. }
  573. $pdf->SetFont('','',7);
  574. $pdf->SetDrawColor(224,224,224);
  575. // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
  576. $nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
  577. //print 'nbofline='.$nbofline; exit;
  578. //print 'e'.$line.'t'.dol_nboflines($line);exit;
  579. $posy=$marge_basse + ($nbofline*3) + ($line1?3:0) + ($line2?3:0) + ($line3?3:0) + ($line4?3:0);
  580. if ($line) // Free text
  581. {
  582. $pdf->SetXY($marge_gauche,-$posy);
  583. $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.
  584. if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) { $width=200; $align='C'; }
  585. $pdf->MultiCell($width, 3, $line, 0, $align, 0);
  586. $posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell
  587. }
  588. $pdf->SetY(-$posy);
  589. $pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
  590. $posy--;
  591. if ($line1)
  592. {
  593. $pdf->SetFont('','B',7);
  594. $pdf->SetXY($marge_gauche,-$posy);
  595. $pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
  596. $posy-=3;
  597. $pdf->SetFont('','',7);
  598. }
  599. if ($line2)
  600. {
  601. $pdf->SetFont('','B',7);
  602. $pdf->SetXY($marge_gauche,-$posy);
  603. $pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
  604. $posy-=3;
  605. $pdf->SetFont('','',7);
  606. }
  607. if ($line3)
  608. {
  609. $pdf->SetXY($marge_gauche,-$posy);
  610. $pdf->MultiCell(200, 2, $line3, 0, 'C', 0);
  611. }
  612. if ($line4)
  613. {
  614. $posy-=3;
  615. $pdf->SetXY($marge_gauche,-$posy);
  616. $pdf->MultiCell(200, 2, $line4, 0, 'C', 0);
  617. }
  618. // Show page nb only on iso languages (so default Helvetica font)
  619. if (pdf_getPDFFont($outputlangs) == 'Helvetica')
  620. {
  621. $pdf->SetXY(-20,-$posy);
  622. $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  623. //print 'xxx'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
  624. }
  625. }
  626. /**
  627. * Output line description into PDF
  628. *
  629. * @param PDF $pdf PDF object
  630. * @param Object $object Object
  631. * @param int $i Current line number
  632. * @param Translate $outputlangs Object lang for output
  633. * @param int $w Width
  634. * @param int $h Height
  635. * @param int $posx Pos x
  636. * @param int $posy Pos y
  637. * @param int $hideref Hide reference
  638. * @param int $hidedesc Hide description
  639. * @param int $issupplierline Is it a line for a supplier object ?
  640. * @param HookManager $hookmanager Instance of HookManager
  641. * @return void
  642. */
  643. function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0,$hookmanager=false)
  644. {
  645. global $db, $conf, $langs;
  646. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  647. {
  648. $special_code = $object->lines[$i]->special_code;
  649. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  650. $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);
  651. $reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  652. }
  653. else
  654. {
  655. $labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
  656. // Description
  657. $pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1);
  658. return $labelproductservice;
  659. }
  660. }
  661. /**
  662. * Return line description translated in outputlangs and encoded in UTF8
  663. *
  664. * @param Object $object Object
  665. * @param int $i Current line number
  666. * @param Translate $outputlangs Object langs for output
  667. * @param int $hideref Hide reference
  668. * @param int $hidedesc Hide description
  669. * @param int $issupplierline Is it a line for a supplier object ?
  670. * @return string String with line
  671. */
  672. function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
  673. {
  674. global $db, $conf, $langs;
  675. $idprod=$object->lines[$i]->fk_product;
  676. $label=$object->lines[$i]->label; if (empty($label)) $label=$object->lines[$i]->libelle;
  677. $desc=$object->lines[$i]->desc; if (empty($desc)) $desc=$object->lines[$i]->description;
  678. $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
  679. $note=$object->lines[$i]->note;
  680. if ($issupplierline) $prodser = new ProductFournisseur($db);
  681. else $prodser = new Product($db);
  682. if ($idprod)
  683. {
  684. $prodser->fetch($idprod);
  685. // If a predefined product and multilang and on other lang, we renamed label with label translated
  686. if ($conf->global->MAIN_MULTILANGS && ($outputlangs->defaultlang != $langs->defaultlang))
  687. {
  688. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"])) $label=$prodser->multilangs[$outputlangs->defaultlang]["libelle"];
  689. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
  690. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"])) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
  691. }
  692. }
  693. // Description short of product line
  694. $libelleproduitservice=$label;
  695. // Description long of product line
  696. if ($desc && ($desc != $label))
  697. {
  698. if ( $libelleproduitservice && empty($hidedesc) ) $libelleproduitservice.="<br>";
  699. if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
  700. {
  701. $discount=new DiscountAbsolute($db);
  702. $discount->fetch($object->lines[$i]->fk_remise_except);
  703. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
  704. }
  705. else
  706. {
  707. if ($idprod)
  708. {
  709. if ( empty($hidedesc) ) $libelleproduitservice.=$desc;
  710. }
  711. else
  712. {
  713. $libelleproduitservice.=$desc;
  714. }
  715. }
  716. }
  717. // If line linked to a product
  718. if ($idprod)
  719. {
  720. // On ajoute la ref
  721. if ($prodser->ref)
  722. {
  723. $prefix_prodserv = "";
  724. $ref_prodserv = "";
  725. if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS) // In standard mode, we do not show this
  726. {
  727. if($prodser->isservice())
  728. {
  729. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  730. }
  731. else
  732. {
  733. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  734. }
  735. }
  736. if ( empty($hideref) )
  737. {
  738. if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
  739. else $ref_prodserv = $prodser->ref; // Show local ref only
  740. $ref_prodserv .= " - ";
  741. }
  742. $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
  743. }
  744. }
  745. $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
  746. if ($object->lines[$i]->date_start || $object->lines[$i]->date_end)
  747. {
  748. // Show duration if exists
  749. if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
  750. {
  751. $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)).')';
  752. }
  753. if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
  754. {
  755. $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
  756. }
  757. if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
  758. {
  759. $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
  760. }
  761. //print '>'.$outputlangs->charset_output.','.$period;
  762. $libelleproduitservice.="<br>".dol_htmlentitiesbr($period,1);
  763. //print $libelleproduitservice;
  764. }
  765. // Note that we used here current custom and origin country code.
  766. /* Fix, this must be done when saving line
  767. if (! empty($prodser->customcode) || ! empty($prodser->country_code))
  768. {
  769. //var_dump($prodser);exit;
  770. $tmptxt='(';
  771. if (! empty($prodser->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prodser->customcode;
  772. if (! empty($prodser->customcode) && ! empty($prodser->country_code)) $tmptxt.=' - ';
  773. if (! empty($prodser->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prodser->country_code,0,$db,$outputlangs,0);
  774. $tmptxt.=')';
  775. $libelleproduitservice.="<br>".$tmptxt;
  776. }*/
  777. return $libelleproduitservice;
  778. }
  779. /**
  780. * Return line num
  781. *
  782. * @param Object $object Object
  783. * @param int $i Current line number
  784. * @param Translate $outputlangs Object langs for output
  785. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  786. * @param HookManager $hookmanager Hook manager instance
  787. * @return void
  788. */
  789. function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  790. {
  791. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  792. {
  793. $special_code = $object->lines[$i]->special_code;
  794. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  795. // TODO add hook function
  796. }
  797. else
  798. {
  799. return dol_htmlentitiesbr($object->lines[$i]->num);
  800. }
  801. }
  802. /**
  803. * Return line product ref
  804. *
  805. * @param Object $object Object
  806. * @param int $i Current line number
  807. * @param Translate $outputlangs Object langs for output
  808. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  809. * @param HookManager $hookmanager Hook manager instance
  810. * @return void
  811. */
  812. function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  813. {
  814. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  815. {
  816. $special_code = $object->lines[$i]->special_code;
  817. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  818. // TODO add hook function
  819. }
  820. else
  821. {
  822. return dol_htmlentitiesbr($object->lines[$i]->product_ref);
  823. }
  824. }
  825. /**
  826. * Return line ref_supplier
  827. *
  828. * @param Object $object Object
  829. * @param int $i Current line number
  830. * @param Translate $outputlangs Object langs for output
  831. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  832. * @param HookManager $hookmanager Hook manager instance
  833. * @return void
  834. */
  835. function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  836. {
  837. if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  838. {
  839. $special_code = $object->lines[$i]->special_code;
  840. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  841. // TODO add hook function
  842. }
  843. else
  844. {
  845. return dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
  846. }
  847. }
  848. /**
  849. * Return line vat rate
  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_getlinevatrate($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  859. {
  860. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  861. {
  862. $special_code = $object->lines[$i]->special_code;
  863. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  864. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  865. return $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  866. }
  867. else
  868. {
  869. if (empty($hidedetails) || $hidedetails > 1) return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits,1);
  870. }
  871. }
  872. /**
  873. * Return line unit price excluding tax
  874. *
  875. * @param Object $object Object
  876. * @param int $i Current line number
  877. * @param Translate $outputlangs Object langs for output
  878. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  879. * @param HookManager $hookmanager Hook manager instance
  880. * @return void
  881. */
  882. function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  883. {
  884. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  885. {
  886. $special_code = $object->lines[$i]->special_code;
  887. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  888. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  889. return $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  890. }
  891. else
  892. {
  893. if (empty($hidedetails) || $hidedetails > 1) return price($object->lines[$i]->subprice);
  894. }
  895. }
  896. /**
  897. * Return line quantity
  898. *
  899. * @param Object $object Object
  900. * @param int $i Current line number
  901. * @param Translate $outputlangs Object langs for output
  902. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  903. * @param HookManager $hookmanager Hook manager instance
  904. */
  905. function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  906. {
  907. if ($object->lines[$i]->special_code != 3)
  908. {
  909. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  910. {
  911. $special_code = $object->lines[$i]->special_code;
  912. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  913. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  914. return $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  915. }
  916. else
  917. {
  918. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty;
  919. }
  920. }
  921. }
  922. /**
  923. * Return line quantity asked
  924. *
  925. * @param Object $object Object
  926. * @param int $i Current line number
  927. * @param Translate $outputlangs Object langs for output
  928. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  929. * @param HookManager $hookmanager Hook manager instance
  930. * @return void
  931. */
  932. function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  933. {
  934. if ($object->lines[$i]->special_code != 3)
  935. {
  936. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  937. {
  938. $special_code = $object->lines[$i]->special_code;
  939. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  940. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  941. return $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  942. }
  943. else
  944. {
  945. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_asked;
  946. }
  947. }
  948. }
  949. /**
  950. * Return line quantity shipped
  951. *
  952. * @param Object $object Object
  953. * @param int $i Current line number
  954. * @param Translate $outputlangs Object langs for output
  955. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  956. * @param HookManager $hookmanager Hook manager instance
  957. * @return void
  958. */
  959. function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  960. {
  961. if ($object->lines[$i]->special_code != 3)
  962. {
  963. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  964. {
  965. $special_code = $object->lines[$i]->special_code;
  966. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  967. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  968. return $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  969. }
  970. else
  971. {
  972. if (empty($hidedetails) || $hidedetails > 1) return $object->lines[$i]->qty_shipped;
  973. }
  974. }
  975. }
  976. /**
  977. * Return line keep to ship quantity
  978. *
  979. * @param Object $object Object
  980. * @param int $i Current line number
  981. * @param Translate $outputlangs Object langs for output
  982. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  983. * @param HookManager $hookmanager Hook manager instance
  984. * @return void
  985. */
  986. function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  987. {
  988. if ($object->lines[$i]->special_code != 3)
  989. {
  990. if (is_object($hookmanager) && (( $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  991. {
  992. $special_code = $object->lines[$i]->special_code;
  993. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  994. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  995. return $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  996. }
  997. else
  998. {
  999. if (empty($hidedetails) || $hidedetails > 1) return ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
  1000. }
  1001. }
  1002. }
  1003. /**
  1004. * Return line remise percent
  1005. *
  1006. * @param Object $object Object
  1007. * @param int $i Current line number
  1008. * @param Translate $outputlangs Object langs for output
  1009. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1010. * @param HookManager $hookmanager Hook manager instance
  1011. * @return void
  1012. */
  1013. function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  1014. {
  1015. include_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
  1016. if ($object->lines[$i]->special_code != 3)
  1017. {
  1018. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  1019. {
  1020. $special_code = $object->lines[$i]->special_code;
  1021. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1022. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1023. return $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1024. }
  1025. else
  1026. {
  1027. if (empty($hidedetails) || $hidedetails > 1) return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
  1028. }
  1029. }
  1030. }
  1031. /**
  1032. * Return line total excluding tax
  1033. *
  1034. * @param Object $object Object
  1035. * @param int $i Current line number
  1036. * @param Translate $outputlangs Object langs for output
  1037. * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
  1038. * @param HookManager $hookmanager Hook manager instance
  1039. * @return void
  1040. */
  1041. function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false)
  1042. {
  1043. if ($object->lines[$i]->special_code == 3)
  1044. {
  1045. return $outputlangs->transnoentities("Option");
  1046. }
  1047. else
  1048. {
  1049. if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
  1050. {
  1051. $special_code = $object->lines[$i]->special_code;
  1052. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1053. $parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
  1054. return $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  1055. }
  1056. else
  1057. {
  1058. if (empty($hidedetails) || $hidedetails > 1) return price($object->lines[$i]->total_ht);
  1059. }
  1060. }
  1061. }
  1062. /**
  1063. * Return total quantity of products and/or services
  1064. *
  1065. * @param Object $object Object
  1066. * @param string $type Type
  1067. * @param Translate $outputlangs Object langs for output
  1068. * @param HookManager $hookmanager Hook manager instance
  1069. * @return void
  1070. */
  1071. function pdf_getTotalQty($object,$type='',$outputlangs,$hookmanager=false)
  1072. {
  1073. $total=0;
  1074. $nblignes=count($object->lines);
  1075. // Loop on each lines
  1076. for ($i = 0 ; $i < $nblignes ; $i++)
  1077. {
  1078. if ($object->lines[$i]->special_code != 3)
  1079. {
  1080. if ($type=='all')
  1081. {
  1082. $total += $object->lines[$i]->qty;
  1083. }
  1084. 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) ) )
  1085. {
  1086. $special_code = $object->lines[$i]->special_code;
  1087. if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
  1088. // TODO add hook function
  1089. }
  1090. else if ($type==0 && $object->lines[$i]->product_type == 0)
  1091. {
  1092. $total += $object->lines[$i]->qty;
  1093. }
  1094. else if ($type==1 && $object->lines[$i]->product_type == 1)
  1095. {
  1096. $total += $object->lines[$i]->qty;
  1097. }
  1098. }
  1099. }
  1100. return $total;
  1101. }
  1102. /**
  1103. * Convert a currency code into its symbol
  1104. *
  1105. * @param PDF $pdf PDF object
  1106. * @param string $currency_code Currency code
  1107. * @return string Currency symbol encoded into UTF8
  1108. */
  1109. function pdf_getCurrencySymbol(&$pdf, $currency_code)
  1110. {
  1111. switch ($currency_code) {
  1112. case "EUR":
  1113. $currency_sign = " ".$pdf->unichr(8364);
  1114. break;
  1115. case "USD":
  1116. $currency_sign = " ".utf8_encode('$');
  1117. break;
  1118. case "GBP":
  1119. $currency_sign = " ".utf8_encode('£');
  1120. break;
  1121. default:
  1122. $currency_sign = " ".$currency;
  1123. break;
  1124. }
  1125. return $currency_sign;
  1126. }
  1127. ?>