index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. // 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->rights->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 (empty($user->rights->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 (empty($user->rights->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 (!empty($conf->global->FICHINTER_CLASSIFY_BILLED)) $listofstatus[] = Fichinter::STATUS_BILLED;
  99. foreach ($listofstatus as $status) {
  100. $dataseries[] = array($fichinterstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  101. if ($status == Fichinter::STATUS_DRAFT) {
  102. $colorseries[$status] = '-'.$badgeStatus0;
  103. }
  104. if ($status == Fichinter::STATUS_VALIDATED) {
  105. $colorseries[$status] = $badgeStatus1;
  106. }
  107. if ($status == Fichinter::STATUS_BILLED) {
  108. $colorseries[$status] = $badgeStatus4;
  109. }
  110. }
  111. if ($conf->use_javascript_ajax) {
  112. print '<tr class="impair"><td class="center" colspan="2">';
  113. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  114. $dolgraph = new DolGraph();
  115. $dolgraph->SetData($dataseries);
  116. $dolgraph->SetDataColor(array_values($colorseries));
  117. $dolgraph->setShowLegend(2);
  118. $dolgraph->setShowPercent(1);
  119. $dolgraph->SetType(array('pie'));
  120. $dolgraph->setHeight('200');
  121. $dolgraph->draw('idgraphstatus');
  122. print $dolgraph->show($total ? 0 : 1);
  123. print '</td></tr>';
  124. }
  125. foreach ($listofstatus as $status) {
  126. if (!$conf->use_javascript_ajax) {
  127. print '<tr class="oddeven">';
  128. print '<td>'.$fichinterstatic->LibStatut($status, 0).'</td>';
  129. print '<td class="right"><a href="list.php?search_status='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).' ';
  130. print $fichinterstatic->LibStatut($status, 3);
  131. print '</a>';
  132. print '</td>';
  133. print "</tr>\n";
  134. }
  135. }
  136. //if ($totalinprocess != $total)
  137. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
  138. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
  139. print "</table></div><br>";
  140. } else {
  141. dol_print_error($db);
  142. }
  143. /*
  144. * Draft orders
  145. */
  146. if (isModEnabled('ficheinter')) {
  147. $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
  148. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  149. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  150. if (empty($user->rights->societe->client->voir) && !$socid) {
  151. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  152. }
  153. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  154. $sql .= " AND f.fk_soc = s.rowid";
  155. $sql .= " AND f.fk_statut = 0";
  156. if ($socid) {
  157. $sql .= " AND f.fk_soc = ".((int) $socid);
  158. }
  159. if (empty($user->rights->societe->client->voir) && !$socid) {
  160. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  161. }
  162. $resql = $db->query($sql);
  163. if ($resql) {
  164. print '<div class="div-table-responsive-no-min">';
  165. print '<table class="noborder centpercent">';
  166. print '<tr class="liste_titre">';
  167. print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
  168. $langs->load("fichinter");
  169. $num = $db->num_rows($resql);
  170. if ($num) {
  171. $i = 0;
  172. while ($i < $num) {
  173. $obj = $db->fetch_object($resql);
  174. print '<tr class="oddeven">';
  175. print '<td class="nowrap">';
  176. print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."</a></td>";
  177. 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>';
  178. $i++;
  179. }
  180. }
  181. print "</table></div><br>";
  182. }
  183. }
  184. print '</div><div class="fichetwothirdright">';
  185. $max = 5;
  186. /*
  187. * Last modified interventions
  188. */
  189. $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
  190. $sql .= " s.nom as name, s.rowid as socid";
  191. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
  192. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  193. if (empty($user->rights->societe->client->voir) && !$socid) {
  194. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  195. }
  196. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  197. $sql .= " AND f.fk_soc = s.rowid";
  198. //$sql.= " AND c.fk_statut > 2";
  199. if ($socid) {
  200. $sql .= " AND f.fk_soc = ".((int) $socid);
  201. }
  202. if (empty($user->rights->societe->client->voir) && !$socid) {
  203. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  204. }
  205. $sql .= " ORDER BY f.tms DESC";
  206. $sql .= $db->plimit($max, 0);
  207. $resql = $db->query($sql);
  208. if ($resql) {
  209. print '<div class="div-table-responsive-no-min">';
  210. print '<table class="noborder centpercent">';
  211. print '<tr class="liste_titre">';
  212. print '<th colspan="4">'.$langs->trans("LastModifiedInterventions", $max).'</th></tr>';
  213. $num = $db->num_rows($resql);
  214. if ($num) {
  215. $i = 0;
  216. while ($i < $num) {
  217. $obj = $db->fetch_object($resql);
  218. print '<tr class="oddeven">';
  219. print '<td width="20%" class="nowrap">';
  220. $fichinterstatic->id = $obj->rowid;
  221. $fichinterstatic->ref = $obj->ref;
  222. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  223. print '<td width="96" class="nobordernopadding nowrap">';
  224. print $fichinterstatic->getNomUrl(1);
  225. print '</td>';
  226. print '<td width="16" class="nobordernopadding nowrap">';
  227. print '&nbsp;';
  228. print '</td>';
  229. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  230. $filename = dol_sanitizeFileName($obj->ref);
  231. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  232. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  233. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  234. print '</td></tr></table>';
  235. print '</td>';
  236. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  237. print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
  238. print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
  239. print '</tr>';
  240. $i++;
  241. }
  242. }
  243. print "</table></div><br>";
  244. } else {
  245. dol_print_error($db);
  246. }
  247. /*
  248. * interventions to process
  249. */
  250. if (isModEnabled('ficheinter')) {
  251. $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
  252. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  253. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  254. if (empty($user->rights->societe->client->voir) && !$socid) {
  255. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  256. }
  257. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  258. $sql .= " AND f.fk_soc = s.rowid";
  259. $sql .= " AND f.fk_statut = 1";
  260. if ($socid) {
  261. $sql .= " AND f.fk_soc = ".((int) $socid);
  262. }
  263. if (empty($user->rights->societe->client->voir) && !$socid) {
  264. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  265. }
  266. $sql .= " ORDER BY f.rowid DESC";
  267. $resql = $db->query($sql);
  268. if ($resql) {
  269. $num = $db->num_rows($resql);
  270. print '<div class="div-table-responsive-no-min">';
  271. print '<table class="noborder centpercent">';
  272. print '<tr class="liste_titre">';
  273. 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>';
  274. if ($num) {
  275. $i = 0;
  276. while ($i < $num) {
  277. $obj = $db->fetch_object($resql);
  278. print '<tr class="oddeven">';
  279. print '<td class="nowrap" width="20%">';
  280. $fichinterstatic->id = $obj->rowid;
  281. $fichinterstatic->ref = $obj->ref;
  282. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  283. print '<td width="96" class="nobordernopadding nowrap">';
  284. print $fichinterstatic->getNomUrl(1);
  285. print '</td>';
  286. print '<td width="16" class="nobordernopadding nowrap">';
  287. print '&nbsp;';
  288. print '</td>';
  289. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  290. $filename = dol_sanitizeFileName($obj->ref);
  291. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  292. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  293. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  294. print '</td></tr></table>';
  295. print '</td>';
  296. 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>';
  297. print '<td class="right">'.$fichinterstatic->LibStatut($obj->fk_statut, 5).'</td>';
  298. print '</tr>';
  299. $i++;
  300. }
  301. }
  302. print "</table></div><br>";
  303. } else {
  304. dol_print_error($db);
  305. }
  306. }
  307. print '</div></div>';
  308. $parameters = array('user' => $user);
  309. $reshook = $hookmanager->executeHooks('dashboardInterventions', $parameters, $object); // Note that $action and $object may have been modified by hook
  310. llxFooter();
  311. $db->close();