From 5861064c8df5625ac337dd1e6676b7f1c49df46d Mon Sep 17 00:00:00 2001 From: Emilio Date: Tue, 4 Nov 2025 13:54:39 -0600 Subject: [PATCH] se creo reportes --- mariadb/aria_log.00000001 | Bin 4972544 -> 4980736 bytes mariadb/aria_log_control | Bin 52 -> 52 bytes src/equipo/equipo.service.ts | 376 ++++++++++++++++++++++++++++++++++- 3 files changed, 374 insertions(+), 2 deletions(-) diff --git a/mariadb/aria_log.00000001 b/mariadb/aria_log.00000001 index 61f3c9037d562abe09b1212f1e796413e8992af7..963acf600ed98095e7aa17690e84bb7babe6e1f3 100644 GIT binary patch delta 5884 zcmZA3T~t(M6vlBRBOC<74?sXbL_|bXL_|bDMAX5s$cW6a$c)I;$jHc$Xh%kbB?M-K zL`Gx=N@PZcW=2E^@~w!V2#AQNh-B1K&ziH+|7tGgV*lou{hasaJ@H2h^yB0A>Bq|u z(U<#VsN63G@_-o1FwuyS3>RZDkrDEsn94{QC8K4Gn2EVq$XKxyE3uYwVk5RAsvtc*z1!-?Jj2vx+~|xg$F&-h3W5dTCSfeV;ROE5 zQiWyaK}N=$TOqKSU=7G4j04mWY*e^?Mr&kTjn%dYxDf0BVTADjA=s->Q2W0X6A)-- zzyV-bgHjU#?gU2_R*h8-it|YbBomwf2MLn_?F45PMvPEa)S}ZA1iT3@fJnkrKpMeS zg~RpAL2*6}fgZwifJGfj%>V=t+*DX^r91`aGZDxnxC6=vvjF`B4;5@pl@;~qG#i1X z1W&*w!W_VEf|m+ajmklBJ{N(13Elvw29%lySWfV{3r5DA``(>vO!gA|04E9a0Ye+H z+h2ugqm+ZKqg@$pp5Y9 zJ+SC+4O*qIH$-`7I%21M{rBb+bMGf6&Sz2YH9#m~6Ci=`Iv}4A3uq#|0Wdg+<(mO+ zgf{`sXbA|Vq{NcarULdXJWE}+#efCnKP5JC7HkV41- z6cfGxbP{$0Ms}gqmjE9^E+C5V6(F6E2RKUj8qiDF1F*b^R^I>u33~z2gl_>^gnU3b zp#U&I*axuhMyvgRU_v1vmhc@Qmrw+#A$$+GMK}O(zJyjk073}|0SSa30r`YtKoj97 zfI$zI9|E`$eg=dSN&rcO!+-;XBY-x-F94IvXmu3eMfer4hHwn9o$wo=gis3TCj1UC z>qVjZF3J^m$0mva#11bqMfI&hn!0{?t z)d4~X^?*1+17HuK5zs(53DCcW<);9ygeJfW!f8Mvp&3v}I0I-Qv;Z`HXw?evAe;q6 z5Y7Qo2yK93!g)X^p&c;tI$CuAd$95KXuY z$RhLt$_ZBh1B9yp`x|I=4G>J|1H=-p19A!dfEvOLz%9Z6zc^fuu*|uX>LD8O)vV8{*RaDg+sXKP!)R}V) r7cO17cH`Earh5-s9<_CJJ$d%x)th%cANoGWU&G1ww37%&-9h*dr4Bm4 diff --git a/mariadb/aria_log_control b/mariadb/aria_log_control index 60663fa1ba66fcf39307f370c0bfbae803d3c824..7bf5c4101219a2538cbd54f54b042a0dc303d066 100644 GIT binary patch delta 27 gcmXppnII=txWXWgk%8gXH*W?Y#qgUQNH8z}0A(Hp^8f$< delta 27 fcmXppnII>|#Pm&wk%6J)yf*`oVi02o5)2FgNoxb< diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index fefb81b..0804c2d 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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';