51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
const moment = require('moment');
|
|
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 Inscripcion = require(`${dbPath}/Inscripcion`);
|
|
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 path = `server/uploads/reporte.csv`;
|
|
const data = [];
|
|
|
|
return Inscripcion.findAll({
|
|
where: {
|
|
[Op.and]: [
|
|
{ fechaInscripcion: { [Op.gte]: inicio.format() } },
|
|
{ fechaInscripcion: { [Op.lte]: fin.format() } },
|
|
],
|
|
},
|
|
include: [
|
|
{
|
|
model: Usuario,
|
|
attributes: ['numeroCuenta'],
|
|
},
|
|
],
|
|
})
|
|
.then(async (res) => {
|
|
for (let i = 0; i < res.length; i++) {
|
|
data.push({
|
|
numeroCuenta: res[i].Usuario.numeroCuenta,
|
|
idArea: res[i].idArea,
|
|
folio: res[i].folio,
|
|
monto: res[i].monto,
|
|
hizoPago: res[i].hizoPago,
|
|
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
|
validacion: res[i].validacion,
|
|
motivoDeclinacion: res[i].motivo,
|
|
});
|
|
}
|
|
await helper.eliminarArchivo(path).catch((err) => {});
|
|
return helper.crearArchivo(path, convertArrayToCSV(data));
|
|
})
|
|
.then((res) => path);
|
|
};
|
|
|
|
module.exports = reporte;
|