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