reporte_de_asistencias.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE);
  3. ini_set("display_errors", 1);
  4. require_once 'class/c_login.php';
  5. if (!isset($_SESSION['user']))
  6. die(header('Location: index.php'));
  7. $user = unserialize($_SESSION['user']);
  8. $user->access('reporte_de_asistencias');
  9. if (!$user->admin && in_array($user->acceso, ['n']))
  10. die(header('Location: main.php?error=1'));
  11. $user->print_to_log('Consultar asistencia');
  12. # Select carreras from facultad
  13. $fs_carrera = queryAll(
  14. "SELECT * FROM FS_CARRERA(:facultad)",
  15. array(
  16. ":facultad" => $user->facultad["facultad_id"]
  17. )
  18. );
  19. $fs_periodo = queryAll(
  20. "SELECT * FROM FS_PERIODO(:periodo, :nivel, :estado)",
  21. array(
  22. ":periodo" => null,
  23. ":nivel" => null,
  24. ":estado" => 1,
  25. )
  26. );
  27. extract($_POST);
  28. $retardos = query("SELECT FS_HAS_RETARDO(:facultad) r", [":facultad" => $user->facultad["facultad_id"]])['r'];
  29. ?>
  30. <!DOCTYPE html>
  31. <html lang="en">
  32. <head>
  33. <title>Reporte asistencias | <?= $user->facultad['facultad'] ?? 'General' ?></title>
  34. <meta charset="utf-8">
  35. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  36. <?php include_once "import/html_css_files.php"; ?>
  37. </head>
  38. <body style="display: block;">
  39. <?php
  40. include("import/html_header.php");
  41. html_header("Reporte asistencias | " . ($user->facultad["facultad"] ?? "General"), "Sistema de gestión de checador");
  42. ?>
  43. <main class="container content marco content-margin">
  44. <section id="message"></section>
  45. <!-- Ajax form -->
  46. <!-- Select periodo -->
  47. <?php include_once 'import/html_forms_asistencia.php'; ?>
  48. <!-- Space -->
  49. <div class="row">
  50. <div class="col-12">
  51. <hr>
  52. </div>
  53. </div>
  54. <!-- Table template_table_asistencia -->
  55. <div id="table-asistencia" class="table-responsive"></div>
  56. <?php
  57. include_once 'include/constantes.php';
  58. ?>
  59. <template id="asistencias">
  60. <p class="text-right">
  61. <button class="btn btn-outline-secondary " id="btn-excel-asistencia" title="Exportar a Excel">
  62. <?php echo $ICO["descargar"]; ?></i> Exportar
  63. </button>
  64. </p>
  65. <table class="table table-striped table-hover table-white table-sm">
  66. <!-- Table primary -->
  67. <thead class="thead-dark">
  68. <tr>
  69. <th id="order-cve" style="cursor: pointer;" onclick="asistenciasOrderby('cve')">Clave</th>
  70. <th id="order-name" style="cursor: pointer;" onclick="asistenciasOrderby('name')">Nombre</th>
  71. <!-- Column small width -->
  72. <th id="order-absence" style="cursor: pointer;" onclick="asistenciasOrderby('absence')">
  73. <span>Total clases</span>
  74. </th>
  75. <th>
  76. </th>
  77. </tr>
  78. </thead>
  79. <tbody id="table-registros" class="text-center">
  80. <!-- Ajax table -->
  81. </tbody>
  82. </table>
  83. </template>
  84. <div class="d-none" id="hidden-forms"></div>
  85. <?php include_once "import/html_scroll.php"; ?>
  86. </main>
  87. <?php
  88. require_once("import/html_footer.php");
  89. ?>
  90. <script src="js/bootstrap/popper.min.js"></script>
  91. <script src="js/bootstrap/bootstrap.min.js"></script>
  92. <script src="js/fetchlib.js"></script>
  93. <script src="js/barra.js"></script>
  94. <script>
  95. var asistencias = [];
  96. var order = {
  97. by: "",
  98. order: false
  99. };
  100. $(document).ready(function() {
  101. var errores = 0;
  102. // Vista profesor
  103. $("#form-asistencia").keydown(function(event) {
  104. if (event.keyCode == 13) {
  105. event.preventDefault();
  106. $("#btn-buscar").click();
  107. return false;
  108. }
  109. });
  110. $(document).on("click", "#btn-excel-asistencia", function() {
  111. // send asistencias to page
  112. var form = document.createElement("form");
  113. form.setAttribute("method", "post");
  114. form.setAttribute("action", "action/action_asistencias_excel.php");
  115. form.setAttribute("target", "_blank");
  116. var hiddenField = document.createElement("input");
  117. hiddenField.setAttribute("type", "hidden");
  118. hiddenField.setAttribute("name", "asistencias");
  119. hiddenField.setAttribute("value", JSON.stringify(asistencias));
  120. form.appendChild(hiddenField);
  121. document.body.appendChild(form);
  122. form.submit();
  123. })
  124. });
  125. function validateDateRange(fecha_inicial, fecha_final) {
  126. var fecha_inicial = new Date(fecha_inicial);
  127. var fecha_final = new Date(fecha_final);
  128. return fecha_inicial <= fecha_final;
  129. }
  130. function fillTable() {
  131. $("#table-asistencia").empty();
  132. // add filter
  133. if (asistencias.length == 0) {
  134. triggerMessage("No se encontraron resultados", "Sin resultados", "warning");
  135. return;
  136. } else if (asistencias.error != undefined) {
  137. triggerMessage(asistencias.error, "Error en los datos");
  138. return;
  139. }
  140. var template = $("template#asistencias");
  141. // append the template to the div#table-asistencia
  142. $("#table-asistencia").append(template.html());
  143. // fill the table
  144. for (var i = 0; i < asistencias.length; i++) {
  145. var row = asistencias[i];
  146. var tr =
  147. `<tr id="${row.profesor_id}">
  148. <td>${row.profesor_clave}</td>
  149. <td>${row.profesor_nombre}</td>
  150. <td class="px-4 py-2" id="barra-${row.profesor_id}">${barra(row, <?= $retardos ? "true" : "false" ?>)}</td>
  151. <td>
  152. <a href="#" id="profesor-${row.profesor_id}">
  153. <?php echo $ICO['ojo']; ?>
  154. </a>
  155. </td>
  156. </tr>`;
  157. $("#table-asistencia table tbody").append(tr);
  158. }
  159. if (retardo)
  160. $(".retardos-h").show();
  161. else
  162. $(".retardos-h").hide();
  163. }
  164. function asistenciasOrderby(by) {
  165. switch (by) {
  166. case "cve":
  167. asistencias.sort((a, b) => (a.cve > b.cve) ? 1 : -1);
  168. break;
  169. case "name":
  170. asistencias.sort((a, b) => (a.name > b.name) ? 1 : -1);
  171. break;
  172. case "absence":
  173. asistencias.sort((a, b) => (a.absence > b.absence) ? 1 : -1);
  174. break;
  175. }
  176. fillTable();
  177. // icon <i id="caret" class="ing-caret ing-fw"></i>
  178. var column = $("#order-" + by)
  179. if (order.by != by)
  180. order.order = false;
  181. if (order.order)
  182. column.append("<i id='caret' class='ing-caret ing-fw'></i>");
  183. else
  184. column.append("<i id='caret' class='ing-caret ing-fw ing-rotate-180'></i>");
  185. order.by = by;
  186. order.order = !order.order;
  187. $("#caret").toggleClass("ing-rotate-180");
  188. // remove caret from other columns
  189. $("#order-cve, #order-name, #order-absence").not("#order-" + by).find("#caret").remove();
  190. }
  191. $("#asistencia").on("submit", async function(e) {
  192. e.preventDefault();
  193. // validar que los datalist esten seleccionados
  194. if (!validateDatalist("#periodo") || !validateDatalist("#filter_facultad")) {
  195. triggerMessage("Por favor, seleccione una opción de cada lista desplegable", "Error en los datos");
  196. return;
  197. }
  198. // suspender el boton
  199. $("#btn-buscar").prop("disabled", true);
  200. $("#btn-buscar").html("Buscando...");
  201. $formData = new FormData();
  202. $formData.append("periodo", $("#periodo").val());
  203. $formData.append("facultad", <?= $user->facultad['facultad_id'] ?>);
  204. $formData.append("carrera", $("#filter_carrera").val());
  205. $formData.append("clave", $("#filterClave").val().replace(/[a-zA-Z]{2}/, '').replace(/^0+/, ''));
  206. $formData.append("nombre", $("#filterNombre").val());
  207. $formData.append("fecha_inicial", $("#fecha_inicial").val());
  208. $formData.append("fecha_final", $("#fecha_final").val());
  209. const data = await fetch("action/action_asistencias.php", {
  210. method: "POST",
  211. body: $formData,
  212. });
  213. const dataJson = await data.json();
  214. if (dataJson.error) {
  215. triggerMessage(data.error, "Error en los datos");
  216. return;
  217. }
  218. retardo = dataJson.retardo.retardo;
  219. asistencias = dataJson.reporte;
  220. fillTable();
  221. $("#btn-buscar").prop("disabled", false);
  222. $("#btn-buscar").html(`<?= $ICO['buscar'] ?> Buscar asistencias`);
  223. });
  224. // function to put it into a loading state
  225. $(document).on("click", "a[id^='profesor-']", function(e) {
  226. // loading state
  227. e.preventDefault();
  228. // spinner
  229. $(this).html(
  230. `
  231. <div class="spinner-border spinner-border-sm text-primary" role="status">
  232. <span class="sr-only">Cargando...</span>
  233. </div>
  234. `)
  235. // disable all the other links
  236. $("a[id^='profesor-']").not(this).prop("disabled", true);
  237. // Make a form to send the data
  238. submit("vista_profesor.php", {
  239. id: $(this).attr("id").replace("profesor-", ""),
  240. periodo: <?= $user->periodo ?>,
  241. facultad: <?= $user->facultad['facultad_id'] ?>,
  242. carrera: $('#filter_carrera').val(),
  243. clave: $('#filterClave').val().replace(/[a-zA-Z]{2}/, ''),
  244. nombre: $('#filterNombre').val(),
  245. fecha_inicial: $('#fecha_inicial').val(),
  246. fecha_final: $('#fecha_final').val()
  247. });
  248. });
  249. <?php if (!empty($_POST)) { ?>
  250. $('#asistencia').submit();
  251. <?php } ?>
  252. </script>
  253. </body>
  254. </html>