index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. // Load translation files required by the page
  29. $langs->loadLangs(array('products', 'companies', 'contracts'));
  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. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  57. {
  58. // Search contract
  59. if (! empty($conf->contrat->enabled))
  60. {
  61. print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
  62. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  63. print '<table class="noborder nohover" width="100%">';
  64. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  65. print '<tr class="oddeven">';
  66. print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  67. print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  68. print "</table></form>\n";
  69. print "<br>";
  70. }
  71. }
  72. /*
  73. * Statistics
  74. */
  75. $nb=array();
  76. $total=0;
  77. $totalinprocess=0;
  78. $dataseries=array();
  79. $vals=array();
  80. // Search by status (except expired)
  81. $sql = "SELECT count(cd.rowid), cd.statut";
  82. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  83. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
  84. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  85. $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
  86. $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
  87. $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
  88. if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
  89. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  90. $sql.= " GROUP BY cd.statut";
  91. $resql = $db->query($sql);
  92. if ($resql)
  93. {
  94. $num = $db->num_rows($resql);
  95. $i = 0;
  96. while ($i < $num)
  97. {
  98. $row = $db->fetch_row($resql);
  99. if ($row)
  100. {
  101. $nb[$row[1]]=$row[0];
  102. if ($row[1]!=5)
  103. {
  104. $vals[$row[1]]=$row[0];
  105. $totalinprocess+=$row[0];
  106. }
  107. $total+=$row[0];
  108. }
  109. $i++;
  110. }
  111. $db->free($resql);
  112. }
  113. else
  114. {
  115. dol_print_error($db);
  116. }
  117. // Search by status (only expired)
  118. $sql = "SELECT count(cd.rowid), cd.statut";
  119. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  120. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
  121. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  122. $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
  123. $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
  124. $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
  125. if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
  126. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  127. $sql.= " GROUP BY cd.statut";
  128. $resql = $db->query($sql);
  129. if ($resql)
  130. {
  131. $num = $db->num_rows($resql);
  132. // 0 inactive, 4 active, 5 closed
  133. $i = 0;
  134. while ($i < $num)
  135. {
  136. $row = $db->fetch_row($resql);
  137. if ($row)
  138. {
  139. $nb[$row[1].true]=$row[0];
  140. if ($row[1]!=5)
  141. {
  142. $vals[$row[1]]=$row[0];
  143. $totalinprocess+=$row[0];
  144. }
  145. $total+=$row[0];
  146. }
  147. $i++;
  148. }
  149. $db->free($resql);
  150. }
  151. else
  152. {
  153. dol_print_error($db);
  154. }
  155. print '<table class="noborder nohover" width="100%">';
  156. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
  157. $listofstatus=array(0,4,4,5); $bool=false;
  158. foreach($listofstatus as $status)
  159. {
  160. $dataseries[]=array($staticcontratligne->LibStatut($status,1,($bool?1:0)),(isset($nb[$status.$bool])?(int) $nb[$status.$bool]:0));
  161. if (empty($conf->use_javascript_ajax))
  162. {
  163. print '<tr class="oddeven">';
  164. print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
  165. 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>';
  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. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  175. $dolgraph = new DolGraph();
  176. $dolgraph->SetData($dataseries);
  177. $dolgraph->setShowLegend(1);
  178. $dolgraph->setShowPercent(1);
  179. $dolgraph->SetType(array('pie'));
  180. $dolgraph->setWidth('100%');
  181. $dolgraph->draw('idgraphstatus');
  182. print $dolgraph->show($total?0:1);
  183. print '</td></tr>';
  184. }
  185. $listofstatus=array(0,4,4,5); $bool=false;
  186. foreach($listofstatus as $status)
  187. {
  188. if (empty($conf->use_javascript_ajax))
  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. if ($status==4 && ! $bool) $bool=true;
  194. else $bool=false;
  195. print "</tr>\n";
  196. }
  197. }
  198. //if ($totalinprocess != $total)
  199. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("ServicesRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
  200. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
  201. print "</table><br>";
  202. // Draft contracts
  203. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  204. {
  205. $sql = "SELECT c.rowid, c.ref,";
  206. $sql.= " s.nom as name, s.rowid as socid";
  207. $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
  208. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  209. $sql.= " WHERE s.rowid = c.fk_soc";
  210. $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
  211. $sql.= " AND c.statut = 0";
  212. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  213. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  214. $resql = $db->query($sql);
  215. if ( $resql )
  216. {
  217. $num = $db->num_rows($resql);
  218. print '<table class="noborder" width="100%">';
  219. print '<tr class="liste_titre">';
  220. print '<th colspan="3">'.$langs->trans("DraftContracts").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
  221. if ($num)
  222. {
  223. $companystatic=new Societe($db);
  224. $i = 0;
  225. //$tot_ttc = 0;
  226. while ($i < $num)
  227. {
  228. $obj = $db->fetch_object($resql);
  229. $staticcontrat->ref=$obj->ref;
  230. $staticcontrat->id=$obj->rowid;
  231. $companystatic->id=$obj->socid;
  232. $companystatic->name=$obj->name;
  233. $companystatic->client=1;
  234. print '<tr class="oddeven"><td class="nowrap">';
  235. print $staticcontrat->getNomUrl(1,'');
  236. print '</td>';
  237. print '<td>';
  238. print $companystatic->getNomUrl(1,'',16);
  239. print '</td>';
  240. print '</tr>';
  241. //$tot_ttc+=$obj->total_ttc;
  242. $i++;
  243. }
  244. }
  245. else
  246. {
  247. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
  248. }
  249. print "</table><br>";
  250. $db->free($resql);
  251. }
  252. else
  253. {
  254. dol_print_error($db);
  255. }
  256. }
  257. //print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  258. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  259. // Last modified contracts
  260. $max=5;
  261. $sql = 'SELECT ';
  262. $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  263. $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,';
  264. $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,';
  265. $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,';
  266. $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
  267. $sql.= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
  268. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
  269. if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  270. $sql.= " ".MAIN_DB_PREFIX."contrat as c";
  271. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  272. $sql.= " WHERE c.fk_soc = s.rowid";
  273. $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
  274. $sql.= " AND c.statut > 0";
  275. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  276. if ($socid) $sql.= " AND s.rowid = ".$socid;
  277. $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
  278. $sql.= " ORDER BY c.tms DESC";
  279. $sql.= " LIMIT ".$max;
  280. dol_syslog("contrat/index.php", LOG_DEBUG);
  281. $result=$db->query($sql);
  282. if ($result)
  283. {
  284. $num = $db->num_rows($result);
  285. $i = 0;
  286. print '<table class="noborder" width="100%">';
  287. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts",5).'</th>';
  288. print '<th align="center">'.$langs->trans("DateModification").'</th>';
  289. //print '<th align="left">'.$langs->trans("Status").'</th>';
  290. print '<th align="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
  291. print "</tr>\n";
  292. while ($i < $num)
  293. {
  294. $obj = $db->fetch_object($result);
  295. print '<tr class="oddeven">';
  296. print '<td width="110" class="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->name=$obj->name;
  305. print $staticcompany->getNomUrl(1,'',20);
  306. print '</td>';
  307. print '<td align="center">'.dol_print_date($db->jdate($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 as name,";
  328. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  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', 0).")";
  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"><th colspan="4">'.$langs->trans("LastModifiedServices",$max).'</th>';
  347. print "</tr>\n";
  348. while ($i < min($num,$max))
  349. {
  350. $obj = $db->fetch_object($resql);
  351. print '<tr class="oddeven">';
  352. print '<td width="110" class="nowrap">';
  353. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  354. $staticcontrat->id=$obj->fk_contrat;
  355. print $staticcontrat->getNomUrl(1,16);
  356. //if (1 == 1) print img_warning($langs->trans("Late"));
  357. print '</td>';
  358. print '<td>';
  359. if ($obj->fk_product > 0)
  360. {
  361. $productstatic->id=$obj->fk_product;
  362. $productstatic->type=$obj->ptype;
  363. $productstatic->ref=$obj->pref;
  364. $productstatic->entity=$obj->pentity;
  365. print $productstatic->getNomUrl(1,'',20);
  366. }
  367. else
  368. {
  369. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  370. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  371. else print '</a> '.dol_trunc($obj->note,20);
  372. }
  373. print '</td>';
  374. print '<td>';
  375. $staticcompany->id=$obj->fk_soc;
  376. $staticcompany->name=$obj->name;
  377. print $staticcompany->getNomUrl(1,'',20);
  378. print '</td>';
  379. print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  380. $dateend=$db->jdate($obj->date_fin_validite);
  381. print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
  382. print '</a></td>';
  383. print "</tr>\n";
  384. $i++;
  385. }
  386. $db->free();
  387. print "</table>";
  388. }
  389. else
  390. {
  391. dol_print_error($db);
  392. }
  393. print '<br>';
  394. // Not activated services
  395. $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,";
  396. $sql.= " s.nom as name,";
  397. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  398. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  399. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  400. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  401. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  402. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  403. $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
  404. $sql.= " AND c.statut = 1";
  405. $sql.= " AND cd.statut = 0";
  406. $sql.= " AND cd.fk_contrat = c.rowid";
  407. $sql.= " AND c.fk_soc = s.rowid";
  408. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  409. if ($socid) $sql.= " AND s.rowid = ".$socid;
  410. $sql.= " ORDER BY cd.tms DESC";
  411. $resql=$db->query($sql);
  412. if ($resql)
  413. {
  414. $num = $db->num_rows($resql);
  415. $i = 0;
  416. print '<table class="noborder" width="100%">';
  417. 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>';
  418. print "</tr>\n";
  419. while ($i < $num)
  420. {
  421. $obj = $db->fetch_object($resql);
  422. print '<tr class="oddeven">';
  423. print '<td width="110" class="nowrap">';
  424. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  425. $staticcontrat->id=$obj->fk_contrat;
  426. print $staticcontrat->getNomUrl(1,16);
  427. print '</td>';
  428. print '<td class="nowrap">';
  429. if ($obj->fk_product > 0)
  430. {
  431. $productstatic->id=$obj->fk_product;
  432. $productstatic->type=$obj->ptype;
  433. $productstatic->ref=$obj->pref;
  434. $productstatic->entity=$obj->pentity;
  435. print $productstatic->getNomUrl(1,'',20);
  436. }
  437. else
  438. {
  439. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  440. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  441. else print '</a> '.dol_trunc($obj->note,20);
  442. }
  443. print '</td>';
  444. print '<td>';
  445. $staticcompany->id=$obj->fk_soc;
  446. $staticcompany->name=$obj->name;
  447. print $staticcompany->getNomUrl(1,'',20);
  448. print '</td>';
  449. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  450. print $staticcontratligne->LibStatut($obj->statut,3);
  451. print '</a></td>';
  452. print "</tr>\n";
  453. $i++;
  454. }
  455. $db->free();
  456. print "</table>";
  457. }
  458. else
  459. {
  460. dol_print_error($db);
  461. }
  462. print '<br>';
  463. // Expired services
  464. $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,";
  465. $sql.= " s.nom as name,";
  466. $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  467. $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
  468. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  469. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  470. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  471. $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  472. $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
  473. $sql.= " AND c.statut = 1";
  474. $sql.= " AND cd.statut = 4";
  475. $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  476. $sql.= " AND cd.fk_contrat = c.rowid";
  477. $sql.= " AND c.fk_soc = s.rowid";
  478. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  479. if ($socid) $sql.= " AND s.rowid = ".$socid;
  480. $sql.= " ORDER BY cd.tms DESC";
  481. $resql=$db->query($sql);
  482. if ($resql)
  483. {
  484. $num = $db->num_rows($resql);
  485. $i = 0;
  486. print '<table class="noborder" width="100%">';
  487. 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>';
  488. print "</tr>\n";
  489. while ($i < $num)
  490. {
  491. $obj = $db->fetch_object($resql);
  492. print '<tr class="oddeven">';
  493. print '<td width="110" class="nowrap">';
  494. $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
  495. $staticcontrat->id=$obj->fk_contrat;
  496. print $staticcontrat->getNomUrl(1,16);
  497. print '</td>';
  498. print '<td class="nowrap">';
  499. if ($obj->fk_product > 0)
  500. {
  501. $productstatic->id=$obj->fk_product;
  502. $productstatic->type=$obj->ptype;
  503. $productstatic->ref=$obj->pref;
  504. $productstatic->entity=$obj->pentity;
  505. print $productstatic->getNomUrl(1,'',20);
  506. }
  507. else
  508. {
  509. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
  510. if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
  511. else print '</a> '.dol_trunc($obj->note,20);
  512. }
  513. print '</td>';
  514. print '<td>';
  515. $staticcompany->id=$obj->fk_soc;
  516. $staticcompany->name=$obj->name;
  517. print $staticcompany->getNomUrl(1,'',20);
  518. print '</td>';
  519. print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  520. print $staticcontratligne->LibStatut($obj->statut,3,1);
  521. print '</a></td>';
  522. print "</tr>\n";
  523. $i++;
  524. }
  525. $db->free();
  526. print "</table>";
  527. }
  528. else
  529. {
  530. dol_print_error($db);
  531. }
  532. //print '</td></tr></table>';
  533. print '</div></div></div>';
  534. llxFooter();
  535. $db->close();