index.php 12 KB

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