PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/core/modules/rapport/pdf_paiement.class.php

https://github.com/asterix14/dolibarr
PHP | 321 lines | 201 code | 62 blank | 58 comment | 16 complexity | ea4d3471db50546000a6cfb30447f5b1 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/rapport/pdf_paiement.class.php
  21. * \ingroup banque
  22. * \brief File to build payment reports
  23. */
  24. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  26. /**
  27. * \class pdf_paiement
  28. * \brief Classe permettant de generer les rapports de paiement
  29. */
  30. class pdf_paiement
  31. {
  32. /**
  33. * \brief Constructeur
  34. * \param db handler acces base de donnee
  35. */
  36. function pdf_paiement($db)
  37. {
  38. global $langs;
  39. $langs->load("bills");
  40. $langs->load("compta");
  41. $this->db = $db;
  42. $this->description = $langs->transnoentities("ListOfCustomerPayments");
  43. // Dimension page pour format A4
  44. $this->type = 'pdf';
  45. $formatarray=pdf_getFormat();
  46. $this->page_largeur = $formatarray['width'];
  47. $this->page_hauteur = $formatarray['height'];
  48. $this->format = array($this->page_largeur,$this->page_hauteur);
  49. $this->marge_gauche=10;
  50. $this->marge_droite=10;
  51. $this->marge_haute=10;
  52. $this->marge_basse=10;
  53. $this->tab_top = 30;
  54. $this->line_height = 5;
  55. $this->line_per_page = 25;
  56. $this->tab_height = 230; //$this->line_height * $this->line_per_page;
  57. }
  58. /**
  59. * \brief Fonction generant le rapport sur le disque
  60. * \param _dir repertoire
  61. * \param month mois du rapport
  62. * \param year annee du rapport
  63. * \param outputlangs Lang output object
  64. */
  65. function write_file($_dir, $month, $year, $outputlangs)
  66. {
  67. include_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
  68. global $user,$langs,$conf;
  69. if (! is_object($outputlangs)) $outputlangs=$langs;
  70. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  71. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  72. $this->month=$month;
  73. $this->year=$year;
  74. $dir=$_dir.'/'.$year;
  75. if (! is_dir($dir))
  76. {
  77. $result=create_exdir($dir);
  78. if ($result < 0)
  79. {
  80. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  81. return -1;
  82. }
  83. }
  84. $month = sprintf("%02d",$month);
  85. $year = sprintf("%04d",$year);
  86. $file = $dir . "/payments-".$year."-".$month.".pdf";
  87. $pdf=pdf_getInstance($this->format);
  88. if (class_exists('TCPDF'))
  89. {
  90. $pdf->setPrintHeader(false);
  91. $pdf->setPrintFooter(false);
  92. }
  93. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  94. $num=0;
  95. $lines=array();
  96. $sql = "SELECT p.datep as dp, f.facnumber";
  97. //$sql .= ", c.libelle as paiement_type, p.num_paiement";
  98. $sql .= ", c.code as paiement_code, p.num_paiement";
  99. $sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount ";
  100. $sql .= ", pf.amount as pf_amount ";
  101. $sql .= ", p.rowid as prowid";
  102. $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f,";
  103. $sql .= " ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf";
  104. $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
  105. $sql .= " AND p.fk_paiement = c.id ";
  106. $sql .= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'";
  107. $sql .= " ORDER BY p.datep ASC, pf.fk_paiement ASC";
  108. dol_syslog("pdf_paiement::write_file sql=".$sql);
  109. $result = $this->db->query($sql);
  110. if ($result)
  111. {
  112. $num = $this->db->num_rows($result);
  113. $i = 0;
  114. $var=True;
  115. while ($i < $num)
  116. {
  117. $objp = $this->db->fetch_object($result);
  118. $var=!$var;
  119. $lines[$i][0] = $objp->facnumber;
  120. $lines[$i][1] = dol_print_date($this->db->jdate($objp->dp),"%d %B %Y",false,$outputlangs,true);
  121. $lines[$i][2] = $langs->transnoentities("PaymentTypeShort".$objp->paiement_code);
  122. $lines[$i][3] = $objp->num_paiement;
  123. $lines[$i][4] = price($objp->paiement_amount);
  124. $lines[$i][5] = price($objp->facture_amount);
  125. $lines[$i][6] = price($objp->pf_amount);
  126. $lines[$i][7] = $objp->prowid;
  127. $i++;
  128. }
  129. }
  130. else
  131. {
  132. dol_print_error($this->db);
  133. }
  134. $pages = intval($num / $this->line_per_page);
  135. if (($lines % $this->line_per_page)>0)
  136. {
  137. $pages++;
  138. }
  139. if ($pages == 0)
  140. {
  141. // force to build at least one page if report has no line
  142. $pages = 1;
  143. }
  144. $pdf->Open();
  145. $pagenb=0;
  146. $pdf->SetDrawColor(128,128,128);
  147. $pdf->SetTitle($outputlangs->transnoentities("Payments"));
  148. $pdf->SetSubject($outputlangs->transnoentities("Payments"));
  149. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  150. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  151. //$pdf->SetKeyWords();
  152. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  153. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  154. $pdf->SetAutoPageBreak(1,0);
  155. // New page
  156. $pdf->AddPage();
  157. $pagenb++;
  158. $this->_pagehead($pdf, $pages, 1, $outputlangs);
  159. $pdf->SetFont('','', 9);
  160. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  161. $pdf->SetTextColor(0,0,0);
  162. $this->Body($pdf, 1, $lines, $outputlangs);
  163. $pdf->AliasNbPages();
  164. $pdf->Close();
  165. $pdf->Output($file,'F');
  166. if (! empty($conf->global->MAIN_UMASK))
  167. @chmod($file, octdec($conf->global->MAIN_UMASK));
  168. return 1;
  169. }
  170. /**
  171. * Show header of page
  172. *
  173. * @param $pdf Object PDF
  174. * @param $object Object
  175. * @param $showaddress 0=no, 1=yes
  176. * @param $outputlangs Object lang for output
  177. */
  178. function _pagehead(&$pdf, $page, $showaddress=1, $outputlangs)
  179. {
  180. global $langs;
  181. // Do not add the BACKGROUND as this is a report
  182. //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  183. $title=$outputlangs->transnoentities("ListOfCustomerPayments");
  184. $title.=' - '.dol_print_date(dol_mktime(0,0,0,$this->month,1,$this->year),"%B %Y",false,$outputlangs,true);
  185. $pdf->SetFont('','B',12);
  186. $pdf->SetXY(10,10);
  187. $pdf->MultiCell(200, 2, $title, 0, 'C');
  188. $pdf->SetFont('','',10);
  189. $pdf->SetXY(11, 16);
  190. $pdf->MultiCell(80, 2, $outputlangs->transnoentities("DateBuild")." : ".dol_print_date(time(),"day",false,$outputlangs,true), 0, 'L');
  191. $pdf->SetXY(11, 22);
  192. $pdf->MultiCell(80, 2, $outputlangs->transnoentities("Page")." : ".$page, 0, 'L');
  193. // Title line
  194. $pdf->SetXY(11, $this->tab_top+2);
  195. $pdf->MultiCell(30, 2, 'Date');
  196. $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
  197. $pdf->SetXY(42, $this->tab_top+2);
  198. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("PaymentMode"), 0, 'L');
  199. $pdf->line(80, $this->tab_top, 80, $this->tab_top + $this->tab_height + 10);
  200. $pdf->SetXY(82, $this->tab_top+2);
  201. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Invoice"), 0, 'L');
  202. $pdf->line(120, $this->tab_top, 120, $this->tab_top + $this->tab_height + 10);
  203. $pdf->SetXY(122, $this->tab_top+2);
  204. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("AmountInvoice"), 0, 'L');
  205. $pdf->line(160, $this->tab_top, 160, $this->tab_top + $this->tab_height + 10);
  206. $pdf->SetXY(162, $this->tab_top+2);
  207. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("AmountPayment"), 0, 'L');
  208. $pdf->line(10, $this->tab_top + 10, 200, $this->tab_top + 10 );
  209. $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
  210. }
  211. /**
  212. *
  213. */
  214. function Body(&$pdf, $page, $lines, $outputlangs)
  215. {
  216. $pdf->SetFont('','', 9);
  217. $oldprowid = 0;
  218. $pdf->SetFillColor(220,220,220);
  219. $yp = 0;
  220. $numlines=count($lines);
  221. for ($j = 0 ; $j < $numlines ; $j++)
  222. {
  223. $i = $j;
  224. if ($oldprowid <> $lines[$j][7])
  225. {
  226. if ($yp > 200)
  227. {
  228. $page++;
  229. $pdf->AddPage();
  230. $this->_pagehead($pdf, $page, 0, $outputlangs);
  231. $pdf->SetFont('','', 9);
  232. $yp = 0;
  233. }
  234. $pdf->SetXY(10, $this->tab_top + 10 + $yp);
  235. $pdf->MultiCell(30, $this->line_height, $lines[$j][1], 0, 'L', 1);
  236. $pdf->SetXY(40, $this->tab_top + 10 + $yp);
  237. $pdf->MultiCell(80, $this->line_height, $lines[$j][2].' '.$lines[$j][3], 0, 'L', 1);
  238. $pdf->SetXY(120, $this->tab_top + 10 + $yp);
  239. $pdf->MultiCell(40, $this->line_height, '', 0, 'R', 1);
  240. $pdf->SetXY(160, $this->tab_top + 10 + $yp);
  241. $pdf->MultiCell(40, $this->line_height, $lines[$j][4], 0, 'R', 1);
  242. $yp = $yp + 5;
  243. }
  244. // Invoice number
  245. $pdf->SetXY(80, $this->tab_top + 10 + $yp);
  246. $pdf->MultiCell(40, $this->line_height, $lines[$j][0], 0, 'L', 0);
  247. $pdf->SetXY(120, $this->tab_top + 10 + $yp);
  248. $pdf->MultiCell(40, $this->line_height, $lines[$j][5], 0, 'R', 0);
  249. $pdf->SetXY(160, $this->tab_top + 10 + $yp);
  250. $pdf->MultiCell(40, $this->line_height, $lines[$j][6], 0, 'R', 0);
  251. $yp = $yp + 5;
  252. if ($oldprowid <> $lines[$j][7])
  253. {
  254. $oldprowid = $lines[$j][7];
  255. }
  256. }
  257. }
  258. }
  259. ?>