index.php 12 KB

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