se creo reportes
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -319,8 +319,8 @@ export class EquipoService {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't') // une la tabla usuario
|
||||
.innerJoin('e.sistemaOperativo', 's') // une la tabla categoria
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.innerJoin('e.sistemaOperativo', 's')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', { tipo_equipo })
|
||||
.select(['s.sistema_operativo AS sistema_operativo'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
@@ -333,4 +333,376 @@ export class EquipoService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async contar_tipoEquipos_procesador(tipo_equipo: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.procesador_tipoequipo', 'pt')
|
||||
.innerJoin('pt.tipoEquipo', 't')
|
||||
.innerJoin('pt.procesador', 'p')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', { tipo_equipo })
|
||||
.select(['p.procesador AS procesador'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('p.procesador')
|
||||
.getRawMany();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async contar_tipoEquipos(tipo_equipo: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', { tipo_equipo })
|
||||
.select(['t.tipo_equipo AS tipo_equipo'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('t.tipoEquipo')
|
||||
.getRawMany();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async contar_tipoEquipos_antiguedad(): Promise<any> {
|
||||
const totalEscrtitorio = this.contar_tipoEquipos([
|
||||
'ESCRITORIO WINDOWS',
|
||||
'ESCRITORIO MAC OS',
|
||||
'ESCRITORIO LINUX',
|
||||
]);
|
||||
const totalPortatiles = this.contar_tipoEquipos([
|
||||
'PORTÁTILES WINDOWS',
|
||||
'PORTÁTILES CHROMEBOOK',
|
||||
'PORTÁTILES MAC OS',
|
||||
]);
|
||||
const totalAltoRendimiento = this.contar_tipoEquipos(['SERVIDOR']);
|
||||
try {
|
||||
const countEscritorios = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', {
|
||||
tipo_equipo: [
|
||||
'ESCRITORIO WINDOWS',
|
||||
'ESCRITORIO MAC OS',
|
||||
'ESCRITORIO LINUX',
|
||||
],
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
const countPortatiles = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', {
|
||||
tipo_equipo: [
|
||||
'PORTÁTILES WINDOWS',
|
||||
'PORTÁTILES CHROMEBOOK',
|
||||
'PORTÁTILES MAC OS',
|
||||
],
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
const countAltoRendimiento = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('t.tipo_equipo IN (:...tipo_equipo)', {
|
||||
tipo_equipo: ['SERVIDOR'],
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
|
||||
interface Porcentaje {
|
||||
antiguedad: any;
|
||||
total: any;
|
||||
porcentaje: string;
|
||||
}
|
||||
|
||||
let porcentajesEscritorios: Porcentaje[] = [];
|
||||
let porcentajesPortatiles: Porcentaje[] = [];
|
||||
let porcentajesAltoRendimiento: Porcentaje[] = [];
|
||||
|
||||
countEscritorios.forEach(async (item) => {
|
||||
porcentajesEscritorios.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: ((item.total / (await totalEscrtitorio)) * 100).toFixed(
|
||||
2,
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
countPortatiles.forEach(async (item) => {
|
||||
porcentajesPortatiles.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: ((item.total / (await totalPortatiles)) * 100).toFixed(2),
|
||||
});
|
||||
});
|
||||
|
||||
countAltoRendimiento.forEach(async (item) => {
|
||||
porcentajesAltoRendimiento.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: (
|
||||
(item.total / (await totalAltoRendimiento)) *
|
||||
100
|
||||
).toFixed(2),
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
escritorios: porcentajesEscritorios,
|
||||
portatiles: porcentajesPortatiles,
|
||||
altoRendimiento: porcentajesAltoRendimiento,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async garantia(tipo_equipo: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('e.fechaFactura >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR)')
|
||||
.andWhere('t.tipo_equipo IN (:...tipo_equipo)', { tipo_equipo })
|
||||
.getCount();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async equipos_impesion(perifericos: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.periferico', 'p')
|
||||
.where('p.periferico IN (:...perifericos)', { perifericos })
|
||||
.getCount();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async equipos_impesion_group(perifericos: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.periferico', 'p')
|
||||
.where('p.periferico IN (:...perifericos)', { perifericos })
|
||||
.groupBy('p.periferico')
|
||||
.getRawMany();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async contar_periferico_tipoUso(perifericos: string[]): Promise<any> {
|
||||
try {
|
||||
const count = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoUso', 't')
|
||||
.innerJoin('e.periferico', 'te')
|
||||
.where('p.periferico IN (:...perifericos)', { perifericos })
|
||||
.select(['t.tipo_uso AS uso'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('t.tipo_uso')
|
||||
.getRawMany();
|
||||
|
||||
return count;
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async contar_perifericos_antiguedad(
|
||||
impresion: string[],
|
||||
digitalizacion: string[],
|
||||
): Promise<any> {
|
||||
const totalImpresion = this.contar_tipoEquipos(impresion);
|
||||
const totalDigitalizacion = this.contar_tipoEquipos(digitalizacion);
|
||||
|
||||
try {
|
||||
const countImpresion = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.periferico', 'p')
|
||||
.where('p.periferico IN (:...periferico)', {
|
||||
periferico: impresion,
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
const countDigitalizacion = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.perriferico', 'p')
|
||||
.where('p.periferico IN (:...periferico)', {
|
||||
tipo_equipo: digitalizacion,
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
|
||||
interface Porcentaje {
|
||||
antiguedad: any;
|
||||
total: any;
|
||||
porcentaje: string;
|
||||
}
|
||||
|
||||
let porcentajesImpresion: Porcentaje[] = [];
|
||||
let porcentajesDigitalizacion: Porcentaje[] = [];
|
||||
|
||||
countImpresion.forEach(async (item) => {
|
||||
porcentajesImpresion.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: ((item.total / (await totalImpresion)) * 100).toFixed(2),
|
||||
});
|
||||
});
|
||||
|
||||
countDigitalizacion.forEach(async (item) => {
|
||||
porcentajesDigitalizacion.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: (
|
||||
(item.total / (await totalDigitalizacion)) *
|
||||
100
|
||||
).toFixed(2),
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
impresion: porcentajesDigitalizacion,
|
||||
digitalizacion: porcentajesImpresion,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async generar_reporte() {
|
||||
let contar_te_tu = await this.contar_tipoEquipos_tipoUso();
|
||||
|
||||
let so_pc = await this.contar_tipoEquipos_sistemasOperativos(equpos_pc);
|
||||
let so_mac = await this.contar_tipoEquipos_sistemasOperativos([
|
||||
estritorio_mac,
|
||||
]);
|
||||
let so_ppc = await this.contar_tipoEquipos_sistemasOperativos(portatiles);
|
||||
let so_pmac = await this.contar_tipoEquipos_sistemasOperativos([
|
||||
portatiles_mac,
|
||||
]);
|
||||
let so_serv = await this.contar_tipoEquipos_sistemasOperativos([servidor]);
|
||||
|
||||
let contar_pc_p = await this.contar_tipoEquipos_procesador(equpos_pc);
|
||||
let contar_macpc_p = await this.contar_tipoEquipos_procesador([
|
||||
estritorio_mac,
|
||||
]);
|
||||
let contar_p_p = await this.contar_tipoEquipos_procesador(portatiles);
|
||||
let contar_pmac_p = await this.contar_tipoEquipos_procesador([
|
||||
portatiles_mac,
|
||||
]);
|
||||
let contar_serv = await this.contar_tipoEquipos_procesador([servidor]);
|
||||
|
||||
let porcentaje = await this.contar_tipoEquipos_antiguedad();
|
||||
|
||||
let garantia_e = await this.garantia(escritorio);
|
||||
let garantia_p = await this.garantia(portatil);
|
||||
let garantia_s = await this.garantia([servidor]);
|
||||
|
||||
let contar_impresoras = await this.equipos_impesion_group(impresoras);
|
||||
let contar_i_u = await this.contar_periferico_tipoUso(impresoras);
|
||||
|
||||
let contar_digitalizacion = await this.equipos_impesion_group(dijitales);
|
||||
let contar_d_u = await this.contar_periferico_tipoUso(dijitales);
|
||||
|
||||
let garantia_periferico = await this.generar_reporte();
|
||||
|
||||
return {
|
||||
...contar_te_tu,
|
||||
...so_pc,
|
||||
...so_mac,
|
||||
...so_ppc,
|
||||
...so_pmac,
|
||||
...so_serv,
|
||||
...contar_pc_p,
|
||||
...contar_macpc_p,
|
||||
...contar_p_p,
|
||||
...contar_pmac_p,
|
||||
...contar_serv,
|
||||
...porcentaje,
|
||||
...garantia_e,
|
||||
...garantia_p,
|
||||
...garantia_s,
|
||||
...contar_impresoras,
|
||||
...contar_i_u,
|
||||
...contar_digitalizacion,
|
||||
...contar_d_u,
|
||||
...garantia_periferico,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let escritorio = [
|
||||
'ESCRITORIO WINDOWS',
|
||||
'ESCRITORIO MAC OS ',
|
||||
'ESCRITORIO LINUX',
|
||||
];
|
||||
let portatil = [
|
||||
'PORTÁTILES WINDOWS',
|
||||
'PORTÁTILES CHROMEBOOK',
|
||||
'PORTÁTILES MAC OS',
|
||||
];
|
||||
|
||||
let equipos_mac = ['ESCRITORIO MAC OS ', 'PORTÁTILES MAC OS'];
|
||||
|
||||
let equpos_pc = ['ESCRITORIO WINDOWS', 'ESCRITORIO LINUX'];
|
||||
let estritorio_mac = 'ESCRITORIO MAC OS ';
|
||||
let portatiles_mac = 'PORTÁTILES MAC OS';
|
||||
|
||||
let portatiles = ['PORTÁTILES WINDOWS', 'PORTÁTILES CHROMEBOOK'];
|
||||
|
||||
let tabletas = ['TABLETA ANDROID', 'TABLETA iPAD OS'];
|
||||
|
||||
let impresoras = [
|
||||
'INYECCIÓN TINTA',
|
||||
'LÁSER DE ALTO VOLUMEN B/N',
|
||||
'LÁSER PEQUEÑA B/N',
|
||||
'LÁSER PEQUEÑA COLOR',
|
||||
'MATRIZ DE PUNTOS',
|
||||
'MULTIFUNCIONALES',
|
||||
];
|
||||
|
||||
let dijitales = [
|
||||
'3D',
|
||||
'DIGITALIZADOR DE CAMA PLANA PARA OFICINA',
|
||||
'DIGITALIZADOR CON ALIMENTADOR DE HOJAS PARA OFICINA',
|
||||
];
|
||||
|
||||
let servidor = 'SERVIDOR';
|
||||
|
||||
Reference in New Issue
Block a user