PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/fichinter/pdf_soleil.modules.php

https://github.com/asterix14/dolibarr
PHP | 387 lines | 249 code | 71 blank | 67 comment | 24 complexity | 532357d94e3ec4e155fd341fee1f8d12 MD5 | raw file
Possible License(s): LGPL-2.0
  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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2011 Fabrice CHERRIER (12/05/2011) http://www.fcinc.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/fichinter/pdf_soleil.modules.php
  23. * \ingroup ficheinter
  24. * \brief Fichier de la classe permettant de generer les fiches d'intervention au modele Soleil
  25. */
  26. require_once(DOL_DOCUMENT_ROOT."/core/modules/fichinter/modules_fichinter.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  29. require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
  30. /**
  31. * \class pdf_soleil
  32. * \brief Class to build interventions documents with model Soleil
  33. */
  34. class pdf_soleil extends ModelePDFFicheinter
  35. {
  36. /**
  37. * \brief Constructeur
  38. * \param db Handler acces base de donnee
  39. */
  40. function pdf_soleil($db=0)
  41. {
  42. global $conf,$langs,$mysoc;
  43. $this->db = $db;
  44. $this->name = 'soleil';
  45. $this->description = $langs->trans("DocumentModelStandard");
  46. // Dimension page pour format A4
  47. $this->type = 'pdf';
  48. $formatarray=pdf_getFormat();
  49. $this->page_largeur = $formatarray['width'];
  50. $this->page_hauteur = $formatarray['height'];
  51. $this->format = array($this->page_largeur,$this->page_hauteur);
  52. $this->marge_gauche=10;
  53. $this->marge_droite=10;
  54. $this->marge_haute=10;
  55. $this->marge_basse=10;
  56. $this->option_logo = 1; // Affiche logo
  57. $this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
  58. $this->option_modereg = 0; // Affiche mode reglement
  59. $this->option_condreg = 0; // Affiche conditions reglement
  60. $this->option_codeproduitservice = 0; // Affiche code produit-service
  61. $this->option_multilang = 0; // Dispo en plusieurs langues
  62. $this->option_draft_watermark = 1; //Support add of a watermark on drafts
  63. // Recupere emmetteur
  64. $this->emetteur=$mysoc;
  65. if (! $this->emetteur->code_pays) $this->emetteur->code_pays=substr($langs->defaultlang,-2); // By default, if not defined
  66. // Defini position des colonnes
  67. $this->posxdesc=$this->marge_gauche+1;
  68. }
  69. /**
  70. * \brief Fonction generant la fiche d'intervention sur le disque
  71. * \param fichinter Object fichinter
  72. * \param outputlangs Lang output object
  73. * \return int 1=ok, 0=ko
  74. */
  75. function write_file($fichinter,$outputlangs)
  76. {
  77. global $user,$langs,$conf,$mysoc;
  78. $default_font_size = pdf_getPDFFontSize($outputlangs);
  79. if (! is_object($outputlangs)) $outputlangs=$langs;
  80. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  81. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  82. $outputlangs->load("main");
  83. $outputlangs->load("dict");
  84. $outputlangs->load("companies");
  85. $outputlangs->load("interventions");
  86. if ($conf->ficheinter->dir_output)
  87. {
  88. // If $fichinter is id instead of object
  89. if (! is_object($fichinter))
  90. {
  91. $id = $fichinter;
  92. $fichinter = new Fichinter($this->db);
  93. $result=$fichinter->fetch($id);
  94. if ($result < 0)
  95. {
  96. dol_print_error($this->db,$fichinter->error);
  97. }
  98. }
  99. $fichinter->fetch_thirdparty();
  100. $fichref = dol_sanitizeFileName($fichinter->ref);
  101. $dir = $conf->ficheinter->dir_output;
  102. if (! preg_match('/specimen/i',$fichref)) $dir.= "/" . $fichref;
  103. $file = $dir . "/" . $fichref . ".pdf";
  104. if (! file_exists($dir))
  105. {
  106. if (create_exdir($dir) < 0)
  107. {
  108. $this->error=$outputlangs->trans("ErrorCanNotCreateDir",$dir);
  109. return 0;
  110. }
  111. }
  112. if (file_exists($dir))
  113. {
  114. $pdf=pdf_getInstance($this->format);
  115. if (class_exists('TCPDF'))
  116. {
  117. $pdf->setPrintHeader(false);
  118. $pdf->setPrintFooter(false);
  119. }
  120. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  121. $pdf->Open();
  122. $pagenb=0;
  123. $pdf->SetDrawColor(128,128,128);
  124. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  125. $pdf->SetAutoPageBreak(1,0);
  126. // New page
  127. $pdf->AddPage();
  128. $pagenb++;
  129. $pdf->SetTextColor(0,0,0);
  130. $pdf->SetFont('','', $default_font_size - 1);
  131. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  132. // Pagehead
  133. //Affiche le filigrane brouillon - Print Draft Watermark
  134. if($fichinter->statut==0 && (! empty($conf->global->FICHINTER_DRAFT_WATERMARK)) )
  135. {
  136. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FICHINTER_DRAFT_WATERMARK);
  137. }
  138. $posy=$this->marge_haute;
  139. $pdf->SetXY($this->marge_gauche,$posy);
  140. // Logo
  141. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  142. if ($mysoc->logo)
  143. {
  144. if (is_readable($logo))
  145. {
  146. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
  147. }
  148. else
  149. {
  150. $pdf->SetTextColor(200,0,0);
  151. $pdf->SetFont('','B', $default_font_size - 2);
  152. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  153. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  154. }
  155. }
  156. // Nom emetteur
  157. $posy=40;
  158. $hautcadre=40;
  159. $pdf->SetTextColor(0,0,0);
  160. $pdf->SetFont('','', $default_font_size - 2);
  161. $pdf->SetXY($this->marge_gauche,$posy);
  162. $pdf->SetFillColor(230,230,230);
  163. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  164. $pdf->SetXY($this->marge_gauche+2,$posy+3);
  165. // Sender name
  166. $pdf->SetTextColor(0,0,60);
  167. $pdf->SetFont('','B', $default_font_size);
  168. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  169. // Sender properties
  170. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  171. $pdf->SetFont('','', $default_font_size - 1);
  172. $pdf->SetXY($this->marge_gauche+2,$posy+9);
  173. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  174. $object=$fichinter;
  175. // Recipient name
  176. if (! empty($usecontact))
  177. {
  178. // On peut utiliser le nom de la societe du contact
  179. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  180. else $socname = $object->client->nom;
  181. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  182. }
  183. else
  184. {
  185. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  186. }
  187. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  188. // Client destinataire
  189. $pdf->SetTextColor(0,0,0);
  190. $pdf->SetFont('','B', $default_font_size);
  191. $fichinter->fetch_thirdparty();
  192. $pdf->SetXY(102,42);
  193. $pdf->MultiCell(86,4, $carac_client_name, 0, 'L');
  194. $pdf->SetFont('','', $default_font_size - 1);
  195. $pdf->SetXY(102,$pdf->GetY());
  196. $pdf->MultiCell(66,4, $carac_client, 0, 'L');
  197. $pdf->rect(100, 40, 100, 40);
  198. $pdf->SetTextColor(0,0,100);
  199. $pdf->SetFont('','B', $default_font_size + 2);
  200. $pdf->SetXY(10,86);
  201. $pdf->MultiCell(120, 4, $outputlangs->transnoentities("InterventionCard")." : ".$outputlangs->convToOutputCharset($fichinter->ref), 0, 'L');
  202. $pdf->SetFillColor(220,220,220);
  203. $pdf->SetTextColor(0,0,0);
  204. $pdf->SetFont('','', $default_font_size);
  205. $tab_top = 100;
  206. $tab_top_newpage = 50;
  207. $tab_height = 110;
  208. $tab_height_newpage = 150;
  209. // Affiche notes
  210. if (! empty($fichinter->note_public))
  211. {
  212. $tab_top = 98;
  213. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  214. $pdf->SetXY($this->posxdesc-1, $tab_top);
  215. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($fichinter->note_public), 0, 'L');
  216. $nexY = $pdf->GetY();
  217. $height_note=$nexY-$tab_top;
  218. // Rect prend une longueur en 3eme param
  219. $pdf->SetDrawColor(192,192,192);
  220. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  221. $tab_height = $tab_height - $height_note;
  222. $tab_top = $nexY+6;
  223. }
  224. else
  225. {
  226. $height_note=0;
  227. }
  228. $pdf->SetXY($this->marge_gauche, $tab_top);
  229. $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
  230. $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8 );
  231. $pdf->SetFont('','', $default_font_size - 1);
  232. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  233. $pdf->SetXY($this->marge_gauche, $tab_top + 8 );
  234. $text=$fichinter->description;
  235. if ($fichinter->duree > 0)
  236. {
  237. $totaltime=ConvertSecondToTime($fichinter->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
  238. $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
  239. }
  240. $desc=dol_htmlentitiesbr($text,1);
  241. //print $outputlangs->convToOutputCharset($desc); exit;
  242. $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
  243. $nexY = $pdf->GetY();
  244. $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
  245. $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
  246. //dol_syslog("desc=".dol_htmlentitiesbr($fichinter->description));
  247. $nblignes = count($fichinter->lines);
  248. $curY = $pdf->GetY();
  249. $nexY = $pdf->GetY();
  250. // Loop on each lines
  251. for ($i = 0 ; $i < $nblignes ; $i++)
  252. {
  253. $fichinterligne = $fichinter->lines[$i];
  254. $valide = $fichinterligne->id ? $fichinterligne->fetch($fichinterligne->id) : 0;
  255. if ($valide>0 || $fichinter->specimen)
  256. {
  257. $curY = $nexY+3;
  258. $pdf->SetXY($this->marge_gauche, $curY);
  259. $pdf->writeHTMLCell(0, 3, $this->marge_gauche, $curY,
  260. dol_htmlentitiesbr($outputlangs->transnoentities("Date")." : ".dol_print_date($fichinterligne->datei,'dayhour',false,$outputlangs,true)." - ".$outputlangs->transnoentities("Duration")." : ".ConvertSecondToTime($fichinterligne->duration),1,$outputlangs->charset_output), 0, 1, 0);
  261. $nexY = $pdf->GetY();
  262. $pdf->SetXY($this->marge_gauche, $curY + 3);
  263. $desc = dol_htmlentitiesbr($fichinterligne->desc,1);
  264. $pdf->writeHTMLCell(0, 3, $this->marge_gauche, $curY + 3, $desc, 0, 1, 0);
  265. $nexY+=dol_nboflines_bis($fichinterligne->desc,52,$outputlangs->charset_output)*3;
  266. }
  267. }
  268. //$pdf->line(10, $tab_top+$tab_height+3, 200, $tab_top+$tab_height+3);
  269. // Rectangle for title and all lines
  270. $pdf->Rect($this->marge_gauche, $tab_top, ($this->page_largeur-$this->marge_gauche-$this->marge_droite), $tab_height+3);
  271. $pdf->SetXY($this->marge_gauche, $pdf->GetY() + 20);
  272. $pdf->MultiCell(60, 5, '', 0, 'J', 0);
  273. $pdf->SetXY(20,220);
  274. $pdf->MultiCell(66,5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"),0,'L',0);
  275. $pdf->SetXY(20,225);
  276. $pdf->MultiCell(80,30, '', 1);
  277. $pdf->SetXY(110,220);
  278. $pdf->MultiCell(80,5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"),0,'L',0);
  279. $pdf->SetXY(110,225);
  280. $pdf->MultiCell(80,30, '', 1);
  281. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  282. $this->_pagefoot($pdf,$fichinter,$outputlangs);
  283. $pdf->AliasNbPages();
  284. $pdf->Close();
  285. $pdf->Output($file,'F');
  286. if (! empty($conf->global->MAIN_UMASK))
  287. @chmod($file, octdec($conf->global->MAIN_UMASK));
  288. return 1;
  289. }
  290. else
  291. {
  292. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  293. return 0;
  294. }
  295. }
  296. else
  297. {
  298. $this->error=$langs->trans("ErrorConstantNotDefined","FICHEINTER_OUTPUTDIR");
  299. return 0;
  300. }
  301. $this->error=$langs->trans("ErrorUnknown");
  302. return 0; // Erreur par defaut
  303. }
  304. /**
  305. * \brief Show footer of page
  306. * \param pdf PDF factory
  307. * \param object Object invoice
  308. * \param outputlangs Object lang for output
  309. * \remarks Need this->emetteur object
  310. */
  311. function _pagefoot(&$pdf,$object,$outputlangs)
  312. {
  313. return pdf_pagefoot($pdf,$outputlangs,'FICHINTER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  314. }
  315. }
  316. ?>