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