dolibarr 18.0.6
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
41 public $db;
42
43 public $param;
44 public $enabled = 1;
45
46 public $info_box_head = array();
47 public $info_box_contents = array();
48
49
56 public function __construct($db, $param)
57 {
58 global $conf, $user;
59
60 $this->db = $db;
61
62 // FIXME: Pb into some status
63 $this->enabled = ($conf->global->MAIN_FEATURES_LEVEL); // Not enabled by default due to bugs (see previous comments)
64
65 $this->hidden = !((isModEnabled('facture') && $user->hasRight('facture', 'read'))
66 || (isModEnabled('commande') && $user->hasRight('commande', 'read'))
67 || (isModEnabled('propal') && $user->hasRight('propal', 'read'))
68 );
69 }
70
77 public function loadBox($max = 5)
78 {
79 global $conf, $user, $langs;
80
81 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
82 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
83
84 $totalnb = 0;
85 $line = 0;
86 $now = dol_now();
87 $nbofperiod = 3;
88
89 // Force use of cache for this box as it has very bad performances
90 $savMAIN_ACTIVATE_FILECACHE = getDolGlobalInt('MAIN_ACTIVATE_FILECACHE');
91 $conf->global->MAIN_ACTIVATE_FILECACHE = 1;
92
93 if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) {
94 $nbofperiod = $conf->global->MAIN_BOX_ACTIVITY_DURATION;
95 }
96
97 $textHead = $langs->trans("Activity").' - '.$langs->trans("LastXMonthRolling", $nbofperiod);
98 $this->info_box_head = array(
99 'text' => $textHead,
100 'limit'=> dol_strlen($textHead),
101 );
102
103 // compute the year limit to show
104 $tmpdate = dol_time_plus_duree(dol_now(), -1 * $nbofperiod, "m");
105
106
107 // list the summary of the propals
108 if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
109 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
110 $propalstatic = new Propal($this->db);
111
112 $data = array();
113
114 $sql = "SELECT p.fk_statut, SUM(p.total_ttc) as Mnttot, COUNT(*) as nb";
115 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
116 if (empty($user->rights->societe->client->voir) && !$user->socid) {
117 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
118 }
119 $sql .= ")";
120 $sql .= " WHERE p.entity IN (".getEntity('propal').")";
121 $sql .= " AND p.fk_soc = s.rowid";
122 if (empty($user->rights->societe->client->voir) && !$user->socid) {
123 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
124 }
125 if ($user->socid) {
126 $sql .= " AND s.rowid = ".((int) $user->socid);
127 }
128 $sql .= " AND p.datep >= '".$this->db->idate($tmpdate)."'";
129 $sql .= " AND p.date_cloture IS NULL"; // just unclosed
130 $sql .= " GROUP BY p.fk_statut";
131 $sql .= " ORDER BY p.fk_statut DESC";
132
133 $result = $this->db->query($sql);
134 if ($result) {
135 $num = $this->db->num_rows($result);
136
137 $j = 0;
138 while ($j < $num) {
139 $data[$j] = $this->db->fetch_object($result);
140
141 $j++;
142 }
143
144 $this->db->free($result);
145 } else {
146 dol_print_error($this->db);
147 }
148
149 if (!empty($data)) {
150 $j = 0;
151 while ($j < count($data)) {
152 $this->info_box_contents[$line][0] = array(
153 'td' => 'class="left" width="16"',
154 'url' => DOL_URL_ROOT."/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".((int) $data[$j]->fk_statut),
155 'tooltip' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
156 'logo' => 'object_propal'
157 );
158
159 $this->info_box_contents[$line][1] = array(
160 'td' => '',
161 'text' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
162 );
163
164 $this->info_box_contents[$line][2] = array(
165 'td' => 'class="right"',
166 'text' => $data[$j]->nb,
167 'tooltip' => $langs->trans("Proposals")."&nbsp;".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
168 'url' => DOL_URL_ROOT."/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".((int) $data[$j]->fk_statut),
169 );
170 $totalnb += $data[$j]->nb;
171
172 $this->info_box_contents[$line][3] = array(
173 'td' => 'class="nowraponall right amount"',
174 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
175 );
176 $this->info_box_contents[$line][4] = array(
177 'td' => 'class="right" width="18"',
178 'text' => $propalstatic->LibStatut($data[$j]->fk_statut, 3),
179 );
180
181 $line++;
182 $j++;
183 }
184 if (count($data) == 0) {
185 $this->info_box_contents[$line][0] = array(
186 'td' => 'class="center"',
187 'text'=>'<span class="opacitymedium">'.$langs->trans("NoRecordedProposals").'</span>',
188 );
189 $line++;
190 }
191 }
192 }
193
194 // list the summary of the orders
195 if (isModEnabled('commande') && $user->hasRight("commande", "lire")) {
196 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
197 $commandestatic = new Commande($this->db);
198
199 $langs->load("orders");
200
201 $data = array();
202
203 $sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb";
204 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
205 if (empty($user->rights->societe->client->voir) && !$user->socid) {
206 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
207 }
208 $sql .= ")";
209 $sql .= " WHERE c.entity IN (".getEntity('commande').")";
210 $sql .= " AND c.fk_soc = s.rowid";
211 if (empty($user->rights->societe->client->voir) && !$user->socid) {
212 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
213 }
214 if ($user->socid) {
215 $sql .= " AND s.rowid = ".((int) $user->socid);
216 }
217 $sql .= " AND c.date_commande >= '".$this->db->idate($tmpdate)."'";
218 $sql .= " GROUP BY c.fk_statut";
219 $sql .= " ORDER BY c.fk_statut DESC";
220
221 $result = $this->db->query($sql);
222 if ($result) {
223 $num = $this->db->num_rows($result);
224 $j = 0;
225 while ($j < $num) {
226 $data[$j] = $this->db->fetch_object($result);
227 $j++;
228 }
229
230 $this->db->free($result);
231 } else {
232 dol_print_error($this->db);
233 }
234
235 if (!empty($data)) {
236 $j = 0;
237 while ($j < count($data)) {
238 $this->info_box_contents[$line][0] = array(
239 'td' => 'class="left" width="16"',
240 'url' => DOL_URL_ROOT."/commande/list.php?mainmenu=commercial&amp;leftmenu=orders&amp;search_status=".$data[$j]->fk_statut,
241 'tooltip' => $langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
242 'logo' => 'object_order',
243 );
244
245 $this->info_box_contents[$line][1] = array(
246 'td' => '',
247 'text' =>$langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
248 );
249
250 $this->info_box_contents[$line][2] = array(
251 'td' => 'class="right"',
252 'text' => $data[$j]->nb,
253 'tooltip' => $langs->trans("Orders")."&nbsp;".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
254 'url' => DOL_URL_ROOT."/commande/list.php?mainmenu=commercial&amp;leftmenu=orders&amp;search_status=".$data[$j]->fk_statut,
255 );
256 $totalnb += $data[$j]->nb;
257
258 $this->info_box_contents[$line][3] = array(
259 'td' => 'class="nowraponall right amount"',
260 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
261 );
262 $this->info_box_contents[$line][4] = array(
263 'td' => 'class="right" width="18"',
264 'text' => $commandestatic->LibStatut($data[$j]->fk_statut, 0, 3),
265 );
266
267 $line++;
268 $j++;
269 }
270 if (count($data) == 0) {
271 $this->info_box_contents[$line][0] = array(
272 'td' => 'class="center"',
273 'text'=>$langs->trans("NoRecordedOrders"),
274 );
275 $line++;
276 }
277 }
278 }
279
280
281 // list the summary of the bills
282 if (isModEnabled('facture') && $user->hasRight("facture", "lire")) {
283 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
284 $facturestatic = new Facture($this->db);
285
286 // part 1
287 $data = array();
288 $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
289 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
290 if (empty($user->rights->societe->client->voir) && !$user->socid) {
291 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
292 }
293 $sql .= ")";
294 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
295 if (empty($user->rights->societe->client->voir) && !$user->socid) {
296 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
297 }
298 if ($user->socid) {
299 $sql .= " AND s.rowid = ".((int) $user->socid);
300 }
301 $sql .= " AND f.fk_soc = s.rowid";
302 $sql .= " AND f.datef >= '".$this->db->idate($tmpdate)."' AND f.paye=1";
303 $sql .= " GROUP BY f.fk_statut";
304 $sql .= " ORDER BY f.fk_statut DESC";
305
306 $result = $this->db->query($sql);
307 if ($result) {
308 $num = $this->db->num_rows($result);
309 $j = 0;
310 while ($j < $num) {
311 $data[$j] = $this->db->fetch_object($result);
312 $j++;
313 }
314
315 $this->db->free($result);
316 } else {
317 dol_print_error($this->db);
318 }
319
320 if (!empty($data)) {
321 $j = 0;
322 while ($j < count($data)) {
323 $billurl = "search_status=2&paye=1";
324 $this->info_box_contents[$line][0] = array(
325 'td' => 'class="left" width="16"',
326 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
327 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
328 'logo' => 'bill',
329 );
330
331 $this->info_box_contents[$line][1] = array(
332 'td' => '',
333 'text' => $langs->trans("Bills")."&nbsp;".$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
334 );
335
336 $this->info_box_contents[$line][2] = array(
337 'td' => 'class="right"',
338 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
339 'text' => $data[$j]->nb,
340 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
341 );
342
343 $this->info_box_contents[$line][3] = array(
344 'td' => 'class="nowraponall right amount"',
345 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)
346 );
347
348 // We add only for the current year
349 $totalnb += $data[$j]->nb;
350
351 $this->info_box_contents[$line][4] = array(
352 'td' => 'class="right" width="18"',
353 'text' => $facturestatic->LibStatut(1, $data[$j]->fk_statut, 3),
354 );
355 $line++;
356 $j++;
357 }
358 if (count($data) == 0) {
359 $this->info_box_contents[$line][0] = array(
360 'td' => 'class="center"',
361 'text'=>$langs->trans("NoRecordedInvoices"),
362 );
363 $line++;
364 }
365 }
366
367 // part 2
368 $data = array();
369 $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
370 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
371 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
372 $sql .= " AND f.fk_soc = s.rowid";
373 $sql .= " AND f.datef >= '".$this->db->idate($tmpdate)."' AND f.paye=0";
374 $sql .= " GROUP BY f.fk_statut";
375 $sql .= " ORDER BY f.fk_statut DESC";
376
377 $result = $this->db->query($sql);
378 if ($result) {
379 $num = $this->db->num_rows($result);
380 $j = 0;
381 while ($j < $num) {
382 $data[$j] = $this->db->fetch_object($result);
383 $j++;
384 }
385
386 $this->db->free($result);
387 } else {
388 dol_print_error($this->db);
389 }
390
391 if (!empty($data)) {
392 $alreadypaid = -1;
393
394 $j = 0;
395 while ($j < count($data)) {
396 $billurl = "search_status=".$data[$j]->fk_statut."&paye=0";
397 $this->info_box_contents[$line][0] = array(
398 'td' => 'class="left" width="16"',
399 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
400 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
401 'logo' => 'bill',
402 );
403
404 $this->info_box_contents[$line][1] = array(
405 'td' => '',
406 'text' => $langs->trans("Bills")."&nbsp;".$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
407 );
408
409 $this->info_box_contents[$line][2] = array(
410 'td' => 'class="right"',
411 'text' => $data[$j]->nb,
412 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
413 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&amp;mainmenu=accountancy&amp;leftmenu=customers_bills",
414 );
415 $totalnb += $data[$j]->nb;
416 $this->info_box_contents[$line][3] = array(
417 'td' => 'class="nowraponall right amount"',
418 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
419 );
420 $this->info_box_contents[$line][4] = array(
421 'td' => 'class="right" width="18"',
422 'text' => $facturestatic->LibStatut(0, $data[$j]->fk_statut, 3, $alreadypaid),
423 );
424 $line++;
425 $j++;
426 }
427 if (count($data) == 0) {
428 $this->info_box_contents[$line][0] = array(
429 'td' => 'class="center"',
430 'text'=>$langs->trans("NoRecordedUnpaidInvoices"),
431 );
432 $line++;
433 }
434 }
435 }
436
437 // Add the sum in the bottom of the boxes
438 $this->info_box_contents[$line][0] = array('tr' => 'class="liste_total_wrap"');
439 $this->info_box_contents[$line][1] = array('td' => 'class="liste_total left" ', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
440 $this->info_box_contents[$line][2] = array('td' => 'class="liste_total right" ', 'text' => $totalnb);
441 $this->info_box_contents[$line][3] = array('td' => 'class="liste_total right" ', 'text' => '');
442 $this->info_box_contents[$line][4] = array('td' => 'class="liste_total right" ', 'text' => "");
443
444 $conf->global->MAIN_ACTIVATE_FILECACHE = $savMAIN_ACTIVATE_FILECACHE;
445 }
446
447
456 public function showBox($head = null, $contents = null, $nooutput = 0)
457 {
458 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
459 }
460}
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:123
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 dolibarr global constant int value.