This commit is contained in:
Your Name
2025-02-17 14:55:02 -06:00
parent 96eba3f917
commit c980c5aecd
5 changed files with 63 additions and 83 deletions

View File

@@ -19,59 +19,59 @@ $user = unserialize($_SESSION['user']);
// check method
try {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
/* $db->query(<<<SQL
REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT
SQL
); */
// pg_send_query($db->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);

View File

@@ -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,

View File

@@ -469,8 +469,13 @@
</main>
</div>
<div class="pp-card" style="grid-row: span 3">
<div class="bg-primary text-white"
v-if="clase_vista.registro_justificada">
<span>Justificada</span>
<i class="ing-finalistas"></i>
</div>
<div class="bg-warning text-white"
v-if="clase_vista.registro_fecha && clase_vista.registro_retardo">
v-else-if="clase_vista.registro_fecha && clase_vista.registro_retardo">
<span>Con retardo</span>
<i class="ing-retardo"></i>
</div>

View File

@@ -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);

View File

@@ -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();