Commit a37d3ffa73ec5342271060f8be9b678424012d8f
1 parent
ba68e26e44
Exists in
master
files
Showing
3 changed files
with
89 additions
and
0 deletions
Show diff stats
db/index.js
... | ... | @@ -0,0 +1,18 @@ |
1 | +module.exports = function(comprobante) { | |
2 | + | |
3 | + var promesas = []; | |
4 | + | |
5 | + promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera)); | |
6 | + | |
7 | + comprobante.cuerpo.forEach(cuerpo => { | |
8 | + promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo)); | |
9 | + }); | |
10 | + | |
11 | + Promise.all(promesas).then(function() { | |
12 | + | |
13 | + console.log('COMPROBANTE GUARDADO CON ÉXITO'); | |
14 | + }).catch(function() { | |
15 | + | |
16 | + console.log('ERROR AL GUARDAR EL COMPROBANTE'); | |
17 | + }); | |
18 | +} |
debo/relaciones.js
... | ... | @@ -0,0 +1,50 @@ |
1 | +module.exports = function(planex, wsServer) { | |
2 | + | |
3 | + return new Promise(function(resolve, reject) { | |
4 | + | |
5 | + var promesasArticulo = []; | |
6 | + | |
7 | + var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); | |
8 | + var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | |
9 | + var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; | |
10 | + | |
11 | + var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo}); | |
12 | + var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP'); | |
13 | + | |
14 | + planex.itemsFactura.forEach(item => { | |
15 | + | |
16 | + var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + | |
17 | + 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + | |
18 | + item.codigoUPCEAN13 + '\''; | |
19 | + | |
20 | + promesasArticulo.push( | |
21 | + wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString) | |
22 | + ); | |
23 | + }); | |
24 | + | |
25 | + promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]); | |
26 | + | |
27 | + Promise.all(promesas).then(function(values) { | |
28 | + | |
29 | + planex.itemsFactura.forEach((item, index) => { | |
30 | + | |
31 | + if (!values[index]) console.error('No se encontró el articulo'); | |
32 | + | |
33 | + item.CodArt = values[index].CodArt; | |
34 | + item.CodSec = values[index].CodSec; | |
35 | + item.CodRub = values[index].CodRub; | |
36 | + item.DET_LAR = values[index].DET_LAR; | |
37 | + | |
38 | + delete values[index]; | |
39 | + }); | |
40 | + | |
41 | + values = values.filter(function(p) { | |
42 | + return p; | |
43 | + }); | |
44 | + | |
45 | + resolve({planex, values}); | |
46 | + | |
47 | + }); | |
48 | + | |
49 | + }); | |
50 | +} | |
0 | 51 | \ No newline at end of file |
debo/validacion.js
... | ... | @@ -0,0 +1,21 @@ |
1 | +module.exports = function(debo, wsServer, gln) { | |
2 | + | |
3 | + return new Promise(function(resolve, reject) { | |
4 | + | |
5 | + wsServer | |
6 | + .getEntidad(gln, 'PMAEFACT_TEMP', { | |
7 | + TIP: debo.cabecera.TIP, | |
8 | + TCO: debo.cabecera.TCO, | |
9 | + SUC: debo.cabecera.SUC, | |
10 | + NCO: debo.cabecera.NCO, | |
11 | + COD: debo.cabecera.COD | |
12 | + }).then(function(values) { | |
13 | + | |
14 | + if (values) { | |
15 | + reject('Ya existe el comprobante', values); | |
16 | + } else { | |
17 | + resolve(); | |
18 | + } | |
19 | + }); | |
20 | + }); | |
21 | +} | |
0 | 22 | \ No newline at end of file |