index.js
1.08 KB
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
38
39
40
41
42
43
44
module.exports = function(comprobante, cuerpos) {
return new Promise((resolve, reject) => {
var idTransaccion = comprobante.idTransaccion;
knex('planex_transacciones')
.where({ id: idTransaccion } )
.then(function(transax) {
transax = transax[0];
fs.readFile(config.dirDestino + '\\' + transax.archivoRecibido, 'utf8', (err, fileString) => {
if (err) {
reject(err);
return;
}
var planex = require('../planex')(fileString);
var result = require('./todos')(planex, cuerpos, fileString, idTransaccion);
var nombreRecadv = 'RECADV_' + planex.identificaxMensaje.idMensaje + '.txt';
fs.writeFile(config.dirRecadv + '/' + nombreRecadv, result, err => {
if (err) return reject(err);
knex('planex_transacciones')
.where({ id: idTransaccion })
.update({ archivoEnviado: nombreRecadv, estado: 1 })
.then(resolve)
.catch(reject);
});
});
})
.catch(reject);
});
}