PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/project/pdf/pdf_baleine.modules.php

https://bitbucket.org/speedealing/speedealing
PHP | 437 lines | 257 code | 71 blank | 109 comment | 26 complexity | 4453d24b1ec2abb663f37bd53d603454 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. * or see http://www.gnu.org/
  16. */
  17. /**
  18. * \file htdocs/core/modules/project/pdf/pdf_baleine.modules.php
  19. * \ingroup project
  20. * \brief Fichier de la classe permettant de generer les projets au modele Baleine
  21. * \author Regis Houssin
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  24. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  28. /**
  29. * \class pdf_baleine
  30. * \brief Classe permettant de generer les projets au modele Baleine
  31. */
  32. class pdf_baleine extends ModelePDFProjects
  33. {
  34. var $emetteur; // Objet societe qui emet
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. function __construct($db = '')
  41. {
  42. global $conf,$langs,$mysoc;
  43. $langs->load("main");
  44. $langs->load("projects");
  45. $langs->load("companies");
  46. $this->db = $db;
  47. $this->name = "baleine";
  48. $this->description = $langs->trans("DocumentModelBaleine");
  49. // Dimension page pour format A4
  50. $this->type = 'pdf';
  51. $formatarray=pdf_getFormat();
  52. $this->page_largeur = $formatarray['width'];
  53. $this->page_hauteur = $formatarray['height'];
  54. $this->format = array($this->page_largeur,$this->page_hauteur);
  55. $this->marge_gauche=10;
  56. $this->marge_droite=10;
  57. $this->marge_haute=10;
  58. $this->marge_basse=10;
  59. $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
  60. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  61. $this->option_codeproduitservice = 1; // Affiche code produit-service
  62. // Recupere emmetteur
  63. $this->emetteur=$mysoc;
  64. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini
  65. // Defini position des colonnes
  66. $this->posxref=$this->marge_gauche+1;
  67. $this->posxlabel=$this->marge_gauche+25;
  68. $this->posxprogress=$this->marge_gauche+140;
  69. $this->posxdatestart=$this->marge_gauche+150;
  70. $this->posxdateend=$this->marge_gauche+170;
  71. }
  72. /**
  73. * Fonction generant le projet sur le disque
  74. *
  75. * @param Project $object Object project a generer
  76. * @param Translate $outputlangs Lang output object
  77. * @return int 1 if OK, <=0 if KO
  78. */
  79. function write_file($object,$outputlangs)
  80. {
  81. global $user,$langs,$conf;
  82. if (! is_object($outputlangs)) $outputlangs=$langs;
  83. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  84. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  85. $outputlangs->load("main");
  86. $outputlangs->load("dict");
  87. $outputlangs->load("companies");
  88. $outputlangs->load("projects");
  89. if ($conf->projet->dir_output)
  90. {
  91. $nblignes = count($object->lines);
  92. $default_font_size = pdf_getPDFFontsize($outputlangs);
  93. $objectref = dol_sanitizeFileName($object->ref);
  94. $dir = $conf->projet->dir_output;
  95. if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
  96. $file = $dir . "/" . $objectref . ".pdf";
  97. if (! file_exists($dir))
  98. {
  99. if (dol_mkdir($dir) < 0)
  100. {
  101. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  102. return 0;
  103. }
  104. }
  105. if (file_exists($dir))
  106. {
  107. $pdf=pdf_getInstance($this->format);
  108. $heightforinfotot = 50; // Height reserved to output the info and total part
  109. $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin)
  110. $pdf->SetAutoPageBreak(1,0);
  111. if (class_exists('TCPDF'))
  112. {
  113. $pdf->setPrintHeader(false);
  114. $pdf->setPrintFooter(false);
  115. }
  116. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  117. // Complete object by loading several other informations
  118. $task = new Task($this->db);
  119. $tasksarray = $task->getTasksArray(0,0,$object->id);
  120. $object->lines=$tasksarray;
  121. $nblignes=count($object->lines);
  122. $pdf->Open();
  123. $pagenb=0;
  124. $pdf->SetDrawColor(128,128,128);
  125. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  126. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  127. $pdf->SetCreator("Speedealing ".DOL_VERSION);
  128. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  129. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  130. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  131. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  132. // New page
  133. $pdf->AddPage();
  134. $pagenb++;
  135. $this->_pagehead($pdf, $object, 1, $outputlangs);
  136. $pdf->SetFont('','', $default_font_size - 1);
  137. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  138. $pdf->SetTextColor(0,0,0);
  139. $tab_top = 50;
  140. $tab_height = 200;
  141. $tab_top_newpage = 40;
  142. $tab_height_newpage = 210;
  143. // Affiche notes
  144. if (! empty($object->note_public))
  145. {
  146. $pdf->SetFont('','', $default_font_size - 1);
  147. $pdf->writeHTMLCell(190, 3, $this->posxref-1, $tab_top-2, dol_htmlentitiesbr($object->note_public), 0, 1);
  148. $nexY = $pdf->GetY();
  149. $height_note=$nexY-($tab_top-2);
  150. // Rect prend une longueur en 3eme param
  151. $pdf->SetDrawColor(192,192,192);
  152. $pdf->Rect($this->marge_gauche, $tab_top-3, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  153. $tab_height = $tab_height - $height_note;
  154. $tab_top = $nexY+6;
  155. }
  156. else
  157. {
  158. $height_note=0;
  159. }
  160. $iniY = $tab_top + 7;
  161. $curY = $tab_top + 7;
  162. $nexY = $tab_top + 7;
  163. // Boucle sur les lignes
  164. for ($i = 0 ; $i < $nblignes ; $i++)
  165. {
  166. $curY = $nexY;
  167. // Description of ligne
  168. $ref=$object->lines[$i]->ref;
  169. $libelleline=$object->lines[$i]->label;
  170. $progress=$object->lines[$i]->progress.'%';
  171. $datestart=dol_print_date($object->lines[$i]->date_start,'day');
  172. $dateend=dol_print_date($object->lines[$i]->date_end,'day');
  173. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  174. $pdf->SetXY($this->posxref, $curY);
  175. $pdf->MultiCell(60, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
  176. $pdf->SetXY($this->posxlabel, $curY);
  177. $pdf->MultiCell(108, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  178. $pdf->SetXY($this->posxprogress, $curY);
  179. $pdf->MultiCell(16, 3, $progress, 0, 'L');
  180. $pdf->SetXY($this->posxdatestart, $curY);
  181. $pdf->MultiCell(20, 3, $datestart, 0, 'L');
  182. $pdf->SetXY($this->posxdateend, $curY);
  183. $pdf->MultiCell(20, 3, $dateend, 0, 'L');
  184. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  185. $nexY = $pdf->GetY();
  186. $nexY+=2; // Passe espace entre les lignes
  187. // Detect if some page were added automatically and output _tableau for past pages
  188. while ($pagenb < $pageposafter)
  189. {
  190. $pdf->setPage($pagenb);
  191. if ($pagenb == 1)
  192. {
  193. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  194. }
  195. else
  196. {
  197. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  198. }
  199. $this->_pagefoot($pdf,$object,$outputlangs);
  200. $pagenb++;
  201. $pdf->setPage($pagenb);
  202. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  203. }
  204. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  205. {
  206. if ($pagenb == 1)
  207. {
  208. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  209. }
  210. else
  211. {
  212. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  213. }
  214. $this->_pagefoot($pdf,$object,$outputlangs);
  215. // New page
  216. $pdf->AddPage();
  217. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  218. $pagenb++;
  219. }
  220. }
  221. // Show square
  222. if ($pagenb == 1)
  223. {
  224. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0);
  225. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  226. }
  227. else
  228. {
  229. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0);
  230. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  231. }
  232. /*
  233. * Pied de page
  234. */
  235. $this->_pagefoot($pdf,$object,$outputlangs);
  236. $pdf->AliasNbPages();
  237. $pdf->Close();
  238. $pdf->Output($file,'F');
  239. if (! empty($conf->global->MAIN_UMASK))
  240. @chmod($file, octdec($conf->global->MAIN_UMASK));
  241. return 1; // Pas d'erreur
  242. }
  243. else
  244. {
  245. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  246. return 0;
  247. }
  248. }
  249. $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
  250. return 0;
  251. }
  252. /**
  253. * Show table for lines
  254. *
  255. * @param PDF &$pdf Object PDF
  256. * @param string $tab_top Top position of table
  257. * @param string $tab_height Height of table (rectangle)
  258. * @param int $nexY Y
  259. * @param Translate $outputlangs Langs object
  260. * @param int $hidetop Hide top bar of array
  261. * @param int $hidebottom Hide bottom bar of array
  262. * @return void
  263. */
  264. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
  265. {
  266. global $conf,$mysoc;
  267. $default_font_size = pdf_getPDFFontSize($outputlangs);
  268. $pdf->SetDrawColor(128,128,128);
  269. // Rect prend une longueur en 3eme param
  270. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  271. // line prend une position y en 3eme param
  272. $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
  273. $pdf->SetTextColor(0,0,0);
  274. $pdf->SetFont('','', $default_font_size);
  275. $pdf->SetXY($this->posxref-1, $tab_top+2);
  276. $pdf->MultiCell(80,2, $outputlangs->transnoentities("Tasks"),'','L');
  277. }
  278. /**
  279. * Show top header of page.
  280. *
  281. * @param PDF &$pdf Object PDF
  282. * @param Object $object Object to show
  283. * @param int $showaddress 0=no, 1=yes
  284. * @param Translate $outputlangs Object lang for output
  285. * @return void
  286. */
  287. function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  288. {
  289. global $langs,$conf,$mysoc;
  290. $default_font_size = pdf_getPDFFontSize($outputlangs);
  291. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  292. $pdf->SetTextColor(0,0,60);
  293. $pdf->SetFont('','B', $default_font_size + 3);
  294. $posx=$this->page_largeur-$this->marge_droite-100;
  295. $posy=$this->marge_haute;
  296. $pdf->SetXY($this->marge_gauche,$posy);
  297. // Logo
  298. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  299. if ($mysoc->logo)
  300. {
  301. if (is_readable($logo))
  302. {
  303. $height=pdf_getHeightForLogo($logo);
  304. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  305. }
  306. else
  307. {
  308. $pdf->SetTextColor(200,0,0);
  309. $pdf->SetFont('','B', $default_font_size - 2);
  310. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  311. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  312. }
  313. }
  314. else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  315. $pdf->SetFont('','B', $default_font_size + 3);
  316. $pdf->SetXY($posx,$posy);
  317. $pdf->SetTextColor(0,0,60);
  318. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  319. $pdf->SetFont('','', $default_font_size + 2);
  320. $posy+=6;
  321. $pdf->SetXY($posx,$posy);
  322. $pdf->SetTextColor(0,0,60);
  323. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : " . dol_print_date($object->date_start,'day',false,$outputlangs,true), '', 'R');
  324. $posy+=6;
  325. $pdf->SetXY($posx,$posy);
  326. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
  327. $pdf->SetTextColor(0,0,60);
  328. // Add list of linked objects
  329. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  330. $object->fetchObjectLinked();
  331. foreach($object->linkedObjects as $objecttype => $objects)
  332. {
  333. var_dump($objects);exit;
  334. if ($objecttype == 'commande')
  335. {
  336. $outputlangs->load('orders');
  337. $num=count($objects);
  338. for ($i=0;$i<$num;$i++)
  339. {
  340. $posy+=4;
  341. $pdf->SetXY($posx,$posy);
  342. $pdf->SetFont('','', $default_font_size - 1);
  343. $text=$objects[$i]->ref;
  344. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  345. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  346. }
  347. }
  348. }
  349. */
  350. }
  351. /**
  352. * Show footer of page. Need this->emetteur object
  353. *
  354. * @param PDF &$pdf PDF
  355. * @param Object $object Object to show
  356. * @param Translate $outputlangs Object lang for output
  357. * @return void
  358. */
  359. function _pagefoot(&$pdf,$object,$outputlangs)
  360. {
  361. return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  362. }
  363. }
  364. ?>