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