dolibarr 20.0.2
box_activity.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Charles-François BENKE <charles.fr@benke.fr>
3 * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014-2021 Frederic France <frederic.france@netlogic.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27
32{
33 public $boxcode = "activity";
34 public $boximg = "object_bill";
35 public $boxlabel = 'BoxGlobalActivity';
36 public $depends = array("facture");
37
38 public $enabled = 1;
39
46 public function __construct($db, $param)
47 {
48 global $conf, $user;
49
50 $this->db = $db;
51
52 // FIXME: Pb into some status
53 $this->enabled = getDolGlobalInt('MAIN_FEATURES_LEVEL'); // Not enabled by default due to bugs (see previous comments)
54
55 $this->hidden = !(
56 (isModEnabled('invoice') && $user->hasRight('facture', 'read'))
57 || (isModEnabled('order') && $user->hasRight('commande', 'read'))
58 || (isModEnabled('propal') && $user->hasRight('propal', 'read'))
59 );
60 }
61
68 public function loadBox($max = 5)
69 {
70 global $conf, $user, $langs;
71
72 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
73 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
74
75 $totalnb = 0;
76 $line = 0;
77 $now = dol_now();
78 $nbofperiod = 3;
79
80 // Force use of cache for this box as it has very bad performances
81 $savMAIN_ACTIVATE_FILECACHE = getDolGlobalInt('MAIN_ACTIVATE_FILECACHE');
82 $conf->global->MAIN_ACTIVATE_FILECACHE = 1;
83
84 if (getDolGlobalString('MAIN_BOX_ACTIVITY_DURATION')) {
85 $nbofperiod = getDolGlobalString('MAIN_BOX_ACTIVITY_DURATION');
86 }
87
88 $textHead = $langs->trans("Activity").' - '.$langs->trans("LastXMonthRolling", $nbofperiod);
89 $this->info_box_head = array(
90 'text' => $textHead,
91 'limit'=> dol_strlen($textHead),
92 );
93
94 // compute the year limit to show
95 $tmpdate = dol_time_plus_duree(dol_now(), -1 * $nbofperiod, "m");
96
97
98 // list the summary of the propals
99 if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
100 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
101 $propalstatic = new Propal($this->db);
102
103 $data = array();
104
105 $sql = "SELECT p.fk_statut, SUM(p.total_ttc) as Mnttot, COUNT(*) as nb";
106 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
107 if (!$user->hasRight('societe', 'client', 'voir')) {
108 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
109 }
110 $sql .= ")";
111 $sql .= " WHERE p.entity IN (".getEntity('propal').")";
112 $sql .= " AND p.fk_soc = s.rowid";
113 if (!$user->hasRight('societe', 'client', 'voir')) {
114 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
115 }
116 if ($user->socid) {
117 $sql .= " AND s.rowid = ".((int) $user->socid);
118 }
119 $sql .= " AND p.datep >= '".$this->db->idate($tmpdate)."'";
120 $sql .= " AND p.date_cloture IS NULL"; // just unclosed
121 $sql .= " GROUP BY p.fk_statut";
122 $sql .= " ORDER BY p.fk_statut DESC";
123
124 $result = $this->db->query($sql);
125 if ($result) {
126 $num = $this->db->num_rows($result);
127
128 $j = 0;
129 while ($j < $num) {
130 $data[$j] = $this->db->fetch_object($result);
131
132 $j++;
133 }
134
135 $this->db->free($result);
136 } else {
137 dol_print_error($this->db);
138 }
139
140 if (!empty($data)) {
141 $j = 0;
142 while ($j < count($data)) {
143 $this->info_box_contents[$line][0] = array(
144 'td' => 'class="left" width="16"',
145 'url' => DOL_URL_ROOT."/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".((int) $data[$j]->fk_statut),
146 'tooltip' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
147 'logo' => 'object_propal'
148 );
149
150 $this->info_box_contents[$line][1] = array(
151 'td' => '',
152 'text' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
153 );
154
155 $this->info_box_contents[$line][2] = array(
156 'td' => 'class="right"',
157 'text' => $data[$j]->nb,
158 'tooltip' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
159 'url' => DOL_URL_ROOT."/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".((int) $data[$j]->fk_statut),
160 );
161 $totalnb += $data[$j]->nb;
162
163 $this->info_box_contents[$line][3] = array(
164 'td' => 'class="nowraponall right amount"',
165 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
166 );
167 $this->info_box_contents[$line][4] = array(
168 'td' => 'class="right" width="18"',
169 'text' => $propalstatic->LibStatut($data[$j]->fk_statut, 3),
170 );
171
172 $line++;
173 $j++;
174 }
175 if (count($data) == 0) {
176 $this->info_box_contents[$line][0] = array(
177 'td' => 'class="center"',
178 'text'=>'<span class="opacitymedium">'.$langs->trans("NoRecordedProposals").'</span>',
179 );
180 $line++;
181 }
182 }
183 }
184
185 // list the summary of the orders
186 if (isModEnabled('order') && $user->hasRight("commande", "lire")) {
187 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
188 $commandestatic = new Commande($this->db);
189
190 $langs->load("orders");
191
192 $data = array();
193
194 $sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb";
195 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
196 if (!$user->hasRight('societe', 'client', 'voir')) {
197 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
198 }
199 $sql .= ")";
200 $sql .= " WHERE c.entity IN (".getEntity('commande').")";
201 $sql .= " AND c.fk_soc = s.rowid";
202 if (!$user->hasRight('societe', 'client', 'voir')) {
203 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
204 }
205 if ($user->socid) {
206 $sql .= " AND s.rowid = ".((int) $user->socid);
207 }
208 $sql .= " AND c.date_commande >= '".$this->db->idate($tmpdate)."'";
209 $sql .= " GROUP BY c.fk_statut";
210 $sql .= " ORDER BY c.fk_statut DESC";
211
212 $result = $this->db->query($sql);
213 if ($result) {
214 $num = $this->db->num_rows($result);
215 $j = 0;
216 while ($j < $num) {
217 $data[$j] = $this->db->fetch_object($result);
218 $j++;
219 }
220
221 $this->db->free($result);
222 } else {
223 dol_print_error($this->db);
224 }
225
226 if (!empty($data)) {
227 $j = 0;
228 while ($j < count($data)) {
229 $this->info_box_contents[$line][0] = array(
230 'td' => 'class="left" width="16"',
231 'url' => DOL_URL_ROOT."/commande/list.php?mainmenu=commercial&amp;leftmenu=orders&amp;search_status=".$data[$j]->fk_statut,
232 'tooltip' => $langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
233 'logo' => 'object_order',
234 );
235
236 $this->info_box_contents[$line][1] = array(
237 'td' => '',
238 'text' =>$langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
239 );
240
241 $this->info_box_contents[$line][2] = array(
242 'td' => 'class="right"',
243 'text' => $data[$j]->nb,
244 'tooltip' => $langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
245 'url' => DOL_URL_ROOT."/commande/list.php?mainmenu=commercial&amp;leftmenu=orders&amp;search_status=".$data[$j]->fk_statut,
246 );
247 $totalnb += $data[$j]->nb;
248
249 $this->info_box_contents[$line][3] = array(
250 'td' => 'class="nowraponall right amount"',
251 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
252 );
253 $this->info_box_contents[$line][4] = array(
254 'td' => 'class="right" width="18"',
255 'text' => $commandestatic->LibStatut($data[$j]->fk_statut, 0, 3),
256 );
257
258 $line++;
259 $j++;
260 }
261 if (count($data) == 0) {
262 $this->info_box_contents[$line][0] = array(
263 'td' => 'class="center"',
264 'text'=>$langs->trans("NoRecordedOrders"),
265 );
266 $line++;
267 }
268 }
269 }
270
271
272 // list the summary of the bills
273 if (isModEnabled('invoice') && $user->hasRight("facture", "lire")) {
274 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
275 $facturestatic = new Facture($this->db);
276
277 // part 1
278 $data = array();
279 $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
280 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
281 if (!$user->hasRight('societe', 'client', 'voir')) {
282 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
283 }
284 $sql .= ")";
285 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
286 if (!$user->hasRight('societe', 'client', 'voir')) {
287 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
288 }
289 if ($user->socid) {
290 $sql .= " AND s.rowid = ".((int) $user->socid);
291 }
292 $sql .= " AND f.fk_soc = s.rowid";
293 $sql .= " AND f.datef >= '".$this->db->idate($tmpdate)."' AND f.paye=1";
294 $sql .= " GROUP BY f.fk_statut";
295 $sql .= " ORDER BY f.fk_statut DESC";
296
297 $result = $this->db->query($sql);
298 if ($result) {
299 $num = $this->db->num_rows($result);
300 $j = 0;
301 while ($j < $num) {
302 $data[$j] = $this->db->fetch_object($result);
303 $j++;
304 }
305
306 $this->db->free($result);
307 } else {
308 dol_print_error($this->db);
309 }
310
311 if (!empty($data)) {
312 $j = 0;
313 while ($j < count($data)) {
314 $billurl = "search_status=2&paye=1";
315 $this->info_box_contents[$line][0] = array(
316 'td' => 'class="left" width="16"',
317 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
318 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
319 'logo' => 'bill',
320 );
321
322 $this->info_box_contents[$line][1] = array(
323 'td' => '',
324 'text' => $langs->trans("Bills")."&nbsp;".$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
325 );
326
327 $this->info_box_contents[$line][2] = array(
328 'td' => 'class="right"',
329 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
330 'text' => $data[$j]->nb,
331 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
332 );
333
334 $this->info_box_contents[$line][3] = array(
335 'td' => 'class="nowraponall right amount"',
336 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)
337 );
338
339 // We add only for the current year
340 $totalnb += $data[$j]->nb;
341
342 $this->info_box_contents[$line][4] = array(
343 'td' => 'class="right" width="18"',
344 'text' => $facturestatic->LibStatut(1, $data[$j]->fk_statut, 3),
345 );
346 $line++;
347 $j++;
348 }
349 if (count($data) == 0) {
350 $this->info_box_contents[$line][0] = array(
351 'td' => 'class="center"',
352 'text'=>$langs->trans("NoRecordedInvoices"),
353 );
354 $line++;
355 }
356 }
357
358 // part 2
359 $data = array();
360 $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
361 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
362 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
363 $sql .= " AND f.fk_soc = s.rowid";
364 $sql .= " AND f.datef >= '".$this->db->idate($tmpdate)."' AND f.paye=0";
365 $sql .= " GROUP BY f.fk_statut";
366 $sql .= " ORDER BY f.fk_statut DESC";
367
368 $result = $this->db->query($sql);
369 if ($result) {
370 $num = $this->db->num_rows($result);
371 $j = 0;
372 while ($j < $num) {
373 $data[$j] = $this->db->fetch_object($result);
374 $j++;
375 }
376
377 $this->db->free($result);
378 } else {
379 dol_print_error($this->db);
380 }
381
382 if (!empty($data)) {
383 $alreadypaid = -1;
384
385 $j = 0;
386 while ($j < count($data)) {
387 $billurl = "search_status=".$data[$j]->fk_statut."&paye=0";
388 $this->info_box_contents[$line][0] = array(
389 'td' => 'class="left" width="16"',
390 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
391 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
392 'logo' => 'bill',
393 );
394
395 $this->info_box_contents[$line][1] = array(
396 'td' => '',
397 'text' => $langs->trans("Bills")."&nbsp;".$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
398 );
399
400 $this->info_box_contents[$line][2] = array(
401 'td' => 'class="right"',
402 'text' => $data[$j]->nb,
403 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
404 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&amp;mainmenu=accountancy&amp;leftmenu=customers_bills",
405 );
406 $totalnb += $data[$j]->nb;
407 $this->info_box_contents[$line][3] = array(
408 'td' => 'class="nowraponall right amount"',
409 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
410 );
411 $this->info_box_contents[$line][4] = array(
412 'td' => 'class="right" width="18"',
413 'text' => $facturestatic->LibStatut(0, $data[$j]->fk_statut, 3, $alreadypaid),
414 );
415 $line++;
416 $j++;
417 }
418 if (count($data) == 0) {
419 $this->info_box_contents[$line][0] = array(
420 'td' => 'class="center"',
421 'text'=>$langs->trans("NoRecordedUnpaidInvoices"),
422 );
423 $line++;
424 }
425 }
426 }
427
428 // Add the sum in the bottom of the boxes
429 $this->info_box_contents[$line][0] = array('tr' => 'class="liste_total_wrap"');
430 $this->info_box_contents[$line][1] = array('td' => 'class="liste_total left" ', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
431 $this->info_box_contents[$line][2] = array('td' => 'class="liste_total right" ', 'text' => $totalnb);
432 $this->info_box_contents[$line][3] = array('td' => 'class="liste_total right" ', 'text' => '');
433 $this->info_box_contents[$line][4] = array('td' => 'class="liste_total right" ', 'text' => "");
434
435 $conf->global->MAIN_ACTIVATE_FILECACHE = $savMAIN_ACTIVATE_FILECACHE;
436 }
437
438
447 public function showBox($head = null, $contents = null, $nooutput = 0)
448 {
449 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
450 }
451}
Class to manage customers orders.
Class to manage invoices.
Class ModeleBoxes.
Class to manage proposals.
Class to manage the box of customer activity (invoice, order, proposal)
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=5)
Charge les donnees en memoire pour affichage ulterieur.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.