dolibarr  7.0.0-beta
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@capnetworks.com>
5  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require ("../main.inc.php");
28 require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
29 require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
30 
31 $langs->load("products");
32 $langs->load("companies");
33 $langs->load("contracts");
34 
35 $sortfield=GETPOST('sortfield','alpha');
36 $sortorder=GETPOST('sortorder','alpha');
37 $page=GETPOST('page','int');
38 
39 $statut=GETPOST('statut')?GETPOST('statut'):1;
40 
41 // Security check
42 $socid=0;
43 $id = GETPOST('id','int');
44 if (! empty($user->societe_id)) $socid=$user->societe_id;
45 $result = restrictedArea($user, 'contrat', $id);
46 
47 $staticcompany=new Societe($db);
48 $staticcontrat=new Contrat($db);
49 $staticcontratligne=new ContratLigne($db);
50 $productstatic=new Product($db);
51 
52 
53 /*
54  * Action
55  */
56 
57 // None
58 
59 
60 /*
61  * View
62  */
63 
64 $now = dol_now();
65 
66 llxHeader();
67 
68 print load_fiche_titre($langs->trans("ContractsArea"),'','title_commercial.png');
69 
70 
71 //print '<table border="0" width="100%" class="notopnoleftnoright">';
72 //print '<tr><td valign="top" width="30%" class="notopnoleft">';
73 print '<div class="fichecenter"><div class="fichethirdleft">';
74 
75 
76 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
77 {
78  // Search contract
79  if (! empty($conf->contrat->enabled))
80  {
81  print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
82  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
83  print '<table class="noborder nohover" width="100%">';
84  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
85  print '<tr class="oddeven">';
86  print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
87  print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
88  print "</table></form>\n";
89  print "<br>";
90  }
91 }
92 
93 
94 /*
95  * Statistics
96  */
97 
98 $nb=array();
99 $total=0;
100 $totalinprocess=0;
101 $dataseries=array();
102 $vals=array();
103 
104 // Search by status (except expired)
105 $sql = "SELECT count(cd.rowid), cd.statut";
106 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
107 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
108 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
109 $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
110 $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
111 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
112 if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
113 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
114 $sql.= " GROUP BY cd.statut";
115 $resql = $db->query($sql);
116 if ($resql)
117 {
118  $num = $db->num_rows($resql);
119  $i = 0;
120  while ($i < $num)
121  {
122  $row = $db->fetch_row($resql);
123  if ($row)
124  {
125  $nb[$row[1]]=$row[0];
126  if ($row[1]!=5)
127  {
128  $vals[$row[1]]=$row[0];
129  $totalinprocess+=$row[0];
130  }
131  $total+=$row[0];
132  }
133  $i++;
134  }
135  $db->free($resql);
136 }
137 else
138 {
139  dol_print_error($db);
140 }
141 // Search by status (only expired)
142 $sql = "SELECT count(cd.rowid), cd.statut";
143 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
144 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
145 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
146 $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
147 $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
148 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
149 if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
150 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
151 $sql.= " GROUP BY cd.statut";
152 $resql = $db->query($sql);
153 if ($resql)
154 {
155  $num = $db->num_rows($resql);
156 
157  // 0 inactive, 4 active, 5 closed
158  $i = 0;
159  while ($i < $num)
160  {
161  $row = $db->fetch_row($resql);
162  if ($row)
163  {
164  $nb[$row[1].true]=$row[0];
165  if ($row[1]!=5)
166  {
167  $vals[$row[1]]=$row[0];
168  $totalinprocess+=$row[0];
169  }
170  $total+=$row[0];
171  }
172  $i++;
173  }
174  $db->free($resql);
175 }
176 else
177 {
178  dol_print_error($db);
179 }
180 
181 
182 print '<table class="noborder nohover" width="100%">';
183 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
184 $listofstatus=array(0,4,4,5); $bool=false;
185 foreach($listofstatus as $status)
186 {
187  $dataseries[]=array($staticcontratligne->LibStatut($status,1,($bool?1:0)),(isset($nb[$status.$bool])?(int) $nb[$status.$bool]:0));
188  if (empty($conf->use_javascript_ajax))
189  {
190 
191  print '<tr class="oddeven">';
192  print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
193  print '<td align="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>';
194  print "</tr>\n";
195  }
196  if ($status==4 && ! $bool) $bool=true;
197  else $bool=false;
198 }
199 if (! empty($conf->use_javascript_ajax))
200 {
201  print '<tr class="impair"><td align="center" colspan="2">';
202 
203  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
204  $dolgraph = new DolGraph();
205  $dolgraph->SetData($dataseries);
206  $dolgraph->setShowLegend(1);
207  $dolgraph->setShowPercent(1);
208  $dolgraph->SetType(array('pie'));
209  $dolgraph->setWidth('100%');
210  $dolgraph->draw('idgraphstatus');
211  print $dolgraph->show($total?0:1);
212 
213  print '</td></tr>';
214 }
215 $listofstatus=array(0,4,4,5); $bool=false;
216 foreach($listofstatus as $status)
217 {
218  if (empty($conf->use_javascript_ajax))
219  {
220  print '<tr class="oddeven">';
221  print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
222  print '<td align="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>';
223  if ($status==4 && ! $bool) $bool=true;
224  else $bool=false;
225  print "</tr>\n";
226  }
227 }
228 //if ($totalinprocess != $total)
229 //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("ServicesRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
230 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
231 print "</table><br>";
232 
233 
234 // Draft contracts
235 
236 if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
237 {
238  $sql = "SELECT c.rowid, c.ref,";
239  $sql.= " s.nom as name, s.rowid as socid";
240  $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
241  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
242  $sql.= " WHERE s.rowid = c.fk_soc";
243  $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
244  $sql.= " AND c.statut = 0";
245  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
246  if ($socid) $sql.= " AND c.fk_soc = ".$socid;
247 
248  $resql = $db->query($sql);
249 
250  if ( $resql )
251  {
252  $num = $db->num_rows($resql);
253 
254  print '<table class="noborder" width="100%">';
255  print '<tr class="liste_titre">';
256  print '<th colspan="3">'.$langs->trans("DraftContracts").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
257  if ($num)
258  {
259  $companystatic=new Societe($db);
260 
261  $i = 0;
262  //$tot_ttc = 0;
263  while ($i < $num)
264  {
265  $obj = $db->fetch_object($resql);
266 
267  $staticcontrat->ref=$obj->ref;
268  $staticcontrat->id=$obj->rowid;
269 
270  $companystatic->id=$obj->socid;
271  $companystatic->name=$obj->name;
272  $companystatic->client=1;
273 
274  print '<tr class="oddeven"><td class="nowrap">';
275  print $staticcontrat->getNomUrl(1,'');
276  print '</td>';
277  print '<td>';
278  print $companystatic->getNomUrl(1,'',16);
279  print '</td>';
280  print '</tr>';
281  //$tot_ttc+=$obj->total_ttc;
282  $i++;
283 
284  }
285  }
286  else
287  {
288  print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
289  }
290  print "</table><br>";
291  $db->free($resql);
292  }
293  else
294  {
295  dol_print_error($db);
296  }
297 }
298 
299 
300 //print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
301 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
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 (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
315 $sql.= " ".MAIN_DB_PREFIX."contrat as c";
316 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
317 $sql.= " WHERE c.fk_soc = s.rowid";
318 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
319 $sql.= " AND c.statut > 0";
320 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
321 if ($socid) $sql.= " AND s.rowid = ".$socid;
322 $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
323 $sql.= " ORDER BY c.tms DESC";
324 $sql.= " LIMIT ".$max;
325 
326 dol_syslog("contrat/index.php", LOG_DEBUG);
327 $result=$db->query($sql);
328 if ($result)
329 {
330  $num = $db->num_rows($result);
331  $i = 0;
332 
333  print '<table class="noborder" width="100%">';
334 
335  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts",5).'</th>';
336  print '<th align="center">'.$langs->trans("DateModification").'</th>';
337  //print '<th align="left">'.$langs->trans("Status").'</th>';
338  print '<th align="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
339  print "</tr>\n";
340 
341  while ($i < $num)
342  {
343  $obj = $db->fetch_object($result);
344 
345  print '<tr class="oddeven">';
346  print '<td width="110" class="nowrap">';
347  $staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
348  $staticcontrat->id=$obj->cid;
349  print $staticcontrat->getNomUrl(1,16);
350  if ($obj->nb_late) print img_warning($langs->trans("Late"));
351  print '</td>';
352  print '<td>';
353  $staticcompany->id=$obj->socid;
354  $staticcompany->name=$obj->name;
355  print $staticcompany->getNomUrl(1,'',20);
356  print '</td>';
357  print '<td align="center">'.dol_print_date($db->jdate($obj->tms),'dayhour').'</td>';
358  //print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
359  print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
360  print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
361  print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
362  print '<td align="right" width="32">'.($obj->nb_closed>0 ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
363  print "</tr>\n";
364  $i++;
365  }
366  $db->free($result);
367 
368  print "</table>";
369 
370 }
371 else
372 {
373  dol_print_error($db);
374 }
375 
376 print '<br>';
377 
378 // Last modified services
379 $sql = "SELECT c.ref, c.fk_soc, ";
380 $sql.= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
381 $sql.= " s.nom as name,";
382 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
383 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
384 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
385 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
386 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
387 $sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
388 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
389 $sql.= " AND cd.fk_contrat = c.rowid";
390 $sql.= " AND c.fk_soc = s.rowid";
391 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
392 if ($socid) $sql.= " AND s.rowid = ".$socid;
393 $sql.= " ORDER BY cd.tms DESC";
394 
395 $resql=$db->query($sql);
396 if ($resql)
397 {
398  $num = $db->num_rows($resql);
399  $i = 0;
400 
401  print '<table class="noborder" width="100%">';
402 
403  print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices",$max).'</th>';
404  print "</tr>\n";
405 
406  while ($i < min($num,$max))
407  {
408  $obj = $db->fetch_object($resql);
409 
410  print '<tr class="oddeven">';
411  print '<td width="110" class="nowrap">';
412  $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
413  $staticcontrat->id=$obj->fk_contrat;
414  print $staticcontrat->getNomUrl(1,16);
415  //if (1 == 1) print img_warning($langs->trans("Late"));
416  print '</td>';
417  print '<td>';
418  if ($obj->fk_product > 0)
419  {
420  $productstatic->id=$obj->fk_product;
421  $productstatic->type=$obj->ptype;
422  $productstatic->ref=$obj->pref;
423  $productstatic->entity=$obj->pentity;
424  print $productstatic->getNomUrl(1,'',20);
425  }
426  else
427  {
428  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
429  if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
430  else print '</a> '.dol_trunc($obj->note,20);
431  }
432  print '</td>';
433  print '<td>';
434  $staticcompany->id=$obj->fk_soc;
435  $staticcompany->name=$obj->name;
436  print $staticcompany->getNomUrl(1,'',20);
437  print '</td>';
438  print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
439  $dateend=$db->jdate($obj->date_fin_validite);
440  print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
441  print '</a></td>';
442  print "</tr>\n";
443  $i++;
444  }
445  $db->free();
446 
447  print "</table>";
448 
449 }
450 else
451 {
452  dol_print_error($db);
453 }
454 
455 print '<br>';
456 
457 // Not activated services
458 $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,";
459 $sql.= " s.nom as name,";
460 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
461 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
462 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
463 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
464 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
465 $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
466 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
467 $sql.= " AND c.statut = 1";
468 $sql.= " AND cd.statut = 0";
469 $sql.= " AND cd.fk_contrat = c.rowid";
470 $sql.= " AND c.fk_soc = s.rowid";
471 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
472 if ($socid) $sql.= " AND s.rowid = ".$socid;
473 $sql.= " ORDER BY cd.tms DESC";
474 
475 $resql=$db->query($sql);
476 if ($resql)
477 {
478  $num = $db->num_rows($resql);
479  $i = 0;
480 
481  print '<table class="noborder" width="100%">';
482 
483  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>';
484  print "</tr>\n";
485 
486  while ($i < $num)
487  {
488  $obj = $db->fetch_object($resql);
489 
490  print '<tr class="oddeven">';
491 
492  print '<td width="110" class="nowrap">';
493  $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
494  $staticcontrat->id=$obj->fk_contrat;
495  print $staticcontrat->getNomUrl(1,16);
496  print '</td>';
497  print '<td class="nowrap">';
498  if ($obj->fk_product > 0)
499  {
500  $productstatic->id=$obj->fk_product;
501  $productstatic->type=$obj->ptype;
502  $productstatic->ref=$obj->pref;
503  $productstatic->entity=$obj->pentity;
504  print $productstatic->getNomUrl(1,'',20);
505  }
506  else
507  {
508  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
509  if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
510  else print '</a> '.dol_trunc($obj->note,20);
511  }
512  print '</td>';
513  print '<td>';
514  $staticcompany->id=$obj->fk_soc;
515  $staticcompany->name=$obj->name;
516  print $staticcompany->getNomUrl(1,'',20);
517  print '</td>';
518  print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
519  print $staticcontratligne->LibStatut($obj->statut,3);
520  print '</a></td>';
521  print "</tr>\n";
522  $i++;
523  }
524  $db->free();
525 
526  print "</table>";
527 
528 }
529 else
530 {
531  dol_print_error($db);
532 }
533 
534 print '<br>';
535 
536 // Expired services
537 $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,";
538 $sql.= " s.nom as name,";
539 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
540 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
541 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
542 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
543 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
544 $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
545 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
546 $sql.= " AND c.statut = 1";
547 $sql.= " AND cd.statut = 4";
548 $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
549 $sql.= " AND cd.fk_contrat = c.rowid";
550 $sql.= " AND c.fk_soc = s.rowid";
551 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
552 if ($socid) $sql.= " AND s.rowid = ".$socid;
553 $sql.= " ORDER BY cd.tms DESC";
554 
555 $resql=$db->query($sql);
556 if ($resql)
557 {
558  $num = $db->num_rows($resql);
559  $i = 0;
560 
561  print '<table class="noborder" width="100%">';
562 
563  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>';
564  print "</tr>\n";
565 
566  while ($i < $num)
567  {
568  $obj = $db->fetch_object($resql);
569 
570  print '<tr class="oddeven">';
571 
572  print '<td width="110" class="nowrap">';
573  $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
574  $staticcontrat->id=$obj->fk_contrat;
575  print $staticcontrat->getNomUrl(1,16);
576  print '</td>';
577  print '<td class="nowrap">';
578  if ($obj->fk_product > 0)
579  {
580  $productstatic->id=$obj->fk_product;
581  $productstatic->type=$obj->ptype;
582  $productstatic->ref=$obj->pref;
583  $productstatic->entity=$obj->pentity;
584  print $productstatic->getNomUrl(1,'',20);
585  }
586  else
587  {
588  print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
589  if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
590  else print '</a> '.dol_trunc($obj->note,20);
591  }
592  print '</td>';
593  print '<td>';
594  $staticcompany->id=$obj->fk_soc;
595  $staticcompany->name=$obj->name;
596  print $staticcompany->getNomUrl(1,'',20);
597  print '</td>';
598  print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
599  print $staticcontratligne->LibStatut($obj->statut,3,1);
600  print '</a></td>';
601  print "</tr>\n";
602  $i++;
603  }
604  $db->free();
605 
606  print "</table>";
607 
608 }
609 else
610 {
611  dol_print_error($db);
612 }
613 
614 
615 //print '</td></tr></table>';
616 print '</div></div></div>';
617 
618 
619 llxFooter();
620 
621 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
Class to manage products or services.
Class to manage contracts.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Classe permettant la gestion des lignes de contrats.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='gmt')
Return date for now.
print
Draft customers invoices.
Definition: index.php:91
Class to build graphs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.