pdf_soleil.modules.php 21 KB

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