PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/core/modules/cheque/pdf/pdf_blochet.class.php

https://github.com/asterix14/dolibarr
PHP | 398 lines | 245 code | 75 blank | 78 comment | 19 complexity | 3c5d9f75e9b6123502a57ff84daf250f MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 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/cheque/pdf/pdf_blochet.class.php
  21. * \ingroup banque
  22. * \brief File to build cheque deposit receipts
  23. */
  24. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/modules/cheque/pdf/modules_chequereceipts.php");
  27. /**
  28. * \class BordereauChequeBlochet
  29. * \brief Class of file to build cheque deposit receipts
  30. */
  31. class BordereauChequeBlochet extends ModeleChequeReceipts
  32. {
  33. var $error='';
  34. var $emetteur; // Objet societe qui emet
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. function BordereauChequeBlochet($db)
  41. {
  42. global $conf,$langs,$mysoc;
  43. $langs->load("main");
  44. $langs->load("bills");
  45. $this->db = $db;
  46. $this->name = "blochet";
  47. $this->tab_top = 60;
  48. // Dimension page pour format A4
  49. $this->type = 'pdf';
  50. $formatarray=pdf_getFormat();
  51. $this->page_largeur = $formatarray['width'];
  52. $this->page_hauteur = $formatarray['height'];
  53. $this->format = array($this->page_largeur,$this->page_hauteur);
  54. $this->marge_gauche=10;
  55. $this->marge_droite=20;
  56. $this->marge_haute=10;
  57. $this->marge_basse=10;
  58. // Recupere emmetteur
  59. $this->emetteur=$mysoc;
  60. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini
  61. // Defini position des colonnes
  62. $this->line_height = 5;
  63. $this->line_per_page = 40;
  64. $this->tab_height = 200; //$this->line_height * $this->line_per_page;
  65. }
  66. /**
  67. * Fonction generant le rapport sur le disque
  68. *
  69. * @param _dir Directory
  70. * @param number Number
  71. * @param outputlangs Lang output object
  72. * @return int 1=ok, 0=ko
  73. */
  74. function write_file($_dir, $number, $outputlangs)
  75. {
  76. global $user,$conf,$langs;
  77. if (! is_object($outputlangs)) $outputlangs=$langs;
  78. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  79. $sav_charset_output=$outputlangs->charset_output;
  80. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  81. $outputlangs->load("main");
  82. $outputlangs->load("companies");
  83. $outputlangs->load("bills");
  84. $outputlangs->load("products");
  85. $outputlangs->load("compta");
  86. $dir = $_dir . "/".get_exdir($number,2,1).$number;
  87. if (! is_dir($dir))
  88. {
  89. $result=create_exdir($dir);
  90. if ($result < 0)
  91. {
  92. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  93. return -1;
  94. }
  95. }
  96. $month = sprintf("%02d",$month);
  97. $year = sprintf("%04d",$year);
  98. $_file = $dir . "/bordereau-".$number.".pdf";
  99. // Create PDF instance
  100. $pdf=pdf_getInstance($this->format);
  101. if (class_exists('TCPDF'))
  102. {
  103. $pdf->setPrintHeader(false);
  104. $pdf->setPrintFooter(false);
  105. }
  106. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  107. $pdf->Open();
  108. $pagenb=0;
  109. $pdf->SetDrawColor(128,128,128);
  110. $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
  111. $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
  112. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  113. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  114. $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
  115. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  116. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  117. $pdf->SetAutoPageBreak(1,0);
  118. $nboflines=count($this->lines);
  119. // Define nb of page
  120. $pages = intval($nboflines / $this->line_per_page);
  121. if (($nboflines % $this->line_per_page)>0)
  122. {
  123. $pages++;
  124. }
  125. if ($pages == 0)
  126. {
  127. // force to build at least one page if report has no lines
  128. $pages = 1;
  129. }
  130. $pdf->AddPage();
  131. $pagenb++;
  132. $this->Header($pdf, $pagenb, $pages, $outputlangs);
  133. $this->Body($pdf, $pagenb, $pages, $outputlangs);
  134. // Pied de page
  135. $this->_pagefoot($pdf,'',$outputlangs);
  136. $pdf->AliasNbPages();
  137. $pdf->Close();
  138. $pdf->Output($_file,'F');
  139. if (! empty($conf->global->MAIN_UMASK))
  140. @chmod($file, octdec($conf->global->MAIN_UMASK));
  141. $outputlangs->charset_output=$sav_charset_output;
  142. return 1; // Pas d'erreur
  143. }
  144. /**
  145. * Generate Header
  146. *
  147. * @param PDF &$pdf Pdf object
  148. * @param int $page Current page number
  149. * @param int $pages Total number of pages
  150. * @param Translate $outputlangs Object language for output
  151. * @return void
  152. */
  153. function Header(&$pdf, $page, $pages, $outputlangs)
  154. {
  155. global $langs;
  156. $default_font_size = pdf_getPDFFontSize($outputlangs);
  157. $outputlangs->load("compta");
  158. $outputlangs->load("banks");
  159. $title = $outputlangs->transnoentities("CheckReceipt");
  160. $pdf->SetFont('','B', $default_font_size);
  161. $pdf->SetXY(10,8);
  162. $pdf->MultiCell(0,2,$title,0,'L');
  163. $pdf->SetFont('','', $default_font_size);
  164. $pdf->SetXY(10,15);
  165. $pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
  166. $pdf->SetXY(32,15);
  167. $pdf->SetFont('','', $default_font_size);
  168. $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->number), 0, 'L');
  169. $pdf->SetFont('','', $default_font_size);
  170. $pdf->SetXY(10,20);
  171. $pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
  172. $pdf->SetXY(32,20);
  173. $pdf->SetFont('','', $default_font_size);
  174. $pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
  175. $pdf->SetFont('','', $default_font_size);
  176. $pdf->SetXY(10,26);
  177. $pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
  178. $pdf->SetFont('','', $default_font_size);
  179. $pdf->SetXY(32,26);
  180. $pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
  181. $pdf->SetFont('','', $default_font_size);
  182. $pdf->SetXY(10,32);
  183. $pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
  184. pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
  185. $pdf->SetFont('','', $default_font_size);
  186. $pdf->SetXY(114,15);
  187. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
  188. $pdf->Rect(9, 14, 192, 35);
  189. $pdf->line(9, 19, 112, 19);
  190. $pdf->line(9, 25, 112, 25);
  191. //$pdf->line(9, 31, 201, 31);
  192. $pdf->line(9, 31, 112, 31);
  193. $pdf->line(30, 14, 30, 49);
  194. $pdf->line(112, 14, 112, 49);
  195. // Number of cheques
  196. $posy=51;
  197. $pdf->Rect(9, $posy, 192, 6);
  198. $pdf->line(55, $posy, 55, $posy+6);
  199. $pdf->line(140, $posy, 140, $posy+6);
  200. $pdf->line(170, $posy, 170, $posy+6);
  201. $pdf->SetFont('','', $default_font_size);
  202. $pdf->SetXY(10,$posy+1);
  203. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
  204. $pdf->SetFont('','B', $default_font_size);
  205. $pdf->SetXY(57,$posy+1);
  206. $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
  207. $pdf->SetFont('','', $default_font_size);
  208. $pdf->SetXY(148,$posy+1);
  209. $pdf->MultiCell(40, 2, $langs->trans("Total"));
  210. $pdf->SetFont('','B', $default_font_size);
  211. $pdf->SetXY(170, $posy+1);
  212. $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
  213. // Tableau
  214. $pdf->SetFont('','', $default_font_size - 2);
  215. $pdf->SetXY(11, $this->tab_top+2);
  216. $pdf->MultiCell(40,2,$outputlangs->transnoentities("Num"), 0, 'L');
  217. $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
  218. $pdf->SetXY(41, $this->tab_top+2);
  219. $pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
  220. $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
  221. $pdf->SetXY(101, $this->tab_top+2);
  222. $pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
  223. $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
  224. $pdf->SetXY(180, $this->tab_top+2);
  225. $pdf->MultiCell(20,2,$outputlangs->transnoentities("Amount"), 0, 'R');
  226. $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
  227. $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
  228. }
  229. /**
  230. * Output array
  231. */
  232. function Body(&$pdf, $pagenb, $pages, $outputlangs)
  233. {
  234. // x=10 - Num
  235. // x=30 - Banque
  236. // x=100 - Emetteur
  237. $default_font_size = pdf_getPDFFontSize($outputlangs);
  238. $pdf->SetFont('','', $default_font_size - 1);
  239. $oldprowid = 0;
  240. $pdf->SetFillColor(220,220,220);
  241. $yp = 0;
  242. $lineinpage=0;
  243. $num=count($this->lines);
  244. for ($j = 0; $j < $num; $j++)
  245. {
  246. $lineinpage++;
  247. $pdf->SetXY(1, $this->tab_top + 10 + $yp);
  248. $pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
  249. $pdf->SetXY(10, $this->tab_top + 10 + $yp);
  250. $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq?$this->lines[$j]->num_chq:'', 0, 'L', 0);
  251. $pdf->SetXY(40, $this->tab_top + 10 + $yp);
  252. $pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq),44), 0, 'L', 0);
  253. $pdf->SetXY(100, $this->tab_top + 10 + $yp);
  254. $pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq),50), 0, 'L', 0);
  255. $pdf->SetXY(180, $this->tab_top + 10 + $yp);
  256. $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
  257. $yp = $yp + $this->line_height;
  258. if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
  259. {
  260. $lineinpage=0; $yp=0;
  261. // New page
  262. $pdf->AddPage();
  263. $pagenb++;
  264. $this->Header($pdf, $pagenb, $pages, $outputlangs);
  265. $pdf->SetFont('','', $default_font_size - 1);
  266. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  267. $pdf->SetTextColor(0,0,0);
  268. }
  269. }
  270. }
  271. /**
  272. * \brief Show footer of page
  273. * \param pdf Object PDF
  274. * \param object Object cheque receipt
  275. * \param outputlangs Object lang for output
  276. * \remarks Need this->emetteur object
  277. */
  278. function _pagefoot(&$pdf,$object,$outputlangs)
  279. {
  280. global $conf;
  281. $default_font_size = pdf_getPDFFontSize($outputlangs);
  282. //return pdf_pagefoot($pdf,$outputlangs,'BANK_CHEQUERECEIPT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  283. $paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
  284. $marge_basse=$this->marge_basse;
  285. $marge_gauche=$this->marge_gauche;
  286. $page_hauteur=$this->page_hauteur;
  287. // Line of free text
  288. $line=(! empty($conf->global->$paramfreetext))?$outputlangs->convToOutputCharset($conf->global->$paramfreetext):"";
  289. $pdf->SetFont('','', $default_font_size - 3);
  290. $pdf->SetDrawColor(224,224,224);
  291. // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
  292. $nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
  293. //print 'e'.$line.'t'.dol_nboflines($line);exit;
  294. $posy=$marge_basse + ($nbofline*3) + ($line1?3:0) + ($line2?3:0);
  295. if ($line) // Free text
  296. {
  297. $pdf->SetXY($marge_gauche,-$posy);
  298. $pdf->MultiCell(20000, 3, $line, 0, 'L', 0); // Use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
  299. $posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell
  300. }
  301. $pdf->SetY(-$posy);
  302. $pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
  303. $posy--;
  304. if ($line1)
  305. {
  306. $pdf->SetXY($marge_gauche,-$posy);
  307. $pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
  308. }
  309. if ($line2)
  310. {
  311. $posy-=3;
  312. $pdf->SetXY($marge_gauche,-$posy);
  313. $pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
  314. }
  315. // Show page nb only on iso languages (so default Helvetica font)
  316. if (pdf_getPDFFont($outputlangs) == 'Helvetica')
  317. {
  318. $pdf->SetXY(-20,-$posy);
  319. $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  320. }
  321. }
  322. }
  323. ?>