Commit 6710c93dc042eba6c6b4ab39511d83a737fbc66b
1 parent
1798fe5137
Exists in
master
RECADV
Showing
15 changed files
with
267 additions
and
23 deletions
Show diff stats
db/index.js
1 | 1 | module.exports = function(comprobante, nameFile) { |
2 | 2 | |
3 | - var promesas = []; | |
4 | - | |
5 | - promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera)); | |
3 | + var nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1]; | |
4 | + | |
5 | + knex('planex_transacciones') | |
6 | + .insert({ | |
7 | + archivoRecibido: nameFileDest, | |
8 | + estado: 0, // Ingresada | |
9 | + GLN: comprobante.cabecera.GLN | |
10 | + }) | |
11 | + .returning('id') | |
12 | + .then(saveDebo); | |
13 | + | |
14 | + function saveDebo(id) { | |
15 | + comprobante.cabecera.idTransaccion = id; | |
16 | + var promesas = [knex('PMAEFACT_TEMP').insert(comprobante.cabecera)]; | |
17 | + | |
18 | + comprobante.cuerpo.forEach(cuerpo => { | |
19 | + promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo)); | |
20 | + }); | |
6 | 21 | |
7 | - comprobante.cuerpo.forEach(cuerpo => { | |
8 | - promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo)); | |
9 | - }); | |
22 | + Promise.all(promesas).then(function() { | |
10 | 23 | |
11 | - Promise.all(promesas).then(function() { | |
24 | + var pathDest = config.dirDestino + '/' + nameFileDest; | |
12 | 25 | |
13 | - nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1]; | |
14 | - var pathDest = config.dirDestino + '/' + nameFileDest; | |
26 | + fs.rename(nameFile, pathDest, function(err) { | |
15 | 27 | |
16 | - fs.rename(nameFile, pathDest, function(err) { | |
28 | + if(err) console.log(err); | |
29 | + console.log('COMPROBANTE GUARDADO CON ÉXITO'); | |
30 | + }); | |
31 | + }).catch(function() { | |
17 | 32 | |
18 | - if(err) console.log(err); | |
19 | - console.log('COMPROBANTE GUARDADO CON ÉXITO'); | |
33 | + console.log('ERROR AL GUARDAR EL COMPROBANTE'); | |
20 | 34 | }); |
21 | - }).catch(function() { | |
22 | - | |
23 | - console.log('ERROR AL GUARDAR EL COMPROBANTE'); | |
24 | - }); | |
35 | + } | |
25 | 36 | } |
debo/cabeceraDebo.js
... | ... | @@ -87,6 +87,6 @@ module.exports = function(comprobante, afipTablas, entities) { |
87 | 87 | CABA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION CABA |
88 | 88 | PERMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE PERCEPCIONES MUNICIPALES |
89 | 89 | IMI2: 0, // [money] NOT NULL, FIJO 0 |
90 | - gln: comprobante.identificaxSucursalReceptorFactura.glnSucursal | |
90 | + GLN: comprobante.identificaxSucursalReceptorFactura.glnSucursal | |
91 | 91 | }; |
92 | 92 | } |
knexfile.js
... | ... | @@ -0,0 +1,47 @@ |
1 | +// Update with your config settings. | |
2 | + | |
3 | +module.exports = { | |
4 | + | |
5 | + development: { | |
6 | + client: 'mssql', | |
7 | + connection: { | |
8 | + host: '10.231.45.211', | |
9 | + user: 'sa', | |
10 | + password: 'xxzza', | |
11 | + database: 'UNITYOIL_28082017' | |
12 | + } | |
13 | + }, | |
14 | + | |
15 | + staging: { | |
16 | + client: 'postgresql', | |
17 | + connection: { | |
18 | + database: 'my_db', | |
19 | + user: 'username', | |
20 | + password: 'password' | |
21 | + }, | |
22 | + pool: { | |
23 | + min: 2, | |
24 | + max: 10 | |
25 | + }, | |
26 | + migrations: { | |
27 | + tableName: 'knex_migrations' | |
28 | + } | |
29 | + }, | |
30 | + | |
31 | + production: { | |
32 | + client: 'postgresql', | |
33 | + connection: { | |
34 | + database: 'my_db', | |
35 | + user: 'username', | |
36 | + password: 'password' | |
37 | + }, | |
38 | + pool: { | |
39 | + min: 2, | |
40 | + max: 10 | |
41 | + }, | |
42 | + migrations: { | |
43 | + tableName: 'knex_migrations' | |
44 | + } | |
45 | + } | |
46 | + | |
47 | +}; |
migrations/20190626112130_v0.0.1.js
... | ... | @@ -0,0 +1,37 @@ |
1 | + | |
2 | +exports.up = function(knex, Promise) { | |
3 | + return Promise.all([ | |
4 | + knex.schema | |
5 | + .createTable('planex_transacciones', function(table) { | |
6 | + | |
7 | + table.increments(); | |
8 | + table.string('archivoRecibido', 1024); | |
9 | + table.string('archivoEnviado', 1024); | |
10 | + // 0: insertado, 1 enviado | |
11 | + table.integer('estado'); | |
12 | + table.string('apies'); | |
13 | + table.string('GLN'); | |
14 | + }) | |
15 | + .table('PMAEFACT_TEMP', function(table) { | |
16 | + | |
17 | + table.string('GLN'); | |
18 | + table.bigInteger('idTransaccion'); | |
19 | + }) | |
20 | + .table('PMOVFACT_TEMP', function(table) { | |
21 | + | |
22 | + table.string('GLN'); | |
23 | + table.bigInteger('codigoBarras'); | |
24 | + }) | |
25 | + ]); | |
26 | +}; | |
27 | + | |
28 | +exports.down = function(knex, Promise) { | |
29 | + return Promise.all([ | |
30 | + knex.schema | |
31 | + .dropTable('planex_transacciones') | |
32 | + .table('PMAEFACT_TEMP', function(table) { | |
33 | + | |
34 | + table.dropColumns('GLN', 'idTransaccion'); | |
35 | + }) | |
36 | + ]); | |
37 | +}; |
package.json
recadv/datosArticulos.js
... | ... | @@ -0,0 +1,10 @@ |
1 | +module.exports = function(cuerpo, index, parseToFijo) { | |
2 | + | |
3 | + return '110;' + | |
4 | + index + ';' + | |
5 | + cuerpo.codigoBarras + ';' + | |
6 | + cuerpo.COD + '-' + cuerpo.ART + ';;' + | |
7 | + cuerpo.TIO + ';' + | |
8 | + parseToFijo(cuerpo.PUN, 4, 15) + ';' + | |
9 | + moment().format('YYYYMMDD') + ';;'; | |
10 | +} |
recadv/datosCabecera.js
recadv/datosCantidadArticulos.js
... | ... | @@ -0,0 +1,11 @@ |
1 | +module.exports = function(cuerpo, index) { | |
2 | + | |
3 | + cuerpo.estado == 'rechazado' ? cuerpo.CAN = 0 : false; | |
4 | + | |
5 | + var cantidadRecibida = cuerpo.recibido ? cuerpo.recibido : cuerpo.CAN; | |
6 | + | |
7 | + return '111;' + | |
8 | + index + ';' + | |
9 | + 45 + ';' + | |
10 | + cantidadRecibida + ';'; | |
11 | +} |
recadv/datosComprador.js
recadv/datosIndentificacionMensaje.js
recadv/datosProveedor.js
recadv/index.js
... | ... | @@ -0,0 +1,41 @@ |
1 | +module.exports = function(comprobante, cuerpos) { | |
2 | + | |
3 | + var idTransaccion = comprobante.idTransaccion; | |
4 | + | |
5 | + knex('planex_transacciones') | |
6 | + .where({ id: idTransaccion } ) | |
7 | + .then(function(transax) { | |
8 | + | |
9 | + transax = transax[0]; | |
10 | + | |
11 | + fs.readFile(config.dirDestino + '\\' + transax.archivoRecibido, 'utf8', function(err, fileString) { | |
12 | + | |
13 | + if (err) { | |
14 | + console.log(err); | |
15 | + return; | |
16 | + } | |
17 | + | |
18 | + var planex = require('../planex')(fileString); | |
19 | + | |
20 | + var result = require('./todos')(planex, cuerpos, fileString, idTransaccion); | |
21 | + | |
22 | + var nombreRecadv = 'RECADV_' + planex.identificaxMensaje.idMensaje + '.txt'; | |
23 | + | |
24 | + fs.writeFile(config.dirRecadv + '/' + nombreRecadv, result, function(err) { | |
25 | + | |
26 | + if (err) return console.log(err); | |
27 | + | |
28 | + knex('planex_transacciones') | |
29 | + .where({ id: idTransaccion }) | |
30 | + .update({ archivoEnviado: nombreRecadv, estado: 1 }) | |
31 | + .then(function() { | |
32 | + | |
33 | + console.log('Archivo Pruebas guardado'); | |
34 | + }); | |
35 | + | |
36 | + }); | |
37 | + | |
38 | + }); | |
39 | + | |
40 | + }); | |
41 | +} |
recadv/todos.js
... | ... | @@ -0,0 +1,52 @@ |
1 | +module.exports = function(planex, cuerpos, fileString, idTransaccion) { | |
2 | + | |
3 | + var result = require('./datosIndentificacionMensaje')(planex) + '\r\n'; | |
4 | + | |
5 | + result += require('./datosCabecera')(planex, idTransaccion) + '\r\n'; | |
6 | + | |
7 | + fileString = fileString.split(/\r?\n/); | |
8 | + | |
9 | + fileString.forEach(bloque => { | |
10 | + | |
11 | + if (bloque.slice(0, 3) == '020') { | |
12 | + result += bloque + '\r\n'; | |
13 | + } | |
14 | + | |
15 | + }); | |
16 | + | |
17 | + result += require('./datosComprador')(planex); | |
18 | + result += require('./datosProveedor')(planex); | |
19 | + | |
20 | + cuerpos.forEach((cuerpo, index) => { | |
21 | + result += require('./datosArticulos')(cuerpo, index, decimalToFijo) + '\r\n'; | |
22 | + }); | |
23 | + | |
24 | + cuerpos.forEach((cuerpo, index) => { | |
25 | + result += require('./datosCantidadArticulos')(cuerpo, index) + '\r\n'; | |
26 | + }); | |
27 | + | |
28 | + result += require('./totalControl')(cuerpos.length); | |
29 | + | |
30 | + return result; | |
31 | +}; | |
32 | + | |
33 | +function decimalToFijo(decimal, cantidadDecimales, fijo) { | |
34 | + | |
35 | + decimal = decimal.toString().split('.'); | |
36 | + | |
37 | + decimal[1] = rellenar(decimal[1] || '0', cantidadDecimales, false); | |
38 | + | |
39 | + decimal = rellenar(decimal[0] + decimal[1], fijo, true); | |
40 | + | |
41 | + function rellenar(aRellenar, cantidad, left) { | |
42 | + | |
43 | + for (let i = 0; i <= cantidad - aRellenar.length; i++) { | |
44 | + left ? aRellenar = '0' + aRellenar : aRellenar = aRellenar + '0'; | |
45 | + } | |
46 | + | |
47 | + return aRellenar; | |
48 | + } | |
49 | + | |
50 | + return decimal; | |
51 | +} | |
52 | + |
recadv/totalControl.js
rutas/comprobantes.js
... | ... | @@ -5,7 +5,7 @@ router.get('/comprobantes/:gln*?', function(req, res) { |
5 | 5 | var cabecera = knex('PMAEFACT_TEMP') |
6 | 6 | .where(function(qb) { |
7 | 7 | if (req.params.gln) { |
8 | - qb.where({gln: req.params.gln}); | |
8 | + qb.where({GLN: req.params.gln}); | |
9 | 9 | } |
10 | 10 | }) |
11 | 11 | .select('*'); |
... | ... | @@ -13,7 +13,7 @@ router.get('/comprobantes/:gln*?', function(req, res) { |
13 | 13 | var cuerpo = knex('PMOVFACT_TEMP') |
14 | 14 | .where(function(qb) { |
15 | 15 | if (req.params.gln) { |
16 | - qb.where({gln: req.params.gln}); | |
16 | + qb.where({GLN: req.params.gln}); | |
17 | 17 | } |
18 | 18 | }) |
19 | 19 | .select('*'); |
... | ... | @@ -40,10 +40,16 @@ router.get('/comprobantes/:gln*?', function(req, res) { |
40 | 40 | }); |
41 | 41 | }); |
42 | 42 | |
43 | -router.post('/comprobante', function(req, res) { | |
43 | +router.post('/comprobante', function(req, res) { | |
44 | 44 | |
45 | 45 | console.log(req.body); |
46 | - delete req.body.cabecera.gln; | |
46 | + | |
47 | + require('../recadv')( | |
48 | + JSON.parse(JSON.stringify(req.body.cabecera)), | |
49 | + JSON.parse(JSON.stringify(req.body.cuerpo))); | |
50 | + | |
51 | + delete req.body.cabecera.idTransaccion; | |
52 | + delete req.body.cabecera.GLN; | |
47 | 53 | delete req.body.cabecera.C_HD2; |
48 | 54 | delete req.body.cabecera.E_HD2; |
49 | 55 | |
... | ... | @@ -124,7 +130,7 @@ router.post('/comprobante', function(req, res) { |
124 | 130 | |
125 | 131 | cuerpo.estado == 'rechazado' ? cuerpo.CAN = 0 : false; |
126 | 132 | |
127 | - delete cuerpo.gln; | |
133 | + delete cuerpo.GLN; | |
128 | 134 | delete cuerpo.C_HD2; |
129 | 135 | delete cuerpo.E_HD2; |
130 | 136 | delete cuerpo.codigoBarras; |