From 9ce1dee3139b39f3882248865da0e79b2bd23217 Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Wed, 16 Aug 2023 19:19:00 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20justificaciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/action_auditoria.php | 15 ++- action/action_justificar.php | 101 +++++++++++----- auditoría.php | 225 +++++++++++++++++++++++++++-------- js/auditoría.js | 100 ++++++++++++---- ts/auditoría.ts | 118 ++++++++++++------ 5 files changed, 422 insertions(+), 137 deletions(-) diff --git a/action/action_auditoria.php b/action/action_auditoria.php index fdbe8dd..9780e51 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -25,18 +25,29 @@ try { SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id FROM horarios h ) - SELECT estado_supervisor.*, usuario.*, registro.*, profesor.*, horarios.*, fechas.* + SELECT estado_supervisor.*, usuario.*, registro.*, profesor.*, horarios.*, fechas.*, + justificador.usuario_nombre as justificador_nombre, + justificador.usuario_clave as justificador_clave, + facultad.facultad_nombre as justificador_facultad, + rol.rol_titulo as justificador_rol FROM horarios JOIN fechas using (horario_id) JOIN horario_profesor using (horario_id) JOIN profesor using (profesor_id) LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id) - left join estado_supervisor using (estado_supervisor_id) + LEFT join estado_supervisor using (estado_supervisor_id) LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id + LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id + LEFT JOIN ROL on ROL.rol_id = justificador.rol_id + left join facultad on facultad.facultad_id = justificador.facultad_id + WHERE fechas.registro_fecha_ideal BETWEEN COALESCE(:fecha_inicio, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN)) AND COALESCE(:fecha_fin, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN)) ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre", [ ':periodo_id' => $user->periodo_id, ':facultad_id' => $user->facultad['facultad_id'], + ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? null, + ':fecha_fin' => $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null, + ] ); diff --git a/action/action_justificar.php b/action/action_justificar.php index 2a42a89..cb6fff6 100644 --- a/action/action_justificar.php +++ b/action/action_justificar.php @@ -1,33 +1,80 @@ - $clave, - 'hora' => $hora, - 'id' => $id - ]]; +if (!isset($_SESSION['user'])) { + http_response_code(401); + echo json_encode(['error' => 'unauthorized']); + exit; } -foreach ($claves as $horario) - try { - $profesor_id = $horario["clave"]; - query("SELECT fi_registrar_asistencia(:id::INT, FALSE, ARRAY[ NOW(), :fecha::DATE + :hora::TIME ]::TIMESTAMP[], :profesor_id::INT, TRUE)", [ - ":fecha" => $fecha->format('Y-m-d'), - ":hora" => $horario["hora"], - ":id" => $horario["id"], - ":profesor_id" => $profesor_id - ]); - } - catch (Exception $e) { - die( json_encode(["error" => $e->getMessage()]) ); + +$user = unserialize($_SESSION['user']); + +try { + if ($_SERVER['REQUEST_METHOD'] === 'PUT') { + // check parameters + $raw = file_get_contents('php://input'); + $post_data = json_decode($raw, true); + // if it's a list + // step 1: get subrutas + if (empty($post_data)) { + http_response_code(400); + echo json_encode(['error' => 'No hay clases pendientes']); + exit; + } + + $data = $db->querySingle( + 'INSERT INTO registro (profesor_id, horario_id, registro_fecha_ideal, registro_justificada, justificador_id, registro_fecha_justificacion, justificacion) + VALUES (:profesor_id, :horario_id, :registro_fecha_ideal, :registro_justificada, :justificador_id, NOW(), :justificacion) + ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal) + DO UPDATE SET registro_justificada = :registro_justificada, justificador_id = :justificador_id, registro_fecha_justificacion = NOW(), justificacion = :justificacion + RETURNING *', + array( + 'profesor_id' => $post_data['profesor_id'], + 'horario_id' => $post_data['horario_id'], + 'registro_fecha_ideal' => $post_data['registro_fecha_ideal'], + 'registro_justificada' => $post_data['registro_justificada'], + 'justificador_id' => $user->user['id'], + 'justificacion' => empty($post_data['justificacion']) ? null : $post_data['justificacion'], + ) + ); + + $data_justificador = $db->querySingle( + "SELECT justificador.usuario_nombre as justificador_nombre, + justificador.usuario_clave as justificador_clave, + facultad.facultad_nombre as justificador_facultad, rol.rol_titulo as justificador_rol + + FROM USUARIO JUSTIFICADOR + JOIN ROL on ROL.rol_id = justificador.rol_id + LEFT JOIN facultad on facultad.facultad_id = justificador.facultad_id + where justificador.usuario_id = :justificador_id", + array( + 'justificador_id' => $user->user['id'], + ) + ); + echo json_encode(array_merge($data, $data_justificador), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } else { + http_response_code(405); + echo json_encode(['error' => 'method not allowed']); + exit; + } -die(json_encode(["success" => true])); +} catch (PDOException $th) { + http_response_code(500); + echo json_encode([ + 'error' => $th->getMessage(), + 'query' => $db->getLastQuery(), + 'post_data' => $post_data, + ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + exit; +} catch (Exception $th) { + http_response_code(500); + echo json_encode([ + 'error' => $th->getMessage(), + ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + exit; +} \ No newline at end of file diff --git a/auditoría.php b/auditoría.php index 33771a1..8e2fb3d 100644 --- a/auditoría.php +++ b/auditoría.php @@ -4,7 +4,7 @@ - Supervisor + Auditoría asistencial @@ -20,16 +20,21 @@ access(); html_header( "Registro de asistencia - Vicerrectoría Académica", "Sistema de gestión de checador", ); - ?> - - periodo_id) { ?> + if (!$user->periodo_id) { ?> @@ -92,16 +97,18 @@ -
-
- +
+ -
-
-
-
- +
@@ -206,11 +213,10 @@
-
- +
+ - Sin registro @@ -224,13 +230,13 @@
-
-
-
+
Loading...
@@ -243,8 +249,8 @@ - Fecha @@ -258,10 +264,10 @@ - + No hay clases en este horario - {{ registro.registro_fecha_ideal }} @@ -293,7 +299,7 @@
- +
Sin registro @@ -303,7 +309,7 @@ - +
@@ -322,23 +328,36 @@

-
Observaciones: {{registro.comentario?.slice(0, 25)}}{{registro.comentario.length > 10 ? '...' : ''}}
-
- +
Sin registro
+ acceso == 'w') { ?> + + @@ -346,23 +365,23 @@
-