pdf_soleil.modules.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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@capnetworks.com>
  5. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  6. * Copyright (C) 2011 Fabrice CHERRIER
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. * or see http://www.gnu.org/
  23. */
  24. /**
  25. * \file htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php
  26. * \ingroup ficheinter
  27. * \brief Fichier de la classe permettant de generer les fiches d'intervention au modele Soleil
  28. */
  29. require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. /**
  34. * Class to build interventions documents with model Soleil
  35. */
  36. class pdf_soleil extends ModelePDFFicheinter
  37. {
  38. var $db;
  39. var $name;
  40. var $description;
  41. var $type;
  42. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  43. var $version = 'dolibarr';
  44. var $page_largeur;
  45. var $page_hauteur;
  46. var $format;
  47. var $marge_gauche;
  48. var $marge_droite;
  49. var $marge_haute;
  50. var $marge_basse;
  51. /**
  52. * Constructor
  53. *
  54. * @param DoliDB $db Database handler
  55. */
  56. function __construct($db)
  57. {
  58. global $conf,$langs,$mysoc;
  59. $this->db = $db;
  60. $this->name = 'soleil';
  61. $this->description = $langs->trans("DocumentModelStandardPDF");
  62. // Dimension page pour format A4
  63. $this->type = 'pdf';
  64. $formatarray=pdf_getFormat();
  65. $this->page_largeur = $formatarray['width'];
  66. $this->page_hauteur = $formatarray['height'];
  67. $this->format = array($this->page_largeur,$this->page_hauteur);
  68. $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  69. $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  70. $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  71. $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  72. $this->option_logo = 1; // Affiche logo
  73. $this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
  74. $this->option_modereg = 0; // Affiche mode reglement
  75. $this->option_condreg = 0; // Affiche conditions reglement
  76. $this->option_codeproduitservice = 0; // Affiche code produit-service
  77. $this->option_multilang = 1; // Dispo en plusieurs langues
  78. $this->option_draft_watermark = 1; //Support add of a watermark on drafts
  79. // Get source company
  80. $this->emetteur=$mysoc;
  81. if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if not defined
  82. // Define position of columns
  83. $this->posxdesc=$this->marge_gauche+1;
  84. }
  85. /**
  86. * Function to build pdf onto disk
  87. *
  88. * @param Object $object Object to generate
  89. * @param Translate $outputlangs Lang output object
  90. * @param string $srctemplatepath Full path of source filename for generator using a template file
  91. * @param int $hidedetails Do not show line details
  92. * @param int $hidedesc Do not show desc
  93. * @param int $hideref Do not show ref
  94. * @return int 1=OK, 0=KO
  95. */
  96. function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
  97. {
  98. global $user,$langs,$conf,$mysoc,$db,$hookmanager;
  99. if (! is_object($outputlangs)) $outputlangs=$langs;
  100. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  101. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  102. $outputlangs->load("main");
  103. $outputlangs->load("dict");
  104. $outputlangs->load("companies");
  105. $outputlangs->load("interventions");
  106. if ($conf->ficheinter->dir_output)
  107. {
  108. $object->fetch_thirdparty();
  109. // Definition of $dir and $file
  110. if ($object->specimen)
  111. {
  112. $dir = $conf->ficheinter->dir_output;
  113. $file = $dir . "/SPECIMEN.pdf";
  114. }
  115. else
  116. {
  117. $objectref = dol_sanitizeFileName($object->ref);
  118. $dir = $conf->ficheinter->dir_output . "/" . $objectref;
  119. $file = $dir . "/" . $objectref . ".pdf";
  120. }
  121. if (! file_exists($dir))
  122. {
  123. if (dol_mkdir($dir) < 0)
  124. {
  125. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  126. return 0;
  127. }
  128. }
  129. if (file_exists($dir))
  130. {
  131. // Add pdfgeneration hook
  132. if (! is_object($hookmanager))
  133. {
  134. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  135. $hookmanager=new HookManager($this->db);
  136. }
  137. $hookmanager->initHooks(array('pdfgeneration'));
  138. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  139. global $action;
  140. $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  141. $nblignes = count($object->lines);
  142. // Create pdf instance
  143. $pdf=pdf_getInstance($this->format);
  144. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  145. $heightforinfotot = 50; // Height reserved to output the info and total part
  146. $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
  147. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  148. $pdf->SetAutoPageBreak(1,0);
  149. if (class_exists('TCPDF'))
  150. {
  151. $pdf->setPrintHeader(false);
  152. $pdf->setPrintFooter(false);
  153. }
  154. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  155. // Set path to the background PDF File
  156. if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  157. {
  158. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  159. $tplidx = $pdf->importPage(1);
  160. }
  161. $pdf->Open();
  162. $pagenb=0;
  163. $pdf->SetDrawColor(128,128,128);
  164. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  165. $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
  166. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  167. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  168. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
  169. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  170. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  171. // New page
  172. $pdf->AddPage();
  173. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  174. $pagenb++;
  175. $this->_pagehead($pdf, $object, 1, $outputlangs);
  176. $pdf->SetFont('','', $default_font_size - 1);
  177. $pdf->SetTextColor(0,0,0);
  178. $tab_top = 90;
  179. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  180. $tab_height = 130;
  181. $tab_height_newpage = 150;
  182. // Affiche notes
  183. $notetoshow=empty($object->note_public)?'':$object->note_public;
  184. if ($notetoshow)
  185. {
  186. $tab_top = 88;
  187. $pdf->SetFont('','', $default_font_size - 1);
  188. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  189. $nexY = $pdf->GetY();
  190. $height_note=$nexY-$tab_top;
  191. // Rect prend une longueur en 3eme param
  192. $pdf->SetDrawColor(192,192,192);
  193. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  194. $tab_height = $tab_height - $height_note;
  195. $tab_top = $nexY+6;
  196. }
  197. else
  198. {
  199. $height_note=0;
  200. }
  201. $iniY = $tab_top + 7;
  202. $curY = $tab_top + 7;
  203. $nexY = $tab_top + 7;
  204. $pdf->SetXY($this->marge_gauche, $tab_top);
  205. $pdf->MultiCell(190,5,$outputlangs->transnoentities("Description"),0,'L',0);
  206. $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur-$this->marge_droite, $tab_top + 5);
  207. $pdf->SetFont('', '', $default_font_size - 1);
  208. $pdf->SetXY($this->marge_gauche, $tab_top + 5);
  209. $text=$object->description;
  210. if ($object->duration > 0)
  211. {
  212. $totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  213. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  214. }
  215. $desc=dol_htmlentitiesbr($text,1);
  216. //print $outputlangs->convToOutputCharset($desc); exit;
  217. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
  218. $nexY = $pdf->GetY();
  219. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  220. $nblines = count($object->lines);
  221. // Loop on each lines
  222. for ($i = 0; $i < $nblines; $i++)
  223. {
  224. $objectligne = $object->lines[$i];
  225. $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
  226. if ($valide > 0 || $object->specimen)
  227. {
  228. $curY = $nexY;
  229. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  230. $pdf->SetTextColor(0,0,0);
  231. $pdf->setTopMargin($tab_top_newpage);
  232. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  233. $pageposbefore=$pdf->getPage();
  234. // Description of product line
  235. $curX = $this->posxdesc-1;
  236. // Description of product line
  237. if (empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR))
  238. {
  239. $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei,'dayhour',false,$outputlangs,true);
  240. }
  241. else
  242. {
  243. $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei,'day',false,$outputlangs,true);
  244. }
  245. if ($objectligne->duration > 0)
  246. {
  247. $txt.=" - ".$outputlangs->transnoentities("Duration")." : ".convertSecondToTime($objectligne->duration);
  248. }
  249. $txt='<strong>'.dol_htmlentitiesbr($txt,1,$outputlangs->charset_output).'</strong>';
  250. $desc=dol_htmlentitiesbr($objectligne->desc,1);
  251. $pdf->startTransaction();
  252. $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt,$desc), 0, 1, 0);
  253. $pageposafter=$pdf->getPage();
  254. if ($pageposafter > $pageposbefore) // There is a pagebreak
  255. {
  256. $pdf->rollbackTransaction(true);
  257. $pageposafter=$pageposbefore;
  258. //print $pageposafter.'-'.$pageposbefore;exit;
  259. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  260. $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt,$desc), 0, 1, 0);
  261. $pageposafter=$pdf->getPage();
  262. $posyafter=$pdf->GetY();
  263. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  264. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  265. {
  266. if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
  267. {
  268. $pdf->AddPage('','',true);
  269. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  270. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  271. $pdf->setPage($pageposafter+1);
  272. }
  273. }
  274. }
  275. else // No pagebreak
  276. {
  277. $pdf->commitTransaction();
  278. }
  279. $nexY = $pdf->GetY();
  280. $pageposafter=$pdf->getPage();
  281. $pdf->setPage($pageposbefore);
  282. $pdf->setTopMargin($this->marge_haute);
  283. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  284. // We suppose that a too long description is moved completely on next page
  285. if ($pageposafter > $pageposbefore) {
  286. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  287. }
  288. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  289. // Detect if some page were added automatically and output _tableau for past pages
  290. while ($pagenb < $pageposafter)
  291. {
  292. $pdf->setPage($pagenb);
  293. if ($pagenb == 1)
  294. {
  295. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  296. }
  297. else
  298. {
  299. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  300. }
  301. $this->_pagefoot($pdf,$object,$outputlangs,1);
  302. $pagenb++;
  303. $pdf->setPage($pagenb);
  304. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  305. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  306. }
  307. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  308. {
  309. if ($pagenb == 1)
  310. {
  311. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  312. }
  313. else
  314. {
  315. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  316. }
  317. $this->_pagefoot($pdf,$object,$outputlangs,1);
  318. // New page
  319. $pdf->AddPage();
  320. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  321. $pagenb++;
  322. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  323. }
  324. }
  325. }
  326. // Show square
  327. if ($pagenb == 1)
  328. {
  329. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  330. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  331. }
  332. else
  333. {
  334. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  335. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  336. }
  337. $this->_pagefoot($pdf,$object,$outputlangs);
  338. if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
  339. $pdf->Close();
  340. $pdf->Output($file,'F');
  341. // Add pdfgeneration hook
  342. $hookmanager->initHooks(array('pdfgeneration'));
  343. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  344. global $action;
  345. $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  346. if (! empty($conf->global->MAIN_UMASK))
  347. @chmod($file, octdec($conf->global->MAIN_UMASK));
  348. return 1;
  349. }
  350. else
  351. {
  352. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  353. return 0;
  354. }
  355. }
  356. else
  357. {
  358. $this->error=$langs->trans("ErrorConstantNotDefined","FICHEINTER_OUTPUTDIR");
  359. return 0;
  360. }
  361. }
  362. /**
  363. * Show table for lines
  364. *
  365. * @param PDF $pdf Object PDF
  366. * @param string $tab_top Top position of table
  367. * @param string $tab_height Height of table (rectangle)
  368. * @param int $nexY Y
  369. * @param Translate $outputlangs Langs object
  370. * @param int $hidetop Hide top bar of array
  371. * @param int $hidebottom Hide bottom bar of array
  372. * @return void
  373. */
  374. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
  375. {
  376. global $conf;
  377. $default_font_size = pdf_getPDFFontSize($outputlangs);
  378. /*
  379. $pdf->SetXY($this->marge_gauche, $tab_top);
  380. $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
  381. $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
  382. $pdf->SetFont('','', $default_font_size - 1);
  383. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  384. $pdf->SetXY($this->marge_gauche, $tab_top + 8);
  385. $text=$object->description;
  386. if ($object->duration > 0)
  387. {
  388. $totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  389. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  390. }
  391. $desc=dol_htmlentitiesbr($text,1);
  392. //print $outputlangs->convToOutputCharset($desc); exit;
  393. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
  394. $nexY = $pdf->GetY();
  395. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  396. $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  397. */
  398. // Output Rect
  399. $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height+1, 0, 0); // Rect prend une longueur en 3eme param et 4eme param
  400. if (empty($hidebottom))
  401. {
  402. $pdf->SetXY(20,230);
  403. $pdf->MultiCell(66,5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"),0,'L',0);
  404. $pdf->SetXY(20,235);
  405. $pdf->MultiCell(80,25, '', 1);
  406. $pdf->SetXY(110,230);
  407. $pdf->MultiCell(80,5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"),0,'L',0);
  408. $pdf->SetXY(110,235);
  409. $pdf->MultiCell(80,25, '', 1);
  410. }
  411. }
  412. /**
  413. * Show top header of page.
  414. *
  415. * @param PDF $pdf Object PDF
  416. * @param Object $object Object to show
  417. * @param int $showaddress 0=no, 1=yes
  418. * @param Translate $outputlangs Object lang for output
  419. * @return void
  420. */
  421. function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  422. {
  423. global $conf,$langs;
  424. $default_font_size = pdf_getPDFFontSize($outputlangs);
  425. $outputlangs->load("main");
  426. $outputlangs->load("dict");
  427. $outputlangs->load("companies");
  428. $outputlangs->load("interventions");
  429. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  430. //Affiche le filigrane brouillon - Print Draft Watermark
  431. if($object->statut==0 && (! empty($conf->global->FICHINTER_DRAFT_WATERMARK)) )
  432. {
  433. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FICHINTER_DRAFT_WATERMARK);
  434. }
  435. //Prepare la suite
  436. $pdf->SetTextColor(0,0,60);
  437. $pdf->SetFont('','B', $default_font_size + 3);
  438. $posx=$this->page_largeur-$this->marge_droite-100;
  439. $posy=$this->marge_haute;
  440. $pdf->SetXY($this->marge_gauche,$posy);
  441. // Logo
  442. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  443. if ($this->emetteur->logo)
  444. {
  445. if (is_readable($logo))
  446. {
  447. $height=pdf_getHeightForLogo($logo);
  448. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  449. }
  450. else
  451. {
  452. $pdf->SetTextColor(200,0,0);
  453. $pdf->SetFont('','B',$default_font_size - 2);
  454. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  455. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  456. }
  457. }
  458. else
  459. {
  460. $text=$this->emetteur->name;
  461. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  462. }
  463. $pdf->SetFont('','B',$default_font_size + 3);
  464. $pdf->SetXY($posx,$posy);
  465. $pdf->SetTextColor(0,0,60);
  466. $title=$outputlangs->transnoentities("InterventionCard");
  467. $pdf->MultiCell(100, 4, $title, '', 'R');
  468. $pdf->SetFont('','B',$default_font_size + 2);
  469. $posy+=5;
  470. $pdf->SetXY($posx,$posy);
  471. $pdf->SetTextColor(0,0,60);
  472. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
  473. $posy+=1;
  474. $pdf->SetFont('','', $default_font_size);
  475. $posy+=4;
  476. $pdf->SetXY($posx,$posy);
  477. $pdf->SetTextColor(0,0,60);
  478. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->datec,"day",false,$outputlangs,true), '', 'R');
  479. if ($object->thirdparty->code_client)
  480. {
  481. $posy+=4;
  482. $pdf->SetXY($posx,$posy);
  483. $pdf->SetTextColor(0,0,60);
  484. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  485. }
  486. if ($showaddress)
  487. {
  488. // Sender properties
  489. $carac_emetteur='';
  490. // Add internal contact of proposal if defined
  491. $arrayidcontact=$object->getIdContact('internal','INTERREPFOLL');
  492. if (count($arrayidcontact) > 0)
  493. {
  494. $object->fetch_user($arrayidcontact[0]);
  495. $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  496. }
  497. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  498. // Show sender
  499. $posy=42;
  500. $posx=$this->marge_gauche;
  501. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  502. $hautcadre=40;
  503. // Show sender frame
  504. $pdf->SetTextColor(0,0,0);
  505. $pdf->SetFont('','', $default_font_size - 2);
  506. $pdf->SetXY($posx,$posy-5);
  507. $pdf->SetXY($posx,$posy);
  508. $pdf->SetFillColor(230,230,230);
  509. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  510. // Show sender name
  511. $pdf->SetXY($posx+2,$posy+3);
  512. $pdf->SetTextColor(0,0,60);
  513. $pdf->SetFont('','B',$default_font_size);
  514. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  515. $posy=$pdf->getY();
  516. // Show sender information
  517. $pdf->SetFont('','', $default_font_size - 1);
  518. $pdf->SetXY($posx+2,$posy);
  519. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  520. // If CUSTOMER contact defined, we use it
  521. $usecontact=false;
  522. $arrayidcontact=$object->getIdContact('external','CUSTOMER');
  523. if (count($arrayidcontact) > 0)
  524. {
  525. $usecontact=true;
  526. $result=$object->fetch_contact($arrayidcontact[0]);
  527. }
  528. //Recipient name
  529. // On peut utiliser le nom de la societe du contact
  530. if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  531. $thirdparty = $object->contact;
  532. } else {
  533. $thirdparty = $object->thirdparty;
  534. }
  535. $carac_client_name=pdfBuildThirdpartyName($thirdparty, $outputlangs);
  536. $carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact)?$object->contact:''), $usecontact, 'target',$object);
  537. // Show recipient
  538. $widthrecbox=100;
  539. if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
  540. $posy=42;
  541. $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
  542. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  543. // Show recipient frame
  544. $pdf->SetTextColor(0,0,0);
  545. $pdf->SetFont('','', $default_font_size - 2);
  546. $pdf->SetXY($posx+2,$posy-5);
  547. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  548. $pdf->SetTextColor(0,0,0);
  549. // Show recipient name
  550. $pdf->SetXY($posx+2,$posy+3);
  551. $pdf->SetFont('','B', $default_font_size);
  552. $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
  553. $posy = $pdf->getY();
  554. // Show recipient information
  555. $pdf->SetFont('','', $default_font_size - 1);
  556. $pdf->SetXY($posx+2,$posy);
  557. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  558. }
  559. }
  560. /**
  561. * Show footer of page. Need this->emetteur object
  562. *
  563. * @param PDF $pdf PDF
  564. * @param Object $object Object to show
  565. * @param Translate $outputlangs Object lang for output
  566. * @param int $hidefreetext 1=Hide free text
  567. * @return integer
  568. */
  569. function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
  570. {
  571. global $conf;
  572. $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  573. return pdf_pagefoot($pdf,$outputlangs,'FICHINTER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
  574. }
  575. }