Commit 248a10673fb25ba2209c515c36ba544d0487c14a
1 parent
4fd71551d8
Exists in
master
linea al final2
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
debo/relaciones.js
1 | module.exports = function(planex, wsServer) { | 1 | module.exports = function(planex, wsServer) { |
2 | 2 | ||
3 | return new Promise(function(resolve, reject) { | 3 | return new Promise(function(resolve, reject) { |
4 | 4 | ||
5 | var promesasArticulo = []; | 5 | var promesasArticulo = []; |
6 | 6 | ||
7 | var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); | 7 | var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); |
8 | var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | 8 | var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; |
9 | var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; | 9 | var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; |
10 | 10 | ||
11 | var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo}); | 11 | var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo}); |
12 | var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP'); | 12 | var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP'); |
13 | 13 | ||
14 | planex.itemsFactura.forEach(item => { | 14 | planex.itemsFactura.forEach(item => { |
15 | 15 | ||
16 | var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + | 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 = \'' + | 17 | 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + |
18 | item.codigoUPCEAN13 + '\''; | 18 | item.codigoUPCEAN13 + '\''; |
19 | 19 | ||
20 | promesasArticulo.push( | 20 | promesasArticulo.push( |
21 | wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString) | 21 | wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString) |
22 | ); | 22 | ); |
23 | }); | 23 | }); |
24 | 24 | ||
25 | promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]); | 25 | promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]); |
26 | 26 | ||
27 | Promise.all(promesas).then(function(values) { | 27 | Promise.all(promesas).then(function(values) { |
28 | 28 | ||
29 | planex.itemsFactura.forEach((item, index) => { | 29 | planex.itemsFactura.forEach((item, index) => { |
30 | 30 | ||
31 | if (!values[index]) return; console.error('No se encontrĂ³ el articulo'); | 31 | if (!values[index]) return; console.error('No se encontrĂ³ el articulo'); |
32 | 32 | ||
33 | item.CodArt = values[index].CodArt; | 33 | item.CodArt = values[index].CodArt; |
34 | item.CodSec = values[index].CodSec; | 34 | item.CodSec = values[index].CodSec; |
35 | item.CodRub = values[index].CodRub; | 35 | item.CodRub = values[index].CodRub; |
36 | item.DET_LAR = values[index].DET_LAR; | 36 | item.DET_LAR = values[index].DET_LAR; |
37 | 37 | ||
38 | delete values[index]; | 38 | delete values[index]; |
39 | }); | 39 | }); |
40 | 40 | ||
41 | values = values.filter(function(p) { | 41 | values = values.filter(function(p) { |
42 | return p; | 42 | return p; |
43 | }); | 43 | }); |
44 | 44 | ||
45 | resolve({planex, values}); | 45 | resolve({planex, values}); |
46 | 46 | ||
47 | }); | 47 | }); |
48 | 48 | ||
49 | }); | 49 | }); |
50 | } | ||
50 | } |