index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Charlie Benke <charlie@patas-monkey.com>
  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/fichinter/index.php
  23. * \ingroup commande
  24. * \brief Home page of interventional module
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  30. if (!$user->rights->ficheinter->lire) {
  31. accessforbidden();
  32. }
  33. $hookmanager = new HookManager($db);
  34. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  35. $hookmanager->initHooks(array('interventionindex'));
  36. // Load translation files required by the page
  37. $langs->load("interventions");
  38. // Security check
  39. $socid = GETPOST('socid', 'int');
  40. if ($user->socid > 0) {
  41. $action = '';
  42. $socid = $user->socid;
  43. }
  44. /*
  45. * View
  46. */
  47. $fichinterstatic = new Fichinter($db);
  48. $form = new Form($db);
  49. $formfile = new FormFile($db);
  50. $help_url = "EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
  51. llxHeader("", $langs->trans("Interventions"), $help_url);
  52. print load_fiche_titre($langs->trans("InterventionsArea"), '', 'intervention');
  53. print '<div class="fichecenter"><div class="fichethirdleft">';
  54. /*
  55. * Statistics
  56. */
  57. $sql = "SELECT count(f.rowid), f.fk_statut";
  58. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  59. $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
  60. if (!$user->rights->societe->client->voir && !$socid) {
  61. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  62. }
  63. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  64. $sql .= " AND f.fk_soc = s.rowid";
  65. if ($user->socid) {
  66. $sql .= ' AND f.fk_soc = '.$user->socid;
  67. }
  68. if (!$user->rights->societe->client->voir && !$socid) {
  69. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  70. }
  71. $sql .= " GROUP BY f.fk_statut";
  72. $resql = $db->query($sql);
  73. if ($resql) {
  74. $num = $db->num_rows($resql);
  75. $i = 0;
  76. $total = 0;
  77. $totalinprocess = 0;
  78. $dataseries = array();
  79. $vals = array();
  80. $bool = false;
  81. // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
  82. while ($i < $num) {
  83. $row = $db->fetch_row($resql);
  84. if ($row) {
  85. //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
  86. {
  87. $bool = (!empty($row[2]) ?true:false);
  88. if (!isset($vals[$row[1].$bool])) {
  89. $vals[$row[1].$bool] = 0;
  90. }
  91. $vals[$row[1].$bool] += $row[0];
  92. $totalinprocess += $row[0];
  93. }
  94. $total += $row[0];
  95. }
  96. $i++;
  97. }
  98. $db->free($resql);
  99. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  100. print '<div class="div-table-responsive-no-min">';
  101. print '<table class="noborder nohover centpercent">';
  102. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
  103. $listofstatus = array(0, 1, 3);
  104. $bool = false;
  105. foreach ($listofstatus as $status) {
  106. $dataseries[] = array($fichinterstatic->LibStatut($status, $bool, 1), (isset($vals[$status.$bool]) ? (int) $vals[$status.$bool] : 0));
  107. if ($status == 3 && !$bool) {
  108. $bool = true;
  109. } else {
  110. $bool = false;
  111. }
  112. if ($status == Fichinter::STATUS_DRAFT) {
  113. $colorseries[$status] = '-'.$badgeStatus0;
  114. }
  115. if ($status == Fichinter::STATUS_VALIDATED) {
  116. $colorseries[$status] = $badgeStatus1;
  117. }
  118. if ($status == Fichinter::STATUS_BILLED) {
  119. $colorseries[$status] = $badgeStatus4;
  120. }
  121. if ($status == Fichinter::STATUS_CLOSED) {
  122. $colorseries[$status] = $badgeStatus6;
  123. }
  124. }
  125. if ($conf->use_javascript_ajax) {
  126. print '<tr class="impair"><td class="center" colspan="2">';
  127. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  128. $dolgraph = new DolGraph();
  129. $dolgraph->SetData($dataseries);
  130. $dolgraph->SetDataColor(array_values($colorseries));
  131. $dolgraph->setShowLegend(2);
  132. $dolgraph->setShowPercent(1);
  133. $dolgraph->SetType(array('pie'));
  134. $dolgraph->setHeight('200');
  135. $dolgraph->draw('idgraphstatus');
  136. print $dolgraph->show($total ? 0 : 1);
  137. print '</td></tr>';
  138. }
  139. $bool = false;
  140. foreach ($listofstatus as $status) {
  141. if (!$conf->use_javascript_ajax) {
  142. print '<tr class="oddeven">';
  143. print '<td>'.$fichinterstatic->LibStatut($status, $bool, 0).'</td>';
  144. print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status.$bool]) ? $vals[$status.$bool] : 0).' ';
  145. print $fichinterstatic->LibStatut($status, $bool, 3);
  146. print '</a>';
  147. print '</td>';
  148. print "</tr>\n";
  149. if ($status == 3 && !$bool) {
  150. $bool = true;
  151. } else {
  152. $bool = false;
  153. }
  154. }
  155. }
  156. //if ($totalinprocess != $total)
  157. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
  158. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
  159. print "</table></div><br>";
  160. } else {
  161. dol_print_error($db);
  162. }
  163. /*
  164. * Draft orders
  165. */
  166. if (!empty($conf->ficheinter->enabled)) {
  167. $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
  168. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  169. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  170. if (!$user->rights->societe->client->voir && !$socid) {
  171. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  172. }
  173. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  174. $sql .= " AND f.fk_soc = s.rowid";
  175. $sql .= " AND f.fk_statut = 0";
  176. if ($socid) {
  177. $sql .= " AND f.fk_soc = ".((int) $socid);
  178. }
  179. if (!$user->rights->societe->client->voir && !$socid) {
  180. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  181. }
  182. $resql = $db->query($sql);
  183. if ($resql) {
  184. print '<div class="div-table-responsive-no-min">';
  185. print '<table class="noborder centpercent">';
  186. print '<tr class="liste_titre">';
  187. print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
  188. $langs->load("fichinter");
  189. $num = $db->num_rows($resql);
  190. if ($num) {
  191. $i = 0;
  192. while ($i < $num) {
  193. $obj = $db->fetch_object($resql);
  194. print '<tr class="oddeven">';
  195. print '<td class="nowrap">';
  196. print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
  197. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'</a></td></tr>';
  198. $i++;
  199. }
  200. }
  201. print "</table></div><br>";
  202. }
  203. }
  204. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  205. $max = 5;
  206. /*
  207. * Last modified interventions
  208. */
  209. $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
  210. $sql .= " s.nom as name, s.rowid as socid";
  211. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
  212. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  213. if (!$user->rights->societe->client->voir && !$socid) {
  214. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  215. }
  216. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  217. $sql .= " AND f.fk_soc = s.rowid";
  218. //$sql.= " AND c.fk_statut > 2";
  219. if ($socid) {
  220. $sql .= " AND f.fk_soc = ".((int) $socid);
  221. }
  222. if (!$user->rights->societe->client->voir && !$socid) {
  223. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  224. }
  225. $sql .= " ORDER BY f.tms DESC";
  226. $sql .= $db->plimit($max, 0);
  227. $resql = $db->query($sql);
  228. if ($resql) {
  229. print '<div class="div-table-responsive-no-min">';
  230. print '<table class="noborder centpercent">';
  231. print '<tr class="liste_titre">';
  232. print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
  233. $num = $db->num_rows($resql);
  234. if ($num) {
  235. $i = 0;
  236. while ($i < $num) {
  237. $obj = $db->fetch_object($resql);
  238. print '<tr class="oddeven">';
  239. print '<td width="20%" class="nowrap">';
  240. $fichinterstatic->id = $obj->rowid;
  241. $fichinterstatic->ref = $obj->ref;
  242. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  243. print '<td width="96" class="nobordernopadding nowrap">';
  244. print $fichinterstatic->getNomUrl(1);
  245. print '</td>';
  246. print '<td width="16" class="nobordernopadding nowrap">';
  247. print '&nbsp;';
  248. print '</td>';
  249. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  250. $filename = dol_sanitizeFileName($obj->ref);
  251. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  252. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  253. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  254. print '</td></tr></table>';
  255. print '</td>';
  256. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  257. print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
  258. print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
  259. print '</tr>';
  260. $i++;
  261. }
  262. }
  263. print "</table></div><br>";
  264. } else {
  265. dol_print_error($db);
  266. }
  267. /*
  268. * interventions to process
  269. */
  270. if (!empty($conf->ficheinter->enabled)) {
  271. $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
  272. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  273. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  274. if (!$user->rights->societe->client->voir && !$socid) {
  275. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  276. }
  277. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  278. $sql .= " AND f.fk_soc = s.rowid";
  279. $sql .= " AND f.fk_statut = 1";
  280. if ($socid) {
  281. $sql .= " AND f.fk_soc = ".((int) $socid);
  282. }
  283. if (!$user->rights->societe->client->voir && !$socid) {
  284. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  285. }
  286. $sql .= " ORDER BY f.rowid DESC";
  287. $resql = $db->query($sql);
  288. if ($resql) {
  289. $num = $db->num_rows($resql);
  290. print '<div class="div-table-responsive-no-min">';
  291. print '<table class="noborder centpercent">';
  292. print '<tr class="liste_titre">';
  293. print '<th colspan="3">'.$langs->trans("FichinterToProcess").' <a href="'.DOL_URL_ROOT.'/fichinter/list.php?search_status=1"><span class="badge">'.$num.'</span></a></th></tr>';
  294. if ($num) {
  295. $i = 0;
  296. while ($i < $num) {
  297. $obj = $db->fetch_object($resql);
  298. print '<tr class="oddeven">';
  299. print '<td class="nowrap" width="20%">';
  300. $fichinterstatic->id = $obj->rowid;
  301. $fichinterstatic->ref = $obj->ref;
  302. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  303. print '<td width="96" class="nobordernopadding nowrap">';
  304. print $fichinterstatic->getNomUrl(1);
  305. print '</td>';
  306. print '<td width="16" class="nobordernopadding nowrap">';
  307. print '&nbsp;';
  308. print '</td>';
  309. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  310. $filename = dol_sanitizeFileName($obj->ref);
  311. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  312. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  313. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  314. print '</td></tr></table>';
  315. print '</td>';
  316. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'</a></td>';
  317. print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
  318. print '</tr>';
  319. $i++;
  320. }
  321. }
  322. print "</table></div><br>";
  323. } else {
  324. dol_print_error($db);
  325. }
  326. }
  327. print '</div></div></div>';
  328. $parameters = array('user' => $user);
  329. $reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
  330. llxFooter();
  331. $db->close();