28 require
"../main.inc.php";
29 require_once DOL_DOCUMENT_ROOT.
"/contrat/class/contrat.class.php";
30 require_once DOL_DOCUMENT_ROOT.
"/product/class/product.class.php";
35 $hookmanager->initHooks(array(
'contractindex'));
38 $langs->loadLangs(array(
'products',
'companies',
'contracts'));
40 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
41 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
49 if (!empty($user->socid)) {
50 $socid = $user->socid;
54 $staticcompany =
new Societe($db);
55 $staticcontrat =
new Contrat($db);
57 $productstatic =
new Product($db);
78 print
'<div class="fichecenter"><div class="fichethirdleft">';
88 $dataseries = array();
92 $sql =
"SELECT count(cd.rowid) as nb, cd.statut as status";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
94 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
95 if (empty($user->rights->societe->client->voir) && !$socid) {
96 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
98 $sql .=
" WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
99 $sql .=
" AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now).
"')))";
100 $sql .=
" AND c.entity IN (".getEntity(
'contract', 0).
")";
102 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
104 if (empty($user->rights->societe->client->voir) && !$socid) {
105 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107 $sql .=
" GROUP BY cd.statut";
108 $resql = $db->query($sql);
110 $num = $db->num_rows(
$resql);
113 $obj = $db->fetch_object(
$resql);
115 $nb[$obj->status] = $obj->nb;
116 if ($obj->status != 5) {
117 $vals[$obj->status] = $obj->nb;
118 $totalinprocess += $obj->nb;
129 $sql =
"SELECT count(cd.rowid) as nb, cd.statut as status";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
131 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
132 if (empty($user->rights->societe->client->voir) && !$socid) {
133 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
135 $sql .=
" WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
136 $sql .=
" AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now).
"')";
137 $sql .=
" AND c.entity IN (".getEntity(
'contract', 0).
")";
139 $sql .=
' AND c.fk_soc = '.((int) $user->socid);
141 if (empty($user->rights->societe->client->voir) && !$socid) {
142 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
144 $sql .=
" GROUP BY cd.statut";
145 $resql = $db->query($sql);
147 $num = $db->num_rows(
$resql);
152 $obj = $db->fetch_object(
$resql);
154 $nb[$obj->status.true] = $obj->nb;
155 if ($obj->status != 5) {
156 $vals[$obj->status.true] = $obj->nb;
157 $totalinprocess += $obj->nb;
168 $colorseries = array();
170 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
172 print
'<div class="div-table-responsive-no-min">';
173 print
'<table class="noborder nohover centpercent">';
174 print
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"Services").
'</th></tr>'.
"\n";
175 $listofstatus = array(0, 4, 4, 5); $bool =
false;
176 foreach ($listofstatus as $status) {
177 $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (
int) $nb[$status.$bool] : 0));
178 if ($status == ContratLigne::STATUS_INITIAL) {
179 $colorseries[$status.$bool] =
'-'.$badgeStatus0;
181 if ($status == ContratLigne::STATUS_OPEN && !$bool) {
182 $colorseries[$status.$bool] = $badgeStatus4;
184 if ($status == ContratLigne::STATUS_OPEN && $bool) {
185 $colorseries[$status.$bool] = $badgeStatus1;
187 if ($status == ContratLigne::STATUS_CLOSED) {
188 $colorseries[$status.$bool] = $badgeStatus6;
191 if (empty($conf->use_javascript_ajax)) {
192 print
'<tr class="oddeven">';
193 print
'<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).
'</td>';
194 print
'<td class="right"><a href="services_list.php?mode='.$status.($bool ?
'&filter=expired' :
'').
'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).
' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).
'</a></td>';
197 if ($status == 4 && !$bool) {
203 if (!empty($conf->use_javascript_ajax)) {
204 print
'<tr class="impair"><td class="center" colspan="2">';
206 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
208 $dolgraph->SetData($dataseries);
209 $dolgraph->SetDataColor(array_values($colorseries));
210 $dolgraph->setShowLegend(2);
211 $dolgraph->setShowPercent(1);
212 $dolgraph->SetType(array(
'pie'));
213 $dolgraph->setHeight(
'200');
214 $dolgraph->draw(
'idgraphstatus');
215 print $dolgraph->show($total ? 0 : 1);
219 $listofstatus = array(0, 4, 4, 5); $bool =
false;
220 foreach ($listofstatus as $status) {
221 if (empty($conf->use_javascript_ajax)) {
222 print
'<tr class="oddeven">';
223 print
'<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).
'</td>';
224 print
'<td class="right"><a href="services_list.php?mode='.$status.($bool ?
'&filter=expired' :
'').
'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).
' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).
'</a></td>';
225 if ($status == 4 && !$bool) {
233 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">'.$total.
'</td></tr>';
234 print
"</table></div><br>";
239 if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
240 $sql =
"SELECT c.rowid, c.ref,";
241 $sql .=
" s.nom as name, s.rowid as socid";
242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"societe as s";
243 if (empty($user->rights->societe->client->voir) && !$socid) {
244 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
246 $sql .=
" WHERE s.rowid = c.fk_soc";
247 $sql .=
" AND c.entity IN (".getEntity(
'contract', 0).
")";
248 $sql .=
" AND c.statut = 0";
249 if (empty($user->rights->societe->client->voir) && !$socid) {
250 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
253 $sql .=
" AND c.fk_soc = ".((int) $socid);
256 $resql = $db->query($sql);
259 $num = $db->num_rows(
$resql);
261 print
'<div class="div-table-responsive-no-min">';
262 print
'<table class="noborder centpercent">';
263 print
'<tr class="liste_titre">';
264 print
'<th colspan="3">'.$langs->trans(
"DraftContracts").($num ?
'<span class="badge marginleftonlyshort">'.$num.
'</span>' :
'').
'</th></tr>';
266 $companystatic =
new Societe($db);
271 $obj = $db->fetch_object(
$resql);
273 $staticcontrat->ref = $obj->ref;
274 $staticcontrat->id = $obj->rowid;
276 $companystatic->id = $obj->socid;
277 $companystatic->name = $obj->name;
278 $companystatic->client = 1;
280 print
'<tr class="oddeven"><td class="nowrap">';
281 print $staticcontrat->getNomUrl(1,
'');
284 print $companystatic->getNomUrl(1,
'', 16);
291 print
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"NoContracts").
'</td></tr>';
293 print
"</table></div><br>";
301 print
'</div><div class="fichetwothirdright">';
307 $sql .=
" sum(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
308 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now).
"')", 1, 0).
') as nb_running,';
309 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now).
"')", 1, 0).
') as nb_expired,';
310 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay).
"')", 1, 0).
') as nb_late,';
311 $sql .=
" sum(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed,';
312 $sql .=
" c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
313 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s,";
314 if (empty($user->rights->societe->client->voir) && !$socid) {
315 $sql .=
" ".MAIN_DB_PREFIX.
"societe_commerciaux as sc,";
317 $sql .=
" ".MAIN_DB_PREFIX.
"contrat as c";
318 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
319 $sql .=
" WHERE c.fk_soc = s.rowid";
320 $sql .=
" AND c.entity IN (".getEntity(
'contract', 0).
")";
321 $sql .=
" AND c.statut > 0";
322 if (empty($user->rights->societe->client->voir) && !$socid) {
323 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
326 $sql .=
" AND s.rowid = ".((int) $socid);
328 $sql .=
" GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
329 $sql .=
" ORDER BY c.tms DESC";
330 $sql .= $db->plimit($max);
333 $result = $db->query($sql);
335 $num = $db->num_rows($result);
338 print
'<div class="div-table-responsive-no-min">';
339 print
'<table class="noborder centpercent">';
341 print
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"LastContracts", 5).
'</th>';
342 print
'<th class="center">'.$langs->trans(
"DateModification").
'</th>';
344 print
'<th class="center" width="80" colspan="4">'.$langs->trans(
"Services").
'</th>';
348 $obj = $db->fetch_object($result);
349 $datem = $db->jdate($obj->tms);
351 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
352 $staticcontrat->id = $obj->cid;
354 $staticcompany->id = $obj->socid;
355 $staticcompany->name = $obj->name;
357 print
'<tr class="oddeven">';
358 print
'<td class="nowraponall">';
359 print $staticcontrat->getNomUrl(1, 16);
365 print
'<td class="tdoverflowmax150">';
366 print $staticcompany->getNomUrl(1,
'', 20);
368 print
'<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
': '.
dol_print_date($datem,
'dayhour',
'tzuserrel')).
'">';
372 print
'<td class="right nowraponall" width="32">'.($obj->nb_initial > 0 ?
'<span class="paddingright">'.$obj->nb_initial.
'</span>'.$staticcontratligne->LibStatut(0, 3, -1,
'class="paddingleft"') :
'').
'</td>';
373 print
'<td class="right nowraponall" width="32">'.($obj->nb_running > 0 ?
'<span class="paddingright">'.$obj->nb_running.
'</span>'.$staticcontratligne->LibStatut(4, 3, 0,
'class="marginleft"') :
'').
'</td>';
374 print
'<td class="right nowraponall" width="32">'.($obj->nb_expired > 0 ?
'<span class="paddingright">'.$obj->nb_expired.
'</span>'.$staticcontratligne->LibStatut(4, 3, 1,
'class="paddingleft"') :
'').
'</td>';
375 print
'<td class="right nowraponall" width="32">'.($obj->nb_closed > 0 ?
'<span class="paddingright">'.$obj->nb_closed.
'</span>'.$staticcontratligne->LibStatut(5, 3, -1,
'class="paddingleft"') :
'').
'</td>';
381 print
"</table></div>";
389 $sql =
"SELECT c.ref, c.fk_soc, ";
390 $sql .=
" cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
391 $sql .=
" s.nom as name,";
392 $sql .=
" p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
393 $sql .=
" FROM (".MAIN_DB_PREFIX.
"contrat as c";
394 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
395 if (empty($user->rights->societe->client->voir) && !$socid) {
396 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
398 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
399 $sql .=
") LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
400 $sql .=
" WHERE c.entity IN (".getEntity(
'contract', 0).
")";
401 $sql .=
" AND cd.fk_contrat = c.rowid";
402 $sql .=
" AND c.fk_soc = s.rowid";
403 if (empty($user->rights->societe->client->voir) && !$socid) {
404 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
407 $sql .=
" AND s.rowid = ".((int) $socid);
409 $sql .=
" ORDER BY cd.tms DESC";
411 $resql = $db->query($sql);
413 $num = $db->num_rows(
$resql);
416 print
'<div class="div-table-responsive-no-min">';
417 print
'<table class="noborder centpercent">';
419 print
'<tr class="liste_titre"><th colspan="4">'.$langs->trans(
"LastModifiedServices", $max).
'</th>';
422 while ($i < min($num, $max)) {
423 $obj = $db->fetch_object(
$resql);
425 print
'<tr class="oddeven">';
426 print
'<td class="nowraponall">';
427 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
428 $staticcontrat->id = $obj->fk_contrat;
429 print $staticcontrat->getNomUrl(1, 16);
433 if ($obj->fk_product > 0) {
434 $productstatic->id = $obj->fk_product;
435 $productstatic->type = $obj->ptype;
436 $productstatic->ref = $obj->pref;
437 $productstatic->entity = $obj->pentity;
438 print $productstatic->getNomUrl(1,
'', 20);
440 print
'<a href="'.DOL_URL_ROOT.
'/contrat/card.php?id='.$obj->fk_contrat.
'">'.
img_object($langs->trans(
"ShowService"),
"service");
442 print
' '.dol_trunc($obj->label, 20).
'</a>';
444 print
'</a> '.dol_trunc($obj->note, 20);
448 print
'<td class="tdoverflowmax125">';
449 $staticcompany->id = $obj->fk_soc;
450 $staticcompany->name = $obj->name;
451 print $staticcompany->getNomUrl(1,
'', 20);
453 print
'<td class="nowrap right"><a href="'.DOL_URL_ROOT.
'/contrat/card.php?id='.$obj->fk_contrat.
'&ligne='.$obj->cid.
'">';
454 $dateend = $db->jdate($obj->date_fin_validite);
455 print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
462 print
"</table></div>";
470 $sql =
"SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
471 $sql .=
" s.nom as name,";
472 $sql .=
" p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
473 $sql .=
" FROM (".MAIN_DB_PREFIX.
"contrat as c";
474 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
475 if (empty($user->rights->societe->client->voir) && !$socid) {
476 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
478 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
479 $sql .=
" ) LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
480 $sql .=
" WHERE c.entity IN (".getEntity(
'contract', 0).
")";
481 $sql .=
" AND c.statut = 1";
482 $sql .=
" AND cd.statut = 0";
483 $sql .=
" AND cd.fk_contrat = c.rowid";
484 $sql .=
" AND c.fk_soc = s.rowid";
485 if (empty($user->rights->societe->client->voir) && !$socid) {
486 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
489 $sql .=
" AND s.rowid = ".((int) $socid);
491 $sql .=
" ORDER BY cd.tms DESC";
493 $resql = $db->query($sql);
495 $num = $db->num_rows(
$resql);
498 print
'<div class="div-table-responsive-no-min">';
499 print
'<table class="noborder centpercent">';
501 print
'<tr class="liste_titre"><th colspan="4">'.$langs->trans(
"NotActivatedServices").
' <a href="'.DOL_URL_ROOT.
'/contrat/services_list.php?mode=0"><span class="badge">'.$num.
'</span></a></th>';
505 $obj = $db->fetch_object(
$resql);
507 print
'<tr class="oddeven">';
509 print
'<td class="nowraponall">';
510 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
511 $staticcontrat->id = $obj->fk_contrat;
512 print $staticcontrat->getNomUrl(1, 16);
514 print
'<td class="nowrap">';
515 if ($obj->fk_product > 0) {
516 $productstatic->id = $obj->fk_product;
517 $productstatic->type = $obj->ptype;
518 $productstatic->ref = $obj->pref;
519 $productstatic->entity = $obj->pentity;
520 print $productstatic->getNomUrl(1,
'', 20);
522 print
'<a href="'.DOL_URL_ROOT.
'/contrat/card.php?id='.$obj->fk_contrat.
'">'.
img_object($langs->trans(
"ShowService"),
"service");
524 print
' '.dol_trunc($obj->label, 20).
'</a>';
526 print
'</a> '.dol_trunc($obj->note, 20);
530 print
'<td class="tdoverflowmax125">';
531 $staticcompany->id = $obj->fk_soc;
532 $staticcompany->name = $obj->name;
533 print $staticcompany->getNomUrl(1,
'', 20);
535 print
'<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.
'&ligne='.$obj->cid.
'">';
536 print $staticcontratligne->LibStatut($obj->statut, 3);
544 print
"</table></div>";
552 $sql =
"SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
553 $sql .=
" s.nom as name,";
554 $sql .=
" p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
555 $sql .=
" FROM (".MAIN_DB_PREFIX.
"contrat as c";
556 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
557 if (empty($user->rights->societe->client->voir) && !$socid) {
558 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
560 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
561 $sql .=
" ) LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
562 $sql .=
" WHERE c.entity IN (".getEntity(
'contract', 0).
")";
563 $sql .=
" AND c.statut = 1";
564 $sql .=
" AND cd.statut = 4";
565 $sql .=
" AND cd.date_fin_validite < '".$db->idate($now).
"'";
566 $sql .=
" AND cd.fk_contrat = c.rowid";
567 $sql .=
" AND c.fk_soc = s.rowid";
568 if (empty($user->rights->societe->client->voir) && !$socid) {
569 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
572 $sql .=
" AND s.rowid = ".((int) $socid);
574 $sql .=
" ORDER BY cd.tms DESC";
576 $resql = $db->query($sql);
578 $num = $db->num_rows(
$resql);
581 print
'<div class="div-table-responsive-no-min">';
582 print
'<table class="noborder centpercent">';
584 print
'<tr class="liste_titre"><th colspan="4">'.$langs->trans(
"ListOfExpiredServices").
' <a href="'.DOL_URL_ROOT.
'/contrat/services_list.php?mode=4&filter=expired"><span class="badge">'.$num.
'</span></a></th>';
588 $obj = $db->fetch_object(
$resql);
590 print
'<tr class="oddeven">';
592 print
'<td class="nowraponall">';
593 $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
594 $staticcontrat->id = $obj->fk_contrat;
595 print $staticcontrat->getNomUrl(1, 16);
597 print
'<td class="nowrap">';
598 if ($obj->fk_product > 0) {
599 $productstatic->id = $obj->fk_product;
600 $productstatic->type = $obj->ptype;
601 $productstatic->ref = $obj->pref;
602 $productstatic->entity = $obj->pentity;
603 print $productstatic->getNomUrl(1,
'', 20);
605 print
'<a href="'.DOL_URL_ROOT.
'/contrat/card.php?id='.$obj->fk_contrat.
'">'.
img_object($langs->trans(
"ShowService"),
"service");
607 print
' '.dol_trunc($obj->label, 20).
'</a>';
609 print
'</a> '.dol_trunc($obj->note, 20);
613 print
'<td class="tdoverflowmax125">';
614 $staticcompany->id = $obj->fk_soc;
615 $staticcompany->name = $obj->name;
616 print $staticcompany->getNomUrl(1,
'', 20);
618 print
'<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.
'&ligne='.$obj->cid.
'">';
619 print $staticcontratligne->LibStatut($obj->statut, 3, 1);
626 print
"</table></div>";
632 print
'</div></div>';
634 $parameters = array(
'user' => $user);
635 $reshook = $hookmanager->executeHooks(
'dashboardContracts', $parameters, $object);