PageRenderTime 49ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/speedealing/speedealing
PHP | 1359 lines | 869 code | 126 blank | 364 comment | 349 complexity | 3cad4782df9e8fac3cf4fd876478e7db MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file