Funcionalidad de graficos de acuerdo a varios filtros
This commit is contained in:
parent
25b076895a
commit
a803956dd6
|
@ -1,52 +1,59 @@
|
||||||
<?php
|
<?php
|
||||||
require_once '../config/Database.php';
|
require_once '../config/Database.php';
|
||||||
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$input = json_decode(file_get_contents('php://input'), true);
|
$input = json_decode(file_get_contents('php://input'), true);
|
||||||
$tipoConsulta = $input['tipoConsulta'] ?? '';
|
$tipoConsulta = $input['tipoConsulta'] ?? '';
|
||||||
|
|
||||||
|
$filtros = [
|
||||||
|
'id_rango_edad' => $input['id_rango_edad'] ?? null,
|
||||||
|
'id_genero' => $input['id_genero'] ?? null,
|
||||||
|
'id_examen' => $input['id_examen'] ?? null,
|
||||||
|
'fechaInicio' => $input['fechaInicio'] ?? null,
|
||||||
|
'fechaFin' => $input['fechaFin'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
$graficos = new Graficos();
|
$graficos = new Graficos();
|
||||||
|
|
||||||
switch ($tipoConsulta) {
|
switch ($tipoConsulta) {
|
||||||
case 'Femenino':
|
case 'Femenino':
|
||||||
$cantidad = $graficos->obtenerGeneroFemenino();
|
$cantidad = $graficos->obtenerGeneroFemenino($filtros);
|
||||||
break;
|
break;
|
||||||
case 'Masculino':
|
case 'Masculino':
|
||||||
$cantidad = $graficos->obtenerGeneroMasculino();
|
$cantidad = $graficos->obtenerGeneroMasculino($filtros);
|
||||||
break;
|
break;
|
||||||
case 'Prefiero no decirlo':
|
case 'Prefiero no decirlo':
|
||||||
$cantidad = $graficos->obtenerGeneroNoDefinido();
|
$cantidad = $graficos->obtenerGeneroNoDefinido($filtros);
|
||||||
break;
|
break;
|
||||||
case 'Menor de 18 años':
|
case 'Menor de 18 años':
|
||||||
$cantidad = $graficos->obtenerEdadMenor18();
|
$cantidad = $graficos->obtenerEdadMenor18($filtros);
|
||||||
break;
|
break;
|
||||||
case '18 a 24 años':
|
case '18 a 24 años':
|
||||||
$cantidad = $graficos->obtenerEdad1824();
|
$cantidad = $graficos->obtenerEdad1824($filtros);
|
||||||
break;
|
break;
|
||||||
case '25 a 34 años':
|
case '25 a 34 años':
|
||||||
$cantidad = $graficos->obtenerEdad2434();
|
$cantidad = $graficos->obtenerEdad2434($filtros);
|
||||||
break;
|
break;
|
||||||
case '35 a 44 años':
|
case '35 a 44 años':
|
||||||
$cantidad = $graficos->obtenerEdad3544();
|
$cantidad = $graficos->obtenerEdad3544($filtros);
|
||||||
break;
|
break;
|
||||||
case '45 a 54 años':
|
case '45 a 54 años':
|
||||||
$cantidad = $graficos->obtenerEdad4554();
|
$cantidad = $graficos->obtenerEdad4554($filtros);
|
||||||
break;
|
break;
|
||||||
case '55 a 64 años':
|
case '55 a 64 años':
|
||||||
$cantidad = $graficos->obtenerEdad5564();
|
$cantidad = $graficos->obtenerEdad5564($filtros);
|
||||||
break;
|
break;
|
||||||
case '65 años o más':
|
case '65 años o más':
|
||||||
$cantidad = $graficos->obtenerEdad65oMas();
|
$cantidad = $graficos->obtenerEdad65oMas($filtros);
|
||||||
break;
|
break;
|
||||||
case 'Estados':
|
case 'Estados':
|
||||||
$cantidad = $graficos->obtenerEstados();
|
$cantidad = $graficos->obtenerEstados($filtros);
|
||||||
echo json_encode($cantidad); // Devolver directamente el array de estados
|
echo json_encode($cantidad);
|
||||||
exit; // Terminar la ejecucion aqui
|
exit;
|
||||||
case 'Examenes':
|
case 'Examenes':
|
||||||
$cantidad = $graficos->obtenerExamenes();
|
$cantidad = $graficos->obtenerExamenes($filtros);
|
||||||
echo json_encode($cantidad); // Devolver directamente el array de examenes
|
echo json_encode($cantidad);
|
||||||
exit; // Terminar la ejecucion aqui
|
exit;
|
||||||
case 'Fechas':
|
case 'Fechas':
|
||||||
$fechaInicio = $input['fechaInicio'] ?? '';
|
$fechaInicio = $input['fechaInicio'] ?? '';
|
||||||
$fechaFin = $input['fechaFin'] ?? '';
|
$fechaFin = $input['fechaFin'] ?? '';
|
||||||
|
@ -69,187 +76,378 @@ class Graficos{
|
||||||
$this->db = $this->Database->getInstance();
|
$this->db = $this->Database->getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function obtenerGeneroFemenino($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS Femenino FROM candidato WHERE id_genero = 2";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
public function obtenerGeneroFemenino() {
|
if (!empty($filtros['id_rango_edad']) && $filtros['id_rango_edad'] !== "NULL") {
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS Femenino FROM candidato WHERE id_genero = 2 ");
|
$sql .= " AND id_rango_edad = ?";
|
||||||
|
$params[] = $filtros['id_rango_edad'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['Femenino'];
|
||||||
$output= $data['Femenino'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerGeneroMasculino($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS Masculino FROM candidato WHERE id_genero = 1";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_rango_edad']) && $filtros['id_rango_edad'] !== "NULL") {
|
||||||
|
$sql .= " AND id_rango_edad = ?";
|
||||||
|
$params[] = $filtros['id_rango_edad'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerGeneroMasculino() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS Maculino FROM candidato WHERE id_genero = 1 ");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['Masculino'];
|
||||||
$output= $data['Maculino'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerGeneroNoDefinido($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS NoDefinido FROM candidato WHERE id_genero = 3";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_rango_edad']) && $filtros['id_rango_edad'] !== "NULL") {
|
||||||
|
$sql .= " AND id_rango_edad = ?";
|
||||||
|
$params[] = $filtros['id_rango_edad'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerGeneroNoDefinido() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS NoDefinido FROM candidato WHERE id_genero = 3 ");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['NoDefinido'];
|
||||||
$output= $data['NoDefinido'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdadMenor18($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS menorEdad FROM candidato WHERE id_rango_edad = 1";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEdadMenor18() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS menorEdad FROM candidato WHERE id_rango_edad = 1");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['menorEdad'];
|
||||||
$output= $data['menorEdad'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad1824($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad1824 FROM candidato WHERE id_rango_edad = 2";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEdad1824() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad1824 FROM candidato WHERE id_rango_edad = 2");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad1824'];
|
||||||
$output= $data['edad1824'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad2434($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad2434 FROM candidato WHERE id_rango_edad = 3";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEdad2434() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad2434 FROM candidato WHERE id_rango_edad = 3");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad2434'];
|
||||||
$output= $data['edad2434'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad3544($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad3544 FROM candidato WHERE id_rango_edad = 4";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEdad3544() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad3544 FROM candidato WHERE id_rango_edad = 4");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad3544'];
|
||||||
$output= $data['edad3544'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad4554($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad4554 FROM candidato WHERE id_rango_edad = 5";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
public function obtenerEdad4554() {
|
if ($params) {
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad4554 FROM candidato WHERE id_rango_edad = 5");
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad4554'];
|
||||||
$output= $data['edad4554'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad5564($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad5564 FROM candidato WHERE id_rango_edad = 6";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
public function obtenerEdad5564() {
|
if ($params) {
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad5564 FROM candidato WHERE id_rango_edad = 6");
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad5564'];
|
||||||
$output= $data['edad5564'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEdad65oMas($filtros = []) {
|
||||||
|
$sql = "SELECT COUNT(*) AS edad65oMas FROM candidato WHERE id_rango_edad = 7";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(fecha_entrada) >= ? AND DATE(fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEdad65oMas() {
|
$query = $this->db->prepare($sql);
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS edad65oMas FROM candidato WHERE id_rango_edad = 7");
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
$output = "0";
|
$output = "0";
|
||||||
|
if ($resultado->num_rows > 0) {
|
||||||
if($resultado->num_rows > 0) {
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
$output = $data['edad65oMas'];
|
||||||
$output= $data['edad65oMas'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query->close();
|
$query->close();
|
||||||
$this->db->close();
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function obtenerEstados($filtros = []) {
|
||||||
|
$sql = "SELECT estados.nombre AS estado, COUNT(*) AS cantidad
|
||||||
|
FROM candidato
|
||||||
|
INNER JOIN info_candidatos ON candidato.id_candidato = info_candidatos.id_candidato
|
||||||
|
INNER JOIN estados ON info_candidatos.id_estado = estados.id
|
||||||
|
WHERE 1=1";
|
||||||
|
$params = [];
|
||||||
|
$types = "";
|
||||||
|
|
||||||
|
if (!empty($filtros['id_rango_edad']) && $filtros['id_rango_edad'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_rango_edad = ?";
|
||||||
|
$params[] = $filtros['id_rango_edad'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_genero']) && $filtros['id_genero'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_genero = ?";
|
||||||
|
$params[] = $filtros['id_genero'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(candidato.fecha_entrada) >= ? AND DATE(candidato.fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerEstados() {
|
$sql .= " GROUP BY estados.nombre ORDER BY estados.nombre";
|
||||||
try {
|
|
||||||
$query = $this->db->prepare("SELECT estados.nombre AS estado, COUNT(*) AS cantidad
|
$query = $this->db->prepare($sql);
|
||||||
FROM estados
|
if ($params) {
|
||||||
INNER JOIN info_candidatos ON info_candidatos.id_estado = estados.id
|
$query->bind_param($types, ...$params);
|
||||||
GROUP BY estados.nombre
|
}
|
||||||
ORDER BY estados.nombre
|
|
||||||
");
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
|
|
||||||
|
@ -257,25 +455,46 @@ class Graficos{
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
while ($data = $resultado->fetch_assoc()) {
|
||||||
$estados[] = $data;
|
$estados[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->close();
|
$query->close();
|
||||||
|
|
||||||
error_log(json_encode($estados));
|
|
||||||
return $estados;
|
return $estados;
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log("Error al obtener los estados: " . $e->getMessage());
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerExamenes() {
|
public function obtenerExamenes($filtros = []) {
|
||||||
try {
|
$sql = "SELECT examen.nombre_examen AS examen, COUNT(*) AS cantidad
|
||||||
$query = $this->db->prepare("SELECT nombre_examen AS examen , COUNT(*) AS cantidad
|
FROM candidato
|
||||||
FROM examen
|
LEFT JOIN examen ON candidato.id_examen = examen.id_examen
|
||||||
INNER JOIN candidato ON candidato.id_examen = examen.id_examen
|
WHERE 1=1";
|
||||||
GROUP BY nombre_examen
|
$params = [];
|
||||||
ORDER BY nombre_examen;
|
$types = "";
|
||||||
");
|
|
||||||
|
if (!empty($filtros['id_rango_edad']) && $filtros['id_rango_edad'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_rango_edad = ?";
|
||||||
|
$params[] = $filtros['id_rango_edad'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_genero']) && $filtros['id_genero'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_genero = ?";
|
||||||
|
$params[] = $filtros['id_genero'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['id_examen']) && $filtros['id_examen'] !== "NULL") {
|
||||||
|
$sql .= " AND candidato.id_examen = ?";
|
||||||
|
$params[] = $filtros['id_examen'];
|
||||||
|
$types .= "i";
|
||||||
|
}
|
||||||
|
if (!empty($filtros['fechaInicio']) && !empty($filtros['fechaFin'])) {
|
||||||
|
$sql .= " AND DATE(candidato.fecha_entrada) >= ? AND DATE(candidato.fecha_salida) <= ?";
|
||||||
|
$params[] = $filtros['fechaInicio'];
|
||||||
|
$params[] = $filtros['fechaFin'];
|
||||||
|
$types .= "ss";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " GROUP BY examen.nombre_examen ORDER BY examen.nombre_examen";
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
|
if ($params) {
|
||||||
|
$query->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
|
|
||||||
|
@ -283,44 +502,25 @@ public function obtenerExamenes() {
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
while ($data = $resultado->fetch_assoc()) {
|
||||||
$examenes[] = $data;
|
$examenes[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->close();
|
$query->close();
|
||||||
|
|
||||||
error_log(json_encode($examenes));
|
|
||||||
return $examenes;
|
return $examenes;
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log("Error al obtener los examenes: " . $e->getMessage());
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function obtenerFecha($fechaInicio, $fechaFin) {
|
public function obtenerFecha($fechaInicio, $fechaFin) {
|
||||||
try {
|
$sql = "SELECT COUNT(*) AS cantidad
|
||||||
$query = $this->db->prepare("SELECT COUNT(*) AS total
|
FROM candidato
|
||||||
FROM candidato
|
WHERE DATE(fecha_entrada) >= ? AND DATE(fecha_entrada) <= ?";
|
||||||
WHERE DATE(fecha_entrada) = ?
|
$query = $this->db->prepare($sql);
|
||||||
AND DATE(fecha_salida) = ?;
|
|
||||||
");
|
|
||||||
$query->bind_param("ss", $fechaInicio, $fechaFin);
|
$query->bind_param("ss", $fechaInicio, $fechaFin);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$resultado = $query->get_result();
|
$resultado = $query->get_result();
|
||||||
|
|
||||||
$fechas = [];
|
$data = $resultado->fetch_assoc();
|
||||||
while ($data = $resultado->fetch_assoc()) {
|
|
||||||
$fechas[] = $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_log("Resultados de la consulta: " . json_encode($fechas)); // <-- Agrega este log
|
|
||||||
|
|
||||||
$query->close();
|
$query->close();
|
||||||
return $fechas;
|
// Devuelve un array con un solo objeto para mantener compatibilidad con el frontend
|
||||||
} catch (Exception $e) {
|
return [ [ 'cantidad' => $data['cantidad'], 'fechaInicio' => $fechaInicio, 'fechaFin' => $fechaFin ] ];
|
||||||
error_log("Error al obtener las fechas: " . $e->getMessage());
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -1,13 +1,10 @@
|
||||||
async function recuperarCantidadGenero(tipoConsulta) {
|
async function recuperarCantidadGenero(tipoConsulta, filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("../controllers/graficos.php", {
|
const response = await fetch("../controllers/graficos.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
||||||
},
|
|
||||||
body: JSON.stringify({ tipoConsulta }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.cantidad || 0;
|
return data.cantidad || 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -16,16 +13,13 @@ async function recuperarCantidadGenero(tipoConsulta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recuperarCantidadEdad(tipoConsulta) {
|
async function recuperarCantidadEdad(tipoConsulta, filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("../controllers/graficos.php", {
|
const response = await fetch("../controllers/graficos.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
||||||
},
|
|
||||||
body: JSON.stringify({ tipoConsulta }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.cantidad || 0;
|
return data.cantidad || 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -34,22 +28,15 @@ async function recuperarCantidadEdad(tipoConsulta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recuperarCantidadEstado(tipoConsulta) {
|
async function recuperarCantidadEstado(tipoConsulta, filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("../controllers/graficos.php", {
|
const response = await fetch("../controllers/graficos.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
||||||
},
|
|
||||||
body: JSON.stringify({ tipoConsulta }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array.");
|
||||||
if (!Array.isArray(data)) {
|
|
||||||
throw new Error("La respuesta del backend no es un array.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al recuperar datos de estados:", error);
|
console.error("Error al recuperar datos de estados:", error);
|
||||||
|
@ -57,22 +44,15 @@ async function recuperarCantidadEstado(tipoConsulta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recuperarCantidadExamen(tipoConsulta) {
|
async function recuperarCantidadExamen(tipoConsulta, filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("../controllers/graficos.php", {
|
const response = await fetch("../controllers/graficos.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
||||||
},
|
|
||||||
body: JSON.stringify({ tipoConsulta }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array");
|
||||||
if (!Array.isArray(data)) {
|
|
||||||
throw new Error("La respuesta del backend no es un array");
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al recuperar datos de examenes:", error);
|
console.error("Error al recuperar datos de examenes:", error);
|
||||||
|
@ -80,22 +60,15 @@ async function recuperarCantidadExamen(tipoConsulta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recuperarCantidadFecha(tipoConsulta) {
|
async function recuperarCantidadFecha(tipoConsulta, filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("../controllers/graficos.php", {
|
const response = await fetch("../controllers/graficos.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
||||||
},
|
|
||||||
body: JSON.stringify({ tipoConsulta }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array.");
|
||||||
if (!Array.isArray(data)) {
|
|
||||||
throw new Error("La respuesta del backend no es un array.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al recuperar datos de fechas:", error);
|
console.error("Error al recuperar datos de fechas:", error);
|
||||||
|
@ -103,39 +76,32 @@ async function recuperarCantidadFecha(tipoConsulta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function obtenerDatosEdades(filtros = {}) {
|
||||||
async function obtenerDatosEdades() {
|
const edad1 = await recuperarCantidadEdad("Menor de 18 años", filtros);
|
||||||
const edad1 = await recuperarCantidadEdad("Menor de 18 años");
|
const edad2 = await recuperarCantidadEdad("18 a 24 años", filtros);
|
||||||
const edad2 = await recuperarCantidadEdad("18 a 24 años");
|
const edad3 = await recuperarCantidadEdad("25 a 34 años", filtros);
|
||||||
const edad3 = await recuperarCantidadEdad("25 a 34 años");
|
const edad4 = await recuperarCantidadEdad("35 a 44 años", filtros);
|
||||||
const edad4 = await recuperarCantidadEdad("35 a 44 años");
|
const edad5 = await recuperarCantidadEdad("45 a 54 años", filtros);
|
||||||
const edad5 = await recuperarCantidadEdad("45 a 54 años");
|
const edad6 = await recuperarCantidadEdad("55 a 64 años", filtros);
|
||||||
const edad6 = await recuperarCantidadEdad("55 a 64 años");
|
const edad7 = await recuperarCantidadEdad("65 años o más", filtros);
|
||||||
const edad7 = await recuperarCantidadEdad("65 años o más");
|
return [edad1, edad2, edad3, edad4, edad5, edad6, edad7];
|
||||||
|
|
||||||
return [edad1, edad2, edad3, edad4, edad5, edad6];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function obtenerDatosGeneros(filtros = {}) {
|
||||||
async function obtenerDatosGeneros() {
|
const femenino = await recuperarCantidadGenero("Femenino", filtros);
|
||||||
const femenino = await recuperarCantidadGenero("Femenino");
|
const masculino = await recuperarCantidadGenero("Masculino", filtros);
|
||||||
const masculino = await recuperarCantidadGenero("Masculino");
|
const noDefinido = await recuperarCantidadGenero("Prefiero no decirlo", filtros);
|
||||||
const noDefinido = await recuperarCantidadGenero("Prefiero no decirlo");
|
|
||||||
|
|
||||||
return [femenino, masculino, noDefinido];
|
return [femenino, masculino, noDefinido];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function obtenerDatosEstados() {
|
async function obtenerDatosEstados(filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const estados = await recuperarCantidadEstado("Estados");
|
const estados = await recuperarCantidadEstado("Estados", filtros);
|
||||||
|
|
||||||
if (!Array.isArray(estados)) {
|
if (!Array.isArray(estados)) {
|
||||||
console.error("Error: 'estados' no es un array. Verifica la respuesta del backend");
|
console.error("Error: 'estados' no es un array. Verifica la respuesta del backend");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const estadosValidos = estados.filter(estado => estado.estado && estado.cantidad !== undefined);
|
const estadosValidos = estados.filter(estado => estado.estado && estado.cantidad !== undefined);
|
||||||
|
|
||||||
return estadosValidos;
|
return estadosValidos;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al obtener datos de estados:", error);
|
console.error("Error al obtener datos de estados:", error);
|
||||||
|
@ -143,17 +109,14 @@ async function obtenerDatosEstados() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function obtenerDatosExamenes() {
|
async function obtenerDatosExamenes(filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const examenes = await recuperarCantidadExamen("Examenes");
|
const examenes = await recuperarCantidadExamen("Examenes", filtros);
|
||||||
|
|
||||||
if (!Array.isArray(examenes)) {
|
if (!Array.isArray(examenes)) {
|
||||||
console.error("Error: 'examenes' no es un array. Verifica la respuesta del backend");
|
console.error("Error: 'examenes' no es un array. Verifica la respuesta del backend");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const examenesValidos = examenes.filter(examen => examen.examen && examen.cantidad !== undefined);
|
const examenesValidos = examenes.filter(examen => examen.examen && examen.cantidad !== undefined);
|
||||||
|
|
||||||
return examenesValidos;
|
return examenesValidos;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al obtener datos de examenes:", error);
|
console.error("Error al obtener datos de examenes:", error);
|
||||||
|
@ -161,24 +124,35 @@ async function obtenerDatosExamenes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function obtenerDatosFechas() {
|
async function obtenerDatosFechas(filtros = {}) {
|
||||||
try {
|
try {
|
||||||
const fechas = await recuperarCantidadFecha("Fechas");
|
const fechas = await recuperarCantidadFecha("Fechas", filtros);
|
||||||
|
if (!Array.isArray(fechas) || !fechas.length) {
|
||||||
if (!Array.isArray(fechas)) {
|
|
||||||
console.error("Error: 'fechas' no es un array. Verifica la respuesta del backend");
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
// Solo un objeto con la cantidad total
|
||||||
const fechasValidas = fechas.filter(fecha => fecha.fecha && fecha.cantidad !== undefined);
|
return fechas;
|
||||||
|
|
||||||
return fechasValidas;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error al obtener datos de fechas:", error);
|
console.error("Error al obtener datos de fechas:", error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFiltrosSeleccionados() {
|
||||||
|
return {
|
||||||
|
id_rango_edad: document.getElementById('id_rango_edad')?.value || "NULL",
|
||||||
|
id_genero: document.getElementById('id_genero')?.value || "NULL",
|
||||||
|
id_examen: document.getElementById('id_examen')?.value || "NULL",
|
||||||
|
fechaInicio: document.getElementById('date1')?.value || "",
|
||||||
|
fechaFin: document.getElementById('date2')?.value || ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
export { obtenerDatosGeneros, obtenerDatosEdades, obtenerDatosEstados, obtenerDatosExamenes, obtenerDatosFechas };
|
obtenerDatosGeneros,
|
||||||
|
obtenerDatosEdades,
|
||||||
|
obtenerDatosEstados,
|
||||||
|
obtenerDatosExamenes,
|
||||||
|
obtenerDatosFechas,
|
||||||
|
getFiltrosSeleccionados
|
||||||
|
};
|
357
js/inicio.js
357
js/inicio.js
|
@ -163,10 +163,67 @@ allProgress.forEach(item=> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { obtenerDatosGeneros, obtenerDatosEdades, obtenerDatosEstados,obtenerDatosExamenes } from './funcionesGraficos.js';
|
import {
|
||||||
|
obtenerDatosGeneros,
|
||||||
|
obtenerDatosEdades,
|
||||||
|
obtenerDatosEstados,
|
||||||
|
obtenerDatosExamenes,
|
||||||
|
obtenerDatosFechas,
|
||||||
|
getFiltrosSeleccionados
|
||||||
|
} from './funcionesGraficos.js';
|
||||||
|
|
||||||
async function inicializarGrafico() {
|
// Variables globales para los graficos
|
||||||
const [femenino, masculino, noDefinido] = await obtenerDatosGeneros();
|
let chartGenero = null;
|
||||||
|
let chartEdad = null;
|
||||||
|
let chartEstado = null;
|
||||||
|
let chartExamen = null;
|
||||||
|
let chartFecha = null;
|
||||||
|
|
||||||
|
// Controla si el filtro de fecha está activo
|
||||||
|
let filtroFechaActivo = false;
|
||||||
|
|
||||||
|
async function inicializarGraficoFecha(filtros) {
|
||||||
|
// Solo dibujar si ambas fechas están presentes y el filtro está activo
|
||||||
|
if (!filtroFechaActivo || !filtros.fechaInicio || !filtros.fechaFin) {
|
||||||
|
if (chartFecha) {
|
||||||
|
chartFecha.destroy();
|
||||||
|
chartFecha = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fechas = await obtenerDatosFechas(filtros);
|
||||||
|
|
||||||
|
if (!fechas.length) {
|
||||||
|
if (chartFecha) {
|
||||||
|
chartFecha.destroy();
|
||||||
|
chartFecha = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solo un valor total
|
||||||
|
const cantidad = fechas[0].cantidad;
|
||||||
|
const label = `Del ${fechas[0].fechaInicio} al ${fechas[0].fechaFin}`;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: [{
|
||||||
|
name: 'Candidatos',
|
||||||
|
data: [cantidad]
|
||||||
|
}],
|
||||||
|
chart: { height: 350, type: 'bar' },
|
||||||
|
xaxis: { categories: [label] },
|
||||||
|
dataLabels: { enabled: true },
|
||||||
|
tooltip: { y: { formatter: val => val + " candidatos" } }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (chartFecha) chartFecha.destroy();
|
||||||
|
chartFecha = new ApexCharts(document.querySelector("#chart5"), options);
|
||||||
|
chartFecha.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function inicializarGrafico(filtros) {
|
||||||
|
const [femenino, masculino, noDefinido] = await obtenerDatosGeneros(filtros);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: [
|
series: [
|
||||||
|
@ -174,40 +231,20 @@ async function inicializarGrafico() {
|
||||||
{ name: 'Masculino', data: [masculino] },
|
{ name: 'Masculino', data: [masculino] },
|
||||||
{ name: 'Prefiero no decirlo', data: [noDefinido] },
|
{ name: 'Prefiero no decirlo', data: [noDefinido] },
|
||||||
],
|
],
|
||||||
chart: {
|
chart: { height: 350, type: 'bar' },
|
||||||
height: 350,
|
plotOptions: { bar: { horizontal: false, columnWidth: '55%', borderRadius: 5 } },
|
||||||
type: 'bar',
|
dataLabels: { enabled: false },
|
||||||
},
|
xaxis: { categories: ['Géneros'] },
|
||||||
plotOptions: {
|
tooltip: { y: { formatter: val => val + " personas" } }
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '55%',
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: ['Géneros'],
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
y: {
|
|
||||||
formatter: function (val) {
|
|
||||||
return val + " personas";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const chart = new ApexCharts(document.querySelector("#chart"), options);
|
if (chartGenero) chartGenero.destroy();
|
||||||
chart.render();
|
chartGenero = new ApexCharts(document.querySelector("#chart"), options);
|
||||||
|
chartGenero.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
inicializarGrafico();
|
async function inicializarGrafico2(filtros) {
|
||||||
|
const [edad1, edad2, edad3, edad4, edad5, edad6, edad7] = await obtenerDatosEdades(filtros);
|
||||||
async function inicializarGrafico2() {
|
|
||||||
const [edad1,edad2,edad3,edad4,edad5,edad6,edad7] = await obtenerDatosEdades();
|
|
||||||
|
|
||||||
const options2 = {
|
const options2 = {
|
||||||
series: [
|
series: [
|
||||||
|
@ -219,47 +256,20 @@ async function inicializarGrafico2() {
|
||||||
{ name: '55 a 64 años', data: [edad6] },
|
{ name: '55 a 64 años', data: [edad6] },
|
||||||
{ name: '65 años o más', data: [edad7] },
|
{ name: '65 años o más', data: [edad7] },
|
||||||
],
|
],
|
||||||
chart: {
|
chart: { height: 350, type: 'bar' },
|
||||||
height: 350,
|
plotOptions: { bar: { horizontal: false, columnWidth: '55%', borderRadius: 5 } },
|
||||||
type: 'bar',
|
dataLabels: { enabled: false },
|
||||||
},
|
xaxis: { categories: ['Edades'] },
|
||||||
plotOptions: {
|
tooltip: { y: { formatter: val => val + " Años" } }
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '55%',
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: ['Edades'],
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
y: {
|
|
||||||
formatter: function (val) {
|
|
||||||
return val + " Años";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const chart2 = new ApexCharts(document.querySelector("#chart2"), options2);
|
if (chartEdad) chartEdad.destroy();
|
||||||
chart2.render();
|
chartEdad = new ApexCharts(document.querySelector("#chart2"), options2);
|
||||||
|
chartEdad.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
inicializarGrafico2();
|
async function inicializarGrafico3(filtros) {
|
||||||
|
const estados = await obtenerDatosEstados(filtros);
|
||||||
|
|
||||||
async function inicializarGrafico3() {
|
|
||||||
try {
|
|
||||||
const estados = await obtenerDatosEstados();
|
|
||||||
|
|
||||||
if (!Array.isArray(estados)) {
|
|
||||||
console.error("Error: 'estados' no es un array. Verifica la funcion obtenerDatosEstados");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const seriesData = estados.map(estado => ({
|
const seriesData = estados.map(estado => ({
|
||||||
name: estado.estado,
|
name: estado.estado,
|
||||||
|
@ -268,49 +278,20 @@ async function inicializarGrafico3() {
|
||||||
|
|
||||||
const options3 = {
|
const options3 = {
|
||||||
series: seriesData,
|
series: seriesData,
|
||||||
chart: {
|
chart: { height: 350, type: 'bar' },
|
||||||
height: 350,
|
plotOptions: { bar: { horizontal: false, columnWidth: '55%', borderRadius: 5 } },
|
||||||
type: 'bar',
|
dataLabels: { enabled: false },
|
||||||
},
|
xaxis: { categories: estados.map(estado => estado.estado) },
|
||||||
plotOptions: {
|
tooltip: { y: { formatter: val => val + " personas" } }
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '55%',
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: estados.map(estado => estado.estado), // categorias en el eje X
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
y: {
|
|
||||||
formatter: function (val) {
|
|
||||||
return val + " personas";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const chart3 = new ApexCharts(document.querySelector("#chart3"), options3);
|
if (chartEstado) chartEstado.destroy();
|
||||||
chart3.render();
|
chartEstado = new ApexCharts(document.querySelector("#chart3"), options3);
|
||||||
} catch (error) {
|
chartEstado.render();
|
||||||
console.error("Error al inicializar el gráfico 3:", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inicializarGrafico3();
|
async function inicializarGrafico4(filtros) {
|
||||||
|
const examenes = await obtenerDatosExamenes(filtros);
|
||||||
async function inicializarGrafico4() {
|
|
||||||
try {
|
|
||||||
const examenes = await obtenerDatosExamenes();
|
|
||||||
|
|
||||||
if (!Array.isArray(examenes)) {
|
|
||||||
console.error("Error: 'examenes' no es un array. Verifica la función obtenerDatosExamenes");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const seriesData = examenes.map(examen => ({
|
const seriesData = examenes.map(examen => ({
|
||||||
name: examen.examen,
|
name: examen.examen,
|
||||||
|
@ -319,123 +300,63 @@ async function inicializarGrafico4() {
|
||||||
|
|
||||||
const options4 = {
|
const options4 = {
|
||||||
series: seriesData,
|
series: seriesData,
|
||||||
chart: {
|
chart: { height: 350, type: 'bar' },
|
||||||
height: 350,
|
plotOptions: { bar: { horizontal: false, columnWidth: '55%', borderRadius: 5 } },
|
||||||
type: 'bar',
|
dataLabels: { enabled: false },
|
||||||
},
|
xaxis: { categories: examenes.map(examen => examen.examen) },
|
||||||
plotOptions: {
|
tooltip: { y: { formatter: val => val + " examenes" } }
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '55%',
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: examenes.map(examen => examen.examen), // categorías en el eje X
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
y: {
|
|
||||||
formatter: function (val) {
|
|
||||||
return val + " examenes";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const chart4 = new ApexCharts(document.querySelector("#chart4"), options4);
|
if (chartExamen) chartExamen.destroy();
|
||||||
chart4.render();
|
chartExamen = new ApexCharts(document.querySelector("#chart4"), options4);
|
||||||
} catch (error) {
|
chartExamen.render();
|
||||||
console.error("Error al inicializar el grafico 4:", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function actualizarTodosLosGraficos() {
|
||||||
inicializarGrafico4();
|
// Si el filtro de fecha está activo, se pasan las fechas, si no, se limpian
|
||||||
|
let filtros = getFiltrosSeleccionados();
|
||||||
|
if (!filtroFechaActivo) {
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
filtros.fechaInicio = "";
|
||||||
const btnbuscar = document.getElementById('buscar');
|
filtros.fechaFin = "";
|
||||||
btnbuscar.addEventListener('click', async function () {
|
|
||||||
const fechaInicioInput = document.getElementById('date1').value;
|
|
||||||
const fechaFinInput = document.getElementById('date2').value;
|
|
||||||
|
|
||||||
if (fechaInicioInput === "" || fechaFinInput === "") {
|
|
||||||
alert("Por favor, ingrese ambas fechas.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
await inicializarGrafico(filtros);
|
||||||
|
await inicializarGrafico2(filtros);
|
||||||
|
await inicializarGrafico3(filtros);
|
||||||
|
await inicializarGrafico4(filtros);
|
||||||
|
await inicializarGraficoFecha(filtros);
|
||||||
|
}
|
||||||
|
|
||||||
// Convertir las fechas al formato YYYY-MM-DD
|
// Espera a que el DOM esté listo antes de agregar eventos
|
||||||
const fechaInicio = convertirFechaAFormatoISO(fechaInicioInput);
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const fechaFin = convertirFechaAFormatoISO(fechaFinInput);
|
// Solo combos, NO fechas
|
||||||
|
['id_rango_edad', 'id_genero', 'id_examen'].forEach(id => {
|
||||||
try {
|
const el = document.getElementById(id);
|
||||||
const response = await fetch('../controllers/graficos.php', {
|
if (el) el.addEventListener('change', actualizarTodosLosGraficos);
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
tipoConsulta: 'Fechas',
|
|
||||||
fechaInicio: fechaInicio,
|
|
||||||
fechaFin: fechaFin,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
// Botón buscar para fechas
|
||||||
console.log("Respuesta del servidor:", data);
|
const btnBuscar = document.getElementById('buscar');
|
||||||
|
if (btnBuscar) {
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
btnBuscar.addEventListener('click', () => {
|
||||||
const seriesData = data.map(fecha => fecha.total);
|
const date1 = document.getElementById('date1').value;
|
||||||
const categories = data.map((_, index) => `Registro ${index + 1}`);
|
const date2 = document.getElementById('date2').value;
|
||||||
|
// Solo activa el filtro si ambas fechas están presentes
|
||||||
const options5 = {
|
filtroFechaActivo = !!(date1 && date2);
|
||||||
series: [{
|
actualizarTodosLosGraficos();
|
||||||
name: 'Cantidad de registros',
|
});
|
||||||
data: seriesData,
|
|
||||||
}],
|
|
||||||
chart: {
|
|
||||||
height: 350,
|
|
||||||
type: 'bar',
|
|
||||||
},
|
|
||||||
plotOptions: {
|
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '55%',
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: categories,
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
y: {
|
|
||||||
formatter: function (val) {
|
|
||||||
return val + " registros";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const chart5 = new ApexCharts(document.querySelector("#chart5"), options5);
|
|
||||||
chart5.render();
|
|
||||||
} else {
|
|
||||||
alert("No se encontraron datos para las fechas seleccionadas.");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error("Error al obtener los datos:", error);
|
// Botón limpiar para quitar filtro de fecha
|
||||||
|
const btnLimpiar = document.getElementById('limpiar');
|
||||||
|
if (btnLimpiar) {
|
||||||
|
btnLimpiar.addEventListener('click', () => {
|
||||||
|
document.getElementById('date1').value = '';
|
||||||
|
document.getElementById('date2').value = '';
|
||||||
|
filtroFechaActivo = false;
|
||||||
|
actualizarTodosLosGraficos();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Función para convertir fechas al formato YYYY-MM-DD
|
|
||||||
function convertirFechaAFormatoISO(fecha) {
|
|
||||||
const partes = fecha.split('-'); // Suponiendo que el input usa el formato DD-MM-YYYY
|
|
||||||
return `${partes[0]}-${partes[1]}-${partes[2]}`; // Retorna YYYY-MM-DD
|
|
||||||
}
|
|
||||||
|
|
||||||
|
filtroFechaActivo = false;
|
||||||
|
actualizarTodosLosGraficos();
|
||||||
|
});
|
|
@ -131,16 +131,12 @@
|
||||||
<input type="date" id="date2" name="date2">
|
<input type="date" id="date2" name="date2">
|
||||||
<br>
|
<br>
|
||||||
<button type="button" id="buscar">Buscar</button>
|
<button type="button" id="buscar">Buscar</button>
|
||||||
|
<button type="button" id="limpiar">Limpiar</button>
|
||||||
<br>
|
<br>
|
||||||
<div class="content-data">
|
<div class="content-data">
|
||||||
<div class="head">
|
<div class="head">
|
||||||
|
<h3>Resultado de registros en el rango de fecha ingresado</h3>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<i class='bx bx-dots-horizontal-rounded icon'></i>
|
|
||||||
<ul class="menu-link">
|
|
||||||
<li><a href="#">Edit</a></li>
|
|
||||||
<li><a href="#">Save</a></li>
|
|
||||||
<li><a href="#">Remove</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chart">
|
<div class="chart">
|
||||||
|
|
Loading…
Reference in New Issue