Commit f00ea060ad04bd61e7b16448ddf85599b5a3b0a1
1 parent
9ee548483b
Exists in
master
git push origin master
Showing
5 changed files
with
92 additions
and
27 deletions
Show diff stats
debo/cuerpoDebo.js
1 | -module.exports = function(comprobante, afipTablas, entities) { | |
1 | +module.exports = function(comprobante, afipTablas, entities, item) { | |
2 | 2 | |
3 | 3 | return { |
4 | 4 | TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M) |
5 | 5 | TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND) |
6 | 6 | SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA DE LA FACTURA |
7 | 7 | NCO: parseInt(comprobante.identificaxComprobante.numero), // [bigint] NOT NULL, NUMERO DE COMPROBANTE |
8 | - PRO: entities.proveedor.COD, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2' | |
9 | - ORD: parseInt(comprobante.itemsFactura.numeroLinea), // [int] NOT NULL, ORDEN DEL ITEM, EMPIEZA EN 1 Y SUMA DE A 1 POR CADA REGISTRO DE MOVIMIENTO | |
10 | - COD: null, // [int] NOT NULL, SECTOR DEBO DEL PRODUCTO | |
11 | - ART: null, // [int] NOT NULL, ARTICULO DEBO DEL PRODUCTO ESTOS 2 SE OBTIENEN A PARTIR DEL CODIGO DE BARRAS: SELECT CodSec AS SECTOR,CodArt AS ARTICULO FROM CODBAR WHERE CODBAR='03239210540' | |
12 | - RUB: null, // [int] NOT NULL, CODIGO DE RUBRO SE OBTIENE DE LA TABLA ARTICULOS SELECT DET_LAR,CODRUB FROM ARTICULOS WHERE CODSEC=SECTOR AND CODART=ARTICULO (DATOS OBTENIDOS EN NOTA ANTERIOR | |
13 | - TIO: null, // [varchar](60) NOT NULL DESCRIPCION DEL PRODUCTO DEL PUNTO ANTERIOR DET_LAR | |
14 | - LI0: comprobante.itemsFactura.descripcion, // [varchar](60) NOT NULL, DESCRIPCION ENVIADA POR EL PROVEEDOR | |
15 | - CAN: comprobante.itemsFactura.cantidad, // [money] NOT NULL, CANTIDAD DEL ITEM | |
16 | - PUN: comprobante.itemsFactura.precioUnitario, // [decimal](20, 8) NOT NULL PRECIO UNITARIO DEL PRODUCTO ITEM | |
17 | - IMI: comprobante.detalleImpuestosItemFactura.importeImpuesto, // [money] NOT NULL, IMPORTE IMPUESTOS INTERNOS DEL ITEM | |
18 | - IVA: comprobante.itemsFactura.importeIVA, // [money] NOT NULL, IMPORTE IVA DEL ITEM | |
19 | - PUT: comprobante.itemsFactura.precioUnitario, // [money] NOT NULL, IGUAL AL PUN | |
8 | + PRO: entities.proveedores.COD, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2' | |
9 | + ORD: parseInt(item.numeroLinea), // [int] NOT NULL, ORDEN DEL ITEM, EMPIEZA EN 1 Y SUMA DE A 1 POR CADA REGISTRO DE MOVIMIENTO | |
10 | + COD: item.CodSec, // [int] NOT NULL, SECTOR DEBO DEL PRODUCTO | |
11 | + ART: item.CodArt, // [int] NOT NULL, ARTICULO DEBO DEL PRODUCTO ESTOS 2 SE OBTIENEN A PARTIR DEL CODIGO DE BARRAS: SELECT CodSec AS SECTOR,CodArt AS ARTICULO FROM CODBAR WHERE CODBAR='03239210540' | |
12 | + RUB: item.CodRub, // [int] NOT NULL, CODIGO DE RUBRO SE OBTIENE DE LA TABLA ARTICULOS SELECT DET_LAR,CODRUB FROM ARTICULOS WHERE CODSEC=SECTOR AND CODART=ARTICULO (DATOS OBTENIDOS EN NOTA ANTERIOR | |
13 | + TIO: item.DET_LAR, // [varchar](60) NOT NULL DESCRIPCION DEL PRODUCTO DEL PUNTO ANTERIOR DET_LAR | |
14 | + LI0: item.descripcion, // [varchar](60) NOT NULL, DESCRIPCION ENVIADA POR EL PROVEEDOR | |
15 | + CAN: item.cantidad, // [money] NOT NULL, CANTIDAD DEL ITEM | |
16 | + PUN: item.precioUnitario, // [decimal](20, 8) NOT NULL PRECIO UNITARIO DEL PRODUCTO ITEM | |
17 | + IMI: item.impuestoInterno ? item.impuestoInterno.importeImpuesto : 0, // [money] NOT NULL, IMPORTE IMPUESTOS INTERNOS DEL ITEM | |
18 | + IVA: item.importeIVA, // [money] NOT NULL, IMPORTE IVA DEL ITEM | |
19 | + PUT: item.precioUnitario, // [money] NOT NULL, IGUAL AL PUN | |
20 | 20 | LEG: 0, // [int] NOT NULL, FIJO 0 |
21 | 21 | CMF: 0, // [int] NOT NULL, FIJO 0 |
22 | 22 | TUR: 0, // [int] NOT NULL, FIJO 0 |
debo/index.js
... | ... | @@ -2,8 +2,15 @@ module.exports = function(comprobante, entities) { |
2 | 2 | |
3 | 3 | var afipTablas = require('../afip/index'); |
4 | 4 | |
5 | - return { | |
5 | + var objReturn = { | |
6 | 6 | cabecera: require('./cabeceraDebo')(comprobante, afipTablas, entities), |
7 | - cuerpo: require('./cuerpoDebo')(comprobante, afipTablas) | |
8 | - }; | |
7 | + cuerpo: [] | |
8 | + } | |
9 | + | |
10 | + comprobante.itemsFactura.forEach((item, index) => { | |
11 | + | |
12 | + objReturn.cuerpo.push(require('./cuerpoDebo')(comprobante, afipTablas, entities, item)); | |
13 | + }); | |
14 | + | |
15 | + return objReturn; | |
9 | 16 | } |
index.js
... | ... | @@ -20,15 +20,36 @@ function onGetFile(event, fileString) { |
20 | 20 | var promiseProveedores = wsServer.getEntidad('7790968003283', 'PROVEED', {CUIT: cuitToDebo}); |
21 | 21 | var promiseEmp = wsServer.getEntidad('7790968003283', 'APAREMP'); |
22 | 22 | |
23 | - Promise.all([promiseProveedores, promiseEmp]).then(function(data) { | |
23 | + var promesasArticulo = []; | |
24 | 24 | |
25 | - entities.proveedores = data[0]; | |
26 | - entities.empresa = data[1]; | |
25 | + planex.itemsFactura.forEach(item => { | |
27 | 26 | |
28 | - var debo = require('./debo/index')(planex, entities); | |
27 | + var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + | |
28 | + 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + | |
29 | + item.codigoUPCEAN13 + '\''; | |
30 | + | |
31 | + promesasArticulo.push(wsServer.getEntidad('7790968003283', null, {}, queryString)); | |
29 | 32 | }); |
30 | 33 | |
31 | - console.log(planex); | |
34 | + Promise.all(promesasArticulo).then(function(values) { | |
35 | + | |
36 | + planex.itemsFactura.forEach((item, index) => { | |
37 | + item.CodArt = values[index].CodArt; | |
38 | + item.CodSec = values[index].CodSec; | |
39 | + item.CodRub = values[index].CodRub; | |
40 | + item.DET_LAR = values[index].DET_LAR; | |
41 | + }); | |
42 | + | |
43 | + Promise.all([promiseProveedores, promiseEmp]).then(function(data) { | |
44 | + | |
45 | + entities.proveedores = data[0]; | |
46 | + entities.empresa = data[1]; | |
47 | + | |
48 | + var debo = require('./debo/index')(planex, entities); | |
49 | + | |
50 | + console.log(debo); | |
51 | + }); | |
52 | + }); | |
32 | 53 | } |
33 | 54 | |
34 | 55 | console.log('listen websocket port ' + config.port); |
planex/index.js
... | ... | @@ -67,5 +67,35 @@ module.exports = function(comprobante) { |
67 | 67 | } |
68 | 68 | }); |
69 | 69 | |
70 | + objReturn.itemsFactura.array.forEach(item => { | |
71 | + | |
72 | + var detalleDescuentos = planex.detalleImpuestosItemFactura.filter(function(descuento) { | |
73 | + return descuento.numeroLinea == item.numeroLinea; | |
74 | + })[0]; | |
75 | + | |
76 | + switch (detalleDescuentos.descripcionImpuesto) { | |
77 | + case 'c05': | |
78 | + item.percepcionIVA = detalleDescuentos; | |
79 | + break; | |
80 | + case 'c06': | |
81 | + item.percepcionIIBB = detalleDescuentos; | |
82 | + break; | |
83 | + case 'c07': | |
84 | + item.impuestoInterno = detalleDescuentos; | |
85 | + break; | |
86 | + case 'c08': | |
87 | + item.impuestoAbasto = detalleDescuentos; | |
88 | + break; | |
89 | + case 'ITC': | |
90 | + item.impuestoTransferenciaCombustibles = detalleDescuentos; | |
91 | + break; | |
92 | + case 'c10': | |
93 | + item.percepcionImpuestosMunicipales = detalleDescuentos; | |
94 | + break; | |
95 | + default: | |
96 | + break; | |
97 | + } | |
98 | + }); | |
99 | + | |
70 | 100 | return objReturn; |
71 | 101 | } |
webSocketServer/index.js
... | ... | @@ -2,7 +2,6 @@ module.exports = function() { |
2 | 2 | |
3 | 3 | const webSocketServer = require('ws').Server; |
4 | 4 | var clients = []; |
5 | -var idsSolicitud = []; | |
6 | 5 | |
7 | 6 | const objWs = {}; |
8 | 7 | |
... | ... | @@ -28,7 +27,7 @@ objWs.wsServer.on('connection', function connection(ws) { |
28 | 27 | }); |
29 | 28 | }); |
30 | 29 | |
31 | -objWs.getEntidad = function(gln, tableName, where) { | |
30 | +objWs.getEntidad = function(gln, tableName, where, queryString) { | |
32 | 31 | |
33 | 32 | return new Promise(function(resolve, reject) { |
34 | 33 | |
... | ... | @@ -36,16 +35,24 @@ objWs.getEntidad = function(gln, tableName, where) { |
36 | 35 | return client.gln == gln |
37 | 36 | })[0]; |
38 | 37 | |
38 | + if (!client) { | |
39 | + reject('No se encuentra el webSocket client'); | |
40 | + } | |
41 | + | |
39 | 42 | var idSolicitud = Math.round(Math.random() * 1000); |
40 | 43 | |
41 | 44 | var enviar = { |
42 | 45 | action: 'getEntity', |
43 | - tableName: tableName, | |
44 | - where: where || {}, | |
45 | 46 | idSolicitud: idSolicitud |
46 | - } | |
47 | + }; | |
47 | 48 | |
48 | - idsSolicitud.push(idSolicitud); | |
49 | + if (queryString) { | |
50 | + | |
51 | + enviar.queryString = queryString; | |
52 | + } else { | |
53 | + enviar.tableName = tableName; | |
54 | + enviar.where = where || {}; | |
55 | + } | |
49 | 56 | |
50 | 57 | client.ws.send(JSON.stringify(enviar)); |
51 | 58 |