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