Files
inscripciones_api/server/controller/Admin/reporte.js
T

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-02-05 00:28:53 -06:00
const moment = require('moment');
const { convertArrayToCSV } = require('convert-array-to-csv');
2022-02-28 23:32:02 -06:00
const { Op } = require('sequelize');
2022-02-05 00:28:53 -06:00
const helperPath = '../../helper';
const helper = require(`${helperPath}/helper`);
const validar = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
2022-02-17 00:17:21 -06:00
const Usuario = require(`${dbPath}/Usuario`);
2022-02-05 00:28:53 -06:00
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() } },
],
},
2022-02-17 00:17:21 -06:00
include: [
{
model: Usuario,
attributes: ['numeroCuenta'],
},
],
2022-02-05 00:28:53 -06:00
})
.then(async (res) => {
2022-03-21 14:03:30 -06:00
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,
2022-03-21 15:17:20 -06:00
motivoDeclinacion: res[i].motivo,
2022-03-21 14:03:30 -06:00
});
2022-02-05 00:28:53 -06:00
}
await helper.eliminarArchivo(path).catch((err) => {});
return helper.crearArchivo(path, convertArrayToCSV(data));
})
.then((res) => path);
};
module.exports = reporte;