CSV para llenar la base del at

This commit is contained in:
Andres2908
2022-02-17 00:17:21 -06:00
parent f1059aa78e
commit 30700e4e76
2 changed files with 32 additions and 19 deletions
+28 -15
View File
@@ -1,11 +1,12 @@
const moment = require('moment');
const { convertArrayToCSV } = require('convert-array-to-csv');
const { Op } = require('sequelize');
const { Op, where } = 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);
@@ -20,23 +21,35 @@ const reporte = async (body) => {
{ fechaInscripcion: { [Op.lte]: fin.format() } },
],
},
include: [
{
model: Usuario,
attributes: ['numeroCuenta'],
},
],
})
.then(async (res) => {
console.log(res);
for (let i = 0; i < res.length; i++) {
console.log(res[i].idInscripcion);
data.push({
idInscripcion: res[i].idInscripcion,
validacion: res[i].validacion,
confirmacion: res[i].confirmacion,
folio: res[i].folio,
monto: res[i].monto,
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
idArea: res[i].idArea,
});
if (body.tipo) {
for (let i = 0; i < res.length; i++) {
data.push({
numeroCuenta: res[i].Usuario.numeroCuenta,
idArea: res[i].idArea,
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
});
}
} else {
for (let i = 0; i < res.length; i++) {
data.push({
numeroCuenta: res[i].Usuario.numeroCuenta,
validacion: res[i].validacion,
confirmacion: res[i].confirmacion,
folio: res[i].folio,
monto: res[i].monto,
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
idArea: res[i].idArea,
});
}
}
console.log(data);
await helper.eliminarArchivo(path).catch((err) => {});
return helper.crearArchivo(path, convertArrayToCSV(data));
})
+4 -4
View File
@@ -1,4 +1,4 @@
idInscripcion,validacion,confirmacion,folio,monto,fechaInscripcion,idArea
1,1,false,8520,65,Wed Feb 16 2022 10:37:15 GMT-0600 (hora estándar central),1
2,2,false,9630,65,Wed Feb 16 2022 10:48:43 GMT-0600 (hora estándar central),3
3,2,false,8563,7,Wed Feb 16 2022 17:30:47 GMT-0600 (hora estándar central),1
numeroCuenta,idArea,fechaInscripcion
419085500,1,02/16/2022
419085500,3,02/16/2022
316304326,1,02/16/2022
1 idInscripcion numeroCuenta validacion idArea confirmacion fechaInscripcion folio monto
2 1 419085500 1 1 false Wed Feb 16 2022 10:37:15 GMT-0600 (hora estándar central) 02/16/2022 8520 65
3 2 419085500 2 3 false Wed Feb 16 2022 10:48:43 GMT-0600 (hora estándar central) 02/16/2022 9630 65
4 3 316304326 2 1 false Wed Feb 16 2022 17:30:47 GMT-0600 (hora estándar central) 02/16/2022 8563 7