index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/fichinter/index.php
  22. * \ingroup commande
  23. * \brief Home page of interventional module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
  28. require_once DOL_DOCUMENT_ROOT .'/fichinter/class/fichinter.class.php';
  29. if (!$user->rights->ficheinter->lire) accessforbidden();
  30. // Load translation files required by the page
  31. $langs->load("interventions");
  32. // Security check
  33. $socid=GETPOST('socid','int');
  34. if ($user->societe_id > 0)
  35. {
  36. $action = '';
  37. $socid = $user->societe_id;
  38. }
  39. /*
  40. * View
  41. */
  42. $fichinterstatic=new Fichinter($db);
  43. $form = new Form($db);
  44. $formfile = new FormFile($db);
  45. $help_url="EN:ModuleFichinters|FR:Module_Fiche_Interventions|ES:Módulo_FichaInterventiones";
  46. llxHeader("",$langs->trans("Interventions"),$help_url);
  47. print load_fiche_titre($langs->trans("InterventionsArea"));
  48. print '<div class="fichecenter"><div class="fichethirdleft">';
  49. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  50. {
  51. // Search ficheinter
  52. $var=false;
  53. print '<table class="noborder nohover" width="100%">';
  54. print '<form method="post" action="'.DOL_URL_ROOT.'/fichinter/list.php">';
  55. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  56. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  57. print '<tr class="oddeven"><td>';
  58. print $langs->trans("Intervention").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  59. print "</form></table><br>\n";
  60. }
  61. /*
  62. * Statistics
  63. */
  64. $sql = "SELECT count(f.rowid), f.fk_statut";
  65. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  66. $sql.= ", ".MAIN_DB_PREFIX."fichinter as f";
  67. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  68. $sql.= " WHERE f.entity IN (".getEntity('intervention').")";
  69. $sql.= " AND f.fk_soc = s.rowid";
  70. if ($user->societe_id) $sql.=' AND f.fk_soc = '.$user->societe_id;
  71. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  72. $sql.= " GROUP BY f.fk_statut";
  73. $resql = $db->query($sql);
  74. if ($resql)
  75. {
  76. $num = $db->num_rows($resql);
  77. $i = 0;
  78. $total=0;
  79. $totalinprocess=0;
  80. $dataseries=array();
  81. $vals=array();
  82. $bool=false;
  83. // -1=Canceled, 0=Draft, 1=Validated, 2=Accepted/On process, 3=Closed (Sent/Received, billed or not)
  84. while ($i < $num)
  85. {
  86. $row = $db->fetch_row($resql);
  87. if ($row)
  88. {
  89. //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
  90. {
  91. $bool=(! empty($row[2])?true:false);
  92. if (! isset($vals[$row[1].$bool])) $vals[$row[1].$bool]=0;
  93. $vals[$row[1].$bool]+=$row[0];
  94. $totalinprocess+=$row[0];
  95. }
  96. $total+=$row[0];
  97. }
  98. $i++;
  99. }
  100. $db->free($resql);
  101. print '<table class="noborder nohover" width="100%">';
  102. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Interventions").'</th></tr>'."\n";
  103. $listofstatus=array(0,1,2);
  104. $bool=false;
  105. foreach ($listofstatus as $status)
  106. {
  107. $dataseries[]=array($fichinterstatic->LibStatut($status,$bool,1), (isset($vals[$status.$bool])?(int) $vals[$status.$bool]:0));
  108. if ($status==3 && ! $bool) $bool=true;
  109. else $bool=false;
  110. }
  111. if ($conf->use_javascript_ajax)
  112. {
  113. print '<tr class="impair"><td align="center" colspan="2">';
  114. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  115. $dolgraph = new DolGraph();
  116. $dolgraph->SetData($dataseries);
  117. $dolgraph->setShowLegend(1);
  118. $dolgraph->setShowPercent(1);
  119. $dolgraph->SetType(array('pie'));
  120. $dolgraph->setWidth('100%');
  121. $dolgraph->draw('idgraphstatus');
  122. print $dolgraph->show($total?0:1);
  123. $data=array('series'=>$dataseries);
  124. print '</td></tr>';
  125. }
  126. $bool=false;
  127. foreach ($listofstatus as $status)
  128. {
  129. if (! $conf->use_javascript_ajax)
  130. {
  131. print '<tr class="oddeven">';
  132. print '<td>'.$fichinterstatic->LibStatut($status,$bool,0).'</td>';
  133. print '<td align="right"><a href="list.php?viewstatut='.$status.'">'.(isset($vals[$status.$bool])?$vals[$status.$bool]:0).' ';
  134. print $fichinterstatic->LibStatut($status,$bool,3);
  135. print '</a>';
  136. print '</td>';
  137. print "</tr>\n";
  138. if ($status==3 && ! $bool) $bool=true;
  139. else $bool=false;
  140. }
  141. }
  142. //if ($totalinprocess != $total)
  143. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
  144. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
  145. print "</table><br>";
  146. }
  147. else
  148. {
  149. dol_print_error($db);
  150. }
  151. /*
  152. * Draft orders
  153. */
  154. if (! empty($conf->ficheinter->enabled))
  155. {
  156. $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid";
  157. $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  158. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  159. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  160. $sql.= " WHERE f.entity IN (".getEntity('intervention').")";
  161. $sql.= " AND f.fk_soc = s.rowid";
  162. $sql.= " AND f.fk_statut = 0";
  163. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  164. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  165. $resql=$db->query($sql);
  166. if ($resql)
  167. {
  168. print '<table class="noborder" width="100%">';
  169. print '<tr class="liste_titre">';
  170. print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
  171. $langs->load("fichinter");
  172. $num = $db->num_rows($resql);
  173. if ($num)
  174. {
  175. $i = 0;
  176. while ($i < $num)
  177. {
  178. $obj = $db->fetch_object($resql);
  179. print '<tr class="oddeven">';
  180. print '<td class="nowrap">';
  181. print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowFichinter"),"intervention").' '.$obj->ref."</a></td>";
  182. 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>';
  183. $i++;
  184. }
  185. }
  186. print "</table><br>";
  187. }
  188. }
  189. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  190. $max=5;
  191. /*
  192. * Last modified interventions
  193. */
  194. $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.date_valid as datec, f.tms as datem,";
  195. $sql.= " s.nom as name, s.rowid as socid";
  196. $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
  197. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  198. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  199. $sql.= " WHERE f.entity IN (".getEntity('intervention').")";
  200. $sql.= " AND f.fk_soc = s.rowid";
  201. //$sql.= " AND c.fk_statut > 2";
  202. if ($socid) $sql .= " AND f.fk_soc = ".$socid;
  203. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  204. $sql.= " ORDER BY f.tms DESC";
  205. $sql.= $db->plimit($max, 0);
  206. $resql=$db->query($sql);
  207. if ($resql)
  208. {
  209. print '<table class="noborder" width="100%">';
  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. {
  215. $i = 0;
  216. while ($i < $num)
  217. {
  218. $obj = $db->fetch_object($resql);
  219. print '<tr class="oddeven">';
  220. print '<td width="20%" class="nowrap">';
  221. $fichinterstatic->id=$obj->rowid;
  222. $fichinterstatic->ref=$obj->ref;
  223. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  224. print '<td width="96" class="nobordernopadding nowrap">';
  225. print $fichinterstatic->getNomUrl(1);
  226. print '</td>';
  227. print '<td width="16" class="nobordernopadding nowrap">';
  228. print '&nbsp;';
  229. print '</td>';
  230. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  231. $filename=dol_sanitizeFileName($obj->ref);
  232. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  233. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  234. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  235. print '</td></tr></table>';
  236. print '</td>';
  237. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
  238. print '<td>'.dol_print_date($db->jdate($obj->datem),'day').'</td>';
  239. print '<td align="right">'.$fichinterstatic->LibStatut($obj->fk_statut,5).'</td>';
  240. print '</tr>';
  241. $i++;
  242. }
  243. }
  244. print "</table><br>";
  245. }
  246. else dol_print_error($db);
  247. /*
  248. * interventions to process
  249. */
  250. if (! empty($conf->ficheinter->enabled))
  251. {
  252. $sql = "SELECT f.rowid, f.ref, f.fk_statut, s.nom as name, s.rowid as socid";
  253. $sql.=" FROM ".MAIN_DB_PREFIX."fichinter as f";
  254. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  255. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  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) $sql.= " AND f.fk_soc = ".$socid;
  260. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  261. $sql.= " ORDER BY f.rowid DESC";
  262. $resql=$db->query($sql);
  263. if ($resql)
  264. {
  265. $num = $db->num_rows($resql);
  266. print '<table class="noborder" width="100%">';
  267. print '<tr class="liste_titre">';
  268. print '<th colspan="3">'.$langs->trans("FichinterToProcess").' <a href="'.DOL_URL_ROOT.'/fichinter/list.php?viewstatut=1"><span class="badge">'.$num.'</span></a></th></tr>';
  269. if ($num)
  270. {
  271. $i = 0;
  272. while ($i < $num)
  273. {
  274. $obj = $db->fetch_object($resql);
  275. print '<tr class="oddeven">';
  276. print '<td class="nowrap" width="20%">';
  277. $fichinterstatic->id=$obj->rowid;
  278. $fichinterstatic->ref=$obj->ref;
  279. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  280. print '<td width="96" class="nobordernopadding nowrap">';
  281. print $fichinterstatic->getNomUrl(1);
  282. print '</td>';
  283. print '<td width="16" class="nobordernopadding nowrap">';
  284. print '&nbsp;';
  285. print '</td>';
  286. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  287. $filename=dol_sanitizeFileName($obj->ref);
  288. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  289. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  290. print $formfile->getDocumentsLink($fichinterstatic->element, $filename, $filedir);
  291. print '</td></tr></table>';
  292. print '</td>';
  293. 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>';
  294. print '<td align="right">'.$fichinterstatic->LibStatut($obj->fk_statut,5).'</td>';
  295. print '</tr>';
  296. $i++;
  297. }
  298. }
  299. print "</table><br>";
  300. }
  301. else dol_print_error($db);
  302. }
  303. print '</div></div></div>';
  304. llxFooter();
  305. $db->close();