index.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 (!$user->hasRight('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 (!$user->hasRight('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 (!$user->hasRight('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 (!$user->hasRight('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?search_status='.((int) $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?search_status='.((int) $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->hasRight('contrat', 'lire')) {
  209. $sql = "SELECT c.rowid, c.ref,";
  210. $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
  211. $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
  212. if (!$user->hasRight('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 (!$user->hasRight('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. $i = 0;
  233. //$tot_ttc = 0;
  234. while ($i < $num) {
  235. $obj = $db->fetch_object($resql);
  236. $staticcontrat->ref = $obj->ref;
  237. $staticcontrat->id = $obj->rowid;
  238. $staticcompany->id = $obj->socid;
  239. $staticcompany->name = $obj->name;
  240. $staticcompany->name_alias = $obj->name_alias;
  241. $staticcompany->photo = 1;
  242. $staticcompany->code_client = $obj->code_client;
  243. $staticcompany->code_fournisseur = $obj->code_fournisseur;
  244. $staticcompany->code_compta = $obj->code_compta;
  245. $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
  246. $staticcompany->client = $obj->client;
  247. $staticcompany->fournisseur = $obj->fournisseur;
  248. print '<tr class="oddeven"><td class="nowrap">';
  249. print $staticcontrat->getNomUrl(1, '');
  250. print '</td>';
  251. print '<td>';
  252. print $staticcompany->getNomUrl(1, '', 16);
  253. print '</td>';
  254. print '</tr>';
  255. //$tot_ttc+=$obj->total_ttc;
  256. $i++;
  257. }
  258. } else {
  259. print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoContracts").'</span></td></tr>';
  260. }
  261. print "</table></div><br>";
  262. $db->free($resql);
  263. } else {
  264. dol_print_error($db);
  265. }
  266. }
  267. print '</div><div class="fichetwothirdright">';
  268. // Last modified contracts
  269. $max = 5;
  270. $sql = 'SELECT ';
  271. $sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
  272. $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,';
  273. $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,';
  274. $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,';
  275. $sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
  276. $sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,";
  277. $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
  278. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
  279. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  280. $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  281. }
  282. $sql .= " ".MAIN_DB_PREFIX."contrat as c";
  283. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  284. $sql .= " WHERE c.fk_soc = s.rowid";
  285. $sql .= " AND c.entity IN (".getEntity('contract', 0).")";
  286. $sql .= " AND c.statut > 0";
  287. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  288. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  289. }
  290. if ($socid) {
  291. $sql .= " AND s.rowid = ".((int) $socid);
  292. }
  293. $sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut,";
  294. $sql .= " s.nom, s.name_alias, s.logo, s.rowid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
  295. $sql .= " ORDER BY c.tms DESC";
  296. $sql .= $db->plimit($max);
  297. dol_syslog("contrat/index.php", LOG_DEBUG);
  298. $result = $db->query($sql);
  299. if ($result) {
  300. $num = $db->num_rows($result);
  301. $i = 0;
  302. print '<div class="div-table-responsive-no-min">';
  303. print '<table class="noborder centpercent">';
  304. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", 5).'</th>';
  305. print '<th class="center">'.$langs->trans("DateModification").'</th>';
  306. //print '<th class="left">'.$langs->trans("Status").'</th>';
  307. print '<th class="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
  308. print "</tr>\n";
  309. while ($i < $num) {
  310. $obj = $db->fetch_object($result);
  311. $datem = $db->jdate($obj->tms);
  312. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
  313. $staticcontrat->id = $obj->cid;
  314. $staticcompany->id = $obj->socid;
  315. $staticcompany->name = $obj->name;
  316. $staticcompany->name_alias = $obj->name_alias;
  317. $staticcompany->photo = 1;
  318. $staticcompany->code_client = $obj->code_client;
  319. $staticcompany->code_fournisseur = $obj->code_fournisseur;
  320. $staticcompany->code_compta = $obj->code_compta;
  321. $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
  322. $staticcompany->client = $obj->client;
  323. $staticcompany->fournisseur = $obj->fournisseur;
  324. print '<tr class="oddeven">';
  325. print '<td class="nowraponall">';
  326. print $staticcontrat->getNomUrl(1, 16);
  327. if ($obj->nb_late) {
  328. print img_warning($langs->trans("Late"));
  329. }
  330. print '</td>';
  331. print '<td class="tdoverflowmax150">';
  332. print $staticcompany->getNomUrl(1, '', 20);
  333. print '</td>';
  334. print '<td class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  335. print dol_print_date($datem, 'dayhour');
  336. print '</td>';
  337. //print '<td class="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
  338. 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>';
  339. 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>';
  340. 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>';
  341. 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>';
  342. print "</tr>\n";
  343. $i++;
  344. }
  345. $db->free($result);
  346. print "</table></div>";
  347. } else {
  348. dol_print_error($db);
  349. }
  350. print '<br>';
  351. // Last modified services
  352. $sql = "SELECT c.ref, c.fk_soc as socid,";
  353. $sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
  354. $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
  355. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  356. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  357. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  358. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  359. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  360. }
  361. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  362. $sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  363. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  364. $sql .= " AND cd.fk_contrat = c.rowid";
  365. $sql .= " AND c.fk_soc = s.rowid";
  366. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  367. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  368. }
  369. if ($socid) {
  370. $sql .= " AND s.rowid = ".((int) $socid);
  371. }
  372. $sql .= " ORDER BY cd.tms DESC";
  373. $resql = $db->query($sql);
  374. if ($resql) {
  375. $num = $db->num_rows($resql);
  376. $i = 0;
  377. print '<div class="div-table-responsive-no-min">';
  378. print '<table class="noborder centpercent">';
  379. print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
  380. print "</tr>\n";
  381. while ($i < min($num, $max)) {
  382. $obj = $db->fetch_object($resql);
  383. print '<tr class="oddeven">';
  384. print '<td class="nowraponall">';
  385. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  386. $staticcontrat->id = $obj->fk_contrat;
  387. $staticcompany->id = $obj->socid;
  388. $staticcompany->name = $obj->name;
  389. $staticcompany->name_alias = $obj->name_alias;
  390. $staticcompany->photo = 1;
  391. $staticcompany->code_client = $obj->code_client;
  392. $staticcompany->code_fournisseur = $obj->code_fournisseur;
  393. $staticcompany->code_compta = $obj->code_compta;
  394. $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
  395. $staticcompany->client = $obj->client;
  396. $staticcompany->fournisseur = $obj->fournisseur;
  397. print $staticcontrat->getNomUrl(1, 16);
  398. //if (1 == 1) print img_warning($langs->trans("Late"));
  399. print '</td>';
  400. print '<td>';
  401. if ($obj->fk_product > 0) {
  402. $productstatic->id = $obj->fk_product;
  403. $productstatic->type = $obj->ptype;
  404. $productstatic->ref = $obj->pref;
  405. $productstatic->entity = $obj->pentity;
  406. print $productstatic->getNomUrl(1, '', 20);
  407. } else {
  408. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  409. if ($obj->label) {
  410. print ' '.dol_trunc($obj->label, 20).'</a>';
  411. } else {
  412. print '</a> '.dol_trunc($obj->note, 20);
  413. }
  414. }
  415. print '</td>';
  416. print '<td class="tdoverflowmax125">';
  417. print $staticcompany->getNomUrl(1, '', 20);
  418. print '</td>';
  419. print '<td class="nowrap right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  420. $dateend = $db->jdate($obj->date_fin_validite);
  421. print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
  422. print '</a></td>';
  423. print "</tr>\n";
  424. $i++;
  425. }
  426. $db->free($resql);
  427. print "</table></div>";
  428. } else {
  429. dol_print_error($db);
  430. }
  431. print '<br>';
  432. // Not activated services
  433. $sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
  434. $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
  435. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  436. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  437. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  438. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  439. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  440. }
  441. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  442. $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  443. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  444. $sql .= " AND c.statut = 1";
  445. $sql .= " AND cd.statut = 0";
  446. $sql .= " AND cd.fk_contrat = c.rowid";
  447. $sql .= " AND c.fk_soc = s.rowid";
  448. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  449. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  450. }
  451. if ($socid) {
  452. $sql .= " AND s.rowid = ".((int) $socid);
  453. }
  454. $sql .= " ORDER BY cd.tms DESC";
  455. $resql = $db->query($sql);
  456. if ($resql) {
  457. $num = $db->num_rows($resql);
  458. $i = 0;
  459. print '<div class="div-table-responsive-no-min">';
  460. print '<table class="noborder centpercent">';
  461. 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>';
  462. print "</tr>\n";
  463. while ($i < $num) {
  464. $obj = $db->fetch_object($resql);
  465. $staticcompany->id = $obj->thirdpartyid;
  466. $staticcompany->name = $obj->name;
  467. $staticcompany->name_alias = $obj->name_alias;
  468. $staticcompany->photo = 1;
  469. $staticcompany->code_client = $obj->code_client;
  470. $staticcompany->code_fournisseur = $obj->code_fournisseur;
  471. $staticcompany->code_compta = $obj->code_compta;
  472. $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
  473. $staticcompany->client = $obj->client;
  474. $staticcompany->fournisseur = $obj->fournisseur;
  475. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  476. $staticcontrat->id = $obj->fk_contrat;
  477. $productstatic->id = $obj->fk_product;
  478. $productstatic->type = $obj->ptype;
  479. $productstatic->ref = $obj->pref;
  480. $productstatic->entity = $obj->pentity;
  481. print '<tr class="oddeven">';
  482. print '<td class="nowraponall">';
  483. print $staticcontrat->getNomUrl(1, 16);
  484. print '</td>';
  485. print '<td class="nowrap">';
  486. if ($obj->fk_product > 0) {
  487. print $productstatic->getNomUrl(1, '', 20);
  488. } else {
  489. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  490. if ($obj->label) {
  491. print ' '.dol_trunc($obj->label, 20).'</a>';
  492. } else {
  493. print '</a> '.dol_trunc($obj->note, 20);
  494. }
  495. }
  496. print '</td>';
  497. print '<td class="tdoverflowmax125">';
  498. print $staticcompany->getNomUrl(1, '', 20);
  499. print '</td>';
  500. print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  501. print $staticcontratligne->LibStatut($obj->statut, 3);
  502. print '</a></td>';
  503. print "</tr>\n";
  504. $i++;
  505. }
  506. $db->free($resql);
  507. print "</table></div>";
  508. } else {
  509. dol_print_error($db);
  510. }
  511. print '<br>';
  512. // Expired services
  513. $sql = "SELECT c.ref, c.fk_soc as thirdpartyid, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
  514. $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
  515. $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
  516. $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
  517. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  518. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  519. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  520. }
  521. $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
  522. $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  523. $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
  524. $sql .= " AND c.statut = 1";
  525. $sql .= " AND cd.statut = 4";
  526. $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  527. $sql .= " AND cd.fk_contrat = c.rowid";
  528. $sql .= " AND c.fk_soc = s.rowid";
  529. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  530. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  531. }
  532. if ($socid) {
  533. $sql .= " AND s.rowid = ".((int) $socid);
  534. }
  535. $sql .= " ORDER BY cd.tms DESC";
  536. $resql = $db->query($sql);
  537. if ($resql) {
  538. $num = $db->num_rows($resql);
  539. $i = 0;
  540. print '<div class="div-table-responsive-no-min">';
  541. print '<table class="noborder centpercent">';
  542. print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?search_status=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';
  543. print "</tr>\n";
  544. while ($i < $num) {
  545. $obj = $db->fetch_object($resql);
  546. $staticcompany->id = $obj->thirdpartyid;
  547. $staticcompany->name = $obj->name;
  548. $staticcompany->name_alias = $obj->name_alias;
  549. $staticcompany->photo = 1;
  550. $staticcompany->code_client = $obj->code_client;
  551. $staticcompany->code_fournisseur = $obj->code_fournisseur;
  552. $staticcompany->code_compta = $obj->code_compta;
  553. $staticcompany->code_compta_fournisseur = $obj->code_compta_fournisseur;
  554. $staticcompany->client = $obj->client;
  555. $staticcompany->fournisseur = $obj->fournisseur;
  556. $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
  557. $staticcontrat->id = $obj->fk_contrat;
  558. $productstatic->id = $obj->fk_product;
  559. $productstatic->type = $obj->ptype;
  560. $productstatic->ref = $obj->pref;
  561. $productstatic->entity = $obj->pentity;
  562. print '<tr class="oddeven">';
  563. print '<td class="nowraponall">';
  564. print $staticcontrat->getNomUrl(1, 16);
  565. print '</td>';
  566. print '<td class="nowrap">';
  567. if ($obj->fk_product > 0) {
  568. print $productstatic->getNomUrl(1, '', 20);
  569. } else {
  570. print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
  571. if ($obj->label) {
  572. print ' '.dol_trunc($obj->label, 20).'</a>';
  573. } else {
  574. print '</a> '.dol_trunc($obj->note, 20);
  575. }
  576. }
  577. print '</td>';
  578. print '<td class="tdoverflowmax125">';
  579. print $staticcompany->getNomUrl(1, '', 20);
  580. print '</td>';
  581. print '<td width="16" class="right"><a href="line.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
  582. print $staticcontratligne->LibStatut($obj->statut, 3, 1);
  583. print '</a></td>';
  584. print "</tr>\n";
  585. $i++;
  586. }
  587. $db->free($resql);
  588. print "</table></div>";
  589. } else {
  590. dol_print_error($db);
  591. }
  592. print '</div></div>';
  593. $parameters = array('user' => $user);
  594. $reshook = $hookmanager->executeHooks('dashboardContracts', $parameters, $object); // Note that $action and $object may have been modified by hook
  595. llxFooter();
  596. $db->close();