From c980c5aecd5157d56828b3cce72aabd32489acb3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 17 Feb 2025 14:55:02 -0600 Subject: [PATCH] Final --- action/action_auditoria.php | 84 ++++++++++++++++++------------------- action/justificar.php | 2 + auditoria.php | 7 +++- export/supervisor_excel.php | 51 ++++++---------------- js/auditoría.js | 2 +- 5 files changed, 63 insertions(+), 83 deletions(-) diff --git a/action/action_auditoria.php b/action/action_auditoria.php index 6e5fdd1..af1ced8 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -19,59 +19,59 @@ $user = unserialize($_SESSION['user']); // check method try { if ($_SERVER['REQUEST_METHOD'] === 'GET') { - /* $db->query(<<getConnection(), "REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT"); $baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null; $params = [ // ':periodo_id' => $_GET['periodo_id'] > 0 ? $user->periodo_id : null, - ':facultad_id' => $user->facultad['facultad_id'], - ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'), - ':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime("$baseDate +24 hours")) : date('Y-m-d H:i:s'), + 'usuario_id' => $user->user['id'], ]; + + $db->where('usuario_id', $user->user['id'])->delete('last_auditoria'); + + // Define relevant columns + $relevant_columns = [ + 'registro_id', + 'registro_fecha_ideal', + 'horario_id', + 'profesor_id', + 'salon', + 'profesor_clave', + 'profesor_nombre', + 'horario_hora', + 'horario_fin', + 'registro_fecha', + 'color', + 'estado_color', + 'estado_icon', + 'estado_supervisor_id', + 'facultad_id', + 'usuario_nombre', + 'registro_fecha_supervisor', + 'comentario', + 'registro_justificada', + 'justificacion', + 'reposicion_id' + ]; + + $relevant_columns_string = implode(', ', $relevant_columns); + + $_SESSION['fecha_inicio'] = $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'); + $_SESSION['fecha_fin'] = date('Y-m-d H:i:s', strtotime(($baseDate ?? 'now') . ' +24 hours')); + $data = $db->query( - "WITH AUDITORIA_DATA AS ( - SELECT * FROM PUBLIC.AUDITORIA_MAT + "SELECT $relevant_columns_string FROM PUBLIC.AUDITORIA_MAT WHERE FACULTAD_ID = COALESCE(:facultad_id, FACULTAD_ID) AND REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin - ), DELETION AS ( - DELETE FROM last_auditoria - WHERE usuario_id = :usuario_id - ), INSERTION AS ( - INSERT INTO last_auditoria - SELECT :usuario_id, to_jsonb(AUDITORIA_DATA), registro_fecha_ideal, horario_id, profesor_id FROM AUDITORIA_DATA - WHERE REGISTRO_FECHA_IDEAL IS NOT NULL - ) - SELECT - registro_id, - registro_fecha_ideal, - horario_id, - profesor_id, - salon, - profesor_clave, - profesor_nombre, - horario_hora, - horario_fin, - registro_fecha, - color, - estado_color, - estado_icon, - estado_supervisor_id, - facultad_id, - usuario_nombre, - registro_fecha_supervisor, - comentario, - registro_justificada, - justificacion, - reposicion_id - FROM AUDITORIA_DATA ORDER BY registro_fecha_ideal, horario_hora", - $params + ORDER BY registro_fecha_ideal, horario_hora", + [ + ':facultad_id' => $user->facultad['facultad_id'], + ':fecha_inicio' => $_SESSION['fecha_inicio'], + ':fecha_fin' => $_SESSION['fecha_fin'], + ] ); - // Print the JSON file + echo json_encode($data); } else { http_response_code(405); diff --git a/action/justificar.php b/action/justificar.php index 76f6894..0d77dc4 100644 --- a/action/justificar.php +++ b/action/justificar.php @@ -39,6 +39,8 @@ try { ] ); + $db->query("REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT"); + $data_justificador = $db->querySingle( "SELECT justificador.usuario_nombre as justificador_nombre, diff --git a/auditoria.php b/auditoria.php index 419c7e1..25b04e2 100644 --- a/auditoria.php +++ b/auditoria.php @@ -469,8 +469,13 @@
+
+ Justificada + +
+ v-else-if="clase_vista.registro_fecha && clase_vista.registro_retardo"> Con retardo
diff --git a/export/supervisor_excel.php b/export/supervisor_excel.php index 1e60a59..217523b 100644 --- a/export/supervisor_excel.php +++ b/export/supervisor_excel.php @@ -21,43 +21,16 @@ $profesor_clave = isset($params['profesor']) : null; $data = $db->query( - "SELECT DISTINCT - auditoria->>'registro_fecha_ideal' as registro_fecha_ideal, - auditoria->>'profesor_clave' as profesor_clave, - auditoria->>'profesor_nombre' as profesor_nombre, - NULLIF(auditoria->>'profesor_correo', '') as profesor_correo, - auditoria->>'facultad' as facultad, - auditoria->>'materia' as materia, - auditoria->>'carrera' as carrera, - NULLIF(auditoria->>'horario_grupo', '') as horario_grupo, - auditoria->>'horario_hora_completa' as horario_hora_completa, - auditoria->>'salon' as salon, - ( - SELECT string_agg(value, ' / ' ORDER BY value) - FROM jsonb_array_elements_text(auditoria->'salon_array') AS value - ) as salon_array, - auditoria->>'asistencia' as asistencia, - auditoria->>'registro_fecha' as registro_fecha, - auditoria->>'usuario_nombre' as usuario_nombre, - auditoria->>'nombre' as nombre, - auditoria->>'registro_fecha_supervisor' as registro_fecha_supervisor, - auditoria->>'comentario' as comentario, - auditoria->>'justificacion' as justificacion, - auditoria->>'horario_hora' as horario_hora, - auditoria->>'horario_fin' as horario_fin, - (auditoria->>'estado_supervisor_id')::integer as estado_id, - (auditoria->>'registro_retardo')::BOOLEAN as registro_retardo - FROM last_auditoria - -- JOIN BLOQUE_HORARIO ON ((auditoria->>'horario_hora')::TIME, (auditoria->>'horario_fin')::TIME) OVERLAPS (HORA_INICIO, HORA_FIN) - WHERE USUARIO_ID = :usuario_id - AND auditoria->>'facultad_id' = COALESCE(:facultad_id, auditoria->>'facultad_id') - AND auditoria->>'profesor_clave' = COALESCE(:profesor_clave, auditoria->>'profesor_clave') - /*AND BLOQUE_HORARIO.ID = COALESCE(:bloque_horario_id, BLOQUE_HORARIO.ID)*/", + "SELECT * FROM auditoria_mat + WHERE facultad_id = COALESCE(:facultad_id, facultad_id) + AND profesor_clave = COALESCE(:profesor_clave, profesor_clave) + AND REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin + ORDER BY REGISTRO_FECHA_IDEAL, HORARIO_HORA", [ - 'usuario_id' => $user->user['id'], 'facultad_id' => $params['facultad_id'], 'profesor_clave' => $profesor_clave, - /* 'bloque_horario_id' => $params['bloque_horario'] */ + 'fecha_inicio' => $_SESSION['fecha_inicio'], + 'fecha_fin' => $_SESSION['fecha_fin'], ] ); @@ -65,7 +38,7 @@ $estados = empty($params['estados']) ? null : $params['estados']; $data = array_filter( $data, - fn($fila) => in_array($fila['estado_id'], $estados ?? [$fila['estado_id']]) + fn($registro) => in_array($registro['estado_supervisor_id'], $estados ?? [$registro['estado_supervisor_id']]) ); $data = array_values($data); @@ -192,12 +165,12 @@ function getFormattedValue($key, $registro) { return match ($key) { 'asistencia' => $registro['registro_fecha'] === null - ? "Sin registro" - : ($registro['registro_retardo'] ? "Retardo " : "Asistencia "), + ? "Sin registro" + : ($registro['registro_retardo'] ? "Retardo " : "Asistencia "), 'registro_fecha', 'registro_fecha_supervisor' => $registro[$key] === null - ? 'Sin registro' - : date('H:i', strtotime($registro[$key])), + ? 'Sin registro' + : date('H:i', strtotime($registro[$key])), 'nombre' => $registro[$key] ?? "Sin registro", 'horario_hora_completa' => "{$registro['horario_hora']} - {$registro['horario_fin']}", 'usuario_nombre' => $registro[$key] ?? "Sin registro", diff --git a/js/auditoría.js b/js/auditoría.js index 5e42921..7179829 100644 --- a/js/auditoría.js +++ b/js/auditoría.js @@ -295,7 +295,7 @@ const store = reactive({ 'facultad_id': store.filters.facultad_id, 'estados': store.filters.estados, 'profesor': store.filters.profesor, - 'bloque_horario': store.filters.bloque_horario, + 'bloque_horario': store.bloques_horario?.data.find((bloque) => bloque.id === store.filters['bloque_horario']), }) }); const blob = await res.blob();