fixed tablaExcel
This commit is contained in:
@@ -1510,7 +1510,7 @@ export class EquipoService {
|
||||
}
|
||||
|
||||
return qb
|
||||
.orderBy(`equipo.adscripcion`, "DESC")
|
||||
.orderBy(`equipo.inventario`, 'ASC')
|
||||
.getRawMany()
|
||||
}
|
||||
|
||||
@@ -1566,16 +1566,20 @@ export class EquipoService {
|
||||
async tablaExcel(filtros?: FiltrosTablaDto) {
|
||||
const qb = this.equipoRepository
|
||||
.createQueryBuilder('equipo')
|
||||
.select([]);
|
||||
.select(['*']);
|
||||
|
||||
qb.leftJoin('equipo.adscripcion', 'adscripcion');
|
||||
qb.leftJoin('equipo.procesador', 'procesador');
|
||||
qb.leftJoin('equipo.sistemaOperativo', 'sistemaOperativo');
|
||||
qb.leftJoin('equipo.sistemaOperativo', 'so');
|
||||
qb.leftJoin('equipo.tipoUso', 'tipoUso');
|
||||
qb.leftJoin('equipo.estado', 'estado');
|
||||
qb.leftJoin('equipo.tipoEquipo', 'tipoEquipo');
|
||||
qb.leftJoin('equipo.marca', 'marca');
|
||||
qb.leftJoin('equipo.laboratorio', 'laboratorio');
|
||||
qb.leftJoin('equipo.proyecto', 'proyecto');
|
||||
qb.leftJoin('equipo.mov', 'mov');
|
||||
qb.leftJoin('mov.user', 'user');
|
||||
|
||||
qb.addSelect('equipo.inventario', 'inventario');
|
||||
qb.addSelect('adscripcion.adscripcion', 'adscripcion');
|
||||
qb.addSelect('equipo.lugar', 'ubicacion');
|
||||
|
||||
const tieneFiltroReal = (arr?: string[]) => arr?.length && !arr.includes("0") && !arr.includes("Todos");
|
||||
|
||||
@@ -1583,8 +1587,6 @@ export class EquipoService {
|
||||
// ADSCRIPCIONES
|
||||
if (filtros?.adscripciones?.length) {
|
||||
|
||||
qb.addSelect('adscripcion.adscripcion', 'adscripcion');
|
||||
|
||||
if (tieneFiltroReal(filtros.adscripciones)) {
|
||||
qb.andWhere('adscripcion.id_adscripcion IN (:...adscripciones)', {
|
||||
adscripciones: filtros.adscripciones
|
||||
@@ -1595,8 +1597,6 @@ export class EquipoService {
|
||||
// PROCESADOR
|
||||
if (filtros?.procesadores?.length) {
|
||||
|
||||
qb.addSelect('procesador.procesador', 'procesador');
|
||||
|
||||
if (tieneFiltroReal(filtros.procesadores)) {
|
||||
qb.andWhere('procesador.id_procesador IN (:...procesadores)', {
|
||||
procesadores: filtros.procesadores
|
||||
@@ -1607,8 +1607,6 @@ export class EquipoService {
|
||||
// SISTEMA OPERATIVO
|
||||
if (filtros?.sistemas?.length) {
|
||||
|
||||
qb.addSelect('sistemaOperativo.sistema_operativo', 'so');
|
||||
|
||||
if (tieneFiltroReal(filtros.sistemas)) {
|
||||
qb.andWhere('sistemaOperativo.id_sistema_operativo IN (:...sistemas)', {
|
||||
sistemas: filtros.sistemas
|
||||
@@ -1619,8 +1617,6 @@ export class EquipoService {
|
||||
// USO
|
||||
if (filtros?.usos?.length) {
|
||||
|
||||
qb.addSelect('tipoUso.tipo_uso', 'uso');
|
||||
|
||||
if (tieneFiltroReal(filtros.usos)) {
|
||||
qb.andWhere('tipoUso.id_uso IN (:...usos)', {
|
||||
usos: filtros.usos
|
||||
@@ -1631,8 +1627,6 @@ export class EquipoService {
|
||||
// ANTIGÜEDAD
|
||||
if (filtros?.antiguedad?.length) {
|
||||
|
||||
qb.addSelect('equipo.antiguedad', 'antiguedad');
|
||||
|
||||
if (tieneFiltroReal(filtros.antiguedad)) {
|
||||
qb.andWhere('equipo.antiguedad IN (:...antiguedad)', {
|
||||
antiguedad: filtros.antiguedad
|
||||
@@ -1641,34 +1635,34 @@ export class EquipoService {
|
||||
}
|
||||
|
||||
const data = await qb
|
||||
.orderBy(`equipo.adscripcion`, "DESC")
|
||||
.orderBy(`equipo.inventario`, 'ASC')
|
||||
.getRawMany();
|
||||
|
||||
console.log(data)
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const sheet = workbook.addWorksheet('Equipos');
|
||||
|
||||
const columns = [
|
||||
{ header: 'Inventario', key: 'inventario', width: 20 },
|
||||
{ header: 'Ubicación', key: 'ubicacion', width: 40 },
|
||||
{ header: 'Adscripción', key: 'adscripcion', width: 40 },
|
||||
{ header: 'serie', key: 'serie', width: 20 },
|
||||
{ header: 'Ubicación', key: 'lugar', width: 40 },
|
||||
{ header: 'Fecha factura', key: 'fecha_factura', width: 10 },
|
||||
{ header: 'Antigüedad', key: 'antiguedad', width: 15 },
|
||||
|
||||
{ header: 'Modelo', key: 'modelo', width: 30 },
|
||||
{ header: 'Marca', key: 'marca', width: 15 },
|
||||
{ header: 'Estado', key: 'estado', width: 15 },
|
||||
{ header: 'Adscripción', key: 'adscripcion', width: 50 },
|
||||
{ header: 'Tipo de Equipo', key: 'tipo_equipo', width: 20 },
|
||||
{ header: 'Sistema Operativo', key: 'sistema_operativo', width: 30 },
|
||||
{ header: 'Procesador', key: 'procesador', width: 45 },
|
||||
{ header: 'Tipo de Uso', key: 'tipo_uso', width: 20 },
|
||||
{ header: 'Proyecto', key: 'proyecto', width: 15 },
|
||||
{ header: 'Laboratorio', key: 'laboratorio', width: 15 },
|
||||
{ header: 'Observaciones', key: 'observaciones', width: 20 },
|
||||
{ header: 'Fecha Movimiento', key: 'fecha_movimiento', width: 10 },
|
||||
{ header: 'Usuario', key: 'nombre', width: 15 },
|
||||
];
|
||||
|
||||
if (data[0]?.procesador !== undefined) {
|
||||
columns.push({ header: 'Procesador', key: 'procesador', width: 25 });
|
||||
}
|
||||
|
||||
if (data[0]?.so !== undefined) {
|
||||
columns.push({ header: 'Sistema Operativo', key: 'so', width: 25 });
|
||||
}
|
||||
|
||||
if (data[0]?.uso !== undefined) {
|
||||
columns.push({ header: 'Uso', key: 'uso', width: 20 });
|
||||
}
|
||||
|
||||
if (data[0]?.antiguedad !== undefined) {
|
||||
columns.push({ header: 'Antigüedad', key: 'antiguedad', width: 15 });
|
||||
}
|
||||
|
||||
sheet.columns = columns;
|
||||
|
||||
data.forEach(row => {
|
||||
|
||||
Reference in New Issue
Block a user