PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/contrat/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 610 lines | 488 code | 71 blank | 51 comment | 80 complexity | e4a65e0ef25493675263c324e3297643 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contrat/index.php
  21. * \ingroup contrat
  22. * \brief Home page of contract area
  23. */
  24. require ("../main.inc.php");
  25. require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  26. require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  27. $langs->load("products");
  28. $langs->load("companies");
  29. $sortfield=GETPOST('sortfield','alpha');
  30. $sortorder=GETPOST('sortorder','alpha');
  31. $page=GETPOST('page','int');
  32. $statut=GETPOST('statut')?GETPOST('statut'):1;
  33. // Security check
  34. $socid=0;
  35. $id = GETPOST('id','int');
  36. if (! empty($user->societe_id)) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'contrat', $id);
  38. $staticcompany=new Societe($db);
  39. $staticcontrat=new Contrat($db);
  40. $staticcontratligne=new ContratLigne($db);
  41. $productstatic=new Product($db);
  42. /*
  43. * Action
  44. */
  45. // None
  46. /*
  47. * View
  48. */
  49. $now = dol_now();
  50. llxHeader();
  51. print_fiche_titre($langs->trans("ContractsArea"));
  52. print '<table class="notopnoleftnoright" width="100%">';
  53. print '<tr><td width="30%" valign="top" class="notopnoleft">';
  54. // Search contract
  55. if (! empty($conf->contrat->enabled))
  56. {
  57. $var=false;
  58. print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/liste.php">';
  59. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  60. print '<table class="noborder nohover" width="100%">';
  61. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAContract").'</td></tr>';
  62. print '<tr '.$bc[$var].'>';
  63. print '<td nowrap>'.$langs->trans("Ref").':</td><td><input type="text" class="flat" name="search_contract" size="18"></td>';
  64. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  65. print '<tr '.$bc[$var].'><td nowrap>'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  66. print '</tr>';
  67. print "</table></form>\n";
  68. print "<br>";
  69. }
  70. /*
  71. * Statistics
  72. */
  73. $nb=array();
  74. $total=0;
  75. $totalinprocess=0;
  76. $dataseries=array();
  77. $vals=array();
  78. // Search by status (except expired)
  79. $sql = "SELECT count(cd.rowid), cd.statut";
  80. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  81. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
  82. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  83. $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
  84. $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
  85. $sql.= " AND c.entity IN (".getEntity('contract').")";
  86. if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
  87. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  88. $sql.= " GROUP BY cd.statut";
  89. $resql = $db->query($sql);
  90. if ($resql)
  91. {
  92. $num = $db->num_rows($resql);
  93. $i = 0;
  94. while ($i < $num)
  95. {
  96. $row = $db->fetch_row($resql);
  97. if ($row)
  98. {
  99. $nb[$row[1]]=$row[0];
  100. if ($row[1]!=5)
  101. {
  102. $vals[$row[1]]=$row[0];
  103. $totalinprocess+=$row[0];
  104. }
  105. $total+=$row[0];
  106. }
  107. $i++;
  108. }
  109. $db->free($resql);
  110. }
  111. else
  112. {
  113. dol_print_error($db);
  114. }
  115. // Search by status (only expired)
  116. $sql = "SELECT count(cd.rowid), cd.statut";
  117. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  118. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
  119. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  120. $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
  121. $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
  122. $sql.= " AND c.entity IN (".getEntity('contract').")";
  123. if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
  124. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  125. $sql.= " GROUP BY cd.statut";
  126. $resql = $db->query($sql);
  127. if ($resql)
  128. {
  129. $num = $db->num_rows($resql);
  130. // 0 inactive, 4 active, 5 closed
  131. $i = 0;
  132. while ($i < $num)
  133. {
  134. $row = $db->fetch_row($resql);
  135. if ($row)
  136. {
  137. $nb[$row[1].true]=$row[0];
  138. if ($row[1]!=5)
  139. {
  140. $vals[$row[1]]=$row[0];
  141. $totalinprocess+=$row[0];
  142. }
  143. $total+=$row[0];
  144. }
  145. $i++;
  146. }
  147. $db->free($resql);
  148. }
  149. else
  150. {
  151. dol_print_error($db);
  152. }
  153. print '<table class="noborder" width="100%">';
  154. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</td></tr>'."\n";
  155. $var=true;
  156. $listofstatus=array(0,4,4,5); $bool=false;
  157. foreach($listofstatus as $status)
  158. {
  159. $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'data'=>(isset($nb[$status.$bool])?(int) $nb[$status.$bool]:0));
  160. if (empty($conf->use_javascript_ajax))
  161. {
  162. $var=!$var;
  163. print '<tr '.$bc[$var].'>';
  164. print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
  165. print '<td align="right"><a href="services.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
  166. print "</tr>\n";
  167. }
  168. if ($status==4 && $bool==false) $bool=true;
  169. else $bool=false;
  170. }
  171. if (! empty($conf->use_javascript_ajax))
  172. {
  173. print '<tr><td align="center" colspan="2">';
  174. $data=array('series'=>$dataseries);
  175. dol_print_graph('stats',300,180,$data,1,'pie',1);
  176. print '</td></tr>';
  177. }
  178. $var=true;
  179. $listofstatus=array(0,4,4,5); $bool=false;
  180. foreach($listofstatus as $status)
  181. {
  182. if (empty($conf->use_javascript_ajax))
  183. {
  184. $var=!$var;
  185. print '<tr '.$bc[$var].'>';
  186. print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
  187. print '<td align="right"><a href="services.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
  188. if ($status==4 && $bool==false) $bool=true;
  189. else $bool=false;
  190. print "</tr>\n";
  191. }
  192. }
  193. //if ($totalinprocess != $total)
  194. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("ServicesRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
  195. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
  196. print "</table><br>";
  197. /**
  198. * Draft contratcs
  199. */
  200. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  201. {
  202. $sql = "SELECT c.rowid as ref, c.rowid,";
  203. $sql.= " s.nom, s.rowid as socid";
  204. $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
  205. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  206. $sql.= " WHERE s.rowid = c.fk_soc";
  207. $sql.= " AND c.entity IN (".getEntity('contract').")";
  208. $sql.= " AND c.statut = 0";
  209. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  210. if ($socid) $sql.= " AND s.fk_soc = ".$socid;
  211. $resql = $db->query($sql);
  212. if ( $resql )
  213. {
  214. $var = false;
  215. $num = $db->num_rows($resql);
  216. print '<table class="noborder" width="100%">';
  217. print '<tr class="liste_titre">';
  218. print '<td colspan="3">'.$langs->trans("DraftContracts").($num?' ('.$num.')':'').'</td></tr>';
  219. if ($num)
  220. {
  221. $companystatic=new Societe($db);
  222. $i = 0;
  223. //$tot_ttc = 0;
  224. while ($i < $num && $i < 20)
  225. {
  226. $obj = $db->fetch_object($resql);
  227. print '<tr '.$bc[$var].'><td nowrap>';
  228. $staticcontrat->ref=$obj->ref;
  229. $staticcontrat->id=$obj->rowid;
  230. print $staticcontrat->getNomUrl(1,'');
  231. print '</td>';
  232. print '<td>';
  233. $companystatic->id=$obj->socid;
  234. $companystatic->nom=$obj->nom;
  235. $companystatic->client=1;
  236. print $companystatic->getNomUrl(1,'',16);
  237. print '</td>';
  238. print '</tr>';
  239. //$tot_ttc+=$obj->total_ttc;
  240. $i++;
  241. $var=!$var;
  242. }
  243. }
  244. else
  245. {
  246. print '<tr colspan="3" '.$bc[$var].'><td>'.$langs->trans("NoContracts").'</td></tr>';
  247. }
  248. print "</table><br>";
  249. $db->free($resql);
  250. }
  251. else
  252. {
  253. dol_print_error($db);
  254. }
  255. }
  256. print '</td><td width="70%" valign="top" class="notopnoleftnoright">';
  257. // Last modified contracts
  258. $max=5;
  259. $sql = 'SELECT ';
  260. $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  261. $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,';
  262. $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,';
  263. $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,';
  264. $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
  265. $sql.= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid as socid";
  266. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
  267. if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  268. $sql.= " ".MAIN_DB_PREFIX."contrat as c";
  269. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  270. $sql.= " WHERE c.fk_soc = s.rowid";
  271. $sql.= " AND c.entity IN (".getEntity('contract').")";
  272. $sql.= " AND c.statut > 0";
  273. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  274. if ($socid) $sql.= " AND s.rowid = ".$socid;
  275. $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
  276. $sql.= " ORDER BY c.tms DESC";
  277. $sql.= " LIMIT ".$max;
  278. dol_syslog("contrat/index.php sql=".$sql, LOG_DEBUG);
  279. $result=$db->query($sql);
  280. if ($result)
  281. {
  282. $num = $db->num_rows($result);
  283. $i = 0;
  284. print '<table class="noborder" width="100%">';
  285. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastContracts",5).'</td>';
  286. print '<td align="center">'.$langs->trans("DateModification").'</td>';
  287. //print '<td align="left">'.$langs->trans("Status").'</td>';
  288. print '<td align="center" width="80" colspan="4">'.$langs->trans("Services").'</td>';
  289. print "</tr>\n";
  290. $var=True;
  291. while ($i < $num)
  292. {
  293. $obj = $db->fetch_object($result);
  294. $var=!$var;
  295. print '<tr '.$bc[$var].'>';
  296. print '<td width="100" nowrap="nowrap">';
  297. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
  298. $staticcontrat->id=$obj->cid;
  299. print $staticcontrat->getNomUrl(1,16);
  300. if ($obj->nb_late) print img_warning($langs->trans("Late"));
  301. print '</td>';
  302. print '<td>';
  303. $staticcompany->id=$obj->socid;
  304. $staticcompany->nom=$obj->nom;
  305. print $staticcompany->getNomUrl(1,'',20);
  306. print '</td>';
  307. print '<td align="center">'.dol_print_date($obj->tms,'dayhour').'</td>';
  308. //print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
  309. print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
  310. print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
  311. print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
  312. print '<td align="right" width="32">'.($obj->nb_closed>0 ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
  313. print "</tr>\n";
  314. $i++;
  315. }
  316. $db->free($result);
  317. print "</table>";
  318. }
  319. else
  320. {
  321. dol_print_error($db);
  322. }
  323. print '<br>';
  324. // Last modified services
  325. $sql = "SELECT c.ref, c.fk_soc, ";
  326. $sql.= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
  327. $sql.= " s.nom,";
  328. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype";
  329. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  330. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  331. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  332. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  333. $sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  334. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  335. $sql.= " AND cd.fk_contrat = c.rowid";
  336. $sql.= " AND c.fk_soc = s.rowid";
  337. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  338. if ($socid) $sql.= " AND s.rowid = ".$socid;
  339. $sql.= " ORDER BY cd.tms DESC";
  340. $resql=$db->query($sql);
  341. if ($resql)
  342. {
  343. $num = $db->num_rows($resql);
  344. $i = 0;
  345. print '<table class="noborder" width="100%">';
  346. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("LastModifiedServices",$max).'</td>';
  347. print "</tr>\n";
  348. $var=True;
  349. while ($i < min($num,$max))
  350. {
  351. $obj = $db->fetch_object($resql);
  352. $var=!$var;
  353. print '<tr '.$bc[$var].'>';
  354. print '<td width="100" nowrap="nowrap">';
  355. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  356. $staticcontrat->id=$obj->fk_contrat;
  357. print $staticcontrat->getNomUrl(1,16);
  358. //if (1 == 1) print img_warning($langs->trans("Late"));
  359. print '</td>';
  360. print '<td>';
  361. if ($obj->fk_product > 0)
  362. {
  363. $productstatic->id=$obj->fk_product;
  364. $productstatic->type=$obj->ptype;
  365. $productstatic->ref=$obj->pref;
  366. print $productstatic->getNomUrl(1,'',20);
  367. }
  368. else
  369. {
  370. print '<a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  371. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  372. else print '</a> '.dol_trunc($obj->note,20);
  373. }
  374. print '</td>';
  375. print '<td>';
  376. $staticcompany->id=$obj->fk_soc;
  377. $staticcompany->nom=$obj->nom;
  378. print $staticcompany->getNomUrl(1,'',20);
  379. print '</td>';
  380. print '<td nowrap="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  381. $dateend=$db->jdate($obj->date_fin_validite);
  382. print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
  383. print '</a></td>';
  384. print "</tr>\n";
  385. $i++;
  386. }
  387. $db->free();
  388. print "</table>";
  389. }
  390. else
  391. {
  392. dol_print_error($db);
  393. }
  394. print '<br>';
  395. // Not activated services
  396. $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,";
  397. $sql.= " s.nom,";
  398. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype";
  399. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  400. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  401. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  402. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  403. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  404. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  405. $sql.= " AND c.statut = 1";
  406. $sql.= " AND cd.statut = 0";
  407. $sql.= " AND cd.fk_contrat = c.rowid";
  408. $sql.= " AND c.fk_soc = s.rowid";
  409. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  410. if ($socid) $sql.= " AND s.rowid = ".$socid;
  411. $sql.= " ORDER BY cd.tms DESC";
  412. $resql=$db->query($sql);
  413. if ($resql)
  414. {
  415. $num = $db->num_rows($resql);
  416. $i = 0;
  417. print '<table class="noborder" width="100%">';
  418. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("NotActivatedServices").' <a href="'.DOL_URL_ROOT.'/contrat/services.php?mode=0">('.$num.')</a></td>';
  419. print "</tr>\n";
  420. $var=True;
  421. while ($i < $num)
  422. {
  423. $obj = $db->fetch_object($resql);
  424. $var=!$var;
  425. print '<tr '.$bc[$var].'>';
  426. print '<td width="100" nowrap="nowrap">';
  427. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  428. $staticcontrat->id=$obj->fk_contrat;
  429. print $staticcontrat->getNomUrl(1,16);
  430. print '</td>';
  431. print '<td nowrap="nowrap">';
  432. if ($obj->fk_product > 0)
  433. {
  434. $productstatic->id=$obj->fk_product;
  435. $productstatic->type=$obj->ptype;
  436. $productstatic->ref=$obj->pref;
  437. print $productstatic->getNomUrl(1,'',20);
  438. }
  439. else
  440. {
  441. print '<a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  442. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  443. else print '</a> '.dol_trunc($obj->note,20);
  444. }
  445. print '</td>';
  446. print '<td>';
  447. $staticcompany->id=$obj->fk_soc;
  448. $staticcompany->nom=$obj->nom;
  449. print $staticcompany->getNomUrl(1,'',20);
  450. print '</td>';
  451. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  452. print $staticcontratligne->LibStatut($obj->statut,3);
  453. print '</a></td>';
  454. print "</tr>\n";
  455. $i++;
  456. }
  457. $db->free();
  458. print "</table>";
  459. }
  460. else
  461. {
  462. dol_print_error($db);
  463. }
  464. print '<br>';
  465. // Expired services
  466. $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,";
  467. $sql.= " s.nom,";
  468. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype";
  469. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  470. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  471. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  472. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  473. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  474. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  475. $sql.= " AND c.statut = 1";
  476. $sql.= " AND cd.statut = 4";
  477. $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  478. $sql.= " AND cd.fk_contrat = c.rowid";
  479. $sql.= " AND c.fk_soc = s.rowid";
  480. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  481. if ($socid) $sql.= " AND s.rowid = ".$socid;
  482. $sql.= " ORDER BY cd.tms DESC";
  483. $resql=$db->query($sql);
  484. if ($resql)
  485. {
  486. $num = $db->num_rows($resql);
  487. $i = 0;
  488. print '<table class="noborder" width="100%">';
  489. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services.php?mode=4&filter=expired">('.$num.')</a></td>';
  490. print "</tr>\n";
  491. $var=True;
  492. while ($i < $num)
  493. {
  494. $obj = $db->fetch_object($resql);
  495. $var=!$var;
  496. print '<tr '.$bc[$var].'>';
  497. print '<td width="100" nowrap="nowrap">';
  498. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  499. $staticcontrat->id=$obj->fk_contrat;
  500. print $staticcontrat->getNomUrl(1,16);
  501. print '</td>';
  502. print '<td nowrap="nowrap">';
  503. if ($obj->fk_product > 0)
  504. {
  505. $productstatic->id=$obj->fk_product;
  506. $productstatic->type=$obj->ptype;
  507. $productstatic->ref=$obj->pref;
  508. print $productstatic->getNomUrl(1,'',20);
  509. }
  510. else
  511. {
  512. print '<a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  513. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  514. else print '</a> '.dol_trunc($obj->note,20);
  515. }
  516. print '</td>';
  517. print '<td>';
  518. $staticcompany->id=$obj->fk_soc;
  519. $staticcompany->nom=$obj->nom;
  520. print $staticcompany->getNomUrl(1,'',20);
  521. print '</td>';
  522. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  523. print $staticcontratligne->LibStatut($obj->statut,3,1);
  524. print '</a></td>';
  525. print "</tr>\n";
  526. $i++;
  527. }
  528. $db->free();
  529. print "</table>";
  530. }
  531. else
  532. {
  533. dol_print_error($db);
  534. }
  535. print '</td></tr></table>';
  536. print '<br>';
  537. llxFooter();
  538. $db->close();
  539. ?>