26 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
33 public $boxcode =
"activity";
34 public $boximg =
"object_bill";
35 public $boxlabel =
'BoxGlobalActivity';
36 public $depends = array(
"facture");
46 public $info_box_head = array();
47 public $info_box_contents = array();
63 $this->enabled = ($conf->global->MAIN_FEATURES_LEVEL);
65 $this->hidden = !((
isModEnabled(
'facture') && $user->rights->facture->lire)
66 || (
isModEnabled(
'commande') && $user->rights->commande->lire)
67 || (
isModEnabled(
'propal') && $user->rights->propale->lire)
79 global $conf, $user, $langs;
81 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
82 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
87 $fileid =
'-e'.$conf->entity.
'-u'.$user->id.
'-s'.$user->socid.
'-r'.($user->rights->societe->client->voir ?
'1' :
'0').
'.cache';
91 if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) {
92 $nbofperiod = $conf->global->MAIN_BOX_ACTIVITY_DURATION;
94 $textHead = $langs->trans(
"Activity").
' - '.$langs->trans(
"LastXMonthRolling", $nbofperiod);
95 $this->info_box_head = array(
105 if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
106 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
107 $propalstatic =
new Propal($this->
db);
109 $cachedir = DOL_DATA_ROOT.
'/propale/temp';
110 $filename =
'/boxactivity-propal'.$fileid;
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";
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);
126 $sql .=
" AND s.rowid = ".((int) $user->socid);
128 $sql .=
" AND p.datep >= '".$this->db->idate($tmpdate).
"'";
129 $sql .=
" AND p.date_cloture IS NULL";
130 $sql .=
" GROUP BY p.fk_statut";
131 $sql .=
" ORDER BY p.fk_statut DESC";
133 $result = $this->
db->query($sql);
135 $num = $this->
db->num_rows($result);
139 $data[$j] = $this->
db->fetch_object($result);
142 if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) {
145 $this->
db->free($result);
155 while ($j < count($data)) {
156 $this->info_box_contents[$line][0] = array(
157 'td' =>
'class="left" width="16"',
158 'url' => DOL_URL_ROOT.
"/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".$data[$j]->fk_statut,
159 'tooltip' => $langs->trans(
"Proposals").
" ".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
160 'logo' =>
'object_propal'
163 $this->info_box_contents[$line][1] = array(
165 'text' => $langs->trans(
"Proposals").
" ".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
168 $this->info_box_contents[$line][2] = array(
169 'td' =>
'class="right"',
170 'text' => $data[$j]->nb,
171 'tooltip' => $langs->trans(
"Proposals").
" ".$propalstatic->LibStatut($data[$j]->fk_statut, 0),
172 'url' => DOL_URL_ROOT.
"/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&search_status=".$data[$j]->fk_statut,
174 $totalnb += $data[$j]->nb;
176 $this->info_box_contents[$line][3] = array(
177 'td' =>
'class="nowraponall right amount"',
178 'text' =>
price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
180 $this->info_box_contents[$line][4] = array(
181 'td' =>
'class="right" width="18"',
182 'text' => $propalstatic->LibStatut($data[$j]->fk_statut, 3),
192 if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
193 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
196 $langs->load(
"orders");
198 $cachedir = DOL_DATA_ROOT.
'/commande/temp';
199 $filename =
'/boxactivity-order'.$fileid;
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 (empty($user->rights->societe->client->voir) && !$user->socid) {
207 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
210 $sql .=
" WHERE c.entity IN (".getEntity(
'commande').
")";
211 $sql .=
" AND c.fk_soc = s.rowid";
212 if (empty($user->rights->societe->client->voir) && !$user->socid) {
213 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
216 $sql .=
" AND s.rowid = ".((int) $user->socid);
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";
222 $result = $this->
db->query($sql);
224 $num = $this->
db->num_rows($result);
227 $data[$j] = $this->
db->fetch_object($result);
230 if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) {
233 $this->
db->free($result);
243 while ($j < count($data)) {
244 $this->info_box_contents[$line][0] = array(
245 'td' =>
'class="left" width="16"',
246 'url' => DOL_URL_ROOT.
"/commande/list.php?mainmenu=commercial&leftmenu=orders&search_status=".$data[$j]->fk_statut,
247 'tooltip' => $langs->trans(
"Orders").
" ".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
248 'logo' =>
'object_order',
251 $this->info_box_contents[$line][1] = array(
253 'text' =>$langs->trans(
"Orders").
" ".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
256 $this->info_box_contents[$line][2] = array(
257 'td' =>
'class="right"',
258 'text' => $data[$j]->nb,
259 'tooltip' => $langs->trans(
"Orders").
" ".$commandestatic->LibStatut($data[$j]->fk_statut, 0, 0),
260 'url' => DOL_URL_ROOT.
"/commande/list.php?mainmenu=commercial&leftmenu=orders&search_status=".$data[$j]->fk_statut,
262 $totalnb += $data[$j]->nb;
264 $this->info_box_contents[$line][3] = array(
265 'td' =>
'class="nowraponall right amount"',
266 'text' =>
price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
268 $this->info_box_contents[$line][4] = array(
269 'td' =>
'class="right" width="18"',
270 'text' => $commandestatic->LibStatut($data[$j]->fk_statut, 0, 3),
281 if (
isModEnabled(
'facture') && $user->rights->facture->lire) {
282 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
286 $cachedir = DOL_DATA_ROOT.
'/facture/temp';
287 $filename =
'/boxactivity-invoice'.$fileid;
292 $sql =
"SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
293 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe as s,".MAIN_DB_PREFIX.
"facture as f";
294 if (empty($user->rights->societe->client->voir) && !$user->socid) {
295 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
298 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
')';
299 if (empty($user->rights->societe->client->voir) && !$user->socid) {
300 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
303 $sql .=
" AND s.rowid = ".((int) $user->socid);
305 $sql .=
" AND f.fk_soc = s.rowid";
306 $sql .=
" AND f.datef >= '".$this->db->idate($tmpdate).
"' AND f.paye=1";
307 $sql .=
" GROUP BY f.fk_statut";
308 $sql .=
" ORDER BY f.fk_statut DESC";
310 $result = $this->
db->query($sql);
312 $num = $this->
db->num_rows($result);
315 $data[$j] = $this->
db->fetch_object($result);
318 if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) {
321 $this->
db->free($result);
331 while ($j < count($data)) {
332 $billurl =
"search_status=2&paye=1";
333 $this->info_box_contents[$line][0] = array(
334 'td' =>
'class="left" width="16"',
335 'tooltip' => $langs->trans(
'Bills').
' '.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
336 'url' => DOL_URL_ROOT.
"/compta/facture/list.php?".$billurl.
"&mainmenu=accountancy&leftmenu=customers_bills",
340 $this->info_box_contents[$line][1] = array(
342 'text' => $langs->trans(
"Bills").
" ".$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
345 $this->info_box_contents[$line][2] = array(
346 'td' =>
'class="right"',
347 'tooltip' => $langs->trans(
'Bills').
' '.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0),
348 'text' => $data[$j]->nb,
349 'url' => DOL_URL_ROOT.
"/compta/facture/list.php?".$billurl.
"&mainmenu=accountancy&leftmenu=customers_bills",
352 $this->info_box_contents[$line][3] = array(
353 'td' =>
'class="nowraponall right amount"',
354 'text' =>
price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)
358 $totalnb += $data[$j]->nb;
360 $this->info_box_contents[$line][4] = array(
361 'td' =>
'class="right" width="18"',
362 'text' => $facturestatic->LibStatut(1, $data[$j]->fk_statut, 3),
367 if (count($data) == 0) {
368 $this->info_box_contents[$line][0] = array(
369 'td' =>
'class="center"',
370 'text'=>$langs->trans(
"NoRecordedInvoices"),
376 $cachedir = DOL_DATA_ROOT.
'/facture/temp';
377 $filename =
'/boxactivity-invoice2'.$fileid;
383 $sql =
"SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
384 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s,".MAIN_DB_PREFIX.
"facture as f";
385 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
')';
386 $sql .=
" AND f.fk_soc = s.rowid";
387 $sql .=
" AND f.datef >= '".$this->db->idate($tmpdate).
"' AND f.paye=0";
388 $sql .=
" GROUP BY f.fk_statut";
389 $sql .=
" ORDER BY f.fk_statut DESC";
391 $result = $this->
db->query($sql);
393 $num = $this->
db->num_rows($result);
396 $data[$j] = $this->
db->fetch_object($result);
399 if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) {
402 $this->
db->free($result);
414 while ($j < count($data)) {
415 $billurl =
"search_status=".$data[$j]->fk_statut.
"&paye=0";
416 $this->info_box_contents[$line][0] = array(
417 'td' =>
'class="left" width="16"',
418 'tooltip' => $langs->trans(
'Bills').
' '.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
419 'url' => DOL_URL_ROOT.
"/compta/facture/list.php?".$billurl.
"&mainmenu=accountancy&leftmenu=customers_bills",
423 $this->info_box_contents[$line][1] = array(
425 'text' => $langs->trans(
"Bills").
" ".$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
428 $this->info_box_contents[$line][2] = array(
429 'td' =>
'class="right"',
430 'text' => $data[$j]->nb,
431 'tooltip' => $langs->trans(
'Bills').
' '.$facturestatic->LibStatut(0, $data[$j]->fk_statut, 0),
432 'url' => DOL_URL_ROOT.
"/compta/facture/list.php?".$billurl.
"&mainmenu=accountancy&leftmenu=customers_bills",
434 $totalnb += $data[$j]->nb;
435 $this->info_box_contents[$line][3] = array(
436 'td' =>
'class="nowraponall right amount"',
437 'text' =>
price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency),
439 $this->info_box_contents[$line][4] = array(
440 'td' =>
'class="right" width="18"',
441 'text' => $facturestatic->LibStatut(0, $data[$j]->fk_statut, 3, $alreadypaid),
446 if (count($data) == 0) {
447 $this->info_box_contents[$line][0] = array(
448 'td' =>
'class="center"',
449 'text'=>$langs->trans(
"NoRecordedInvoices"),
456 $this->info_box_contents[$line][0] = array(
'tr' =>
'class="liste_total_wrap"');
457 $this->info_box_contents[$line][1] = array(
'td' =>
'class="liste_total left" ',
'text' => $langs->trans(
"Total").
" ".$textHead);
458 $this->info_box_contents[$line][2] = array(
'td' =>
'class="liste_total right" ',
'text' => $totalnb);
459 $this->info_box_contents[$line][3] = array(
'td' =>
'class="liste_total right" ',
'text' =>
'');
460 $this->info_box_contents[$line][4] = array(
'td' =>
'class="liste_total right" ',
'text' =>
"");
472 public function showBox($head =
null, $contents =
null, $nooutput = 0)
474 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);