pdf_paiement.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015-2018 Charlene BENKE <charlie@patas-monkey.com>
  5. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. * or see https://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/rapport/pdf_paiement.class.php
  23. * \ingroup banque
  24. * \brief File to build payment reports
  25. */
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. /**
  29. * Classe permettant de generer les rapports de paiement
  30. */
  31. class pdf_paiement
  32. {
  33. /**
  34. * Constructor
  35. *
  36. * @param DoliDb $db Database handler
  37. */
  38. public function __construct($db)
  39. {
  40. global $langs, $conf;
  41. // Load translation files required by the page
  42. $langs->loadLangs(array("bills", "compta", "main"));
  43. $this->db = $db;
  44. $this->description = $langs->transnoentities("ListOfCustomerPayments");
  45. // Page size for A4 format
  46. $this->type = 'pdf';
  47. $formatarray = pdf_getFormat();
  48. $this->page_largeur = $formatarray['width'];
  49. $this->page_hauteur = $formatarray['height'];
  50. $this->format = array($this->page_largeur, $this->page_hauteur);
  51. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  52. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  53. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  54. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  55. $this->tab_top = 30;
  56. $this->line_height = 5;
  57. $this->line_per_page = 40;
  58. $this->tab_height = $this->page_hauteur - $this->marge_haute - $this->marge_basse - $this->tab_top - 5; // must be > $this->line_height * $this->line_per_page and < $this->page_hauteur - $this->marge_haute - $this->marge_basse - $this->tab_top - 5;
  59. $this->posxdate = $this->marge_gauche + 2;
  60. $this->posxpaymenttype = 42;
  61. $this->posxinvoice = 82;
  62. $this->posxbankaccount = 110;
  63. $this->posxinvoiceamount = 132;
  64. $this->posxpaymentamount = 162;
  65. if ($this->page_largeur < 210) { // To work with US executive format
  66. $this->line_per_page = 35;
  67. $this->posxpaymenttype -= 10;
  68. $this->posxinvoice -= 0;
  69. $this->posxinvoiceamount -= 10;
  70. $this->posxpaymentamount -= 20;
  71. }
  72. // which type of document will be generated: clients (client) or providers (fourn) invoices
  73. $this->doc_type = "client";
  74. }
  75. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  76. /**
  77. * Fonction generant la rapport sur le disque
  78. *
  79. * @param string $_dir repertoire
  80. * @param int $month mois du rapport
  81. * @param int $year annee du rapport
  82. * @param string $outputlangs Lang output object
  83. * @return int <0 if KO, >0 if OK
  84. */
  85. public function write_file($_dir, $month, $year, $outputlangs)
  86. {
  87. // phpcs:enable
  88. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  89. global $conf, $hookmanager, $langs, $user;
  90. $socid = 0;
  91. if ($user->socid) {
  92. $socid = $user->socid;
  93. }
  94. if (!is_object($outputlangs)) {
  95. $outputlangs = $langs;
  96. }
  97. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  98. if (!empty($conf->global->MAIN_USE_FPDF)) {
  99. $outputlangs->charset_output = 'ISO-8859-1';
  100. }
  101. $this->month = $month;
  102. $this->year = $year;
  103. $dir = $_dir.'/'.$year;
  104. if (!is_dir($dir)) {
  105. $result = dol_mkdir($dir);
  106. if ($result < 0) {
  107. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  108. return -1;
  109. }
  110. }
  111. $month = sprintf("%02d", $month);
  112. $year = sprintf("%04d", $year);
  113. $file = $dir."/payments-".$year."-".$month.".pdf";
  114. switch ($this->doc_type) {
  115. case "client":
  116. $file = $dir."/payments-".$year."-".$month.".pdf";
  117. break;
  118. case "fourn":
  119. $file = $dir."/supplier_payments-".$year."-".$month.".pdf";
  120. break;
  121. }
  122. // Add pdfgeneration hook
  123. if (!is_object($hookmanager)) {
  124. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  125. $hookmanager = new HookManager($this->db);
  126. }
  127. $hookmanager->initHooks(array('pdfgeneration'));
  128. $parameters = array('file'=>$file, 'outputlangs'=>$outputlangs);
  129. global $action;
  130. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  131. $pdf = pdf_getInstance($this->format);
  132. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  133. if (class_exists('TCPDF')) {
  134. $pdf->setPrintHeader(false);
  135. $pdf->setPrintFooter(false);
  136. }
  137. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  138. $num = 0;
  139. $lines = array();
  140. // count number of lines of payment
  141. $sql = "SELECT p.rowid as prowid";
  142. switch ($this->doc_type) {
  143. case "client":
  144. $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
  145. break;
  146. case "fourn":
  147. $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
  148. break;
  149. }
  150. $sql .= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."'";
  151. $sql .= " AND p.entity = ".$conf->entity;
  152. $result = $this->db->query($sql);
  153. if ($result) {
  154. $numpaiement = $this->db->num_rows($result);
  155. }
  156. // number of bill
  157. switch ($this->doc_type) {
  158. case "client":
  159. $sql = "SELECT p.datep as dp, f.ref";
  160. $sql .= ", c.code as paiement_code, p.num_paiement as num_payment";
  161. $sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount";
  162. $sql .= ", pf.amount as pf_amount";
  163. if (isModEnabled("banque")) {
  164. $sql .= ", ba.ref as bankaccount";
  165. }
  166. $sql .= ", p.rowid as prowid";
  167. $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
  168. $sql .= ", ".MAIN_DB_PREFIX."facture as f,";
  169. $sql .= " ".MAIN_DB_PREFIX."paiement_facture as pf,";
  170. if (isModEnabled("banque")) {
  171. $sql .= " ".MAIN_DB_PREFIX."bank as b, ".MAIN_DB_PREFIX."bank_account as ba,";
  172. }
  173. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  174. if (empty($user->rights->societe->client->voir) && !$socid) {
  175. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  176. }
  177. $sql .= " WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
  178. if (isModEnabled("banque")) {
  179. $sql .= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
  180. }
  181. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  182. $sql .= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."'";
  183. if (empty($user->rights->societe->client->voir) && !$socid) {
  184. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  185. }
  186. if (!empty($socid)) {
  187. $sql .= " AND s.rowid = ".((int) $socid);
  188. }
  189. // If global param PAYMENTS_REPORT_GROUP_BY_MOD is set, payement are ordered by paiement_code
  190. if (!empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) {
  191. $sql .= " ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
  192. } else {
  193. $sql .= " ORDER BY p.datep ASC, pf.fk_paiement ASC";
  194. }
  195. break;
  196. case "fourn":
  197. $sql = "SELECT p.datep as dp, f.ref as ref";
  198. $sql .= ", c.code as paiement_code, p.num_paiement as num_payment";
  199. $sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount";
  200. $sql .= ", pf.amount as pf_amount";
  201. if (isModEnabled("banque")) {
  202. $sql .= ", ba.ref as bankaccount";
  203. }
  204. $sql .= ", p.rowid as prowid";
  205. $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
  206. $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f,";
  207. $sql .= " ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
  208. if (isModEnabled("banque")) {
  209. $sql .= " ".MAIN_DB_PREFIX."bank as b, ".MAIN_DB_PREFIX."bank_account as ba,";
  210. }
  211. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  212. if (empty($user->rights->societe->client->voir) && !$socid) {
  213. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  214. }
  215. $sql .= " WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
  216. if (isModEnabled("banque")) {
  217. $sql .= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
  218. }
  219. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  220. $sql .= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."'";
  221. if (empty($user->rights->societe->client->voir) && !$socid) {
  222. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  223. }
  224. if (!empty($socid)) {
  225. $sql .= " AND s.rowid = ".((int) $socid);
  226. }
  227. // If global param PAYMENTS_FOURN_REPORT_GROUP_BY_MOD is set, payement fourn are ordered by paiement_code
  228. if (!empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD)) {
  229. $sql .= " ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
  230. } else {
  231. $sql .= " ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
  232. }
  233. break;
  234. }
  235. dol_syslog(get_class($this)."::write_file", LOG_DEBUG);
  236. $result = $this->db->query($sql);
  237. if ($result) {
  238. $num = $this->db->num_rows($result);
  239. $i = 0;
  240. while ($i < $num) {
  241. $objp = $this->db->fetch_object($result);
  242. $lines[$i][0] = $objp->ref;
  243. $lines[$i][1] = dol_print_date($this->db->jdate($objp->dp), "day", false, $outputlangs, true);
  244. $lines[$i][2] = $langs->transnoentities("PaymentTypeShort".$objp->paiement_code);
  245. $lines[$i][3] = $objp->num_payment;
  246. $lines[$i][4] = price($objp->paiement_amount);
  247. $lines[$i][5] = price($objp->facture_amount);
  248. $lines[$i][6] = price($objp->pf_amount);
  249. $lines[$i][7] = $objp->prowid;
  250. $lines[$i][8] = $objp->bankaccount;
  251. $lines[$i][9] = $objp->paiement_amount;
  252. $i++;
  253. }
  254. } else {
  255. dol_print_error($this->db);
  256. }
  257. $pages = intval(($num + $numpaiement) / $this->line_per_page);
  258. if ((($num + $numpaiement) % $this->line_per_page) > 0) {
  259. $pages++;
  260. }
  261. if ($pages == 0) {
  262. // force to build at least one page if report has no line
  263. $pages = 1;
  264. }
  265. $pdf->Open();
  266. $pagenb = 0;
  267. $pdf->SetDrawColor(128, 128, 128);
  268. $pdf->SetTitle($outputlangs->transnoentities("Payments"));
  269. $pdf->SetSubject($outputlangs->transnoentities("Payments"));
  270. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  271. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  272. //$pdf->SetKeyWords();
  273. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  274. $pdf->SetCompression(false);
  275. }
  276. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  277. $pdf->SetAutoPageBreak(1, 0);
  278. // New page
  279. $pdf->AddPage();
  280. $pagenb++;
  281. $this->_pagehead($pdf, $pagenb, 1, $outputlangs);
  282. $pdf->SetFont('', '', 9);
  283. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  284. $pdf->SetTextColor(0, 0, 0);
  285. $this->Body($pdf, 1, $lines, $outputlangs);
  286. if (method_exists($pdf, 'AliasNbPages')) {
  287. $pdf->AliasNbPages();
  288. }
  289. $pdf->Close();
  290. $pdf->Output($file, 'F');
  291. // Add pdfgeneration hook
  292. if (!is_object($hookmanager)) {
  293. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  294. $hookmanager = new HookManager($this->db);
  295. }
  296. $hookmanager->initHooks(array('pdfgeneration'));
  297. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  298. global $action;
  299. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  300. if ($reshook < 0) {
  301. $this->error = $hookmanager->error;
  302. $this->errors = $hookmanager->errors;
  303. }
  304. if (!empty($conf->global->MAIN_UMASK)) {
  305. @chmod($file, octdec($conf->global->MAIN_UMASK));
  306. }
  307. $this->result = array('fullpath'=>$file);
  308. return 1;
  309. }
  310. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  311. /**
  312. * Show top header of page.
  313. *
  314. * @param TCPDF $pdf Object PDF
  315. * @param int $page Object to show
  316. * @param int $showaddress 0=no, 1=yes
  317. * @param Translate $outputlangs Object lang for output
  318. * @return void
  319. */
  320. protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
  321. {
  322. // phpcs:enable
  323. global $langs, $conf;
  324. // Do not add the BACKGROUND as this is a report
  325. //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  326. $default_font_size = pdf_getPDFFontSize($outputlangs);
  327. $title = $conf->global->MAIN_INFO_SOCIETE_NOM;
  328. switch ($this->doc_type) {
  329. case "client":
  330. $title .= ' - '.$outputlangs->transnoentities("ListOfCustomerPayments");
  331. break;
  332. case "fourn":
  333. $title .= ' - '.$outputlangs->transnoentities("ListOfSupplierPayments");
  334. break;
  335. }
  336. $title .= ' - '.dol_print_date(dol_mktime(0, 0, 0, $this->month, 1, $this->year), "%B %Y", false, $outputlangs, true);
  337. $pdf->SetFont('', 'B', $default_font_size + 1);
  338. $pdf->SetXY($this->marge_gauche, 10);
  339. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0, 'C');
  340. $pdf->SetFont('', '', $default_font_size);
  341. $pdf->SetXY($this->posxdate, 16);
  342. $pdf->MultiCell(80, 2, $outputlangs->transnoentities("DateBuild")." : ".dol_print_date(time(), "day", false, $outputlangs, true), 0, 'L');
  343. $pdf->SetXY($this->posxdate + 100, 16);
  344. $pdf->MultiCell(80, 2, $outputlangs->transnoentities("Page")." : ".$page, 0, 'R');
  345. // Title line
  346. $pdf->SetXY($this->posxdate, $this->tab_top + 2);
  347. $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2, 'Date');
  348. $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
  349. $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
  350. $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities("PaymentMode"), 0, 'L');
  351. $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
  352. $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
  353. $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities("Invoice"), 0, 'L');
  354. $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
  355. $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
  356. $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities("Account"), 0, 'L');
  357. $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
  358. $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
  359. $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities("AmountInvoice"), 0, 'R');
  360. $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
  361. $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
  362. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities("AmountPayment"), 0, 'R');
  363. $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
  364. $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
  365. }
  366. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  367. /**
  368. * Output body
  369. *
  370. * @param TCPDF $pdf PDF object
  371. * @param string $page Page
  372. * @param array $lines Array of lines
  373. * @param Translate $outputlangs Object langs
  374. * @return void
  375. */
  376. public function Body(&$pdf, $page, $lines, $outputlangs)
  377. {
  378. // phpcs:enable
  379. global $langs, $conf;
  380. $default_font_size = pdf_getPDFFontSize($outputlangs);
  381. $pdf->SetFont('', '', $default_font_size - 1);
  382. $oldprowid = 0;
  383. $total_page = 0;
  384. $total = 0;
  385. $pdf->SetFillColor(220, 220, 220);
  386. $yp = 0;
  387. $numlines = count($lines);
  388. if (($this->doc_type == 'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type == 'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) {
  389. $mod = $lines[0][2];
  390. $total_mod = 0;
  391. }
  392. for ($j = 0; $j < $numlines; $j++) {
  393. $i = $j;
  394. if ($yp > $this->tab_height - 5) {
  395. $page++;
  396. $pdf->AddPage();
  397. $this->_pagehead($pdf, $page, 0, $outputlangs);
  398. $pdf->SetFont('', '', $default_font_size - 1);
  399. $yp = 0;
  400. }
  401. if ($oldprowid <> $lines[$j][7]) {
  402. if ($yp > $this->tab_height - 15) {
  403. $pdf->SetFillColor(255, 255, 255);
  404. $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height, 'F', array(), array());
  405. $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array('dash'=>1));
  406. $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
  407. $pdf->SetFont('', 'B', $default_font_size - 1);
  408. $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
  409. $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities('SubTotal')." : ", 0, 'R', 1);
  410. $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
  411. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height, price($total_page), 0, 'R', 1);
  412. $pdf->SetFont('', '', $default_font_size - 1);
  413. $pdf->SetFillColor(220, 220, 220);
  414. $page++;
  415. $pdf->AddPage();
  416. $this->_pagehead($pdf, $page, 0, $outputlangs);
  417. $pdf->SetFont('', '', $default_font_size - 1);
  418. $yp = 0;
  419. $total += $total_page;
  420. $total_page = 0;
  421. }
  422. $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
  423. $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0, 'L', 1);
  424. $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
  425. $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].' '.$lines[$j][3], 0, 'L', 1);
  426. $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
  427. $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height, '', 0, 'R', 1);
  428. $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
  429. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0, 'R', 1);
  430. $yp = $yp + 5;
  431. $total_page += $lines[$j][9];
  432. if (($this->doc_type == 'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type == 'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) {
  433. $total_mod += $lines[$j][9];
  434. }
  435. }
  436. // Invoice number
  437. $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
  438. $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0, 'L', 0);
  439. // BankAccount
  440. $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
  441. $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0, 'L', 0);
  442. // Invoice amount
  443. $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
  444. $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0, 'R', 0);
  445. // Payment amount
  446. $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
  447. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0, 'R', 0);
  448. $yp = $yp + 5;
  449. if ($oldprowid <> $lines[$j][7]) {
  450. $oldprowid = $lines[$j][7];
  451. }
  452. // Add line to add total by payment mode if mode reglement for nex line change
  453. if ((($this->doc_type == 'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type == 'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) && ($mod != $lines[$j + 1][2])) {
  454. $pdf->SetFillColor(245, 245, 245);
  455. $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height, 'F', array(), array());
  456. $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array('dash'=>1));
  457. $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
  458. $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
  459. $pdf->SetFont('', 'I', $default_font_size - 1);
  460. $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities('Total').' '.$mod." : ", 0, 'R', 1);
  461. $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
  462. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height, price($total_mod), 0, 'R', 1);
  463. $pdf->SetFont('', '', $default_font_size - 1);
  464. $mod = $lines[$j + 1][2];
  465. $total_mod = 0;
  466. $yp = $yp + 5;
  467. if ($yp > $this->tab_height - 5) {
  468. $page++;
  469. $pdf->AddPage();
  470. $this->_pagehead($pdf, $page, 0, $outputlangs);
  471. $pdf->SetFont('', '', $default_font_size - 1);
  472. $yp = 0;
  473. }
  474. $pdf->SetFillColor(220, 220, 220);
  475. }
  476. }
  477. $total += $total_page;
  478. $pdf->SetFillColor(255, 255, 255);
  479. $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height, 'F', array(), array());
  480. $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array('dash'=>1));
  481. $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
  482. $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
  483. $pdf->SetFont('', 'B');
  484. $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities('Total')." : ", 0, 'R', 1);
  485. $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
  486. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height, price($total), 0, 'R', 1);
  487. $pdf->SetFillColor(220, 220, 220);
  488. }
  489. }