index.php 21 KB

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