dolibarr  16.0.5
box_validated_projects.php
Go to the documentation of this file.
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 
27 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28 
29 
34 {
35  public $boxcode = "validated_project";
36  public $boximg = "object_projectpub";
37  public $boxlabel;
38  //var $depends = array("projet");
39 
43  public $db;
44 
45  public $param;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50  public $enabled = 1;
51 
52 
59  public function __construct($db, $param = '')
60  {
61  global $conf, $user, $langs;
62 
63  // Load translation files required by the page
64  $langs->loadLangs(array('boxes', 'projects'));
65 
66  $this->db = $db;
67  $this->boxlabel = "ProjectTasksWithoutTimeSpent";
68 
69  $this->hidden = empty($user->rights->projet->lire);
70 
71  if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
72  $this->enabled = 0;
73  }
74  }
75 
82  public function loadBox($max = 5)
83  {
84  global $conf, $user, $langs;
85 
86  $this->max = $max;
87 
88  $totalMnt = 0;
89  $totalnb = 0;
90  $totalnbTask = 0;
91 
92  $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
93  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
94 
95  // list the summary of the orders
96  if ($user->rights->projet->lire) {
97  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
98  $projectstatic = new Project($this->db);
99 
100  $socid = 0;
101  //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.
102 
103  // Get list of project id allowed to user (in a string list separated by coma)
104  $projectsListId = '';
105  if (empty($user->rights->projet->all->lire)) {
106  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
107  }
108 
109  // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
110  // Count of tasks without time spent for tasks we are assigned too or
111  // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
112  $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
113  $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
114  $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
115  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
116  // 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.
117  $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)";
118  $sql .= " WHERE p.fk_statut = 1"; // Only open projects
119  if ($projectsListId) {
120  $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed
121  }
122  $sql .= " AND t.rowid NOT IN (SELECT fk_task FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_user = ".((int) $user->id).")";
123  $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
124  $sql .= " ORDER BY p.dateo ASC";
125 
126  $result = $this->db->query($sql);
127  if ($result) {
128  $num = $this->db->num_rows($result);
129  $i = 0;
130  $this->info_box_contents[$i][] = array(
131  'td' => 'class="nowraponall"',
132  'text' => "Reference projet",
133  );
134  $this->info_box_contents[$i][] = array(
135  'td' => 'class="center"',
136  'text' => 'Client',
137  );
138  $this->info_box_contents[$i][] = array(
139  'td' => 'class="center"',
140  'text' => 'Date debut de projet',
141  );
142  $this->info_box_contents[$i][] = array(
143  'td' => 'class="center"',
144  'text' => 'Nombre de mes tâches sans temps saisi',
145  );
146  $i++;
147 
148  while ($i < min($num + 1, $max + 1)) {
149  $objp = $this->db->fetch_object($result);
150 
151  $projectstatic->id = $objp->rowid;
152  $projectstatic->ref = $objp->ref;
153 
154  $this->info_box_contents[$i][] = array(
155  'td' => 'class="nowraponall"',
156  'text' => $projectstatic->getNomUrl(1),
157  'asis' => 1
158  );
159 
160  if ($objp->fk_soc > 0) {
161  $sql = "SELECT rowid, nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $objp->fk_soc);
162  $resql = $this->db->query($sql);
163  //$socstatic = new Societe($this->db);
164  $obj2 = $this->db->fetch_object($resql);
165  $this->info_box_contents[$i][] = array(
166  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
167  'text' => $obj2->name,
168  'asis' => 1,
169  'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
170  );
171  } else {
172  $this->info_box_contents[$i][] = array(
173  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
174  'text' => '',
175  'asis' => 1,
176  'url' => ''
177  );
178  }
179 
180  $this->info_box_contents[$i][] = array(
181  'td' => 'class="center"',
182  'text' => $objp->startDate,
183  );
184 
185  $this->info_box_contents[$i][] = array(
186  'td' => 'class="center"',
187  'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
188  'asis' => 1,
189  );
190  $i++;
191  }
192  } else {
193  dol_print_error($this->db);
194  }
195  }
196  }
197 
206  public function showBox($head = null, $contents = null, $nooutput = 0)
207  {
208  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
209  }
210 }
db
$conf db
API class for accounts.
Definition: inc.php:41
Project
Class to manage projects.
Definition: project.class.php:35
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
box_validated_projects\loadBox
loadBox($max=5)
Load data for box to show them later.
Definition: box_validated_projects.php:82
box_validated_projects\__construct
__construct($db, $param='')
Constructor.
Definition: box_validated_projects.php:59
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
box_validated_projects\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_validated_projects.php:206
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
box_validated_projects
Class to manage the box to show last projet.
Definition: box_validated_projects.php:33
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34