index.php 22 KB

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