index.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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 (empty($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 = '.((int) $user->socid);
  80. }
  81. if (empty($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 (empty($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 = '.((int) $user->socid);
  117. }
  118. if (empty($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 (empty($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 (empty($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">';
  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 (empty($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 (empty($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. $datem = $db->jdate($obj->tms);
  302. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
  303. $staticcontrat->id = $obj->cid;
  304. $staticcompany->id = $obj->socid;
  305. $staticcompany->name = $obj->name;
  306. print '<tr class="oddeven">';
  307. print '<td class="nowraponall">';
  308. print $staticcontrat->getNomUrl(1, 16);
  309. if ($obj->nb_late) {
  310. print img_warning($langs->trans("Late"));
  311. }
  312. print '</td>';
  313. print '<td class="tdoverflowmax150">';
  314. print $staticcompany->getNomUrl(1, '', 20);
  315. print '</td>';
  316. print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  317. print dol_print_date($datem, 'dayhour');
  318. print '</td>';
  319. //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
  320. 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>';
  321. 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>';
  322. 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>';
  323. 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>';
  324. print "</tr>\n";
  325. $i++;
  326. }
  327. $db->free($result);
  328. print "</table></div>";
  329. } else {
  330. dol_print_error($db);
  331. }
  332. print '<br>';
  333. // Last modified services
  334. $sql = "SELECT c.ref, c.fk_soc, ";
  335. $sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
  336. $sql .= " s.nom as name,";
  337. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  338. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  339. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  340. if (empty($user->rights->societe->client->voir) && !$socid) {
  341. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  342. }
  343. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  344. $sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  345. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  346. $sql .= " AND cd.fk_contrat = c.rowid";
  347. $sql .= " AND c.fk_soc = s.rowid";
  348. if (empty($user->rights->societe->client->voir) && !$socid) {
  349. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  350. }
  351. if ($socid) {
  352. $sql .= " AND s.rowid = ".((int) $socid);
  353. }
  354. $sql .= " ORDER BY cd.tms DESC";
  355. $resql = $db->query($sql);
  356. if ($resql) {
  357. $num = $db->num_rows($resql);
  358. $i = 0;
  359. print '<div class="div-table-responsive-no-min">';
  360. print '<table class="noborder centpercent">';
  361. print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
  362. print "</tr>\n";
  363. while ($i < min($num, $max)) {
  364. $obj = $db->fetch_object($resql);
  365. print '<tr class="oddeven">';
  366. print '<td class="nowraponall">';
  367. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  368. $staticcontrat->id = $obj->fk_contrat;
  369. print $staticcontrat->getNomUrl(1, 16);
  370. //if (1 == 1) print img_warning($langs->trans("Late"));
  371. print '</td>';
  372. print '<td>';
  373. if ($obj->fk_product > 0) {
  374. $productstatic->id = $obj->fk_product;
  375. $productstatic->type = $obj->ptype;
  376. $productstatic->ref = $obj->pref;
  377. $productstatic->entity = $obj->pentity;
  378. print $productstatic->getNomUrl(1, '', 20);
  379. } else {
  380. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  381. if ($obj->label) {
  382. print ' '.dol_trunc($obj->label, 20).'</a>';
  383. } else {
  384. print '</a> '.dol_trunc($obj->note, 20);
  385. }
  386. }
  387. print '</td>';
  388. print '<td class="tdoverflowmax125">';
  389. $staticcompany->id = $obj->fk_soc;
  390. $staticcompany->name = $obj->name;
  391. print $staticcompany->getNomUrl(1, '', 20);
  392. print '</td>';
  393. print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  394. $dateend = $db->jdate($obj->date_fin_validite);
  395. print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
  396. print '</a></td>';
  397. print "</tr>\n";
  398. $i++;
  399. }
  400. $db->free($resql);
  401. print "</table></div>";
  402. } else {
  403. dol_print_error($db);
  404. }
  405. print '<br>';
  406. // Not activated services
  407. $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,";
  408. $sql .= " s.nom as name,";
  409. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  410. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  411. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  412. if (empty($user->rights->societe->client->voir) && !$socid) {
  413. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  414. }
  415. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  416. $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  417. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  418. $sql .= " AND c.statut = 1";
  419. $sql .= " AND cd.statut = 0";
  420. $sql .= " AND cd.fk_contrat = c.rowid";
  421. $sql .= " AND c.fk_soc = s.rowid";
  422. if (empty($user->rights->societe->client->voir) && !$socid) {
  423. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  424. }
  425. if ($socid) {
  426. $sql .= " AND s.rowid = ".((int) $socid);
  427. }
  428. $sql .= " ORDER BY cd.tms DESC";
  429. $resql = $db->query($sql);
  430. if ($resql) {
  431. $num = $db->num_rows($resql);
  432. $i = 0;
  433. print '<div class="div-table-responsive-no-min">';
  434. print '<table class="noborder centpercent">';
  435. 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>';
  436. print "</tr>\n";
  437. while ($i < $num) {
  438. $obj = $db->fetch_object($resql);
  439. print '<tr class="oddeven">';
  440. print '<td class="nowraponall">';
  441. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  442. $staticcontrat->id = $obj->fk_contrat;
  443. print $staticcontrat->getNomUrl(1, 16);
  444. print '</td>';
  445. print '<td class="nowrap">';
  446. if ($obj->fk_product > 0) {
  447. $productstatic->id = $obj->fk_product;
  448. $productstatic->type = $obj->ptype;
  449. $productstatic->ref = $obj->pref;
  450. $productstatic->entity = $obj->pentity;
  451. print $productstatic->getNomUrl(1, '', 20);
  452. } else {
  453. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  454. if ($obj->label) {
  455. print ' '.dol_trunc($obj->label, 20).'</a>';
  456. } else {
  457. print '</a> '.dol_trunc($obj->note, 20);
  458. }
  459. }
  460. print '</td>';
  461. print '<td class="tdoverflowmax125">';
  462. $staticcompany->id = $obj->fk_soc;
  463. $staticcompany->name = $obj->name;
  464. print $staticcompany->getNomUrl(1, '', 20);
  465. print '</td>';
  466. print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  467. print $staticcontratligne->LibStatut($obj->statut, 3);
  468. print '</a></td>';
  469. print "</tr>\n";
  470. $i++;
  471. }
  472. $db->free($resql);
  473. print "</table></div>";
  474. } else {
  475. dol_print_error($db);
  476. }
  477. print '<br>';
  478. // Expired services
  479. $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,";
  480. $sql .= " s.nom as name,";
  481. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  482. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  483. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  484. if (empty($user->rights->societe->client->voir) && !$socid) {
  485. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  486. }
  487. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  488. $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  489. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  490. $sql .= " AND c.statut = 1";
  491. $sql .= " AND cd.statut = 4";
  492. $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  493. $sql .= " AND cd.fk_contrat = c.rowid";
  494. $sql .= " AND c.fk_soc = s.rowid";
  495. if (empty($user->rights->societe->client->voir) && !$socid) {
  496. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  497. }
  498. if ($socid) {
  499. $sql .= " AND s.rowid = ".((int) $socid);
  500. }
  501. $sql .= " ORDER BY cd.tms DESC";
  502. $resql = $db->query($sql);
  503. if ($resql) {
  504. $num = $db->num_rows($resql);
  505. $i = 0;
  506. print '<div class="div-table-responsive-no-min">';
  507. print '<table class="noborder centpercent">';
  508. 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>';
  509. print "</tr>\n";
  510. while ($i < $num) {
  511. $obj = $db->fetch_object($resql);
  512. print '<tr class="oddeven">';
  513. print '<td class="nowraponall">';
  514. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  515. $staticcontrat->id = $obj->fk_contrat;
  516. print $staticcontrat->getNomUrl(1, 16);
  517. print '</td>';
  518. print '<td class="nowrap">';
  519. if ($obj->fk_product > 0) {
  520. $productstatic->id = $obj->fk_product;
  521. $productstatic->type = $obj->ptype;
  522. $productstatic->ref = $obj->pref;
  523. $productstatic->entity = $obj->pentity;
  524. print $productstatic->getNomUrl(1, '', 20);
  525. } else {
  526. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  527. if ($obj->label) {
  528. print ' '.dol_trunc($obj->label, 20).'</a>';
  529. } else {
  530. print '</a> '.dol_trunc($obj->note, 20);
  531. }
  532. }
  533. print '</td>';
  534. print '<td class="tdoverflowmax125">';
  535. $staticcompany->id = $obj->fk_soc;
  536. $staticcompany->name = $obj->name;
  537. print $staticcompany->getNomUrl(1, '', 20);
  538. print '</td>';
  539. print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  540. print $staticcontratligne->LibStatut($obj->statut, 3, 1);
  541. print '</a></td>';
  542. print "</tr>\n";
  543. $i++;
  544. }
  545. $db->free($resql);
  546. print "</table></div>";
  547. } else {
  548. dol_print_error($db);
  549. }
  550. print '</div></div>';
  551. $parameters = array('user' => $user);
  552. $reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
  553. llxFooter();
  554. $db->close();