reporte_de_asistencias.php 11 KB

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