pdf_strato.modules.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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 = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
  127. $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
  128. $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
  129. $this->marge_basse = getDolGlobalInt('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_multilang = 0; // Available in several languages
  135. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  136. // Get source company
  137. $this->emetteur = $mysoc;
  138. if (empty($this->emetteur->country_code)) {
  139. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
  140. }
  141. // Define position of columns
  142. $this->posxdesc = $this->marge_gauche + 1;
  143. }
  144. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  145. /**
  146. * Function to build pdf onto disk
  147. *
  148. * @param Contrat $object Object to generate
  149. * @param Translate $outputlangs Lang output object
  150. * @param string $srctemplatepath Full path of source filename for generator using a template file
  151. * @param int $hidedetails Do not show line details
  152. * @param int $hidedesc Do not show desc
  153. * @param int $hideref Do not show ref
  154. * @return int 1=OK, 0=KO
  155. */
  156. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  157. {
  158. // phpcs:enable
  159. global $user, $langs, $conf, $hookmanager, $mysoc;
  160. if (!is_object($outputlangs)) {
  161. $outputlangs = $langs;
  162. }
  163. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  164. if (!empty($conf->global->MAIN_USE_FPDF)) {
  165. $outputlangs->charset_output = 'ISO-8859-1';
  166. }
  167. // Load traductions files required by page
  168. $outputlangs->loadLangs(array("main", "dict", "companies", "contracts"));
  169. if ($conf->contrat->dir_output) {
  170. $object->fetch_thirdparty();
  171. // Definition of $dir and $file
  172. if ($object->specimen) {
  173. $dir = $conf->contrat->dir_output;
  174. $file = $dir."/SPECIMEN.pdf";
  175. } else {
  176. $objectref = dol_sanitizeFileName($object->ref);
  177. $dir = $conf->contrat->multidir_output[$object->entity]."/".$objectref;
  178. $file = $dir."/".$objectref.".pdf";
  179. }
  180. if (!file_exists($dir)) {
  181. if (dol_mkdir($dir) < 0) {
  182. $this->error = $outputlangs->trans("ErrorCanNotCreateDir", $dir);
  183. return 0;
  184. }
  185. }
  186. if (file_exists($dir)) {
  187. // Add pdfgeneration hook
  188. if (!is_object($hookmanager)) {
  189. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  190. $hookmanager = new HookManager($this->db);
  191. }
  192. $hookmanager->initHooks(array('pdfgeneration'));
  193. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  194. global $action;
  195. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  196. $pdf = pdf_getInstance($this->format);
  197. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  198. $heightforinfotot = 50; // Height reserved to output the info and total part
  199. $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
  200. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  201. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
  202. $heightforfooter += 6;
  203. }
  204. $pdf->SetAutoPageBreak(1, 0);
  205. if (class_exists('TCPDF')) {
  206. $pdf->setPrintHeader(false);
  207. $pdf->setPrintFooter(false);
  208. }
  209. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  210. // Set path to the background PDF File
  211. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  212. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  213. $tplidx = $pdf->importPage(1);
  214. }
  215. $pdf->Open();
  216. $pagenb = 0;
  217. $pdf->SetDrawColor(128, 128, 128);
  218. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  219. $pdf->SetSubject($outputlangs->transnoentities("ContractCard"));
  220. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  221. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  222. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("ContractCard")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  223. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  224. $pdf->SetCompression(false);
  225. }
  226. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  227. // New page
  228. $pdf->AddPage();
  229. if (!empty($tplidx)) {
  230. $pdf->useTemplate($tplidx);
  231. }
  232. $pagenb++;
  233. $this->_pagehead($pdf, $object, 1, $outputlangs);
  234. $pdf->SetFont('', '', $default_font_size - 1);
  235. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  236. $pdf->SetTextColor(0, 0, 0);
  237. $tab_top = 90;
  238. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
  239. // Display notes
  240. if (!empty($object->note_public)) {
  241. $tab_top -= 2;
  242. $pdf->SetFont('', '', $default_font_size - 1);
  243. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
  244. $nexY = $pdf->GetY();
  245. $height_note = $nexY - $tab_top;
  246. // Rect takes a length in 3rd parameter
  247. $pdf->SetDrawColor(192, 192, 192);
  248. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
  249. $tab_top = $nexY + 6;
  250. }
  251. $iniY = $tab_top + 7;
  252. $curY = $tab_top + 7;
  253. $nexY = $tab_top + 2;
  254. $pdf->SetXY($this->marge_gauche, $tab_top);
  255. $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  256. $nblines = count($object->lines);
  257. // Loop on each lines
  258. for ($i = 0; $i < $nblines; $i++) {
  259. $objectligne = $object->lines[$i];
  260. $valide = $objectligne->id ? 1 : 0;
  261. if ($valide > 0 || $object->specimen) {
  262. $curX = $this->posxdesc - 1;
  263. $curY = $nexY;
  264. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  265. $pdf->SetTextColor(0, 0, 0);
  266. $pdf->setTopMargin($tab_top_newpage);
  267. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  268. $pageposbefore = $pdf->getPage();
  269. // Description of product line
  270. if (!empty($objectligne->date_start)) {
  271. $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
  272. } else {
  273. $datei = $langs->trans("Unknown");
  274. }
  275. if (!empty($objectligne->date_end)) {
  276. $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
  277. $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
  278. } else {
  279. $durationi = $langs->trans("Unknown");
  280. $datee = $langs->trans("Unknown");
  281. }
  282. if (!empty($objectligne->date_start_real)) {
  283. $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
  284. } else {
  285. $daters = $langs->trans("Unknown");
  286. }
  287. if (!empty($objectligne->date_end_real)) {
  288. $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
  289. } else {
  290. $datere = $langs->trans("Unknown");
  291. }
  292. $txtpredefinedservice = $objectligne->product_ref;
  293. if ($objectligne->product_label) {
  294. $txtpredefinedservice .= ' - ';
  295. $txtpredefinedservice .= $objectligne->product_label;
  296. }
  297. $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
  298. $txt = '';
  299. if (empty($conf->global->CONTRACT_HIDE_QTY_ON_PDF)) {
  300. $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
  301. }
  302. if (empty($conf->global->CONTRACT_HIDE_PRICE_ON_PDF)) {
  303. $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
  304. }
  305. if (empty($conf->global->CONTRACT_HIDE_PLANNED_DATE_ON_PDF)) {
  306. $txt .= '<br>';
  307. $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
  308. }
  309. if (empty($conf->global->CONTRACT_HIDE_REAL_DATE_ON_PDF)) {
  310. $txt .= '<br>';
  311. $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
  312. if (!empty($objectligne->date_end_real)) {
  313. $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
  314. }
  315. }
  316. $pdf->startTransaction();
  317. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
  318. $pageposafter = $pdf->getPage();
  319. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  320. $pdf->rollbackTransaction(true);
  321. $pageposafter = $pageposbefore;
  322. //print $pageposafter.'-'.$pageposbefore;exit;
  323. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  324. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
  325. $pageposafter = $pdf->getPage();
  326. $posyafter = $pdf->GetY();
  327. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
  328. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  329. $pdf->AddPage('', '', true);
  330. if (!empty($tplidx)) {
  331. $pdf->useTemplate($tplidx);
  332. }
  333. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  334. $this->_pagehead($pdf, $object, 0, $outputlangs);
  335. }
  336. $pdf->setPage($pageposafter + 1);
  337. }
  338. } else {
  339. // We found a page break
  340. // Allows data in the first page if description is long enough to break in multiples pages
  341. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  342. $showpricebeforepagebreak = 1;
  343. } else {
  344. $showpricebeforepagebreak = 0;
  345. }
  346. }
  347. } else // No pagebreak
  348. {
  349. $pdf->commitTransaction();
  350. }
  351. $nexY = $pdf->GetY() + 2;
  352. $pageposafter = $pdf->getPage();
  353. $pdf->setPage($pageposbefore);
  354. $pdf->setTopMargin($this->marge_haute);
  355. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  356. // We suppose that a too long description is moved completely on next page
  357. if ($pageposafter > $pageposbefore) {
  358. $pdf->setPage($pageposafter);
  359. $curY = $tab_top_newpage;
  360. }
  361. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  362. // Detect if some page were added automatically and output _tableau for past pages
  363. while ($pagenb < $pageposafter) {
  364. $pdf->setPage($pagenb);
  365. if ($pagenb == 1) {
  366. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
  367. } else {
  368. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
  369. }
  370. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  371. $pagenb++;
  372. $pdf->setPage($pagenb);
  373. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  374. if (!empty($tplidx)) {
  375. $pdf->useTemplate($tplidx);
  376. }
  377. }
  378. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  379. if ($pagenb == 1) {
  380. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
  381. } else {
  382. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
  383. }
  384. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  385. // New page
  386. $pdf->AddPage();
  387. if (!empty($tplidx)) {
  388. $pdf->useTemplate($tplidx);
  389. }
  390. $pagenb++;
  391. }
  392. }
  393. }
  394. // Show square
  395. if ($pagenb == 1) {
  396. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  397. $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
  398. $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
  399. } else {
  400. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  401. $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
  402. $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
  403. }
  404. $this->_pagefoot($pdf, $object, $outputlangs);
  405. if (method_exists($pdf, 'AliasNbPages')) {
  406. $pdf->AliasNbPages();
  407. }
  408. $pdf->Close();
  409. $pdf->Output($file, 'F');
  410. // Add pdfgeneration hook
  411. if (!is_object($hookmanager)) {
  412. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  413. $hookmanager = new HookManager($this->db);
  414. }
  415. $hookmanager->initHooks(array('pdfgeneration'));
  416. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  417. global $action;
  418. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  419. if ($reshook < 0) {
  420. $this->error = $hookmanager->error;
  421. $this->errors = $hookmanager->errors;
  422. }
  423. if (!empty($conf->global->MAIN_UMASK)) {
  424. @chmod($file, octdec($conf->global->MAIN_UMASK));
  425. }
  426. $this->result = array('fullpath'=>$file);
  427. return 1;
  428. } else {
  429. $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
  430. return 0;
  431. }
  432. } else {
  433. $this->error = $langs->trans("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
  434. return 0;
  435. }
  436. }
  437. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  438. /**
  439. * Show table for lines
  440. *
  441. * @param TCPDF $pdf Object PDF
  442. * @param string $tab_top Top position of table
  443. * @param string $tab_height Height of table (rectangle)
  444. * @param int $nexY Y
  445. * @param Translate $outputlangs Langs object
  446. * @param int $hidetop Hide top bar of array
  447. * @param int $hidebottom Hide bottom bar of array
  448. * @return void
  449. */
  450. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
  451. {
  452. global $conf;
  453. // Force to disable hidetop and hidebottom
  454. $hidebottom = 0;
  455. if ($hidetop) {
  456. $hidetop = -1;
  457. }
  458. $default_font_size = pdf_getPDFFontSize($outputlangs);
  459. /*
  460. $pdf->SetXY($this->marge_gauche, $tab_top);
  461. $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
  462. $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
  463. $pdf->SetFont('','', $default_font_size - 1);
  464. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  465. $pdf->SetXY($this->marge_gauche, $tab_top + 8);
  466. $text=$object->description;
  467. if ($object->duree > 0)
  468. {
  469. $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  470. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  471. }
  472. $desc=dol_htmlentitiesbr($text,1);
  473. //print $outputlangs->convToOutputCharset($desc); exit;
  474. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
  475. $nexY = $pdf->GetY();
  476. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  477. $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  478. */
  479. // Output Rect
  480. $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
  481. }
  482. /**
  483. * Show footer signature of page
  484. * @param TCPDF $pdf Object PDF
  485. * @param int $tab_top tab height position
  486. * @param int $tab_height tab height
  487. * @param Translate $outputlangs Object language for output
  488. * @return void
  489. */
  490. protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
  491. {
  492. $pdf->SetDrawColor(128, 128, 128);
  493. $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
  494. $posy = $tab_top + $tab_height + 3 + 3;
  495. $pdf->SetXY($this->marge_gauche, $posy);
  496. $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
  497. $pdf->SetXY($this->marge_gauche, $posy + 5);
  498. $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20, '', 1);
  499. $pdf->SetXY($posmiddle + 5, $posy);
  500. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
  501. $pdf->SetXY($posmiddle + 5, $posy + 5);
  502. $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, '', 1);
  503. }
  504. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  505. /**
  506. * Show top header of page.
  507. *
  508. * @param TCPDF $pdf Object PDF
  509. * @param Contrat $object Object to show
  510. * @param int $showaddress 0=no, 1=yes
  511. * @param Translate $outputlangs Object lang for output
  512. * @return void
  513. */
  514. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  515. {
  516. global $conf, $langs;
  517. $default_font_size = pdf_getPDFFontSize($outputlangs);
  518. // Load traductions files required by page
  519. $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
  520. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  521. //Affiche le filigrane brouillon - Print Draft Watermark
  522. if ($object->statut == 0 && (!empty($conf->global->CONTRACT_DRAFT_WATERMARK))) {
  523. pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->CONTRACT_DRAFT_WATERMARK);
  524. }
  525. //Prepare next
  526. $pdf->SetTextColor(0, 0, 60);
  527. $pdf->SetFont('', 'B', $default_font_size + 3);
  528. $posx = $this->page_largeur - $this->marge_droite - 100;
  529. $posy = $this->marge_haute;
  530. $pdf->SetXY($this->marge_gauche, $posy);
  531. // Logo
  532. $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  533. if ($this->emetteur->logo) {
  534. if (is_readable($logo)) {
  535. $height = pdf_getHeightForLogo($logo);
  536. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  537. } else {
  538. $pdf->SetTextColor(200, 0, 0);
  539. $pdf->SetFont('', 'B', $default_font_size - 2);
  540. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  541. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  542. }
  543. } else {
  544. $text = $this->emetteur->name;
  545. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  546. }
  547. $pdf->SetFont('', 'B', $default_font_size + 3);
  548. $pdf->SetXY($posx, $posy);
  549. $pdf->SetTextColor(0, 0, 60);
  550. $title = $outputlangs->transnoentities("ContractCard");
  551. $pdf->MultiCell(100, 4, $title, '', 'R');
  552. $pdf->SetFont('', 'B', $default_font_size + 2);
  553. $posy += 5;
  554. $pdf->SetXY($posx, $posy);
  555. $pdf->SetTextColor(0, 0, 60);
  556. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  557. $posy += 1;
  558. $pdf->SetFont('', '', $default_font_size);
  559. $posy += 4;
  560. $pdf->SetXY($posx, $posy);
  561. $pdf->SetTextColor(0, 0, 60);
  562. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
  563. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
  564. $posy += 4;
  565. $pdf->SetXY($posx, $posy);
  566. $pdf->SetTextColor(0, 0, 60);
  567. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  568. }
  569. if ($showaddress) {
  570. // Sender properties
  571. $carac_emetteur = '';
  572. // Add internal contact of proposal if defined
  573. $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
  574. if (count($arrayidcontact) > 0) {
  575. $object->fetch_user($arrayidcontact[0]);
  576. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  577. }
  578. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  579. // Show sender
  580. $posy = 42;
  581. $posx = $this->marge_gauche;
  582. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  583. $posx = $this->page_largeur - $this->marge_droite - 80;
  584. }
  585. $hautcadre = 40;
  586. // Show sender frame
  587. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  588. $pdf->SetTextColor(0, 0, 0);
  589. $pdf->SetFont('', '', $default_font_size - 2);
  590. $pdf->SetXY($posx, $posy - 5);
  591. $pdf->SetXY($posx, $posy);
  592. $pdf->SetFillColor(230, 230, 230);
  593. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  594. }
  595. // Show sender name
  596. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  597. $pdf->SetXY($posx + 2, $posy + 3);
  598. $pdf->SetTextColor(0, 0, 60);
  599. $pdf->SetFont('', 'B', $default_font_size);
  600. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  601. $posy = $pdf->getY();
  602. }
  603. // Show sender information
  604. $pdf->SetFont('', '', $default_font_size - 1);
  605. $pdf->SetXY($posx + 2, $posy);
  606. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  607. // If CUSTOMER contact defined, we use it
  608. $usecontact = false;
  609. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  610. if (count($arrayidcontact) > 0) {
  611. $usecontact = true;
  612. $result = $object->fetch_contact($arrayidcontact[0]);
  613. }
  614. $this->recipient = $object->thirdparty;
  615. // Recipient name
  616. 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)))) {
  617. $thirdparty = $object->contact;
  618. } else {
  619. $thirdparty = $object->thirdparty;
  620. }
  621. $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  622. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, 'target', $object);
  623. // Show recipient
  624. $widthrecbox = 100;
  625. if ($this->page_largeur < 210) {
  626. $widthrecbox = 84; // To work with US executive format
  627. }
  628. $posy = 42;
  629. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  630. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  631. $posx = $this->marge_gauche;
  632. }
  633. // Show recipient frame
  634. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  635. $pdf->SetTextColor(0, 0, 0);
  636. $pdf->SetFont('', '', $default_font_size - 2);
  637. $pdf->SetXY($posx + 2, $posy - 5);
  638. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  639. $pdf->SetTextColor(0, 0, 0);
  640. }
  641. // Show recipient name
  642. $pdf->SetXY($posx + 2, $posy + 3);
  643. $pdf->SetFont('', 'B', $default_font_size);
  644. $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, 'L');
  645. $posy = $pdf->getY();
  646. // Show recipient information
  647. $pdf->SetFont('', '', $default_font_size - 1);
  648. $pdf->SetXY($posx + 2, $posy);
  649. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  650. }
  651. }
  652. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  653. /**
  654. * Show footer of page. Need this->emetteur object
  655. *
  656. * @param PDF $pdf PDF
  657. * @param Contrat $object Object to show
  658. * @param Translate $outputlangs Object lang for output
  659. * @param int $hidefreetext 1=Hide free text
  660. * @return integer
  661. */
  662. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  663. {
  664. global $conf;
  665. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  666. return pdf_pagefoot($pdf, $outputlangs, 'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
  667. }
  668. }