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