box_project.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  5. * Copyright (C) 2016 Juan José Menent <jmenent@2byte.es>
  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 3 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. */
  20. /**
  21. * \file htdocs/core/boxes/box_activite.php
  22. * \ingroup projet
  23. * \brief Module to show Projet activity of the current Year
  24. */
  25. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  26. /**
  27. * Class to manage the box to show last projet
  28. */
  29. class box_project extends ModeleBoxes
  30. {
  31. var $boxcode="project";
  32. var $boximg="object_projectpub";
  33. var $boxlabel;
  34. //var $depends = array("projet");
  35. var $db;
  36. var $param;
  37. var $info_box_head = array();
  38. var $info_box_contents = array();
  39. /**
  40. * Constructor
  41. *
  42. * @param DoliDB $db Database handler
  43. * @param string $param More parameters
  44. */
  45. function __construct($db,$param='')
  46. {
  47. global $user, $langs;
  48. $langs->load("boxes");
  49. $langs->load("projects");
  50. $this->db = $db;
  51. $this->boxlabel="Projects";
  52. $this->hidden=! ($user->rights->projet->lire);
  53. }
  54. /**
  55. * Load data for box to show them later
  56. *
  57. * @param int $max Maximum number of records to load
  58. * @return void
  59. */
  60. function loadBox($max=5)
  61. {
  62. global $conf, $user, $langs, $db;
  63. $this->max=$max;
  64. $totalMnt = 0;
  65. $totalnb = 0;
  66. $totalnbTask=0;
  67. $textHead = $langs->trans("OpenedProjects");
  68. $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
  69. // list the summary of the orders
  70. if ($user->rights->projet->lire) {
  71. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  72. $projectstatic = new Project($this->db);
  73. $socid=$user->societe_id;
  74. // Get list of project id allowed to user (in a string list separated by coma)
  75. $projectsListId='';
  76. if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
  77. $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
  78. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  79. if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
  80. $sql.= " WHERE p.entity IN (".getEntity('project').')';
  81. if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
  82. if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
  83. $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
  84. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  85. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
  86. $sql.= " ORDER BY p.datec DESC";
  87. //$sql.= $db->plimit($max, 0);
  88. $result = $db->query($sql);
  89. if ($result) {
  90. $num = $db->num_rows($result);
  91. $i = 0;
  92. while ($i < min($num, $max)) {
  93. $objp = $db->fetch_object($result);
  94. $projectstatic->id = $objp->rowid;
  95. $projectstatic->ref = $objp->ref;
  96. $projectstatic->title = $objp->title;
  97. $projectstatic->public = $objp->public;
  98. $this->info_box_contents[$i][] = array(
  99. 'td' => '',
  100. 'text' => $projectstatic->getNomUrl(1),
  101. 'asis' => 1
  102. );
  103. $this->info_box_contents[$i][] = array(
  104. 'td' => '',
  105. 'text' => $objp->title,
  106. );
  107. $sql ="SELECT count(*) as nb, sum(progress) as totprogress";
  108. $sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
  109. $sql.= " WHERE p.entity IN (".getEntity('project').')';
  110. $sql.=" AND p.rowid = ".$objp->rowid;
  111. $resultTask = $db->query($sql);
  112. if ($resultTask) {
  113. $objTask = $db->fetch_object($resultTask);
  114. $this->info_box_contents[$i][] = array(
  115. 'td' => 'class="right"',
  116. 'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
  117. );
  118. if ($objTask->nb > 0)
  119. $this->info_box_contents[$i][] = array(
  120. 'td' => 'class="right"',
  121. 'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
  122. );
  123. else
  124. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  125. $totalnbTask += $objTask->nb;
  126. } else {
  127. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
  128. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  129. }
  130. $i++;
  131. }
  132. if ($max < $num)
  133. {
  134. $this->info_box_contents[$i][] = array('td' => 'colspan="5"', 'text' => '...');
  135. $i++;
  136. }
  137. }
  138. }
  139. // Add the sum à the bottom of the boxes
  140. $this->info_box_contents[$i][] = array(
  141. 'td' => '',
  142. 'text' => $langs->trans("Total")."&nbsp;".$textHead,
  143. 'text' => "&nbsp;",
  144. );
  145. $this->info_box_contents[$i][] = array(
  146. 'td' => 'align="right" ',
  147. 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
  148. );
  149. $this->info_box_contents[$i][] = array(
  150. 'td' => 'align="right" ',
  151. 'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
  152. );
  153. $this->info_box_contents[$i][] = array(
  154. 'td' => '',
  155. 'text' => "&nbsp;",
  156. );
  157. }
  158. /**
  159. * Method to show box
  160. *
  161. * @param array $head Array with properties of box title
  162. * @param array $contents Array with properties of box lines
  163. * @param int $nooutput No print, only return string
  164. * @return string
  165. */
  166. function showBox($head = null, $contents = null, $nooutput=0)
  167. {
  168. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  169. }
  170. }