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