From 37f4cc42c11482894b3c4b64af98a4590ac3127c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Jan 2025 15:44:19 -0600 Subject: [PATCH] Individual JSON's --- action/action_auditoria.php | 9 +++++---- export/supervisor_excel.php | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/action/action_auditoria.php b/action/action_auditoria.php index 05db5ed..028e93b 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -38,11 +38,12 @@ try { SELECT * 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 VALUES (:usuario_id , COALESCE(( - SELECT jsonb_agg(AUDITORIA_DATA) FROM AUDITORIA_DATA - ), '[]'::JSONB)) - ON CONFLICT (usuario_id) DO UPDATE SET auditoria = EXCLUDED.auditoria + INSERT INTO last_auditoria + SELECT :usuario_id, to_jsonb(AUDITORIA_DATA) FROM AUDITORIA_DATA ) SELECT registro_id, diff --git a/export/supervisor_excel.php b/export/supervisor_excel.php index d80d43d..c615d4f 100644 --- a/export/supervisor_excel.php +++ b/export/supervisor_excel.php @@ -16,11 +16,34 @@ $user = unserialize($_SESSION['user']); /* $json = file_get_contents('php://input'); $data = json_decode($json, true); */ -$query = $db - ->where('usuario_id', $user->user['id']) - ->getOne('last_auditoria', 'auditoria')['auditoria']; - -$data = json_decode($query, true); +$data = $db->query( +"SELECT + auditoria->>'registro_fecha_ideal' as registro_fecha_ideal, + auditoria->>'profesor_clave' as profesor_clave, + auditoria->>'profesor_nombre' as profesor_nombre, + auditoria->>'profesor_correo' as profesor_correo, + auditoria->>'facultad' as facultad, + auditoria->>'materia' as materia, + auditoria->>'carrera' as carrera, + auditoria->>'horario_grupo' as horario_grupo, + auditoria->>'horario_hora_completa' as horario_hora_completa, + auditoria->>'salon' as salon, + auditoria->>'salon_array' 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->>'registro_retardo' as registro_retardo + FROM last_auditoria + WHERE auditoria->>'registro_fecha_ideal' IS NOT NULL + AND USUARIO_ID = ?", + [$user->user['id']] +); empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data])); @@ -149,7 +172,7 @@ function getFormattedValue($key, $registro) 'nombre' => $registro[$key] ?? "Sin registro", 'horario_hora_completa' => "{$registro['horario_hora']} - {$registro['horario_fin']}", 'usuario_nombre' => $registro[$key] ?? "Sin registro", - 'salon_array' => json_encode($registro[$key], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), + 'salon_array' => json_encode($registro[$key], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 'justificacion', 'comentario' => $registro[$key] ?? "Sin registro", default => $registro[$key] @@ -172,7 +195,7 @@ foreach ($data as $index => $registro) { array_walk($values, function ($row, $column_index) use ($sheet, $index, $registro) { $value = getFormattedValue($row, $registro); $cellLocation = chr(65 + $column_index) . (ROW + $index + 1); - + $sheet->setCellValue($cellLocation, $value); if ($value == "Sin registro") {