Commit 55c7bcadb161130cada4029db40f17087bbae51c
1 parent
5eda16ee29
Exists in
master
avances
Showing
6 changed files
with
51 additions
and
36 deletions
Show diff stats
debo/cabeceraDebo.js
1 | -module.exports = function(comprobante, afipTablas) { | |
1 | +module.exports = function(comprobante, afipTablas, entities) { | |
2 | 2 | |
3 | 3 | return { |
4 | 4 | TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M,E) |
5 | 5 | TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND,RE,CI,LP) |
6 | 6 | SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA |
7 | 7 | NCO: parseInt(comprobante.identificaxComprobante.numero), // [bigint] NOT NULL, NUMERO DE COMPROBANTE |
8 | - COD: null, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2' | |
8 | + COD: 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 | 9 | FEC: comprobante.identificaxComprobante.fechaComprobante, // [smalldatetime] NULL, FECHA DEL COMPROBANTE |
10 | - NOM: null, // [varchar](40) NOT NULL, NOMBRE DEL PROVEEDOR TABLA PROVEED CAMPO NOM | |
11 | - TIV: null, // [tinyint] NOT NULL, TIPO DE IVA CAMPO IVA TABLA PROVEED | |
12 | - CUI: null, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION | |
13 | - FPA: null, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED | |
10 | + NOM: entities.proveedores.NOM, // [varchar](40) NOT NULL, NOMBRE DEL PROVEEDOR TABLA PROVEED CAMPO NOM | |
11 | + TIV: entities.proveedores.IVA, // [tinyint] NOT NULL, TIPO DE IVA CAMPO IVA TABLA PROVEED | |
12 | + CUI: entities.proveedores.CUIT, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION | |
13 | + FPA: entities.proveedores.FPA, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED | |
14 | 14 | TCA: 1, // [money] NOT NULL, FIJO 1 |
15 | 15 | DTO: comprobante.descuentosGlobalesFactura.importe, // [money] NOT NULL, DESCUENTO TOTAL SUMATORIA DE LOS DTO POR ITEM |
16 | 16 | PDT: 0, // [money] NOT NULL, FIJO 0 |
... | ... | @@ -20,11 +20,11 @@ module.exports = function(comprobante, afipTablas) { |
20 | 20 | IRS: 0, // [money] NOT NULL, FIJO 0 |
21 | 21 | IMI: comprobante.importesTotales.importeImpuestosInternos, // [money] NOT NULL, SUMATORIA DE LOS IMPUESTOS INTERNOS POR ITEM |
22 | 22 | RGA: null, // [money] NOT NULL, IMPORTE RETENCION DE GANANCIAS |
23 | - RIB: null, // [money] NOT NULL, IMPORTE RETENCION DE INBRESOS BRUTOS | |
23 | + RIB: null, // [money] NOT NULL, IMPORTE RETENCION DE INGRESOS BRUTOS | |
24 | 24 | PIV: null, // [money] NOT NULL, IMPORTE PERCEPCION DE IVA |
25 | 25 | CNG: comprobante.importesTotales.totalConceptosNoNetoGravado, // [money] NULL, IMPORTE DE CONCEPTOS NO GRAVADOS |
26 | 26 | TOT: null, // [money] NOT NULL, IMPORTE TOTAL DE LA FACTURA |
27 | - ZON: null, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP | |
27 | + ZON: entities.empresa.ZON, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP | |
28 | 28 | FEV: comprobante.identificaxComprobante.fechaComprobante, // [datetime] NULL, FECHA DE VENCIMIENTO |
29 | 29 | OCP: null, // [char](10) NOT NULL, SI VIENE LA ORDEN DE COMPRA FORMATO "0000000000" (DOS PRIMERO PARA PVE Y 8 ULTIMOS EL NUMERO DE LA OC) |
30 | 30 | OPE: 0, // [int] NOT NULL, FIJO 0 |
debo/cuerpoDebo.js
1 | -module.exports = function(comprobante) { | |
1 | +module.exports = function(comprobante, afipTablas, entities) { | |
2 | 2 | |
3 | 3 | return { |
4 | - TIP: null, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M) | |
5 | - TCO: null, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND) | |
4 | + TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M) | |
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: null, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2' | |
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 | 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 | 10 | COD: null, // [int] NOT NULL, SECTOR DEBO DEL PRODUCTO |
11 | 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' |
... | ... | @@ -20,7 +20,7 @@ module.exports = function(comprobante) { |
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 |
23 | - PLA: 0, // [int] NOT NULL, FIJO 0 | |
23 | + PLA: 0, // [int] NOT NULL, FIJO 0 | |
24 | 24 | LUG: 0, // [int] NOT NULL, FIJO 0 |
25 | 25 | ESC: 0, // [bit] NOT NULL, FIJO 0 |
26 | 26 | TAN: 0, // [int] NOT NULL, FIJO 0 |
debo/index.js
1 | -module.exports = function(comprobante) { | |
1 | +module.exports = function(comprobante, entities) { | |
2 | 2 | |
3 | 3 | var afipTablas = require('../afip/index'); |
4 | 4 | |
5 | 5 | return { |
6 | - cabecera: require('./cabeceraDebo')(comprobante, afipTablas), | |
6 | + cabecera: require('./cabeceraDebo')(comprobante, afipTablas, entities), | |
7 | 7 | cuerpo: require('./cuerpoDebo')(comprobante, afipTablas) |
8 | 8 | }; |
9 | 9 | } |
index.js
... | ... | @@ -10,18 +10,25 @@ function onGetFile(event, fileString) { |
10 | 10 | |
11 | 11 | var planex = require('./planex/index')(fileString); |
12 | 12 | |
13 | - var entidades = []; | |
13 | + var entities = {}; | |
14 | 14 | |
15 | - wsServer.getEntidad('7790968003283', 'PROVEED').then(function(data) { | |
16 | - entidades.push({ entidad:'proveedores', data: data}) | |
17 | - }); | |
15 | + var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); | |
16 | + var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | |
17 | + | |
18 | + var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; | |
18 | 19 | |
19 | - console.log(entidades.length); | |
20 | + var promiseProveedores = wsServer.getEntidad('7790968003283', 'PROVEED', {CUIT: cuitToDebo}); | |
21 | + var promiseEmp = wsServer.getEntidad('7790968003283', 'APAREMP'); | |
20 | 22 | |
21 | - var debo = require('./debo/index')(planex, entidades); | |
23 | + Promise.all([promiseProveedores, promiseEmp]).then(function(data) { | |
22 | 24 | |
23 | - // console.log(debo); | |
25 | + entities.proveedores = data[0]; | |
26 | + entities.empresa = data[1]; | |
27 | + | |
28 | + var debo = require('./debo/index')(planex, entities); | |
29 | + }); | |
24 | 30 | |
31 | + console.log(planex); | |
25 | 32 | } |
26 | 33 | |
27 | 34 | console.log('listen websocket port ' + config.port); |
watch/index.js
webSocketServer/index.js
... | ... | @@ -2,6 +2,7 @@ module.exports = function() { |
2 | 2 | |
3 | 3 | const webSocketServer = require('ws').Server; |
4 | 4 | var clients = []; |
5 | +var idsSolicitud = []; | |
5 | 6 | |
6 | 7 | const objWs = {}; |
7 | 8 | |
... | ... | @@ -22,7 +23,7 @@ objWs.wsServer.on('connection', function connection(ws) { |
22 | 23 | clients.push({ws: ws, gln: message.gln}); |
23 | 24 | break; |
24 | 25 | default: |
25 | - console.log(message.action); | |
26 | + // console.log(message.action); | |
26 | 27 | } |
27 | 28 | }); |
28 | 29 | }); |
... | ... | @@ -31,25 +32,32 @@ objWs.getEntidad = function(gln, tableName, where) { |
31 | 32 | |
32 | 33 | return new Promise(function(resolve, reject) { |
33 | 34 | |
34 | - clients.forEach(client => { | |
35 | + var client = clients.filter(function(client) { | |
36 | + return client.gln == gln | |
37 | + })[0]; | |
35 | 38 | |
36 | - if (client.gln == gln) { | |
39 | + var idSolicitud = Math.round(Math.random() * 1000); | |
37 | 40 | |
38 | - var enviar = { | |
39 | - action: 'getEntity', | |
40 | - tableName: tableName, | |
41 | - where: where | |
42 | - } | |
41 | + var enviar = { | |
42 | + action: 'getEntity', | |
43 | + tableName: tableName, | |
44 | + where: where || {}, | |
45 | + idSolicitud: idSolicitud | |
46 | + } | |
47 | + | |
48 | + idsSolicitud.push(idSolicitud); | |
43 | 49 | |
44 | - client.ws.send(JSON.stringify(enviar)); | |
50 | + client.ws.send(JSON.stringify(enviar)); | |
45 | 51 | |
46 | - client.ws.on('message', function(message) { | |
52 | + client.ws.on('message', function(message) { | |
47 | 53 | |
48 | - console.log(JSON.parse(message)); | |
54 | + message = JSON.parse(message); | |
49 | 55 | |
50 | - resolve(message.data); | |
51 | - }); | |
56 | + if (idSolicitud == message.idSolicitud) { | |
57 | + | |
58 | + resolve(message.data); | |
52 | 59 | } |
60 | + | |
53 | 61 | }); |
54 | 62 | }); |
55 | 63 | } |