pdf_strato.modules.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  6. * Copyright (C) 2011 Fabrice CHERRIER
  7. * Copyright (C) 2013-2020 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. * or see https://www.gnu.org/
  24. */
  25. /**
  26. * \file htdocs/core/modules/contract/doc/pdf_strato.modules.php
  27. * \ingroup ficheinter
  28. * \brief Strato contracts template class file
  29. */
  30. require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  35. /**
  36. * Class to build contracts documents with model Strato
  37. */
  38. class pdf_strato extends ModelePDFContract
  39. {
  40. /**
  41. * @var DoliDb Database handler
  42. */
  43. public $db;
  44. /**
  45. * @var string model name
  46. */
  47. public $name;
  48. /**
  49. * @var string model description (short text)
  50. */
  51. public $description;
  52. /**
  53. * @var int Save the name of generated file as the main doc when generating a doc with this template
  54. */
  55. public $update_main_doc_field;
  56. /**
  57. * @var string document type
  58. */
  59. public $type;
  60. /**
  61. * @var array Minimum version of PHP required by module.
  62. * e.g.: PHP ≥ 5.6 = array(5, 6)
  63. */
  64. public $phpmin = array(5, 6);
  65. /**
  66. * Dolibarr version of the loaded document
  67. * @var string
  68. */
  69. public $version = 'dolibarr';
  70. /**
  71. * @var int page_largeur
  72. */
  73. public $page_largeur;
  74. /**
  75. * @var int page_hauteur
  76. */
  77. public $page_hauteur;
  78. /**
  79. * @var array format
  80. */
  81. public $format;
  82. /**
  83. * @var int marge_gauche
  84. */
  85. public $marge_gauche;
  86. /**
  87. * @var int marge_droite
  88. */
  89. public $marge_droite;
  90. /**
  91. * @var int marge_haute
  92. */
  93. public $marge_haute;
  94. /**
  95. * @var int marge_basse
  96. */
  97. public $marge_basse;
  98. /**
  99. * Issuer
  100. * @var Societe
  101. */
  102. public $emetteur;
  103. /**
  104. * Recipient
  105. * @var Societe
  106. */
  107. public $recipient;
  108. /**
  109. * Constructor
  110. *
  111. * @param DoliDB $db Database handler
  112. */
  113. public function __construct($db)
  114. {
  115. global $conf, $langs, $mysoc;
  116. $this->db = $db;
  117. $this->name = 'strato';
  118. $this->description = $langs->trans("StandardContractsTemplate");
  119. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  120. // Page size for A4 format
  121. $this->type = 'pdf';
  122. $formatarray = pdf_getFormat();
  123. $this->page_largeur = $formatarray['width'];
  124. $this->page_hauteur = $formatarray['height'];
  125. $this->format = array($this->page_largeur, $this->page_hauteur);
  126. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  127. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  128. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  129. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  130. $this->option_logo = 1; // Display logo
  131. $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
  132. $this->option_modereg = 0; // Display payment mode
  133. $this->option_condreg = 0; // Display payment terms
  134. $this->option_codeproduitservice = 0; // Display product-service code
  135. $this->option_multilang = 0; // Available in several languages
  136. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  137. // Get source company
  138. $this->emetteur = $mysoc;
  139. if (empty($this->emetteur->country_code)) {
  140. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
  141. }
  142. // Define position of columns
  143. $this->posxdesc = $this->marge_gauche + 1;
  144. }
  145. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  146. /**
  147. * Function to build pdf onto disk
  148. *
  149. * @param Contrat $object Object to generate
  150. * @param Translate $outputlangs Lang output object
  151. * @param string $srctemplatepath Full path of source filename for generator using a template file
  152. * @param int $hidedetails Do not show line details
  153. * @param int $hidedesc Do not show desc
  154. * @param int $hideref Do not show ref
  155. * @return int 1=OK, 0=KO
  156. */
  157. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  158. {
  159. // phpcs:enable
  160. global $user, $langs, $conf, $hookmanager, $mysoc;
  161. if (!is_object($outputlangs)) {
  162. $outputlangs = $langs;
  163. }
  164. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  165. if (!empty($conf->global->MAIN_USE_FPDF)) {
  166. $outputlangs->charset_output = 'ISO-8859-1';
  167. }
  168. // Load traductions files required by page
  169. $outputlangs->loadLangs(array("main", "dict", "companies", "contracts"));
  170. if ($conf->contrat->dir_output) {
  171. $object->fetch_thirdparty();
  172. // Definition of $dir and $file
  173. if ($object->specimen) {
  174. $dir = $conf->contrat->dir_output;
  175. $file = $dir."/SPECIMEN.pdf";
  176. } else {
  177. $objectref = dol_sanitizeFileName($object->ref);
  178. $dir = $conf->contrat->multidir_output[$object->entity]."/".$objectref;
  179. $file = $dir."/".$objectref.".pdf";
  180. }
  181. if (!file_exists($dir)) {
  182. if (dol_mkdir($dir) < 0) {
  183. $this->error = $outputlangs->trans("ErrorCanNotCreateDir", $dir);
  184. return 0;
  185. }
  186. }
  187. if (file_exists($dir)) {
  188. // Add pdfgeneration hook
  189. if (!is_object($hookmanager)) {
  190. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  191. $hookmanager = new HookManager($this->db);
  192. }
  193. $hookmanager->initHooks(array('pdfgeneration'));
  194. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  195. global $action;
  196. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  197. $pdf = pdf_getInstance($this->format);
  198. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  199. $heightforinfotot = 50; // Height reserved to output the info and total part
  200. $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
  201. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  202. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  203. $heightforfooter += 6;
  204. }
  205. $pdf->SetAutoPageBreak(1, 0);
  206. if (class_exists('TCPDF')) {
  207. $pdf->setPrintHeader(false);
  208. $pdf->setPrintFooter(false);
  209. }
  210. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  211. // Set path to the background PDF File
  212. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  213. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  214. $tplidx = $pdf->importPage(1);
  215. }
  216. $pdf->Open();
  217. $pagenb = 0;
  218. $pdf->SetDrawColor(128, 128, 128);
  219. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  220. $pdf->SetSubject($outputlangs->transnoentities("ContractCard"));
  221. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  222. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  223. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("ContractCard")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  224. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  225. $pdf->SetCompression(false);
  226. }
  227. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  228. // New page
  229. $pdf->AddPage();
  230. if (!empty($tplidx)) {
  231. $pdf->useTemplate($tplidx);
  232. }
  233. $pagenb++;
  234. $this->_pagehead($pdf, $object, 1, $outputlangs);
  235. $pdf->SetFont('', '', $default_font_size - 1);
  236. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  237. $pdf->SetTextColor(0, 0, 0);
  238. $tab_top = 90;
  239. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  240. // Display notes
  241. if (!empty($object->note_public)) {
  242. $tab_top -= 2;
  243. $pdf->SetFont('', '', $default_font_size - 1);
  244. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
  245. $nexY = $pdf->GetY();
  246. $height_note = $nexY - $tab_top;
  247. // Rect takes a length in 3rd parameter
  248. $pdf->SetDrawColor(192, 192, 192);
  249. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  250. $tab_top = $nexY + 6;
  251. }
  252. $iniY = $tab_top + 7;
  253. $curY = $tab_top + 7;
  254. $nexY = $tab_top + 2;
  255. $pdf->SetXY($this->marge_gauche, $tab_top);
  256. $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  257. $nblines = count($object->lines);
  258. // Loop on each lines
  259. for ($i = 0; $i < $nblines; $i++) {
  260. $objectligne = $object->lines[$i];
  261. $valide = $objectligne->id ? 1 : 0;
  262. if ($valide > 0 || $object->specimen) {
  263. $curX = $this->posxdesc - 1;
  264. $curY = $nexY;
  265. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  266. $pdf->SetTextColor(0, 0, 0);
  267. $pdf->setTopMargin($tab_top_newpage);
  268. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  269. $pageposbefore = $pdf->getPage();
  270. // Description of product line
  271. if (!empty($objectligne->date_start)) {
  272. $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
  273. } else {
  274. $datei = $langs->trans("Unknown");
  275. }
  276. if (!empty($objectligne->date_end)) {
  277. $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
  278. $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
  279. } else {
  280. $durationi = $langs->trans("Unknown");
  281. $datee = $langs->trans("Unknown");
  282. }
  283. if (!empty($objectligne->date_start_real)) {
  284. $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
  285. } else {
  286. $daters = $langs->trans("Unknown");
  287. }
  288. if (!empty($objectligne->date_end_real)) {
  289. $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
  290. } else {
  291. $datere = $langs->trans("Unknown");
  292. }
  293. $txtpredefinedservice = $objectligne->product_ref;
  294. if ($objectligne->product_label) {
  295. $txtpredefinedservice .= ' - ';
  296. $txtpredefinedservice .= $objectligne->product_label;
  297. }
  298. $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
  299. $txt = '';
  300. $txt .= $outputlangs->transnoentities("Quantity").' : <strong>'.$objectligne->qty.'</strong> - '.$outputlangs->transnoentities("UnitPrice").' : <strong>'.price($objectligne->subprice).'</strong>'; // Desc (not empty for free lines)
  301. if (empty($conf->global->CONTRACT_HIDE_PLANNED_DATE_ON_PDF)) {
  302. $txt .= '<br>';
  303. $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
  304. }
  305. if (empty($conf->global->CONTRACT_HIDE_REAL_DATE_ON_PDF)) {
  306. $txt .= '<br>';
  307. $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
  308. if (!empty($objectligne->date_end_real)) {
  309. $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
  310. }
  311. }
  312. $pdf->startTransaction();
  313. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
  314. $pageposafter = $pdf->getPage();
  315. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  316. $pdf->rollbackTransaction(true);
  317. $pageposafter = $pageposbefore;
  318. //print $pageposafter.'-'.$pageposbefore;exit;
  319. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  320. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
  321. $pageposafter = $pdf->getPage();
  322. $posyafter = $pdf->GetY();
  323. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  324. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  325. $pdf->AddPage('', '', true);
  326. if (!empty($tplidx)) {
  327. $pdf->useTemplate($tplidx);
  328. }
  329. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  330. $this->_pagehead($pdf, $object, 0, $outputlangs);
  331. }
  332. $pdf->setPage($pageposafter + 1);
  333. }
  334. } else {
  335. // We found a page break
  336. // Allows data in the first page if description is long enough to break in multiples pages
  337. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  338. $showpricebeforepagebreak = 1;
  339. } else {
  340. $showpricebeforepagebreak = 0;
  341. }
  342. }
  343. } else // No pagebreak
  344. {
  345. $pdf->commitTransaction();
  346. }
  347. $nexY = $pdf->GetY() + 2;
  348. $pageposafter = $pdf->getPage();
  349. $pdf->setPage($pageposbefore);
  350. $pdf->setTopMargin($this->marge_haute);
  351. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  352. // We suppose that a too long description is moved completely on next page
  353. if ($pageposafter > $pageposbefore) {
  354. $pdf->setPage($pageposafter);
  355. $curY = $tab_top_newpage;
  356. }
  357. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  358. // Detect if some page were added automatically and output _tableau for past pages
  359. while ($pagenb < $pageposafter) {
  360. $pdf->setPage($pagenb);
  361. if ($pagenb == 1) {
  362. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
  363. } else {
  364. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
  365. }
  366. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  367. $pagenb++;
  368. $pdf->setPage($pagenb);
  369. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  370. }
  371. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  372. if ($pagenb == 1) {
  373. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
  374. } else {
  375. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
  376. }
  377. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  378. // New page
  379. $pdf->AddPage();
  380. if (!empty($tplidx)) {
  381. $pdf->useTemplate($tplidx);
  382. }
  383. $pagenb++;
  384. }
  385. }
  386. }
  387. // Show square
  388. if ($pagenb == 1) {
  389. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  390. $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
  391. $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
  392. } else {
  393. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  394. $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
  395. $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
  396. }
  397. $this->_pagefoot($pdf, $object, $outputlangs);
  398. if (method_exists($pdf, 'AliasNbPages')) {
  399. $pdf->AliasNbPages();
  400. }
  401. $pdf->Close();
  402. $pdf->Output($file, 'F');
  403. // Add pdfgeneration hook
  404. if (!is_object($hookmanager)) {
  405. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  406. $hookmanager = new HookManager($this->db);
  407. }
  408. $hookmanager->initHooks(array('pdfgeneration'));
  409. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  410. global $action;
  411. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  412. if ($reshook < 0) {
  413. $this->error = $hookmanager->error;
  414. $this->errors = $hookmanager->errors;
  415. }
  416. if (!empty($conf->global->MAIN_UMASK)) {
  417. @chmod($file, octdec($conf->global->MAIN_UMASK));
  418. }
  419. $this->result = array('fullpath'=>$file);
  420. return 1;
  421. } else {
  422. $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
  423. return 0;
  424. }
  425. } else {
  426. $this->error = $langs->trans("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
  427. return 0;
  428. }
  429. }
  430. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  431. /**
  432. * Show table for lines
  433. *
  434. * @param TCPDF $pdf Object PDF
  435. * @param string $tab_top Top position of table
  436. * @param string $tab_height Height of table (rectangle)
  437. * @param int $nexY Y
  438. * @param Translate $outputlangs Langs object
  439. * @param int $hidetop Hide top bar of array
  440. * @param int $hidebottom Hide bottom bar of array
  441. * @return void
  442. */
  443. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  444. {
  445. global $conf;
  446. // Force to disable hidetop and hidebottom
  447. $hidebottom = 0;
  448. if ($hidetop) {
  449. $hidetop = -1;
  450. }
  451. $default_font_size = pdf_getPDFFontSize($outputlangs);
  452. /*
  453. $pdf->SetXY($this->marge_gauche, $tab_top);
  454. $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
  455. $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
  456. $pdf->SetFont('','', $default_font_size - 1);
  457. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  458. $pdf->SetXY($this->marge_gauche, $tab_top + 8);
  459. $text=$object->description;
  460. if ($object->duree > 0)
  461. {
  462. $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  463. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  464. }
  465. $desc=dol_htmlentitiesbr($text,1);
  466. //print $outputlangs->convToOutputCharset($desc); exit;
  467. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
  468. $nexY = $pdf->GetY();
  469. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  470. $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  471. */
  472. // Output Rect
  473. $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 3); // Rect takes a length in 3rd parameter and 4th parameter
  474. }
  475. /**
  476. * Show footer signature of page
  477. * @param TCPDF $pdf Object PDF
  478. * @param int $tab_top tab height position
  479. * @param int $tab_height tab height
  480. * @param Translate $outputlangs Object language for output
  481. * @return void
  482. */
  483. protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
  484. {
  485. $pdf->SetDrawColor(128, 128, 128);
  486. $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
  487. $posy = $tab_top + $tab_height + 3 + 3;
  488. $pdf->SetXY($this->marge_gauche, $posy);
  489. $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
  490. $pdf->SetXY($this->marge_gauche, $posy + 5);
  491. $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20, '', 1);
  492. $pdf->SetXY($posmiddle + 5, $posy);
  493. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
  494. $pdf->SetXY($posmiddle + 5, $posy + 5);
  495. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, '', 1);
  496. }
  497. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  498. /**
  499. * Show top header of page.
  500. *
  501. * @param TCPDF $pdf Object PDF
  502. * @param Contrat $object Object to show
  503. * @param int $showaddress 0=no, 1=yes
  504. * @param Translate $outputlangs Object lang for output
  505. * @return void
  506. */
  507. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  508. {
  509. global $conf, $langs;
  510. $default_font_size = pdf_getPDFFontSize($outputlangs);
  511. // Load traductions files required by page
  512. $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
  513. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  514. //Affiche le filigrane brouillon - Print Draft Watermark
  515. if ($object->statut == 0 && (!empty($conf->global->CONTRACT_DRAFT_WATERMARK))) {
  516. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->CONTRACT_DRAFT_WATERMARK);
  517. }
  518. //Prepare next
  519. $pdf->SetTextColor(0, 0, 60);
  520. $pdf->SetFont('', 'B', $default_font_size + 3);
  521. $posx = $this->page_largeur - $this->marge_droite - 100;
  522. $posy = $this->marge_haute;
  523. $pdf->SetXY($this->marge_gauche, $posy);
  524. // Logo
  525. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  526. if ($this->emetteur->logo) {
  527. if (is_readable($logo)) {
  528. $height = pdf_getHeightForLogo($logo);
  529. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  530. } else {
  531. $pdf->SetTextColor(200, 0, 0);
  532. $pdf->SetFont('', 'B', $default_font_size - 2);
  533. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  534. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  535. }
  536. } else {
  537. $text = $this->emetteur->name;
  538. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  539. }
  540. $pdf->SetFont('', 'B', $default_font_size + 3);
  541. $pdf->SetXY($posx, $posy);
  542. $pdf->SetTextColor(0, 0, 60);
  543. $title = $outputlangs->transnoentities("ContractCard");
  544. $pdf->MultiCell(100, 4, $title, '', 'R');
  545. $pdf->SetFont('', 'B', $default_font_size + 2);
  546. $posy += 5;
  547. $pdf->SetXY($posx, $posy);
  548. $pdf->SetTextColor(0, 0, 60);
  549. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  550. $posy += 1;
  551. $pdf->SetFont('', '', $default_font_size);
  552. $posy += 4;
  553. $pdf->SetXY($posx, $posy);
  554. $pdf->SetTextColor(0, 0, 60);
  555. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
  556. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
  557. $posy += 4;
  558. $pdf->SetXY($posx, $posy);
  559. $pdf->SetTextColor(0, 0, 60);
  560. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  561. }
  562. if ($showaddress) {
  563. // Sender properties
  564. $carac_emetteur = '';
  565. // Add internal contact of proposal if defined
  566. $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
  567. if (count($arrayidcontact) > 0) {
  568. $object->fetch_user($arrayidcontact[0]);
  569. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  570. }
  571. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  572. // Show sender
  573. $posy = 42;
  574. $posx = $this->marge_gauche;
  575. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  576. $posx = $this->page_largeur - $this->marge_droite - 80;
  577. }
  578. $hautcadre = 40;
  579. // Show sender frame
  580. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  581. $pdf->SetTextColor(0, 0, 0);
  582. $pdf->SetFont('', '', $default_font_size - 2);
  583. $pdf->SetXY($posx, $posy - 5);
  584. $pdf->SetXY($posx, $posy);
  585. $pdf->SetFillColor(230, 230, 230);
  586. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  587. }
  588. // Show sender name
  589. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  590. $pdf->SetXY($posx + 2, $posy + 3);
  591. $pdf->SetTextColor(0, 0, 60);
  592. $pdf->SetFont('', 'B', $default_font_size);
  593. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  594. $posy = $pdf->getY();
  595. }
  596. // Show sender information
  597. $pdf->SetFont('', '', $default_font_size - 1);
  598. $pdf->SetXY($posx + 2, $posy);
  599. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  600. // If CUSTOMER contact defined, we use it
  601. $usecontact = false;
  602. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  603. if (count($arrayidcontact) > 0) {
  604. $usecontact = true;
  605. $result = $object->fetch_contact($arrayidcontact[0]);
  606. }
  607. $this->recipient = $object->thirdparty;
  608. // Recipient name
  609. if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  610. $thirdparty = $object->contact;
  611. } else {
  612. $thirdparty = $object->thirdparty;
  613. }
  614. $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  615. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, 'target', $object);
  616. // Show recipient
  617. $widthrecbox = 100;
  618. if ($this->page_largeur < 210) {
  619. $widthrecbox = 84; // To work with US executive format
  620. }
  621. $posy = 42;
  622. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  623. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  624. $posx = $this->marge_gauche;
  625. }
  626. // Show recipient frame
  627. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  628. $pdf->SetTextColor(0, 0, 0);
  629. $pdf->SetFont('', '', $default_font_size - 2);
  630. $pdf->SetXY($posx + 2, $posy - 5);
  631. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  632. $pdf->SetTextColor(0, 0, 0);
  633. }
  634. // Show recipient name
  635. $pdf->SetXY($posx + 2, $posy + 3);
  636. $pdf->SetFont('', 'B', $default_font_size);
  637. $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, 'L');
  638. $posy = $pdf->getY();
  639. // Show recipient information
  640. $pdf->SetFont('', '', $default_font_size - 1);
  641. $pdf->SetXY($posx + 2, $posy);
  642. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  643. }
  644. }
  645. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  646. /**
  647. * Show footer of page. Need this->emetteur object
  648. *
  649. * @param PDF $pdf PDF
  650. * @param Contrat $object Object to show
  651. * @param Translate $outputlangs Object lang for output
  652. * @param int $hidefreetext 1=Hide free text
  653. * @return integer
  654. */
  655. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  656. {
  657. global $conf;
  658. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  659. return pdf_pagefoot($pdf, $outputlangs, 'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  660. }
  661. }