pdf_sepamandate.modules.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. /* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
  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 3 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 <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php
  21. * \ingroup project
  22. * \brief File of class to generate document with template sepamandate
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
  25. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. /**
  30. * Class to generate SEPA mandate
  31. */
  32. class pdf_sepamandate extends ModeleBankAccountDoc
  33. {
  34. /**
  35. * Issuer
  36. * @var Societe
  37. */
  38. public $emetteur;
  39. /**
  40. * Dolibarr version of the loaded document
  41. * @var string
  42. */
  43. public $version = 'dolibarr';
  44. /**
  45. * Constructor
  46. *
  47. * @param DoliDB $db Database handler
  48. */
  49. public function __construct($db)
  50. {
  51. global $conf, $langs, $mysoc;
  52. // Translations
  53. $langs->loadLangs(array("main", "bank", "withdrawals", "companies"));
  54. $this->db = $db;
  55. $this->name = "sepamandate";
  56. $this->description = $langs->transnoentitiesnoconv("DocumentModelSepaMandate");
  57. // Page size for A4 format
  58. $this->type = 'pdf';
  59. $formatarray = pdf_getFormat();
  60. $this->page_largeur = $formatarray['width'];
  61. $this->page_hauteur = $formatarray['height'];
  62. $this->format = array($this->page_largeur, $this->page_hauteur);
  63. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  64. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  65. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  66. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  67. $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
  68. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  69. $this->option_codeproduitservice = 1; // Affiche code produit-service
  70. // Retrieves transmitter
  71. $this->emetteur = $mysoc;
  72. if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
  73. // Define column position
  74. $this->posxref = $this->marge_gauche;
  75. }
  76. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  77. /**
  78. * Fonction generant le projet sur le disque
  79. *
  80. * @param Project $object Object project a generer
  81. * @param Translate $outputlangs Lang output object
  82. * @param string $srctemplatepath Full path of source filename for generator using a template file
  83. * @param int $hidedetails Do not show line details (not used for this template)
  84. * @param int $hidedesc Do not show desc (not used for this template)
  85. * @param int $hideref Do not show ref (not used for this template)
  86. * @param null|array $moreparams More parameters
  87. * @return int 1 if OK, <=0 if KO
  88. */
  89. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  90. {
  91. // phpcs:enable
  92. global $conf, $hookmanager, $langs, $user, $mysoc;
  93. if (!is_object($outputlangs)) $outputlangs = $langs;
  94. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  95. if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
  96. // Load translation files required by the page
  97. $outputlangs->loadLangs(array("main", "dict", "withdrawals", "companies", "projects", "bills"));
  98. if (!empty($conf->bank->dir_output))
  99. {
  100. //$nblines = count($object->lines); // This is set later with array of tasks
  101. // Definition of $dir and $file
  102. if ($object->specimen)
  103. {
  104. if (!empty($moreparams['force_dir_output'])) $dir = $moreparams['force_dir_output'];
  105. else $dir = $conf->bank->dir_output;
  106. $file = $dir."/SPECIMEN.pdf";
  107. } else {
  108. $objectref = dol_sanitizeFileName($object->ref);
  109. if (!empty($moreparams['force_dir_output'])) $dir = $moreparams['force_dir_output'];
  110. else $dir = $conf->bank->dir_output."/".$objectref;
  111. $file = $dir."/".$langs->transnoentitiesnoconv("SepaMandateShort").' '.$objectref."-".dol_sanitizeFileName($object->rum).".pdf";
  112. }
  113. if (!file_exists($dir))
  114. {
  115. if (dol_mkdir($dir) < 0)
  116. {
  117. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  118. return 0;
  119. }
  120. }
  121. if (file_exists($dir))
  122. {
  123. // Add pdfgeneration hook
  124. if (!is_object($hookmanager))
  125. {
  126. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  127. $hookmanager = new HookManager($this->db);
  128. }
  129. $hookmanager->initHooks(array('pdfgeneration'));
  130. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  131. global $action;
  132. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  133. $pdf = pdf_getInstance($this->format);
  134. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  135. $heightforinfotot = 50; // Height reserved to output the info and total part
  136. $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
  137. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  138. if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
  139. $pdf->SetAutoPageBreak(1, 0);
  140. if (class_exists('TCPDF'))
  141. {
  142. $pdf->setPrintHeader(false);
  143. $pdf->setPrintFooter(false);
  144. }
  145. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  146. $pdf->Open();
  147. $pagenb = 0;
  148. $pdf->SetDrawColor(128, 128, 128);
  149. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  150. $pdf->SetSubject($outputlangs->transnoentities("SepaMandate"));
  151. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  152. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  153. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("SepaMandate"));
  154. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  155. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  156. // New page
  157. $pdf->AddPage();
  158. $pagenb++;
  159. $this->_pagehead($pdf, $object, 1, $outputlangs);
  160. $pdf->SetFont('', '', $default_font_size - 1);
  161. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  162. $pdf->SetTextColor(0, 0, 0);
  163. $tab_top = 50;
  164. $tab_height = 200;
  165. $tab_top_newpage = 40;
  166. $tab_height_newpage = 210;
  167. // Show notes
  168. if (!empty($object->note_public))
  169. {
  170. $pdf->SetFont('', '', $default_font_size - 1);
  171. $pdf->writeHTMLCell(190, 3, $this->posxref, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
  172. $nexY = $pdf->GetY();
  173. $height_note = $nexY - ($tab_top - 2);
  174. // Rect takes a length in 3rd parameter
  175. $pdf->SetDrawColor(192, 192, 192);
  176. $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  177. $tab_height = $tab_height - $height_note;
  178. $tab_top = $nexY + 6;
  179. } else {
  180. $height_note = 0;
  181. }
  182. $iniY = $tab_top + 7;
  183. $curY = $tab_top + 7;
  184. $nexY = $tab_top + 7;
  185. $posY = $curY;
  186. $pdf->SetFont('', '', $default_font_size);
  187. $pdf->line($this->marge_gauche, $posY, $this->page_largeur - $this->marge_droite, $posY);
  188. $posY += 2;
  189. $pdf->SetXY($this->marge_gauche, $posY);
  190. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("RUMLong").' ('.$outputlangs->transnoentitiesnoconv("RUM").') : '.$object->rum, 0, 'L');
  191. $posY = $pdf->GetY();
  192. $posY += 2;
  193. $pdf->SetXY($this->marge_gauche, $posY);
  194. $ics = '';
  195. if (!empty($conf->global->PRELEVEMENT_ICS)) $ics = $conf->global->PRELEVEMENT_ICS;
  196. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("CreditorIdentifier").' ('.$outputlangs->transnoentitiesnoconv("ICS").') : '.$ics, 0, 'L');
  197. $posY = $pdf->GetY();
  198. $posY += 1;
  199. $pdf->SetXY($this->marge_gauche, $posY);
  200. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("CreditorName").' : '.$mysoc->name, 0, 'L');
  201. $posY = $pdf->GetY();
  202. $posY += 1;
  203. $pdf->SetXY($this->marge_gauche, $posY);
  204. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("Address").' : ', 0, 'L');
  205. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $mysoc->getFullAddress(), 0, 'L');
  206. $posY = $pdf->GetY();
  207. $posY += 3;
  208. $pdf->line($this->marge_gauche, $posY, $this->page_largeur - $this->marge_droite, $posY);
  209. $pdf->SetFont('', '', $default_font_size - 1);
  210. $posY += 8;
  211. $pdf->SetXY($this->marge_gauche, $posY);
  212. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 8, $outputlangs->transnoentitiesnoconv("SEPALegalText", $mysoc->name, $mysoc->name), 0, 'L');
  213. // Your data form
  214. $posY = $pdf->GetY();
  215. $posY += 8;
  216. $pdf->line($this->marge_gauche, $posY, $this->page_largeur - $this->marge_droite, $posY);
  217. $posY += 2;
  218. $pdf->SetFont('', '', $default_font_size);
  219. $pdf->SetXY($this->marge_gauche, $posY);
  220. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("SEPAFillForm"), 0, 'C');
  221. $thirdparty = new Societe($this->db);
  222. if ($object->socid > 0) $thirdparty->fetch($object->socid);
  223. $sepaname = '______________________________________________';
  224. if ($thirdparty->id > 0)
  225. {
  226. $sepaname = $thirdparty->name.($object->account_owner ? ' ('.$object->account_owner.')' : '');
  227. }
  228. $posY = $pdf->GetY();
  229. $posY += 3;
  230. $pdf->SetXY($this->marge_gauche, $posY);
  231. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("SEPAFormYourName").' * : ', 0, 'L');
  232. $pdf->SetXY(80, $posY);
  233. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $sepaname, 0, 'L');
  234. $sepavatid = '__________________________________________________';
  235. if (!empty($thirdparty->idprof1)) $sepavatid = $thirdparty->idprof1;
  236. $posY = $pdf->GetY();
  237. $posY += 1;
  238. $pdf->SetXY($this->marge_gauche, $posY);
  239. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv('ProfId1'.$thirdparty->country_code).' * : ', 0, 'L');
  240. $pdf->SetXY(80, $posY);
  241. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $sepavatid, 0, 'L');
  242. $address = '______________________________________________';
  243. if ($thirdparty->id > 0)
  244. {
  245. $address = $thirdparty->getFullAddress();
  246. }
  247. $posY = $pdf->GetY();
  248. $posY += 1;
  249. $pdf->SetXY($this->marge_gauche, $posY);
  250. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("Address").' : ', 0, 'L');
  251. $pdf->SetXY(80, $posY);
  252. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $address, 0, 'L');
  253. if (preg_match('/_____/', $address))
  254. {
  255. $posY += 6;
  256. $pdf->SetXY(80, $posY);
  257. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $address, 0, 'L');
  258. }
  259. $ban = '__________________________________________________';
  260. if (!empty($object->iban)) $ban = $object->iban;
  261. $posY = $pdf->GetY();
  262. $posY += 1;
  263. $pdf->SetXY($this->marge_gauche, $posY);
  264. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("SEPAFormYourBAN").' * : ', 0, 'L');
  265. $pdf->SetXY(80, $posY);
  266. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $ban, 0, 'L');
  267. $bic = '__________________________________________________';
  268. if (!empty($object->bic)) $bic = $object->bic;
  269. $posY = $pdf->GetY();
  270. $posY += 1;
  271. $pdf->SetXY($this->marge_gauche, $posY);
  272. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $outputlangs->transnoentitiesnoconv("SEPAFormYourBIC").' * : ', 0, 'L');
  273. $pdf->SetXY(80, $posY);
  274. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $bic, 0, 'L');
  275. $posY = $pdf->GetY();
  276. $posY += 1;
  277. $pdf->SetXY($this->marge_gauche, $posY);
  278. $txt = $outputlangs->transnoentitiesnoconv("SEPAFrstOrRecur").' * : ';
  279. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $txt, 0, 'L');
  280. $pdf->Rect(80, $posY, 5, 5);
  281. $pdf->SetXY(80, $posY);
  282. if ($object->frstrecur == 'RECUR') $pdf->MultiCell(5, 3, 'X', 0, 'L');
  283. $pdf->SetXY(86, $posY);
  284. $txt = $langs->transnoentitiesnoconv("ModeRECUR").' '.$langs->transnoentitiesnoconv("or");
  285. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $txt, 0, 'L');
  286. $posY += 6;
  287. $pdf->Rect(80, $posY, 5, 5);
  288. $pdf->SetXY(80, $posY);
  289. if ($object->frstrecur == 'FRST') $pdf->MultiCell(5, 3, 'X', 0, 'L');
  290. $pdf->SetXY(86, $posY);
  291. $txt = $langs->transnoentitiesnoconv("ModeFRST");
  292. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $txt, 0, 'L');
  293. if (empty($object->frstrecur))
  294. {
  295. $posY += 6;
  296. $pdf->SetXY(80, $posY);
  297. $txt = '('.$langs->transnoentitiesnoconv("PleaseCheckOne").')';
  298. $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $txt, 0, 'L');
  299. }
  300. $posY = $pdf->GetY();
  301. $posY += 3;
  302. $pdf->line($this->marge_gauche, $posY, $this->page_largeur - $this->marge_droite, $posY);
  303. $posY += 3;
  304. // Show square
  305. if ($pagenb == 1)
  306. {
  307. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  308. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  309. } else {
  310. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  311. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  312. }
  313. /*var_dump($tab_top);
  314. var_dump($heightforinfotot);
  315. var_dump($heightforfreetext);
  316. var_dump($heightforfooter);
  317. var_dump($bottomlasttab);*/
  318. // Affiche zone infos
  319. $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  320. /*
  321. * Footer of the page
  322. */
  323. $this->_pagefoot($pdf, $object, $outputlangs);
  324. if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
  325. $pdf->Close();
  326. $pdf->Output($file, 'F');
  327. // Add pdfgeneration hook
  328. if (!is_object($hookmanager))
  329. {
  330. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  331. $hookmanager = new HookManager($this->db);
  332. }
  333. $hookmanager->initHooks(array('pdfgeneration'));
  334. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  335. global $action;
  336. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  337. if ($reshook < 0)
  338. {
  339. $this->error = $hookmanager->error;
  340. $this->errors = $hookmanager->errors;
  341. }
  342. if (!empty($conf->global->MAIN_UMASK))
  343. @chmod($file, octdec($conf->global->MAIN_UMASK));
  344. $this->result = array('fullpath'=>$file);
  345. return 1; // No error
  346. } else {
  347. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  348. return 0;
  349. }
  350. }
  351. $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
  352. return 0;
  353. }
  354. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  355. /**
  356. * Show table for lines
  357. *
  358. * @param TCPDF $pdf Object PDF
  359. * @param string $tab_top Top position of table
  360. * @param string $tab_height Height of table (rectangle)
  361. * @param int $nexY Y
  362. * @param Translate $outputlangs Langs object
  363. * @param int $hidetop Hide top bar of array
  364. * @param int $hidebottom Hide bottom bar of array
  365. * @return void
  366. */
  367. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  368. {
  369. // phpcs:enable
  370. global $conf, $mysoc;
  371. $default_font_size = pdf_getPDFFontSize($outputlangs);
  372. }
  373. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  374. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  375. /**
  376. * Show miscellaneous information (payment mode, payment term, ...)
  377. *
  378. * @param TCPDF $pdf Object PDF
  379. * @param Object $object Object to show
  380. * @param int $posy Y
  381. * @param Translate $outputlangs Langs object
  382. * @return void
  383. */
  384. protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  385. {
  386. // phpcs:enable
  387. global $conf, $mysoc;
  388. $default_font_size = pdf_getPDFFontSize($outputlangs);
  389. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 1 : $conf->global->PDF_DIFFSIZE_TITLE);
  390. $posy += $this->_signature_area($pdf, $object, $posy, $outputlangs);
  391. $pdf->SetXY($this->marge_gauche, $posy);
  392. $pdf->SetFont('', '', $default_font_size);
  393. $pdf->MultiCell(100, 3, $outputlangs->transnoentitiesnoconv("PleaseReturnMandate", $mysoc->email).':', 0, 'L', 0);
  394. $posy = $pdf->GetY() + 2;
  395. $pdf->SetXY($this->marge_gauche, $posy);
  396. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  397. $pdf->MultiCell(100, 6, $mysoc->name, 0, 'L', 0);
  398. $pdf->MultiCell(100, 6, $outputlangs->convToOutputCharset($mysoc->getFullAddress()), 0, 'L', 0);
  399. $posy = $pdf->GetY() + 2;
  400. return $posy;
  401. }
  402. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  403. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  404. /**
  405. * Show area for the customer to sign
  406. *
  407. * @param TCPDF $pdf Object PDF
  408. * @param Facture $object Object invoice
  409. * @param int $posy Position depart
  410. * @param Translate $outputlangs Objet langs
  411. * @return int Position pour suite
  412. */
  413. protected function _signature_area(&$pdf, $object, $posy, $outputlangs)
  414. {
  415. // phpcs:enable
  416. $default_font_size = pdf_getPDFFontSize($outputlangs);
  417. $tab_top = $posy + 4;
  418. $tab_hl = 4;
  419. $posx = $this->marge_gauche;
  420. $pdf->SetXY($posx, $tab_top + 0);
  421. $pdf->SetFont('', '', $default_font_size - 2);
  422. $pdf->MultiCell(100, 3, $outputlangs->transnoentitiesnoconv("DateOfSignature"), 0, 'L', 0);
  423. $pdf->MultiCell(100, 3, ' ');
  424. $pdf->MultiCell(100, 3, '______________________', 0, 'L', 0);
  425. $posx = 120;
  426. $largcol = ($this->page_largeur - $this->marge_droite - $posx);
  427. $useborder = 0;
  428. $index = 0;
  429. // Total HT
  430. $pdf->SetFillColor(255, 255, 255);
  431. $pdf->SetXY($posx, $tab_top + 0);
  432. $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentitiesnoconv("Signature"), 0, 'L', 1);
  433. $pdf->SetXY($posx, $tab_top + $tab_hl);
  434. $pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
  435. return ($tab_hl * 7);
  436. }
  437. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  438. /**
  439. * Show top header of page.
  440. *
  441. * @param TCPDF $pdf Object PDF
  442. * @param Project $object Object to show
  443. * @param int $showaddress 0=no, 1=yes
  444. * @param Translate $outputlangs Object lang for output
  445. * @return void
  446. */
  447. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  448. {
  449. // phpcs:enable
  450. global $langs, $conf, $mysoc;
  451. $default_font_size = pdf_getPDFFontSize($outputlangs);
  452. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  453. $pdf->SetTextColor(0, 0, 60);
  454. $pdf->SetFont('', 'B', $default_font_size + 3);
  455. $posx = $this->page_largeur - $this->marge_droite - 100;
  456. $posy = $this->marge_haute;
  457. $pdf->SetXY($this->marge_gauche, $posy);
  458. // Logo
  459. $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  460. if ($mysoc->logo)
  461. {
  462. if (is_readable($logo))
  463. {
  464. $height = pdf_getHeightForLogo($logo);
  465. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  466. } else {
  467. $pdf->SetTextColor(200, 0, 0);
  468. $pdf->SetFont('', 'B', $default_font_size - 2);
  469. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  470. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  471. }
  472. } else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  473. $pdf->SetFont('', 'B', $default_font_size + 3);
  474. $pdf->SetXY($posx, $posy);
  475. $pdf->SetTextColor(0, 0, 60);
  476. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("SepaMandate"), '', 'R');
  477. $pdf->SetFont('', '', $default_font_size + 2);
  478. $posy += 6;
  479. $pdf->SetXY($posx, $posy);
  480. $pdf->SetTextColor(0, 0, 60);
  481. $daterum = '__________________';
  482. if (!empty($object->date_rum))
  483. {
  484. $daterum = dol_print_date($object->date_rum, 'day', false, $outputlangs, true);
  485. } else $daterum = dol_print_date($object->datec, 'day', false, $outputlangs, true); // For old record, the date_rum was not saved.
  486. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".$daterum, '', 'R');
  487. /*$posy+=6;
  488. $pdf->SetXY($posx,$posy);
  489. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
  490. */
  491. $pdf->SetTextColor(0, 0, 60);
  492. // Add list of linked objects
  493. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  494. $object->fetchObjectLinked();
  495. foreach($object->linkedObjects as $objecttype => $objects)
  496. {
  497. var_dump($objects);exit;
  498. if ($objecttype == 'commande')
  499. {
  500. $outputlangs->load('orders');
  501. $num=count($objects);
  502. for ($i=0;$i<$num;$i++)
  503. {
  504. $posy+=4;
  505. $pdf->SetXY($posx,$posy);
  506. $pdf->SetFont('','', $default_font_size - 1);
  507. $text=$objects[$i]->ref;
  508. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  509. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  510. }
  511. }
  512. }
  513. */
  514. }
  515. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  516. /**
  517. * Show footer of page. Need this->emetteur object
  518. *
  519. * @param TCPDF $pdf PDF
  520. * @param Project $object Object to show
  521. * @param Translate $outputlangs Object lang for output
  522. * @param int $hidefreetext 1=Hide free text
  523. * @return integer
  524. */
  525. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  526. {
  527. // phpcs:enable
  528. global $conf;
  529. $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  530. return pdf_pagefoot($pdf, $outputlangs, 'PAYMENTORDER_FREE_TEXT', null, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  531. }
  532. }