dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
6  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
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";
31 
32 $hookmanager = new HookManager($db);
33 
34 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
35 $hookmanager->initHooks(array('contractindex'));
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('products', 'companies', 'contracts'));
39 
40 $sortfield = GETPOST('sortfield', 'aZ09comma');
41 $sortorder = GETPOST('sortorder', 'aZ09comma');
42 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
43 
44 $statut = GETPOST('statut') ?GETPOST('statut') : 1;
45 
46 // Security check
47 $socid = 0;
48 $id = GETPOST('id', 'int');
49 if (!empty($user->socid)) {
50  $socid = $user->socid;
51 }
52 $result = restrictedArea($user, 'contrat', $id);
53 
54 $staticcompany = new Societe($db);
55 $staticcontrat = new Contrat($db);
56 $staticcontratligne = new ContratLigne($db);
57 $productstatic = new Product($db);
58 
59 
60 /*
61  * Action
62  */
63 
64 // None
65 
66 
67 /*
68  * View
69  */
70 
71 $now = dol_now();
72 
73 llxHeader();
74 
75 print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract');
76 
77 
78 print '<div class="fichecenter"><div class="fichethirdleft">';
79 
80 
81 /*
82  * Statistics
83  */
84 
85 $nb = array();
86 $total = 0;
87 $totalinprocess = 0;
88 $dataseries = array();
89 $vals = array();
90 
91 // Search by status (except expired)
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";
97 }
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).")";
101 if ($user->socid) {
102  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
103 }
104 if (empty($user->rights->societe->client->voir) && !$socid) {
105  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
106 }
107 $sql .= " GROUP BY cd.statut";
108 $resql = $db->query($sql);
109 if ($resql) {
110  $num = $db->num_rows($resql);
111  $i = 0;
112  while ($i < $num) {
113  $obj = $db->fetch_object($resql);
114  if ($obj) {
115  $nb[$obj->status] = $obj->nb;
116  if ($obj->status != 5) {
117  $vals[$obj->status] = $obj->nb;
118  $totalinprocess += $obj->nb;
119  }
120  $total += $obj->nb;
121  }
122  $i++;
123  }
124  $db->free($resql);
125 } else {
126  dol_print_error($db);
127 }
128 // Search by status (only expired)
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";
134 }
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).")";
138 if ($user->socid) {
139  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
140 }
141 if (empty($user->rights->societe->client->voir) && !$socid) {
142  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
143 }
144 $sql .= " GROUP BY cd.statut";
145 $resql = $db->query($sql);
146 if ($resql) {
147  $num = $db->num_rows($resql);
148 
149  // 0 inactive, 4 active, 5 closed
150  $i = 0;
151  while ($i < $num) {
152  $obj = $db->fetch_object($resql);
153  if ($obj) {
154  $nb[$obj->status.true] = $obj->nb;
155  if ($obj->status != 5) {
156  $vals[$obj->status.true] = $obj->nb;
157  $totalinprocess += $obj->nb;
158  }
159  $total += $obj->nb;
160  }
161  $i++;
162  }
163  $db->free($resql);
164 } else {
165  dol_print_error($db);
166 }
167 
168 $colorseries = array();
169 
170 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
171 
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;
180  }
181  if ($status == ContratLigne::STATUS_OPEN && !$bool) {
182  $colorseries[$status.$bool] = $badgeStatus4;
183  }
184  if ($status == ContratLigne::STATUS_OPEN && $bool) {
185  $colorseries[$status.$bool] = $badgeStatus1;
186  }
187  if ($status == ContratLigne::STATUS_CLOSED) {
188  $colorseries[$status.$bool] = $badgeStatus6;
189  }
190 
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>';
195  print "</tr>\n";
196  }
197  if ($status == 4 && !$bool) {
198  $bool = true;
199  } else {
200  $bool = false;
201  }
202 }
203 if (!empty($conf->use_javascript_ajax)) {
204  print '<tr class="impair"><td class="center" colspan="2">';
205 
206  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
207  $dolgraph = new DolGraph();
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);
216 
217  print '</td></tr>';
218 }
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) {
226  $bool = true;
227  } else {
228  $bool = false;
229  }
230  print "</tr>\n";
231  }
232 }
233 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
234 print "</table></div><br>";
235 
236 
237 // Draft contracts
238 
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";
245  }
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);
251  }
252  if ($socid) {
253  $sql .= " AND c.fk_soc = ".((int) $socid);
254  }
255 
256  $resql = $db->query($sql);
257 
258  if ($resql) {
259  $num = $db->num_rows($resql);
260 
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>';
265  if ($num) {
266  $companystatic = new Societe($db);
267 
268  $i = 0;
269  //$tot_ttc = 0;
270  while ($i < $num) {
271  $obj = $db->fetch_object($resql);
272 
273  $staticcontrat->ref = $obj->ref;
274  $staticcontrat->id = $obj->rowid;
275 
276  $companystatic->id = $obj->socid;
277  $companystatic->name = $obj->name;
278  $companystatic->client = 1;
279 
280  print '<tr class="oddeven"><td class="nowrap">';
281  print $staticcontrat->getNomUrl(1, '');
282  print '</td>';
283  print '<td>';
284  print $companystatic->getNomUrl(1, '', 16);
285  print '</td>';
286  print '</tr>';
287  //$tot_ttc+=$obj->total_ttc;
288  $i++;
289  }
290  } else {
291  print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
292  }
293  print "</table></div><br>";
294  $db->free($resql);
295  } else {
296  dol_print_error($db);
297  }
298 }
299 
300 
301 print '</div><div class="fichetwothirdright">';
302 
303 
304 // Last modified contracts
305 $max = 5;
306 $sql = 'SELECT ';
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,";
316 }
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);
324 }
325 if ($socid) {
326  $sql .= " AND s.rowid = ".((int) $socid);
327 }
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);
331 
332 dol_syslog("contrat/index.php", LOG_DEBUG);
333 $result = $db->query($sql);
334 if ($result) {
335  $num = $db->num_rows($result);
336  $i = 0;
337 
338  print '<div class="div-table-responsive-no-min">';
339  print '<table class="noborder centpercent">';
340 
341  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", 5).'</th>';
342  print '<th class="center">'.$langs->trans("DateModification").'</th>';
343  //print '<th class="left">'.$langs->trans("Status").'</th>';
344  print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
345  print "</tr>\n";
346 
347  while ($i < $num) {
348  $obj = $db->fetch_object($result);
349  $datem = $db->jdate($obj->tms);
350 
351  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
352  $staticcontrat->id = $obj->cid;
353 
354  $staticcompany->id = $obj->socid;
355  $staticcompany->name = $obj->name;
356 
357  print '<tr class="oddeven">';
358  print '<td class="nowraponall">';
359  print $staticcontrat->getNomUrl(1, 16);
360  if ($obj->nb_late) {
361  print img_warning($langs->trans("Late"));
362  }
363  print '</td>';
364 
365  print '<td class="tdoverflowmax150">';
366  print $staticcompany->getNomUrl(1, '', 20);
367  print '</td>';
368  print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
369  print dol_print_date($datem, 'dayhour');
370  print '</td>';
371  //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
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>';
376  print "</tr>\n";
377  $i++;
378  }
379  $db->free($result);
380 
381  print "</table></div>";
382 } else {
383  dol_print_error($db);
384 }
385 
386 print '<br>';
387 
388 // Last modified services
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";
397 }
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);
405 }
406 if ($socid) {
407  $sql .= " AND s.rowid = ".((int) $socid);
408 }
409 $sql .= " ORDER BY cd.tms DESC";
410 
411 $resql = $db->query($sql);
412 if ($resql) {
413  $num = $db->num_rows($resql);
414  $i = 0;
415 
416  print '<div class="div-table-responsive-no-min">';
417  print '<table class="noborder centpercent">';
418 
419  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
420  print "</tr>\n";
421 
422  while ($i < min($num, $max)) {
423  $obj = $db->fetch_object($resql);
424 
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);
430  //if (1 == 1) print img_warning($langs->trans("Late"));
431  print '</td>';
432  print '<td>';
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);
439  } else {
440  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
441  if ($obj->label) {
442  print ' '.dol_trunc($obj->label, 20).'</a>';
443  } else {
444  print '</a> '.dol_trunc($obj->note, 20);
445  }
446  }
447  print '</td>';
448  print '<td class="tdoverflowmax125">';
449  $staticcompany->id = $obj->fk_soc;
450  $staticcompany->name = $obj->name;
451  print $staticcompany->getNomUrl(1, '', 20);
452  print '</td>';
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);
456  print '</a></td>';
457  print "</tr>\n";
458  $i++;
459  }
460  $db->free($resql);
461 
462  print "</table></div>";
463 } else {
464  dol_print_error($db);
465 }
466 
467 print '<br>';
468 
469 // Not activated services
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";
477 }
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);
487 }
488 if ($socid) {
489  $sql .= " AND s.rowid = ".((int) $socid);
490 }
491 $sql .= " ORDER BY cd.tms DESC";
492 
493 $resql = $db->query($sql);
494 if ($resql) {
495  $num = $db->num_rows($resql);
496  $i = 0;
497 
498  print '<div class="div-table-responsive-no-min">';
499  print '<table class="noborder centpercent">';
500 
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>';
502  print "</tr>\n";
503 
504  while ($i < $num) {
505  $obj = $db->fetch_object($resql);
506 
507  print '<tr class="oddeven">';
508 
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);
513  print '</td>';
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);
521  } else {
522  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
523  if ($obj->label) {
524  print ' '.dol_trunc($obj->label, 20).'</a>';
525  } else {
526  print '</a> '.dol_trunc($obj->note, 20);
527  }
528  }
529  print '</td>';
530  print '<td class="tdoverflowmax125">';
531  $staticcompany->id = $obj->fk_soc;
532  $staticcompany->name = $obj->name;
533  print $staticcompany->getNomUrl(1, '', 20);
534  print '</td>';
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);
537  print '</a></td>';
538  print "</tr>\n";
539  $i++;
540  }
541 
542  $db->free($resql);
543 
544  print "</table></div>";
545 } else {
546  dol_print_error($db);
547 }
548 
549 print '<br>';
550 
551 // Expired services
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";
559 }
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);
570 }
571 if ($socid) {
572  $sql .= " AND s.rowid = ".((int) $socid);
573 }
574 $sql .= " ORDER BY cd.tms DESC";
575 
576 $resql = $db->query($sql);
577 if ($resql) {
578  $num = $db->num_rows($resql);
579  $i = 0;
580 
581  print '<div class="div-table-responsive-no-min">';
582  print '<table class="noborder centpercent">';
583 
584  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';
585  print "</tr>\n";
586 
587  while ($i < $num) {
588  $obj = $db->fetch_object($resql);
589 
590  print '<tr class="oddeven">';
591 
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);
596  print '</td>';
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);
604  } else {
605  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
606  if ($obj->label) {
607  print ' '.dol_trunc($obj->label, 20).'</a>';
608  } else {
609  print '</a> '.dol_trunc($obj->note, 20);
610  }
611  }
612  print '</td>';
613  print '<td class="tdoverflowmax125">';
614  $staticcompany->id = $obj->fk_soc;
615  $staticcompany->name = $obj->name;
616  print $staticcompany->getNomUrl(1, '', 20);
617  print '</td>';
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);
620  print '</a></td>';
621  print "</tr>\n";
622  $i++;
623  }
624  $db->free($resql);
625 
626  print "</table></div>";
627 } else {
628  dol_print_error($db);
629 }
630 
631 
632 print '</div></div>';
633 
634 $parameters = array('user' => $user);
635 $reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
636 
637 llxFooter();
638 
639 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5190
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4830
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4507
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2500
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1589
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Product
Class to manage products or services.
Definition: product.class.php:46
ContratLigne
Class to manage lines of contracts.
Definition: contrat.class.php:2607
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4197
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2831
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30