dolibarr  21.0.0-alpha
box_project.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 
32 class box_project extends ModeleBoxes
33 {
34  public $boxcode = "project";
35  public $boximg = "object_projectpub";
36  public $boxlabel;
37  // var $depends = array("projet");
38 
45  public function __construct($db, $param = '')
46  {
47  global $user, $langs;
48 
49  // Load translation files required by the page
50  $langs->loadLangs(array('boxes', 'projects'));
51 
52  $this->db = $db;
53  $this->boxlabel = "OpenedProjects";
54 
55  $this->hidden = !$user->hasRight('projet', 'lire');
56  }
57 
64  public function loadBox($max = 5)
65  {
66  global $conf, $user, $langs;
67 
68  $this->max = $max;
69 
70  $totalMnt = 0;
71  $totalnb = 0;
72  $totalnbTask = 0;
73 
74  $textHead = $langs->trans("OpenedProjects");
75  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
76 
77  $i = 0;
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  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
82  $projectstatic = new Project($this->db);
83  $companystatic = new Societe($this->db);
84 
85  $socid = 0;
86  //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 assignment.
87 
88  // Get list of project id allowed to user (in a string list separated by coma)
89  $projectsListId = '';
90  if (!$user->hasRight('projet', 'all', 'lire')) {
91  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
92  }
93 
94  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public, p.fk_soc,";
95  $sql .= " s.nom as name, s.name_alias";
96  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
97  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
98  $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
99  $sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
100  if (!$user->hasRight('projet', 'all', 'lire')) {
101  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
102  }
103 
104  $sql .= " ORDER BY p.datec DESC";
105  //$sql.= $this->db->plimit($max, 0);
106 
107  $result = $this->db->query($sql);
108 
109  if ($result) {
110  $num = $this->db->num_rows($result);
111  while ($i < min($num, $max)) {
112  $objp = $this->db->fetch_object($result);
113 
114  $projectstatic->id = $objp->rowid;
115  $projectstatic->ref = $objp->ref;
116  $projectstatic->title = $objp->title;
117  $projectstatic->public = $objp->public;
118  $projectstatic->statut = $objp->status;
119 
120  $companystatic->id = $objp->fk_soc;
121  $companystatic->name = $objp->name;
122  $companystatic->name_alias = $objp->name_alias;
123 
124  $this->info_box_contents[$i][] = array(
125  'td' => 'class="nowraponall"',
126  'text' => $projectstatic->getNomUrl(1),
127  'asis' => 1
128  );
129 
130  $this->info_box_contents[$i][] = array(
131  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
132  'text' => $objp->title,
133  );
134 
135  $this->info_box_contents[$i][] = array(
136  'td' => 'class="tdoverflowmax100"',
137  'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
138  'asis' => 1
139  );
140 
141  $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
142  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
143  $sql .= " WHERE p.entity IN (".getEntity('project').')';
144  $sql .= " AND p.rowid = ".((int) $objp->rowid);
145 
146  $resultTask = $this->db->query($sql);
147  if ($resultTask) {
148  $objTask = $this->db->fetch_object($resultTask);
149  $this->info_box_contents[$i][] = array(
150  'td' => 'class="right"',
151  'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
152  );
153  if ($objTask->nb > 0) {
154  $this->info_box_contents[$i][] = array(
155  'td' => 'class="right"',
156  'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
157  );
158  } else {
159  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
160  }
161  $totalnbTask += $objTask->nb;
162  } else {
163  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
164  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
165  }
166  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
167 
168  $i++;
169  }
170  if ($max < $num) {
171  $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
172  $i++;
173  }
174  }
175  }
176 
177 
178  // Add the sum à the bottom of the boxes
179  $this->info_box_contents[$i][] = array(
180  'tr' => 'class="liste_total_wrap"',
181  'td' => 'class="liste_total"',
182  'text' => $langs->trans("Total")."&nbsp;".$textHead,
183  );
184  $this->info_box_contents[$i][] = array(
185  'td' => 'class="right liste_total" ',
186  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
187  );
188  $this->info_box_contents[$i][] = array(
189  'td' => 'class="right liste_total" ',
190  'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
191  );
192  $this->info_box_contents[$i][] = array(
193  'td' => 'class="liste_total"',
194  'text' => "&nbsp;",
195  );
196  $this->info_box_contents[$i][] = array(
197  'td' => 'class="liste_total"',
198  'text' => "&nbsp;",
199  );
200  $this->info_box_contents[$i][] = array(
201  'td' => 'class="liste_total"',
202  'text' => "&nbsp;",
203  );
204  }
205 
214  public function showBox($head = null, $contents = null, $nooutput = 0)
215  {
216  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
217  }
218 }
Class ModeleBoxes.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last project.
Definition: box_project.php:33
loadBox($max=5)
Load data for box to show them later.
Definition: box_project.php:64
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
Definition: box_project.php:45
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.