reportes por mes y año
This commit is contained in:
@@ -59,11 +59,26 @@ export class AlumnoInscritoController {
|
||||
return this.alumnoInscritoService.findById(id_cuenta);
|
||||
}
|
||||
|
||||
@Get('inscritos/:inicio/:fin')
|
||||
findAllInscritosByRango(
|
||||
@Get('inscritos/periodo/:inicio/:fin')
|
||||
findByPeriodo(
|
||||
@Param('inicio', ParseIntPipe) inicio: number,
|
||||
@Param('fin', ParseIntPipe) fin: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(inicio, fin);
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(inicio, fin, 'periodo');
|
||||
}
|
||||
|
||||
@Get('inscritos/anio/:inicio/:fin')
|
||||
findByAnio(
|
||||
@Param('inicio', ParseIntPipe) inicio: number,
|
||||
@Param('fin', ParseIntPipe) fin: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(inicio, fin, 'anio');
|
||||
}
|
||||
|
||||
@Get('inscritos/mes/:anio')
|
||||
findByMes(
|
||||
@Param('anio', ParseIntPipe) anio: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.findAllInscritosByRango(anio, 0, 'mes');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,22 +231,28 @@ async findAllInscritos(idPeriodo: number) {
|
||||
const create = repo.create(data);
|
||||
return await repo.save(create);
|
||||
}
|
||||
|
||||
async findAllInscritosByRango(
|
||||
idPeriodoInicio: number,
|
||||
idPeriodoFin: number,
|
||||
async findAllInscritosByRango(
|
||||
inicio: number,
|
||||
fin: number,
|
||||
tipo: 'periodo' | 'mes' | 'anio',
|
||||
) {
|
||||
return this.alumnoInscritoRepo
|
||||
const qb = this.alumnoInscritoRepo
|
||||
.createQueryBuilder('inscritos')
|
||||
.innerJoin('inscritos.alumno', 'alumno')
|
||||
.innerJoin('alumno.carrera', 'carrera')
|
||||
.innerJoin('inscritos.plataforma', 'plataforma')
|
||||
.innerJoin('inscritos.periodo', 'periodo')
|
||||
.where('periodo.id_periodo BETWEEN :inicio AND :fin', {
|
||||
inicio: idPeriodoInicio,
|
||||
fin: idPeriodoFin,
|
||||
})
|
||||
.select([
|
||||
.innerJoin('inscritos.periodo', 'periodo');
|
||||
|
||||
// ============================
|
||||
// 🟢 PERIODO
|
||||
// ============================
|
||||
if (tipo === 'periodo') {
|
||||
qb.where('periodo.id_periodo BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
});
|
||||
|
||||
qb.select([
|
||||
'periodo.id_periodo AS id_periodo',
|
||||
'periodo.semestre AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
@@ -263,11 +269,81 @@ async findAllInscritos(idPeriodo: number) {
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
])
|
||||
.groupBy('periodo.id_periodo')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('periodo.id_periodo', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
]);
|
||||
|
||||
qb.groupBy('periodo.id_periodo')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('periodo.id_periodo', 'ASC');
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 🔵 AÑO
|
||||
// ============================
|
||||
else if (tipo === 'anio') {
|
||||
qb.where(
|
||||
'periodo.fecha_inicio_servicio BETWEEN :inicio AND :fin',
|
||||
{
|
||||
inicio: `${inicio}-01-01`,
|
||||
fin: `${fin}-12-31`,
|
||||
},
|
||||
);
|
||||
|
||||
qb.select([
|
||||
'YEAR(periodo.fecha_inicio_servicio) AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
'plataforma.nombre AS profesor',
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('F', 'Femenino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS femenino`,
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('M', 'Masculino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
]);
|
||||
|
||||
qb.groupBy('YEAR(periodo.fecha_inicio_servicio)')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('YEAR(periodo.fecha_inicio_servicio)', 'ASC')
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 🟡 MES (UN SOLO AÑO)
|
||||
// ============================
|
||||
else if (tipo === 'mes') {
|
||||
qb.where('YEAR(periodo.fecha_inicio_servicio) = :anio', {
|
||||
anio: inicio, // aquí "inicio" es el año
|
||||
});
|
||||
|
||||
qb.select([
|
||||
'MONTH(periodo.fecha_inicio_servicio) AS semestre',
|
||||
'carrera.carrera AS carrera',
|
||||
'plataforma.nombre AS profesor',
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('F', 'Femenino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS femenino`,
|
||||
|
||||
`COUNT(DISTINCT CASE
|
||||
WHEN alumno.genero IN ('M', 'Masculino')
|
||||
THEN alumno.id_cuenta
|
||||
END) AS masculino`,
|
||||
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total',
|
||||
]);
|
||||
qb.groupBy('MONTH(periodo.fecha_inicio_servicio)')
|
||||
.addGroupBy('carrera.carrera')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
.orderBy('YEAR(periodo.fecha_inicio_servicio)', 'ASC')
|
||||
}
|
||||
|
||||
return qb.getRawMany();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user