dolibarr  x.y.z
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 $title = $langs->trans("ContractsArea");
74 $help_url = '';
75 
76 llxHeader('', $title, $help_url);
77 
78 print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract');
79 
80 
81 print '<div class="fichecenter"><div class="fichethirdleft">';
82 
83 
84 /*
85  * Statistics
86  */
87 
88 $nb = array();
89 $total = 0;
90 $totalinprocess = 0;
91 $dataseries = array();
92 $vals = array();
93 
94 // Search by status (except expired)
95 $sql = "SELECT count(cd.rowid) as nb, cd.statut as status";
96 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
97 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
98 if (empty($user->rights->societe->client->voir) && !$socid) {
99  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
100 }
101 $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
102 $sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
103 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
104 if ($user->socid) {
105  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
106 }
107 if (empty($user->rights->societe->client->voir) && !$socid) {
108  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
109 }
110 $sql .= " GROUP BY cd.statut";
111 $resql = $db->query($sql);
112 if ($resql) {
113  $num = $db->num_rows($resql);
114  $i = 0;
115  while ($i < $num) {
116  $obj = $db->fetch_object($resql);
117  if ($obj) {
118  $nb[$obj->status] = $obj->nb;
119  if ($obj->status != 5) {
120  $vals[$obj->status] = $obj->nb;
121  $totalinprocess += $obj->nb;
122  }
123  $total += $obj->nb;
124  }
125  $i++;
126  }
127  $db->free($resql);
128 } else {
129  dol_print_error($db);
130 }
131 // Search by status (only expired)
132 $sql = "SELECT count(cd.rowid) as nb, cd.statut as status";
133 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
134 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
135 if (empty($user->rights->societe->client->voir) && !$socid) {
136  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
137 }
138 $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
139 $sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
140 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
141 if ($user->socid) {
142  $sql .= ' AND c.fk_soc = '.((int) $user->socid);
143 }
144 if (empty($user->rights->societe->client->voir) && !$socid) {
145  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
146 }
147 $sql .= " GROUP BY cd.statut";
148 $resql = $db->query($sql);
149 if ($resql) {
150  $num = $db->num_rows($resql);
151 
152  // 0 inactive, 4 active, 5 closed
153  $i = 0;
154  while ($i < $num) {
155  $obj = $db->fetch_object($resql);
156  if ($obj) {
157  $nb[$obj->status.true] = $obj->nb;
158  if ($obj->status != 5) {
159  $vals[$obj->status.true] = $obj->nb;
160  $totalinprocess += $obj->nb;
161  }
162  $total += $obj->nb;
163  }
164  $i++;
165  }
166  $db->free($resql);
167 } else {
168  dol_print_error($db);
169 }
170 
171 $colorseries = array();
172 
173 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
174 
175 print '<div class="div-table-responsive-no-min">';
176 print '<table class="noborder nohover centpercent">';
177 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
178 $listofstatus = array(0, 4, 4, 5); $bool = false;
179 foreach ($listofstatus as $status) {
180  $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (int) $nb[$status.$bool] : 0));
181  if ($status == ContratLigne::STATUS_INITIAL) {
182  $colorseries[$status.$bool] = '-'.$badgeStatus0;
183  }
184  if ($status == ContratLigne::STATUS_OPEN && !$bool) {
185  $colorseries[$status.$bool] = $badgeStatus4;
186  }
187  if ($status == ContratLigne::STATUS_OPEN && $bool) {
188  $colorseries[$status.$bool] = $badgeStatus1;
189  }
190  if ($status == ContratLigne::STATUS_CLOSED) {
191  $colorseries[$status.$bool] = $badgeStatus6;
192  }
193 
194  if (empty($conf->use_javascript_ajax)) {
195  print '<tr class="oddeven">';
196  print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
197  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>';
198  print "</tr>\n";
199  }
200  if ($status == 4 && !$bool) {
201  $bool = true;
202  } else {
203  $bool = false;
204  }
205 }
206 if (!empty($conf->use_javascript_ajax)) {
207  print '<tr class="impair"><td class="center" colspan="2">';
208 
209  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
210  $dolgraph = new DolGraph();
211  $dolgraph->SetData($dataseries);
212  $dolgraph->SetDataColor(array_values($colorseries));
213  $dolgraph->setShowLegend(2);
214  $dolgraph->setShowPercent(1);
215  $dolgraph->SetType(array('pie'));
216  $dolgraph->setHeight('200');
217  $dolgraph->draw('idgraphstatus');
218  print $dolgraph->show($total ? 0 : 1);
219 
220  print '</td></tr>';
221 }
222 $listofstatus = array(0, 4, 4, 5); $bool = false;
223 foreach ($listofstatus as $status) {
224  if (empty($conf->use_javascript_ajax)) {
225  print '<tr class="oddeven">';
226  print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
227  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>';
228  if ($status == 4 && !$bool) {
229  $bool = true;
230  } else {
231  $bool = false;
232  }
233  print "</tr>\n";
234  }
235 }
236 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
237 print "</table></div><br>";
238 
239 
240 // Draft contracts
241 
242 if (isModEnabled('contrat') && $user->rights->contrat->lire) {
243  $sql = "SELECT c.rowid, c.ref,";
244  $sql .= " s.nom as name, s.rowid as socid";
245  $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
246  if (empty($user->rights->societe->client->voir) && !$socid) {
247  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
248  }
249  $sql .= " WHERE s.rowid = c.fk_soc";
250  $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
251  $sql .= " AND c.statut = 0";
252  if (empty($user->rights->societe->client->voir) && !$socid) {
253  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
254  }
255  if ($socid) {
256  $sql .= " AND c.fk_soc = ".((int) $socid);
257  }
258 
259  $resql = $db->query($sql);
260 
261  if ($resql) {
262  $num = $db->num_rows($resql);
263 
264  print '<div class="div-table-responsive-no-min">';
265  print '<table class="noborder centpercent">';
266  print '<tr class="liste_titre">';
267  print '<th colspan="3">'.$langs->trans("DraftContracts").($num ? '<span class="badge marginleftonlyshort">'.$num.'</span>' : '').'</th></tr>';
268  if ($num) {
269  $companystatic = new Societe($db);
270 
271  $i = 0;
272  //$tot_ttc = 0;
273  while ($i < $num) {
274  $obj = $db->fetch_object($resql);
275 
276  $staticcontrat->ref = $obj->ref;
277  $staticcontrat->id = $obj->rowid;
278 
279  $companystatic->id = $obj->socid;
280  $companystatic->name = $obj->name;
281  $companystatic->client = 1;
282 
283  print '<tr class="oddeven"><td class="nowrap">';
284  print $staticcontrat->getNomUrl(1, '');
285  print '</td>';
286  print '<td>';
287  print $companystatic->getNomUrl(1, '', 16);
288  print '</td>';
289  print '</tr>';
290  //$tot_ttc+=$obj->total_ttc;
291  $i++;
292  }
293  } else {
294  print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
295  }
296  print "</table></div><br>";
297  $db->free($resql);
298  } else {
299  dol_print_error($db);
300  }
301 }
302 
303 
304 print '</div><div class="fichetwothirdright">';
305 
306 
307 // Last modified contracts
308 $max = 5;
309 $sql = 'SELECT ';
310 $sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
311 $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,';
312 $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,';
313 $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,';
314 $sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
315 $sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
316 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
317 if (empty($user->rights->societe->client->voir) && !$socid) {
318  $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
319 }
320 $sql .= " ".MAIN_DB_PREFIX."contrat as c";
321 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
322 $sql .= " WHERE c.fk_soc = s.rowid";
323 $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
324 $sql .= " AND c.statut > 0";
325 if (empty($user->rights->societe->client->voir) && !$socid) {
326  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
327 }
328 if ($socid) {
329  $sql .= " AND s.rowid = ".((int) $socid);
330 }
331 $sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
332 $sql .= " ORDER BY c.tms DESC";
333 $sql .= $db->plimit($max);
334 
335 dol_syslog("contrat/index.php", LOG_DEBUG);
336 $result = $db->query($sql);
337 if ($result) {
338  $num = $db->num_rows($result);
339  $i = 0;
340 
341  print '<div class="div-table-responsive-no-min">';
342  print '<table class="noborder centpercent">';
343 
344  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", 5).'</th>';
345  print '<th class="center">'.$langs->trans("DateModification").'</th>';
346  //print '<th class="left">'.$langs->trans("Status").'</th>';
347  print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
348  print "</tr>\n";
349 
350  while ($i < $num) {
351  $obj = $db->fetch_object($result);
352  $datem = $db->jdate($obj->tms);
353 
354  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
355  $staticcontrat->id = $obj->cid;
356 
357  $staticcompany->id = $obj->socid;
358  $staticcompany->name = $obj->name;
359 
360  print '<tr class="oddeven">';
361  print '<td class="nowraponall">';
362  print $staticcontrat->getNomUrl(1, 16);
363  if ($obj->nb_late) {
364  print img_warning($langs->trans("Late"));
365  }
366  print '</td>';
367 
368  print '<td class="tdoverflowmax150">';
369  print $staticcompany->getNomUrl(1, '', 20);
370  print '</td>';
371  print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
372  print dol_print_date($datem, 'dayhour');
373  print '</td>';
374  //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
375  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>';
376  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>';
377  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>';
378  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>';
379  print "</tr>\n";
380  $i++;
381  }
382  $db->free($result);
383 
384  print "</table></div>";
385 } else {
386  dol_print_error($db);
387 }
388 
389 print '<br>';
390 
391 // Last modified services
392 $sql = "SELECT c.ref, c.fk_soc, ";
393 $sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
394 $sql .= " s.nom as name,";
395 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
396 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
397 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
398 if (empty($user->rights->societe->client->voir) && !$socid) {
399  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
400 }
401 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
402 $sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
403 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
404 $sql .= " AND cd.fk_contrat = c.rowid";
405 $sql .= " AND c.fk_soc = s.rowid";
406 if (empty($user->rights->societe->client->voir) && !$socid) {
407  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
408 }
409 if ($socid) {
410  $sql .= " AND s.rowid = ".((int) $socid);
411 }
412 $sql .= " ORDER BY cd.tms DESC";
413 
414 $resql = $db->query($sql);
415 if ($resql) {
416  $num = $db->num_rows($resql);
417  $i = 0;
418 
419  print '<div class="div-table-responsive-no-min">';
420  print '<table class="noborder centpercent">';
421 
422  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
423  print "</tr>\n";
424 
425  while ($i < min($num, $max)) {
426  $obj = $db->fetch_object($resql);
427 
428  print '<tr class="oddeven">';
429  print '<td class="nowraponall">';
430  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
431  $staticcontrat->id = $obj->fk_contrat;
432  print $staticcontrat->getNomUrl(1, 16);
433  //if (1 == 1) print img_warning($langs->trans("Late"));
434  print '</td>';
435  print '<td>';
436  if ($obj->fk_product > 0) {
437  $productstatic->id = $obj->fk_product;
438  $productstatic->type = $obj->ptype;
439  $productstatic->ref = $obj->pref;
440  $productstatic->entity = $obj->pentity;
441  print $productstatic->getNomUrl(1, '', 20);
442  } else {
443  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
444  if ($obj->label) {
445  print ' '.dol_trunc($obj->label, 20).'</a>';
446  } else {
447  print '</a> '.dol_trunc($obj->note, 20);
448  }
449  }
450  print '</td>';
451  print '<td class="tdoverflowmax125">';
452  $staticcompany->id = $obj->fk_soc;
453  $staticcompany->name = $obj->name;
454  print $staticcompany->getNomUrl(1, '', 20);
455  print '</td>';
456  print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
457  $dateend = $db->jdate($obj->date_fin_validite);
458  print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
459  print '</a></td>';
460  print "</tr>\n";
461  $i++;
462  }
463  $db->free($resql);
464 
465  print "</table></div>";
466 } else {
467  dol_print_error($db);
468 }
469 
470 print '<br>';
471 
472 // Not activated services
473 $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,";
474 $sql .= " s.nom as name,";
475 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
476 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
477 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
478 if (empty($user->rights->societe->client->voir) && !$socid) {
479  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
480 }
481 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
482 $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
483 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
484 $sql .= " AND c.statut = 1";
485 $sql .= " AND cd.statut = 0";
486 $sql .= " AND cd.fk_contrat = c.rowid";
487 $sql .= " AND c.fk_soc = s.rowid";
488 if (empty($user->rights->societe->client->voir) && !$socid) {
489  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
490 }
491 if ($socid) {
492  $sql .= " AND s.rowid = ".((int) $socid);
493 }
494 $sql .= " ORDER BY cd.tms DESC";
495 
496 $resql = $db->query($sql);
497 if ($resql) {
498  $num = $db->num_rows($resql);
499  $i = 0;
500 
501  print '<div class="div-table-responsive-no-min">';
502  print '<table class="noborder centpercent">';
503 
504  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  print "</tr>\n";
506 
507  while ($i < $num) {
508  $obj = $db->fetch_object($resql);
509 
510  print '<tr class="oddeven">';
511 
512  print '<td class="nowraponall">';
513  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
514  $staticcontrat->id = $obj->fk_contrat;
515  print $staticcontrat->getNomUrl(1, 16);
516  print '</td>';
517  print '<td class="nowrap">';
518  if ($obj->fk_product > 0) {
519  $productstatic->id = $obj->fk_product;
520  $productstatic->type = $obj->ptype;
521  $productstatic->ref = $obj->pref;
522  $productstatic->entity = $obj->pentity;
523  print $productstatic->getNomUrl(1, '', 20);
524  } else {
525  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
526  if ($obj->label) {
527  print ' '.dol_trunc($obj->label, 20).'</a>';
528  } else {
529  print '</a> '.dol_trunc($obj->note, 20);
530  }
531  }
532  print '</td>';
533  print '<td class="tdoverflowmax125">';
534  $staticcompany->id = $obj->fk_soc;
535  $staticcompany->name = $obj->name;
536  print $staticcompany->getNomUrl(1, '', 20);
537  print '</td>';
538  print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
539  print $staticcontratligne->LibStatut($obj->statut, 3);
540  print '</a></td>';
541  print "</tr>\n";
542  $i++;
543  }
544 
545  $db->free($resql);
546 
547  print "</table></div>";
548 } else {
549  dol_print_error($db);
550 }
551 
552 print '<br>';
553 
554 // Expired services
555 $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,";
556 $sql .= " s.nom as name,";
557 $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
558 $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
559 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
560 if (empty($user->rights->societe->client->voir) && !$socid) {
561  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
562 }
563 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
564 $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
565 $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
566 $sql .= " AND c.statut = 1";
567 $sql .= " AND cd.statut = 4";
568 $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
569 $sql .= " AND cd.fk_contrat = c.rowid";
570 $sql .= " AND c.fk_soc = s.rowid";
571 if (empty($user->rights->societe->client->voir) && !$socid) {
572  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
573 }
574 if ($socid) {
575  $sql .= " AND s.rowid = ".((int) $socid);
576 }
577 $sql .= " ORDER BY cd.tms DESC";
578 
579 $resql = $db->query($sql);
580 if ($resql) {
581  $num = $db->num_rows($resql);
582  $i = 0;
583 
584  print '<div class="div-table-responsive-no-min">';
585  print '<table class="noborder centpercent">';
586 
587  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>';
588  print "</tr>\n";
589 
590  while ($i < $num) {
591  $obj = $db->fetch_object($resql);
592 
593  print '<tr class="oddeven">';
594 
595  print '<td class="nowraponall">';
596  $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
597  $staticcontrat->id = $obj->fk_contrat;
598  print $staticcontrat->getNomUrl(1, 16);
599  print '</td>';
600  print '<td class="nowrap">';
601  if ($obj->fk_product > 0) {
602  $productstatic->id = $obj->fk_product;
603  $productstatic->type = $obj->ptype;
604  $productstatic->ref = $obj->pref;
605  $productstatic->entity = $obj->pentity;
606  print $productstatic->getNomUrl(1, '', 20);
607  } else {
608  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
609  if ($obj->label) {
610  print ' '.dol_trunc($obj->label, 20).'</a>';
611  } else {
612  print '</a> '.dol_trunc($obj->note, 20);
613  }
614  }
615  print '</td>';
616  print '<td class="tdoverflowmax125">';
617  $staticcompany->id = $obj->fk_soc;
618  $staticcompany->name = $obj->name;
619  print $staticcompany->getNomUrl(1, '', 20);
620  print '</td>';
621  print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
622  print $staticcontratligne->LibStatut($obj->statut, 3, 1);
623  print '</a></td>';
624  print "</tr>\n";
625  $i++;
626  }
627  $db->free($resql);
628 
629  print "</table></div>";
630 } else {
631  dol_print_error($db);
632 }
633 
634 
635 print '</div></div>';
636 
637 $parameters = array('user' => $user);
638 $reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
639 
640 llxFooter();
641 
642 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
Class to manage contracts.
Class to manage lines of contracts.
Class to build graphs.
Class to manage hooks.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter()
Footer empty.
Definition: index.php:71
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
restrictedArea(User $user, $features, $object=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.