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