PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/asterix14/dolibarr
PHP | 416 lines | 239 code | 76 blank | 101 comment | 20 complexity | 2119e604939b43300686e9cf24faef52 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  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 2 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 pdf_baleine($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. * \brief Fonction generant le projet sur le disque
  74. * \param object Object project a generer
  75. * \param outputlangs Lang output object
  76. * \return int 1 if OK, <=0 if KO
  77. */
  78. function write_file($object,$outputlangs)
  79. {
  80. global $user,$langs,$conf;
  81. if (! is_object($outputlangs)) $outputlangs=$langs;
  82. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  83. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  84. $outputlangs->load("main");
  85. $outputlangs->load("dict");
  86. $outputlangs->load("companies");
  87. $outputlangs->load("projects");
  88. if ($conf->projet->dir_output)
  89. {
  90. $nblignes = count($object->lines);
  91. $default_font_size = pdf_getPDFFontsize($outputlangs);
  92. $objectref = dol_sanitizeFileName($object->ref);
  93. $dir = $conf->projet->dir_output;
  94. if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
  95. $file = $dir . "/" . $objectref . ".pdf";
  96. if (! file_exists($dir))
  97. {
  98. if (create_exdir($dir) < 0)
  99. {
  100. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  101. return 0;
  102. }
  103. }
  104. if (file_exists($dir))
  105. {
  106. $pdf=pdf_getInstance($this->format);
  107. if (class_exists('TCPDF'))
  108. {
  109. $pdf->setPrintHeader(false);
  110. $pdf->setPrintFooter(false);
  111. }
  112. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  113. // Complete object by loading several other informations
  114. $task = new Task($this->db);
  115. $tasksarray = $task->getTasksArray(0,0,$object->id);
  116. $object->lines=$tasksarray;
  117. $nblignes=count($object->lines);
  118. $pdf->Open();
  119. $pagenb=0;
  120. $pdf->SetDrawColor(128,128,128);
  121. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  122. $pdf->SetSubject($outputlangs->transnoentities("Project"));
  123. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  124. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  125. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Project"));
  126. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  127. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  128. $pdf->SetAutoPageBreak(1,0);
  129. // New page
  130. $pdf->AddPage();
  131. $pagenb++;
  132. $this->_pagehead($pdf, $object, 1, $outputlangs);
  133. $pdf->SetFont('','', $default_font_size - 1);
  134. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  135. $pdf->SetTextColor(0,0,0);
  136. $tab_top = 50;
  137. $tab_height = 200;
  138. $tab_top_newpage = 40;
  139. $tab_height_newpage = 210;
  140. // Affiche notes
  141. if (! empty($object->note_public))
  142. {
  143. $pdf->SetFont('','', $default_font_size - 1);
  144. $pdf->SetXY($this->posxref-1, $tab_top-2);
  145. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
  146. $nexY = $pdf->GetY();
  147. $height_note=$nexY-($tab_top-2);
  148. // Rect prend une longueur en 3eme param
  149. $pdf->SetDrawColor(192,192,192);
  150. $pdf->Rect($this->marge_gauche, $tab_top-3, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  151. $tab_height = $tab_height - $height_note;
  152. $tab_top = $nexY+6;
  153. }
  154. else
  155. {
  156. $height_note=0;
  157. }
  158. $iniY = $tab_top + 7;
  159. $curY = $tab_top + 7;
  160. $nexY = $tab_top + 7;
  161. // Boucle sur les lignes
  162. for ($i = 0 ; $i < $nblignes ; $i++)
  163. {
  164. $curY = $nexY;
  165. // Description of ligne
  166. $ref=$object->lines[$i]->ref;
  167. $libelleline=$object->lines[$i]->label;
  168. $progress=$object->lines[$i]->progress.'%';
  169. $datestart=dol_print_date($object->lines[$i]->date_start,'day');
  170. $dateend=dol_print_date($object->lines[$i]->date_end,'day');
  171. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  172. $pdf->SetXY($this->posxref, $curY);
  173. $pdf->MultiCell(60, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
  174. $pdf->SetXY($this->posxlabel, $curY);
  175. $pdf->MultiCell(108, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
  176. $pdf->SetXY($this->posxprogress, $curY);
  177. $pdf->MultiCell(16, 3, $progress, 0, 'L');
  178. $pdf->SetXY($this->posxdatestart, $curY);
  179. $pdf->MultiCell(20, 3, $datestart, 0, 'L');
  180. $pdf->SetXY($this->posxdateend, $curY);
  181. $pdf->MultiCell(20, 3, $dateend, 0, 'L');
  182. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  183. $nexY = $pdf->GetY();
  184. $nexY+=2; // Passe espace entre les lignes
  185. // Cherche nombre de lignes a venir pour savoir si place suffisante
  186. if ($i < ($nblignes - 1) && empty($hidedesc)) // If it's not last line
  187. {
  188. //on recupere la description du produit suivant
  189. $follow_descproduitservice = $object->lines[$i+1]->desc;
  190. //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
  191. $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4);
  192. }
  193. else // If it's last line
  194. {
  195. $nblineFollowDesc = 0;
  196. }
  197. if (($nexY+$nblineFollowDesc) > ($tab_top+$tab_height) && $i < ($nblignes - 1))
  198. {
  199. $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
  200. $this->_pagefoot($pdf, $object, $outputlangs);
  201. // New page
  202. $pdf->AddPage();
  203. $pagenb++;
  204. $this->_pagehead($pdf, $object, 0, $outputlangs);
  205. $pdf->SetFont('','', $default_font_size - 1);
  206. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  207. $pdf->SetTextColor(0,0,0);
  208. $tab_top=$tab_top_newpage;
  209. $tab_height=$tab_height_newpage;
  210. $nexY = $tab_top + 7;
  211. }
  212. }
  213. // Show square
  214. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  215. $bottomlasttab=$tab_top + $tab_height + 1;
  216. /*
  217. * Pied de page
  218. */
  219. $this->_pagefoot($pdf,$object,$outputlangs);
  220. $pdf->AliasNbPages();
  221. $pdf->Close();
  222. $pdf->Output($file,'F');
  223. if (! empty($conf->global->MAIN_UMASK))
  224. @chmod($file, octdec($conf->global->MAIN_UMASK));
  225. return 1; // Pas d'erreur
  226. }
  227. else
  228. {
  229. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  230. return 0;
  231. }
  232. }
  233. $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
  234. return 0;
  235. }
  236. /*
  237. * \brief Affiche la grille des lignes
  238. * \param pdf objet PDF
  239. */
  240. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  241. {
  242. global $conf,$mysoc;
  243. $default_font_size = pdf_getPDFFontSize($outputlangs);
  244. $pdf->SetDrawColor(128,128,128);
  245. // Rect prend une longueur en 3eme param
  246. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  247. // line prend une position y en 3eme param
  248. $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
  249. $pdf->SetTextColor(0,0,0);
  250. $pdf->SetFont('','', $default_font_size);
  251. $pdf->SetXY($this->posxref-1, $tab_top+2);
  252. $pdf->MultiCell(80,2, $outputlangs->transnoentities("Tasks"),'','L');
  253. }
  254. /**
  255. * Show header of page
  256. *
  257. * @param $pdf Object PDF
  258. * @param $object Object project
  259. * @param $showaddress 0=no, 1=yes
  260. * @param $outputlangs Object lang for output
  261. */
  262. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  263. {
  264. global $langs,$conf,$mysoc;
  265. $default_font_size = pdf_getPDFFontSize($outputlangs);
  266. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  267. $pdf->SetTextColor(0,0,60);
  268. $pdf->SetFont('','B', $default_font_size + 3);
  269. $posx=$this->page_largeur-$this->marge_droite-100;
  270. $posy=$this->marge_haute;
  271. $pdf->SetXY($this->marge_gauche,$posy);
  272. // Logo
  273. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  274. if ($mysoc->logo)
  275. {
  276. if (is_readable($logo))
  277. {
  278. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
  279. }
  280. else
  281. {
  282. $pdf->SetTextColor(200,0,0);
  283. $pdf->SetFont('','B', $default_font_size - 2);
  284. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  285. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  286. }
  287. }
  288. else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
  289. $pdf->SetFont('','B', $default_font_size + 3);
  290. $pdf->SetXY($posx,$posy);
  291. $pdf->SetTextColor(0,0,60);
  292. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  293. $pdf->SetFont('','', $default_font_size + 2);
  294. $posy+=6;
  295. $pdf->SetXY($posx,$posy);
  296. $pdf->SetTextColor(0,0,60);
  297. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart")." : " . dol_print_date($object->date_start,'day',false,$outputlangs,true), '', 'R');
  298. $posy+=6;
  299. $pdf->SetXY($posx,$posy);
  300. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
  301. $pdf->SetTextColor(0,0,60);
  302. // Add list of linked objects
  303. /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
  304. $object->fetchObjectLinked();
  305. foreach($object->linkedObjects as $objecttype => $objects)
  306. {
  307. var_dump($objects);exit;
  308. if ($objecttype == 'commande')
  309. {
  310. $outputlangs->load('orders');
  311. $num=count($objects);
  312. for ($i=0;$i<$num;$i++)
  313. {
  314. $posy+=4;
  315. $pdf->SetXY($posx,$posy);
  316. $pdf->SetFont('','', $default_font_size - 1);
  317. $text=$objects[$i]->ref;
  318. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  319. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  320. }
  321. }
  322. }
  323. */
  324. }
  325. /**
  326. * Show footer of page
  327. * Need this->emetteur object
  328. *
  329. * @param pdf PDF factory
  330. * @param object Object invoice
  331. * @param outputlangs Object lang for output
  332. */
  333. function _pagefoot(&$pdf,$object,$outputlangs)
  334. {
  335. return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  336. }
  337. }
  338. ?>