pdf_blochet.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2009-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/cheque/doc/pdf_blochet.class.php
  22. * \ingroup banque
  23. * \brief File to build cheque deposit receipts
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
  28. /**
  29. * Class of file to build cheque deposit receipts
  30. */
  31. class BordereauChequeBlochet extends ModeleChequeReceipts
  32. {
  33. /**
  34. * Issuer
  35. * @var Societe
  36. */
  37. public $emetteur;
  38. /**
  39. * Constructor
  40. *
  41. * @param DoliDB $db Database handler
  42. */
  43. public function __construct($db)
  44. {
  45. global $conf, $langs, $mysoc;
  46. // Load traductions files required by page
  47. $langs->loadLangs(array("main", "bills"));
  48. $this->db = $db;
  49. $this->name = "blochet";
  50. $this->tab_top = 60;
  51. // Page size for A4 format
  52. $this->type = 'pdf';
  53. $formatarray = pdf_getFormat();
  54. $this->page_largeur = $formatarray['width'];
  55. $this->page_hauteur = $formatarray['height'];
  56. $this->format = array($this->page_largeur, $this->page_hauteur);
  57. $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  58. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  59. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  60. $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
  61. // Retrieves transmitter
  62. $this->emetteur = $mysoc;
  63. if (!$this->emetteur->country_code) {
  64. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  65. }
  66. // Define column position
  67. $this->line_height = 5;
  68. $this->line_per_page = 40;
  69. $this->tab_height = 200; //$this->line_height * $this->line_per_page;
  70. }
  71. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  72. /**
  73. * Fonction to generate document on disk
  74. *
  75. * @param RemiseCheque $object Object RemiseCheque
  76. * @param string $_dir Directory
  77. * @param string $number Number
  78. * @param Translate $outputlangs Lang output object
  79. * @return int 1=ok, 0=ko
  80. */
  81. public function write_file($object, $_dir, $number, $outputlangs)
  82. {
  83. // phpcs:enable
  84. global $user, $conf, $langs, $hookmanager;
  85. if (!is_object($outputlangs)) {
  86. $outputlangs = $langs;
  87. }
  88. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  89. $sav_charset_output = $outputlangs->charset_output;
  90. if (!empty($conf->global->MAIN_USE_FPDF)) {
  91. $outputlangs->charset_output = 'ISO-8859-1';
  92. }
  93. // Load traductions files required by page
  94. $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta"));
  95. $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'checkdeposits');
  96. if (!is_dir($dir)) {
  97. $result = dol_mkdir($dir);
  98. if ($result < 0) {
  99. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  100. return -1;
  101. }
  102. }
  103. $file = $dir."/bordereau-".$number.".pdf";
  104. // Add pdfgeneration hook
  105. if (!is_object($hookmanager)) {
  106. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  107. $hookmanager = new HookManager($this->db);
  108. }
  109. $hookmanager->initHooks(array('pdfgeneration'));
  110. $parameters = array('file'=>$file, 'outputlangs'=>$outputlangs);
  111. global $action;
  112. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  113. // Create PDF instance
  114. $pdf = pdf_getInstance($this->format);
  115. $heightforinfotot = 50; // Height reserved to output the info and total part
  116. $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
  117. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  118. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  119. $heightforfooter += 6;
  120. }
  121. $pdf->SetAutoPageBreak(1, 0);
  122. if (class_exists('TCPDF')) {
  123. $pdf->setPrintHeader(false);
  124. $pdf->setPrintFooter(false);
  125. }
  126. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  127. $pdf->Open();
  128. $pagenb = 0;
  129. $pdf->SetDrawColor(128, 128, 128);
  130. $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
  131. $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
  132. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  133. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  134. $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
  135. if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
  136. $pdf->SetCompression(false);
  137. }
  138. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  139. $nboflines = count($this->lines);
  140. // Define nb of page
  141. $pages = intval($nboflines / $this->line_per_page);
  142. if (($nboflines % $this->line_per_page) > 0) {
  143. $pages++;
  144. }
  145. if ($pages == 0) {
  146. // force to build at least one page if report has no lines
  147. $pages = 1;
  148. }
  149. $pdf->AddPage();
  150. $pagenb++;
  151. $this->Header($pdf, $pagenb, $pages, $outputlangs);
  152. $this->Body($pdf, $pagenb, $pages, $outputlangs);
  153. // Pied de page
  154. $this->_pagefoot($pdf, '', $outputlangs);
  155. if (method_exists($pdf, 'AliasNbPages')) {
  156. $pdf->AliasNbPages();
  157. }
  158. $pdf->Close();
  159. $pdf->Output($file, 'F');
  160. // Add pdfgeneration hook
  161. if (!is_object($hookmanager)) {
  162. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  163. $hookmanager = new HookManager($this->db);
  164. }
  165. $hookmanager->initHooks(array('pdfgeneration'));
  166. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  167. global $action;
  168. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  169. if ($reshook < 0) {
  170. $this->error = $hookmanager->error;
  171. $this->errors = $hookmanager->errors;
  172. }
  173. dolChmod($file);
  174. $this->result = array('fullpath'=>$file);
  175. $outputlangs->charset_output = $sav_charset_output;
  176. return 1; // No error
  177. }
  178. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  179. /**
  180. * Generate Header
  181. *
  182. * @param TCPDF $pdf Pdf object
  183. * @param int $page Current page number
  184. * @param int $pages Total number of pages
  185. * @param Translate $outputlangs Object language for output
  186. * @return void
  187. */
  188. public function Header(&$pdf, $page, $pages, $outputlangs)
  189. {
  190. // phpcs:enable
  191. global $langs;
  192. $default_font_size = pdf_getPDFFontSize($outputlangs);
  193. // Load traductions files required by page
  194. $outputlangs->loadLangs(array("compta", "banks"));
  195. $title = $outputlangs->transnoentities("CheckReceipt");
  196. $pdf->SetFont('', 'B', $default_font_size);
  197. $pdf->SetXY(10, 8);
  198. $pdf->MultiCell(0, 2, $title, 0, 'L');
  199. $pdf->SetFont('', '', $default_font_size);
  200. $pdf->SetXY(10, 15);
  201. $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L');
  202. $pdf->SetXY(32, 15);
  203. $pdf->SetFont('', '', $default_font_size);
  204. $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L');
  205. $pdf->SetFont('', '', $default_font_size);
  206. $pdf->SetXY(10, 20);
  207. $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L');
  208. $pdf->SetXY(32, 20);
  209. $pdf->SetFont('', '', $default_font_size);
  210. $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs));
  211. $pdf->SetFont('', '', $default_font_size);
  212. $pdf->SetXY(10, 26);
  213. $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L');
  214. $pdf->SetFont('', '', $default_font_size);
  215. $pdf->SetXY(32, 26);
  216. $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->proprio), 0, 'L');
  217. $pdf->SetFont('', '', $default_font_size);
  218. $pdf->SetXY(10, 32);
  219. $pdf->MultiCell(0, 2, $outputlangs->transnoentities("Account"), 0, 'L');
  220. pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1);
  221. $pdf->SetFont('', '', $default_font_size);
  222. $pdf->SetXY(114, 15);
  223. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
  224. $pdf->Rect(9, 14, 192, 35);
  225. $pdf->line(9, 19, 112, 19);
  226. $pdf->line(9, 25, 112, 25);
  227. //$pdf->line(9, 31, 201, 31);
  228. $pdf->line(9, 31, 112, 31);
  229. $pdf->line(30, 14, 30, 49);
  230. $pdf->line(112, 14, 112, 49);
  231. // Number of cheques
  232. $posy = 51;
  233. $pdf->Rect(9, $posy, 192, 6);
  234. $pdf->line(55, $posy, 55, $posy + 6);
  235. $pdf->line(140, $posy, 140, $posy + 6);
  236. $pdf->line(170, $posy, 170, $posy + 6);
  237. $pdf->SetFont('', '', $default_font_size);
  238. $pdf->SetXY(10, $posy + 1);
  239. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
  240. $pdf->SetFont('', 'B', $default_font_size);
  241. $pdf->SetXY(57, $posy + 1);
  242. $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
  243. $pdf->SetFont('', '', $default_font_size);
  244. $pdf->SetXY(148, $posy + 1);
  245. $pdf->MultiCell(40, 2, $langs->trans("Total"));
  246. $pdf->SetFont('', 'B', $default_font_size);
  247. $pdf->SetXY(170, $posy + 1);
  248. $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
  249. // Tableau
  250. $pdf->SetFont('', '', $default_font_size - 2);
  251. $pdf->SetXY(11, $this->tab_top + 2);
  252. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Num"), 0, 'L');
  253. $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
  254. $pdf->SetXY(41, $this->tab_top + 2);
  255. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L');
  256. $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
  257. $pdf->SetXY(101, $this->tab_top + 2);
  258. $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
  259. $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
  260. $pdf->SetXY(180, $this->tab_top + 2);
  261. $pdf->MultiCell(20, 2, $outputlangs->transnoentities("Amount"), 0, 'R');
  262. $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
  263. $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
  264. }
  265. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  266. /**
  267. * Output array
  268. *
  269. * @param TCPDF $pdf PDF object
  270. * @param int $pagenb Page nb
  271. * @param int $pages Pages
  272. * @param Translate $outputlangs Object lang
  273. * @return void
  274. */
  275. public function Body(&$pdf, $pagenb, $pages, $outputlangs)
  276. {
  277. // phpcs:enable
  278. // x=10 - Num
  279. // x=30 - Banque
  280. // x=100 - Emetteur
  281. $default_font_size = pdf_getPDFFontSize($outputlangs);
  282. $pdf->SetFont('', '', $default_font_size - 1);
  283. $oldprowid = 0;
  284. $pdf->SetFillColor(220, 220, 220);
  285. $yp = 0;
  286. $lineinpage = 0;
  287. $num = count($this->lines);
  288. for ($j = 0; $j < $num; $j++) {
  289. // Dynamic max line heigh calculation
  290. $dynamic_line_height = array();
  291. $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq));
  292. $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq));
  293. $max_line_height = max($dynamic_line_height);
  294. // Calculate number of line used function of estimated line size
  295. if ($max_line_height > $this->line_height) {
  296. $nb_lines = floor($max_line_height / $this->line_height) + 1;
  297. } else {
  298. $nb_lines = 1;
  299. }
  300. // Add page break if we do not have space to add current line
  301. if ($lineinpage >= ($this->line_per_page - 1)) {
  302. $lineinpage = 0;
  303. $yp = 0;
  304. // New page
  305. $pdf->AddPage();
  306. $pagenb++;
  307. $this->Header($pdf, $pagenb, $pages, $outputlangs);
  308. $pdf->SetFont('', '', $default_font_size - 1);
  309. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  310. $pdf->SetTextColor(0, 0, 0);
  311. }
  312. $lineinpage += $nb_lines;
  313. $pdf->SetXY(1, $this->tab_top + 10 + $yp);
  314. $pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0);
  315. $pdf->SetXY(10, $this->tab_top + 10 + $yp);
  316. $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq ? $this->lines[$j]->num_chq : '', 0, 'L', 0);
  317. $pdf->SetXY(40, $this->tab_top + 10 + $yp);
  318. $pdf->MultiCell(60, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq, 44), 0, 'L', 0);
  319. $pdf->SetXY(100, $this->tab_top + 10 + $yp);
  320. $pdf->MultiCell(80, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq, 50), 0, 'L', 0);
  321. $pdf->SetXY(180, $this->tab_top + 10 + $yp);
  322. $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
  323. $yp = $yp + ($this->line_height * $nb_lines);
  324. }
  325. }
  326. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  327. /**
  328. * Show footer of page. Need this->emetteur object
  329. *
  330. * @param TCPDF $pdf PDF
  331. * @param Object $object Object to show
  332. * @param Translate $outputlangs Object lang for output
  333. * @param int $hidefreetext 1=Hide free text
  334. * @return mixed
  335. */
  336. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  337. {
  338. global $conf;
  339. $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
  340. // Line of free text
  341. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  342. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  343. $newfreetext = '';
  344. $paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT';
  345. if (!empty($conf->global->$paramfreetext)) {
  346. $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
  347. }
  348. return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  349. }
  350. }