se agregaron cambios de al reporte
This commit is contained in:
+112
-10
@@ -62,7 +62,7 @@ export class EquipoService {
|
||||
private readonly laboratorioRepo: Repository<Laboratorio>,
|
||||
@InjectRepository(Proyecto)
|
||||
private readonly proyectoRepo: Repository<Proyecto>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async deleteEquipo(inventario: string): Promise<{ message: string }> {
|
||||
const equipo = await this.equipoRepository.findOne({
|
||||
@@ -293,12 +293,12 @@ export class EquipoService {
|
||||
equipo.isImpresora
|
||||
? { ...datosBase, periferico: { id_periferico: equipo.id_periferico } }
|
||||
: {
|
||||
...datosBase,
|
||||
sistemaOperativo: {
|
||||
id_sistema_operativo: equipo.id_sistema_operativo,
|
||||
},
|
||||
procesador: { id_procesador: equipo.id_procesador },
|
||||
...datosBase,
|
||||
sistemaOperativo: {
|
||||
id_sistema_operativo: equipo.id_sistema_operativo,
|
||||
},
|
||||
procesador: { id_procesador: equipo.id_procesador },
|
||||
},
|
||||
);
|
||||
|
||||
let equip = await this.equipoRepository.save(nuevoEquipo);
|
||||
@@ -358,11 +358,14 @@ export class EquipoService {
|
||||
return await this.procesadorRepo.find();
|
||||
}
|
||||
|
||||
async createEcxel(res: Response) {
|
||||
const data = await this.generar_reporte();
|
||||
return this.exportarReporteAExcel(data, res);
|
||||
}
|
||||
// async createEcxel(res: Response) {
|
||||
// const data = await this.generar_reporte();
|
||||
// return this.exportarReporteAExcel(data, res);
|
||||
// }
|
||||
|
||||
async createEcxel(res: Response) {
|
||||
return await this.exportarEquiposAExcel(res);
|
||||
}
|
||||
@Cron('0 0 0 * * *')
|
||||
async llenadoDeAntiguedad() {
|
||||
const result = await this.equipoRepository
|
||||
@@ -384,6 +387,105 @@ export class EquipoService {
|
||||
return result;
|
||||
}
|
||||
|
||||
async exportarEquiposAExcel(res: Response) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const sheet = workbook.addWorksheet('Equipos');
|
||||
|
||||
// =====================================
|
||||
// ✅ ENCABEZADOS
|
||||
// =====================================
|
||||
sheet.columns = [
|
||||
{ header: 'Inventario', key: 'inventario', width: 70 },
|
||||
{ header: 'Serie', key: 'serie', width: 70 },
|
||||
{ header: 'Lugar', key: 'lugar', width: 70 },
|
||||
{ header: 'Fecha Factura', key: 'fechaFactura', width: 70 },
|
||||
{ header: 'Antigüedad', key: 'antiguedad', width: 70 },
|
||||
{ header: 'Modelo', key: 'modelo', width: 70 },
|
||||
{ header: 'Marca', key: 'marca', width: 70 },
|
||||
{ header: 'Estado', key: 'estado', width: 70 },
|
||||
{ header: 'Adscripción', key: 'adscripcion', width: 70 },
|
||||
{ header: 'Tipo de Equipo', key: 'tipoEquipo', width: 70 },
|
||||
{ header: 'Sistema Operativo', key: 'sistemaOperativo', width: 70 },
|
||||
{ header: 'Procesador', key: 'procesador', width: 70 },
|
||||
{ header: 'Tipo de Uso', key: 'tipoUso', width: 70 },
|
||||
{ header: 'Periférico', key: 'periferico', width: 70 },
|
||||
{ header: 'Proyecto', key: 'proyecto', width: 70 },
|
||||
{ header: 'Laboratorio', key: 'laboratorio', width: 70 },
|
||||
{ header: 'Observaciones', key: 'observaciones', width: 100 },
|
||||
{ header: 'Fecha Movimiento', key: 'fechaMovimiento', width: 70 },
|
||||
{ header: 'Usuario', key: 'user', width: 70 },
|
||||
|
||||
];
|
||||
|
||||
// =====================================
|
||||
// ✅ OBTENER EQUIPOS
|
||||
// =====================================
|
||||
const equipos = await this.equipoRepository.find({
|
||||
relations: [
|
||||
'marca',
|
||||
'estado',
|
||||
'adscripcion',
|
||||
'tipoEquipo',
|
||||
'sistemaOperativo',
|
||||
'procesador',
|
||||
'tipoUso',
|
||||
'periferico',
|
||||
'proyecto',
|
||||
'laboratorio',
|
||||
],
|
||||
});
|
||||
|
||||
// =====================================
|
||||
// ✅ LLENAR FILAS
|
||||
// =====================================
|
||||
for (const equipo of equipos) {
|
||||
const movimiento = await this.movimiento.buscar(equipo.id_equipo);
|
||||
|
||||
sheet.addRow({
|
||||
inventario: equipo.inventario,
|
||||
serie: equipo.serie,
|
||||
lugar: equipo.lugar,
|
||||
fechaFactura: equipo.fechaFactura,
|
||||
antiguedad: equipo.antiguedad,
|
||||
modelo: equipo.modelo,
|
||||
marca: equipo.marca?.marca ?? '',
|
||||
estado: equipo.estado?.estado ?? '',
|
||||
adscripcion: equipo.adscripcion?.adscripcion ?? '',
|
||||
tipoEquipo: equipo.tipoEquipo?.tipo_equipo ?? '',
|
||||
sistemaOperativo: equipo.sistemaOperativo?.sistema_operativo ?? '',
|
||||
procesador: equipo.procesador?.procesador ?? '',
|
||||
tipoUso: equipo.tipoUso?.tipo_uso ?? '',
|
||||
periferico: equipo.periferico?.periferico ?? '',
|
||||
proyecto: equipo.proyecto?.proyecto ?? '',
|
||||
laboratorio: equipo.laboratorio?.laboratorio ?? '',
|
||||
observaciones: movimiento?.observaciones ?? '',
|
||||
fechaMovimiento: movimiento?.fechaMovimiento ?? '',
|
||||
user: movimiento?.user?.nombre ?? '',
|
||||
});
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// ✅ ESTILO HEADER
|
||||
// =====================================
|
||||
sheet.getRow(1).font = { bold: true };
|
||||
|
||||
// =====================================
|
||||
// ✅ RESPUESTA AL NAVEGADOR
|
||||
// =====================================
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=equipos.xlsx',
|
||||
);
|
||||
|
||||
await workbook.xlsx.write(res);
|
||||
res.end();
|
||||
}
|
||||
|
||||
async exportarReporteAExcel(data: any, res: Response) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
let count = 1;
|
||||
|
||||
@@ -11,7 +11,7 @@ export class MovimientoService {
|
||||
constructor(
|
||||
@InjectRepository(Movimiento)
|
||||
private readonly movimientoRepo: Repository<Movimiento>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async crear(dto: CreateMovimientoDto) {
|
||||
const movimiento = this.movimientoRepo.create({
|
||||
@@ -28,6 +28,7 @@ export class MovimientoService {
|
||||
const movimiento = await this.movimientoRepo.findOne({
|
||||
where: { equipo: { id_equipo: idEquipo } },
|
||||
order: { fechaMovimiento: 'DESC' },
|
||||
relations: ['user'],
|
||||
});
|
||||
|
||||
return movimiento;
|
||||
|
||||
Reference in New Issue
Block a user