box_validated_projects.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/boxes/box_validated_projects.php
  23. * \ingroup projet
  24. * \brief Module to show validated projects whose tasks are assigned to the connected person, without any time entered by the connected person
  25. */
  26. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  27. /**
  28. * Class to manage the box to show last projet
  29. */
  30. class box_validated_projects extends ModeleBoxes
  31. {
  32. public $boxcode = "validated_project";
  33. public $boximg = "object_projectpub";
  34. public $boxlabel;
  35. //var $depends = array("projet");
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  40. public $param;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. public $enabled = 1;
  44. /**
  45. * Constructor
  46. *
  47. * @param DoliDB $db Database handler
  48. * @param string $param More parameters
  49. */
  50. public function __construct($db, $param = '')
  51. {
  52. global $conf, $user, $langs;
  53. // Load translation files required by the page
  54. $langs->loadLangs(array('boxes', 'projects'));
  55. $this->db = $db;
  56. $this->boxlabel = "ProjectsWithTask";
  57. $this->hidden = !($user->rights->projet->lire);
  58. if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
  59. $this->enabled = 0;
  60. }
  61. }
  62. /**
  63. * Load data for box to show them later
  64. *
  65. * @param int $max Maximum number of records to load
  66. * @return void
  67. */
  68. public function loadBox($max = 5)
  69. {
  70. global $conf, $user, $langs;
  71. $this->max = $max;
  72. $totalMnt = 0;
  73. $totalnb = 0;
  74. $totalnbTask = 0;
  75. $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
  76. $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
  77. // list the summary of the orders
  78. if ($user->rights->projet->lire) {
  79. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  80. $projectstatic = new Project($this->db);
  81. $socid = 0;
  82. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  83. // Get list of project id allowed to user (in a string list separated by coma)
  84. $projectsListId = '';
  85. if (!$user->rights->projet->all->lire) {
  86. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  87. }
  88. // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
  89. // Count of tasks without time spent for tasks we are assigned too or
  90. // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
  91. $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
  92. $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
  93. $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
  94. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
  95. // TODO Replace -1, -2, -3 with ID used for type of contat project_task into llx_c_type_contact. Once done, we can switch widget as stable.
  96. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = t.rowid AND fk_c_type_contact IN (-1, -2, -3)";
  97. $sql .= " WHERE p.fk_statut = 1"; // Only open projects
  98. if ($projectsListId) {
  99. $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only project we ara allowed
  100. }
  101. $sql .= " AND t.rowid NOT IN (SELECT fk_task FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_user = ".((int) $user->id).")";
  102. $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
  103. $sql .= " ORDER BY p.dateo ASC";
  104. $result = $this->db->query($sql);
  105. if ($result) {
  106. $num = $this->db->num_rows($result);
  107. $i = 0;
  108. $this->info_box_contents[$i][] = array(
  109. 'td' => 'class="nowraponall"',
  110. 'text' => "Reference projet",
  111. );
  112. $this->info_box_contents[$i][] = array(
  113. 'td' => 'class="center"',
  114. 'text' => 'Client',
  115. );
  116. $this->info_box_contents[$i][] = array(
  117. 'td' => 'class="center"',
  118. 'text' => 'Date debut de projet',
  119. );
  120. $this->info_box_contents[$i][] = array(
  121. 'td' => 'class="center"',
  122. 'text' => 'Nombre de mes tâches sans temps saisi',
  123. );
  124. $i++;
  125. while ($i < min($num + 1, $max + 1)) {
  126. $objp = $this->db->fetch_object($result);
  127. $projectstatic->id = $objp->rowid;
  128. $projectstatic->ref = $objp->ref;
  129. $this->info_box_contents[$i][] = array(
  130. 'td' => 'class="nowraponall"',
  131. 'text' => $projectstatic->getNomUrl(1),
  132. 'asis' => 1
  133. );
  134. if ($objp->fk_soc > 0) {
  135. $sql = 'SELECT rowid, nom as name FROM '.MAIN_DB_PREFIX.'societe WHERE rowid = '.((int) $objp->fk_soc);
  136. $resql = $this->db->query($sql);
  137. //$socstatic = new Societe($this->db);
  138. $obj2 = $this->db->fetch_object($resql);
  139. $this->info_box_contents[$i][] = array(
  140. 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
  141. 'text' => $obj2->name,
  142. 'asis' => 1,
  143. 'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
  144. );
  145. } else {
  146. $this->info_box_contents[$i][] = array(
  147. 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
  148. 'text' => '',
  149. 'asis' => 1,
  150. 'url' => ''
  151. );
  152. }
  153. $this->info_box_contents[$i][] = array(
  154. 'td' => 'class="center"',
  155. 'text' => $objp->startDate,
  156. );
  157. $this->info_box_contents[$i][] = array(
  158. 'td' => 'class="center"',
  159. 'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
  160. 'asis' => 1,
  161. );
  162. $i++;
  163. }
  164. } else {
  165. dol_print_error($this->db);
  166. }
  167. }
  168. }
  169. /**
  170. * Method to show box
  171. *
  172. * @param array $head Array with properties of box title
  173. * @param array $contents Array with properties of box lines
  174. * @param int $nooutput No print, only return string
  175. * @return string
  176. */
  177. public function showBox($head = null, $contents = null, $nooutput = 0)
  178. {
  179. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  180. }
  181. }