pdf_strato.modules.php 24 KB

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