reporte
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
|
||||
const get = async () => Carrera.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -0,0 +1,136 @@
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const { Op } = require('sequelize');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const validar = require(`${helperPath}/validar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Carrito = require(`${dbPath}/Carrito`);
|
||||
const Equipo = require(`${dbPath}/Equipo`);
|
||||
const Modulo = require(`${dbPath}/Modulo`);
|
||||
const Operador = require(`${dbPath}/Operador`);
|
||||
const Prestamo = require(`${dbPath}/Prestamo`);
|
||||
const Programa = require(`${dbPath}/Programa`);
|
||||
const TipoCarrito = require(`${dbPath}/TipoCarrito`);
|
||||
const TipoUsuario = require(`${dbPath}/TipoUsuario`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const reporte = async (body) => {
|
||||
const inicio = validar.validarFecha(body.inicio, 'fecha de inicio', false);
|
||||
const fin = validar.validarFecha(body.fin, 'fecha fin', false);
|
||||
const idCarrera = body.idCarrera
|
||||
? validar.validarNumeroEntero(body.idCarrera, 'id carrera', true)
|
||||
: '';
|
||||
const idTipoUsuario = body.idTipoUsuario
|
||||
? validar.validarNumeroEntero(body.idTipoUsuario, 'id tipo usuario', true)
|
||||
: '';
|
||||
const idTipoCarrito = body.idTipoCarrito
|
||||
? validar.validarNumeroEntero(body.idTipoCarrito, 'id tipo carrito', true)
|
||||
: '';
|
||||
const path = `server/uploads/reporte.csv`;
|
||||
const data = [];
|
||||
|
||||
return Prestamo.findAll({
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ createdAt: { [Op.gte]: inicio.format() } },
|
||||
{ createdAt: { [Op.lte]: fin.format() } },
|
||||
],
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Equipo,
|
||||
include: [
|
||||
{
|
||||
model: Carrito,
|
||||
include: [{ model: TipoCarrito }, { model: Modulo }],
|
||||
},
|
||||
{ model: Programa },
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Usuario,
|
||||
include: [{ model: Carrera }, { model: TipoUsuario }],
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorEntrega',
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorRegreso',
|
||||
},
|
||||
{
|
||||
model: Operador,
|
||||
as: 'OperadorCancelacion',
|
||||
},
|
||||
],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let agregar = false;
|
||||
|
||||
if (idTipoCarrito) {
|
||||
if (idTipoCarrito === res[i].Equipo.Carrito.idTipoCarrito) {
|
||||
if (idTipoUsuario) {
|
||||
if (idTipoUsuario === res[i].Usuario.idTipoUsuario) {
|
||||
if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idTipoUsuario) {
|
||||
if (idTipoUsuario === res[i].Usuario.idTipoUsuario) {
|
||||
if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
}
|
||||
} else if (idCarrera) {
|
||||
if (idCarrera === res[i].Usuario.idCarrera) agregar = true;
|
||||
} else agregar = true;
|
||||
if (agregar)
|
||||
data.push({
|
||||
idPrestamo: res[i].idPrestamo,
|
||||
activo: res[i].activo,
|
||||
horaMaxRecoger: helper.crearDDMMAAAAHHMM(res[i].horaMaxRecoger),
|
||||
horaInicio: helper.crearDDMMAAAAHHMM(res[i].horaInicio),
|
||||
horaFin: helper.crearDDMMAAAAHHMM(res[i].horaFin),
|
||||
horaEntrega: helper.crearDDMMAAAAHHMM(res[i].horaEntrega),
|
||||
canceladoUsuario: res[i].canceladoUsuario,
|
||||
createdAt: helper.crearDDMMAAAAHHMM(res[i].createdAt),
|
||||
numeroInventario: res[i].Equipo.numeroInventario,
|
||||
numeroSerie: res[i].Equipo.numeroSerie,
|
||||
sobrenombre: res[i].Equipo.sobrenombre,
|
||||
programa: res[i].Equipo.Programa
|
||||
? res[i].Equipo.Programa.programa
|
||||
: null,
|
||||
carrito: res[i].Equipo.Carrito.carrito,
|
||||
modulo: res[i].Equipo.Carrito.Modulo.modulo,
|
||||
tipoCarrito: res[i].Equipo.Carrito.TipoCarrito.tipoCarrito,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
usuario: res[i].Usuario.usuario,
|
||||
tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario,
|
||||
carrera: res[i].Usuario.Carrera.carrera,
|
||||
operadorEntrega: res[i].OperadorEntrega
|
||||
? res[i].OperadorEntrega.operador
|
||||
: null,
|
||||
operadorRegreso: res[i].OperadorRegreso
|
||||
? res[i].OperadorRegreso.operador
|
||||
: null,
|
||||
operadorCancelacion: res[i].OperadorCancelacion
|
||||
? res[i].OperadorCancelacion.operador
|
||||
: null,
|
||||
});
|
||||
}
|
||||
await helper.eliminarArchivo(path).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then((res) => path);
|
||||
};
|
||||
|
||||
module.exports = reporte;
|
||||
@@ -0,0 +1,7 @@
|
||||
const { Op } = require('sequelize');
|
||||
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||
|
||||
const get = async () =>
|
||||
TipoUsuario.findAll({ where: { idTipoUsuario: { [Op.gt]: 2 } } });
|
||||
|
||||
module.exports = get;
|
||||
Reference in New Issue
Block a user