index.js
992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = function(comprobante, nameFile) {
var nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1];
knex('planex_transacciones')
.insert({
archivoRecibido: nameFileDest,
estado: 0, // Ingresada
GLN: comprobante.cabecera.GLN
})
.returning('id')
.then(saveDebo);
function saveDebo(id) {
comprobante.cabecera.idTransaccion = id;
var promesas = [knex('PMAEFACT_TEMP').insert(comprobante.cabecera)];
comprobante.cuerpo.forEach(cuerpo => {
promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo));
});
Promise.all(promesas).then(function() {
var pathDest = config.dirDestino + '/' + nameFileDest;
fs.rename(nameFile, pathDest, function(err) {
if(err) console.log(err);
console.log('COMPROBANTE PROCESADO Y GUARDADO EN PMAEFACT_TEMP CON ÉXITO');
});
}).catch(function(e) {
console.log(e);
console.log('ERROR AL GUARDAR EL COMPROBANTE');
});
}
}