index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. /**
  21. * \file htdocs/contrat/index.php
  22. * \ingroup contrat
  23. * \brief Home page of contract area
  24. */
  25. require ("../main.inc.php");
  26. require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  27. require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  28. $langs->load("products");
  29. $langs->load("companies");
  30. $sortfield=GETPOST('sortfield','alpha');
  31. $sortorder=GETPOST('sortorder','alpha');
  32. $page=GETPOST('page','int');
  33. $statut=GETPOST('statut')?GETPOST('statut'):1;
  34. // Security check
  35. $socid=0;
  36. $id = GETPOST('id','int');
  37. if (! empty($user->societe_id)) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'contrat', $id);
  39. $staticcompany=new Societe($db);
  40. $staticcontrat=new Contrat($db);
  41. $staticcontratligne=new ContratLigne($db);
  42. $productstatic=new Product($db);
  43. /*
  44. * Action
  45. */
  46. // None
  47. /*
  48. * View
  49. */
  50. $now = dol_now();
  51. llxHeader();
  52. print load_fiche_titre($langs->trans("ContractsArea"),'','title_commercial.png');
  53. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  54. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  55. print '<div class="fichecenter"><div class="fichethirdleft">';
  56. // Search contract
  57. if (! empty($conf->contrat->enabled))
  58. {
  59. $var=false;
  60. print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
  61. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  62. print '<table class="noborder nohover" width="100%">';
  63. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  64. print '<tr '.$bc[$var].'>';
  65. print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  66. print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></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 nohover" 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) $bool=true;
  169. else $bool=false;
  170. }
  171. if (! empty($conf->use_javascript_ajax))
  172. {
  173. print '<tr class="impair"><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) $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 as name, 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 c.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?' <span class="badge">'.$num.'</span>':'').'</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 class="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->name=$obj->name;
  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 '.$bc[$var].' class><td colspan="3" class="opacitymedium">'.$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 valign="top" width="70%" class="notopnoleftnoright">';
  257. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  258. // Last modified contracts
  259. $max=5;
  260. $sql = 'SELECT ';
  261. $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  262. $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,';
  263. $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,';
  264. $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,';
  265. $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
  266. $sql.= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
  267. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
  268. if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  269. $sql.= " ".MAIN_DB_PREFIX."contrat as c";
  270. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  271. $sql.= " WHERE c.fk_soc = s.rowid";
  272. $sql.= " AND c.entity IN (".getEntity('contract').")";
  273. $sql.= " AND c.statut > 0";
  274. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  275. if ($socid) $sql.= " AND s.rowid = ".$socid;
  276. $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
  277. $sql.= " ORDER BY c.tms DESC";
  278. $sql.= " LIMIT ".$max;
  279. dol_syslog("contrat/index.php", LOG_DEBUG);
  280. $result=$db->query($sql);
  281. if ($result)
  282. {
  283. $num = $db->num_rows($result);
  284. $i = 0;
  285. print '<table class="noborder" width="100%">';
  286. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("LastContracts",5).'</td>';
  287. print '<td align="center">'.$langs->trans("DateModification").'</td>';
  288. //print '<td align="left">'.$langs->trans("Status").'</td>';
  289. print '<td align="center" width="80" colspan="4">'.$langs->trans("Services").'</td>';
  290. print "</tr>\n";
  291. $var=True;
  292. while ($i < $num)
  293. {
  294. $obj = $db->fetch_object($result);
  295. $var=!$var;
  296. print '<tr '.$bc[$var].'>';
  297. print '<td width="110" class="nowrap">';
  298. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
  299. $staticcontrat->id=$obj->cid;
  300. print $staticcontrat->getNomUrl(1,16);
  301. if ($obj->nb_late) print img_warning($langs->trans("Late"));
  302. print '</td>';
  303. print '<td>';
  304. $staticcompany->id=$obj->socid;
  305. $staticcompany->name=$obj->name;
  306. print $staticcompany->getNomUrl(1,'',20);
  307. print '</td>';
  308. print '<td align="center">'.dol_print_date($obj->tms,'dayhour').'</td>';
  309. //print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
  310. print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
  311. print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
  312. print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
  313. print '<td align="right" width="32">'.($obj->nb_closed>0 ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
  314. print "</tr>\n";
  315. $i++;
  316. }
  317. $db->free($result);
  318. print "</table>";
  319. }
  320. else
  321. {
  322. dol_print_error($db);
  323. }
  324. print '<br>';
  325. // Last modified services
  326. $sql = "SELECT c.ref, c.fk_soc, ";
  327. $sql.= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
  328. $sql.= " s.nom as name,";
  329. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  330. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  331. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  332. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  333. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  334. $sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  335. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  336. $sql.= " AND cd.fk_contrat = c.rowid";
  337. $sql.= " AND c.fk_soc = s.rowid";
  338. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  339. if ($socid) $sql.= " AND s.rowid = ".$socid;
  340. $sql.= " ORDER BY cd.tms DESC";
  341. $resql=$db->query($sql);
  342. if ($resql)
  343. {
  344. $num = $db->num_rows($resql);
  345. $i = 0;
  346. print '<table class="noborder" width="100%">';
  347. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("LastModifiedServices",$max).'</td>';
  348. print "</tr>\n";
  349. $var=True;
  350. while ($i < min($num,$max))
  351. {
  352. $obj = $db->fetch_object($resql);
  353. $var=!$var;
  354. print '<tr '.$bc[$var].'>';
  355. print '<td width="110" class="nowrap">';
  356. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  357. $staticcontrat->id=$obj->fk_contrat;
  358. print $staticcontrat->getNomUrl(1,16);
  359. //if (1 == 1) print img_warning($langs->trans("Late"));
  360. print '</td>';
  361. print '<td>';
  362. if ($obj->fk_product > 0)
  363. {
  364. $productstatic->id=$obj->fk_product;
  365. $productstatic->type=$obj->ptype;
  366. $productstatic->ref=$obj->pref;
  367. $productstatic->entity=$obj->pentity;
  368. print $productstatic->getNomUrl(1,'',20);
  369. }
  370. else
  371. {
  372. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  373. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  374. else print '</a> '.dol_trunc($obj->note,20);
  375. }
  376. print '</td>';
  377. print '<td>';
  378. $staticcompany->id=$obj->fk_soc;
  379. $staticcompany->name=$obj->name;
  380. print $staticcompany->getNomUrl(1,'',20);
  381. print '</td>';
  382. print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  383. $dateend=$db->jdate($obj->date_fin_validite);
  384. print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
  385. print '</a></td>';
  386. print "</tr>\n";
  387. $i++;
  388. }
  389. $db->free();
  390. print "</table>";
  391. }
  392. else
  393. {
  394. dol_print_error($db);
  395. }
  396. print '<br>';
  397. // Not activated services
  398. $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,";
  399. $sql.= " s.nom as name,";
  400. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  401. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  402. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  403. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  404. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  405. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  406. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  407. $sql.= " AND c.statut = 1";
  408. $sql.= " AND cd.statut = 0";
  409. $sql.= " AND cd.fk_contrat = c.rowid";
  410. $sql.= " AND c.fk_soc = s.rowid";
  411. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  412. if ($socid) $sql.= " AND s.rowid = ".$socid;
  413. $sql.= " ORDER BY cd.tms DESC";
  414. $resql=$db->query($sql);
  415. if ($resql)
  416. {
  417. $num = $db->num_rows($resql);
  418. $i = 0;
  419. print '<table class="noborder" width="100%">';
  420. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("NotActivatedServices").' <a href="'.DOL_URL_ROOT.'/contrat/services.php?mode=0"><span class="badge">'.$num.'</span></a></td>';
  421. print "</tr>\n";
  422. $var=True;
  423. while ($i < $num)
  424. {
  425. $obj = $db->fetch_object($resql);
  426. $var=!$var;
  427. print '<tr '.$bc[$var].'>';
  428. print '<td width="110" class="nowrap">';
  429. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  430. $staticcontrat->id=$obj->fk_contrat;
  431. print $staticcontrat->getNomUrl(1,16);
  432. print '</td>';
  433. print '<td class="nowrap">';
  434. if ($obj->fk_product > 0)
  435. {
  436. $productstatic->id=$obj->fk_product;
  437. $productstatic->type=$obj->ptype;
  438. $productstatic->ref=$obj->pref;
  439. $productstatic->entity=$obj->pentity;
  440. print $productstatic->getNomUrl(1,'',20);
  441. }
  442. else
  443. {
  444. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  445. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  446. else print '</a> '.dol_trunc($obj->note,20);
  447. }
  448. print '</td>';
  449. print '<td>';
  450. $staticcompany->id=$obj->fk_soc;
  451. $staticcompany->name=$obj->name;
  452. print $staticcompany->getNomUrl(1,'',20);
  453. print '</td>';
  454. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  455. print $staticcontratligne->LibStatut($obj->statut,3);
  456. print '</a></td>';
  457. print "</tr>\n";
  458. $i++;
  459. }
  460. $db->free();
  461. print "</table>";
  462. }
  463. else
  464. {
  465. dol_print_error($db);
  466. }
  467. print '<br>';
  468. // Expired services
  469. $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,";
  470. $sql.= " s.nom as name,";
  471. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  472. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  473. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  474. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  475. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  476. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  477. $sql.= " WHERE c.entity IN (".getEntity('contract').")";
  478. $sql.= " AND c.statut = 1";
  479. $sql.= " AND cd.statut = 4";
  480. $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  481. $sql.= " AND cd.fk_contrat = c.rowid";
  482. $sql.= " AND c.fk_soc = s.rowid";
  483. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  484. if ($socid) $sql.= " AND s.rowid = ".$socid;
  485. $sql.= " ORDER BY cd.tms DESC";
  486. $resql=$db->query($sql);
  487. if ($resql)
  488. {
  489. $num = $db->num_rows($resql);
  490. $i = 0;
  491. print '<table class="noborder" width="100%">';
  492. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services.php?mode=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></td>';
  493. print "</tr>\n";
  494. $var=True;
  495. while ($i < $num)
  496. {
  497. $obj = $db->fetch_object($resql);
  498. $var=!$var;
  499. print '<tr '.$bc[$var].'>';
  500. print '<td width="110" class="nowrap">';
  501. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  502. $staticcontrat->id=$obj->fk_contrat;
  503. print $staticcontrat->getNomUrl(1,16);
  504. print '</td>';
  505. print '<td class="nowrap">';
  506. if ($obj->fk_product > 0)
  507. {
  508. $productstatic->id=$obj->fk_product;
  509. $productstatic->type=$obj->ptype;
  510. $productstatic->ref=$obj->pref;
  511. $productstatic->entity=$obj->pentity;
  512. print $productstatic->getNomUrl(1,'',20);
  513. }
  514. else
  515. {
  516. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  517. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  518. else print '</a> '.dol_trunc($obj->note,20);
  519. }
  520. print '</td>';
  521. print '<td>';
  522. $staticcompany->id=$obj->fk_soc;
  523. $staticcompany->name=$obj->name;
  524. print $staticcompany->getNomUrl(1,'',20);
  525. print '</td>';
  526. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  527. print $staticcontratligne->LibStatut($obj->statut,3,1);
  528. print '</a></td>';
  529. print "</tr>\n";
  530. $i++;
  531. }
  532. $db->free();
  533. print "</table>";
  534. }
  535. else
  536. {
  537. dol_print_error($db);
  538. }
  539. //print '</td></tr></table>';
  540. print '</div></div></div>';
  541. llxFooter();
  542. $db->close();