fix: Correcion de filtro de graficos

This commit is contained in:
Hectorgh24 2025-06-15 23:20:03 -06:00
parent 1cfaddf5e6
commit 26031d2c4d
2 changed files with 52 additions and 16 deletions

View File

@ -99,7 +99,7 @@ class Graficos{
$types .= "i";
}
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
$sql .= " AND DATE(c.fecha_entrada) >= ? AND DATE(c.fecha_entrada) <= ?";
$sql .= " AND DATE(c.fecha_entrada) BETWEEN ? AND ?";
$params[] = $filtros['fechaInicio'];
$params[] = $filtros['fechaFin'];
$types .= "ss";
@ -134,7 +134,7 @@ class Graficos{
$types .= "i";
}
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
$sql .= " AND DATE(c.fecha_entrada) >= ? AND DATE(c.fecha_entrada) <= ?";
$sql .= " AND DATE(c.fecha_entrada) BETWEEN ? AND ?";
$params[] = $filtros['fechaInicio'];
$params[] = $filtros['fechaFin'];
$types .= "ss";
@ -159,17 +159,23 @@ class Graficos{
$sql = "SELECT e.nombre AS estado, COUNT(*) AS cantidad
FROM info_candidatos i
INNER JOIN estados e ON i.id_estado = e.id
INNER JOIN candidato c ON i.id_candidato = c.id_candidato
WHERE 1=1";
$params = [];
$types = "";
if (!empty($filtros['id_estado'])) {
$sql .= " AND i.id_estado = ?";
$params[] = $filtros['id_estado'];
if (!empty($filtros['id_genero'])) {
$sql .= " AND c.id_genero = ?";
$params[] = $filtros['id_genero'];
$types .= "i";
}
if (!empty($filtros['id_rango_edad'])) {
$sql .= " AND c.id_rango_edad = ?";
$params[] = $filtros['id_rango_edad'];
$types .= "i";
}
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
$sql .= " AND DATE(i.fecha_entrada) >= ? AND DATE(i.fecha_entrada) <= ?";
$sql .= " AND DATE(c.fecha_entrada) BETWEEN ? AND ?";
$params[] = $filtros['fechaInicio'];
$params[] = $filtros['fechaFin'];
$types .= "ss";
@ -203,8 +209,13 @@ class Graficos{
$params[] = $filtros['id_examen'];
$types .= "i";
}
if (!empty($filtros['id_rango_edad'])) {
$sql .= " AND c.id_rango_edad = ?";
$params[] = $filtros['id_rango_edad'];
$types .= "i";
}
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
$sql .= " AND DATE(c.fecha_entrada) >= ? AND DATE(c.fecha_entrada) <= ?";
$sql .= " AND DATE(c.fecha_entrada) BETWEEN ? AND ?";
$params[] = $filtros['fechaInicio'];
$params[] = $filtros['fechaFin'];
$types .= "ss";

View File

@ -85,23 +85,48 @@ function getFiltrosSeleccionados() {
const fechaInicio = document.getElementById('date1')?.value || "";
const fechaFin = document.getElementById('date2')?.value || "";
if (filtroActivo === 'id_rango_edad' && id_rango_edad !== "NULL") {
return { id_rango_edad };
const filtros = {};
if (id_rango_edad !== "NULL") {
filtros.id_rango_edad = id_rango_edad;
}
if (filtroActivo === 'id_genero' && id_genero !== "NULL") {
return { id_genero };
if (id_genero !== "NULL") {
filtros.id_genero = id_genero;
}
if (filtroActivo === 'id_examen' && id_examen !== "NULL") {
return { id_examen };
if (id_examen !== "NULL") {
filtros.id_examen = id_examen;
}
if (filtroActivo === 'fechas' && fechaInicio && fechaFin) {
return { fechaInicio, fechaFin };
if (fechaInicio && fechaFin) {
filtros.fechaInicio = fechaInicio;
filtros.fechaFin = fechaFin;
}
return {}; // Sin filtros
return filtros;
}
function setFiltroActivo(tipo) {
filtroActivo = tipo;
// Limpiar otros filtros cuando se activa uno nuevo
if (tipo === 'id_rango_edad') {
document.getElementById('id_genero').value = "NULL";
document.getElementById('id_examen').value = "NULL";
document.getElementById('date1').value = "";
document.getElementById('date2').value = "";
} else if (tipo === 'id_genero') {
document.getElementById('id_rango_edad').value = "NULL";
document.getElementById('id_examen').value = "NULL";
document.getElementById('date1').value = "";
document.getElementById('date2').value = "";
} else if (tipo === 'id_examen') {
document.getElementById('id_rango_edad').value = "NULL";
document.getElementById('id_genero').value = "NULL";
document.getElementById('date1').value = "";
document.getElementById('date2').value = "";
} else if (tipo === 'fechas') {
document.getElementById('id_rango_edad').value = "NULL";
document.getElementById('id_genero').value = "NULL";
document.getElementById('id_examen').value = "NULL";
}
}
function getFiltroActivo() {
return filtroActivo;