box_validated_projects.php 7.0 KB

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