Commit cb380bbbed94d2e49a34014916d873942fe578ce
1 parent
a37d3ffa73
Exists in
master
arreglos fechas pmaefact
Showing
8 changed files
with
93 additions
and
61 deletions
Show diff stats
debo/cabeceraDebo.js
... | ... | @@ -87,5 +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 | 91 | }; |
91 | 92 | } |
debo/cuerpoDebo.js
... | ... | @@ -37,5 +37,7 @@ module.exports = function(comprobante, afipTablas, entities, item) { |
37 | 37 | COSTO_PMOV: comprobante.itemsFactura.precioUnitario, // [money] NOT NULL, IGUAL AL PUN |
38 | 38 | SAL_ITEM: 0, // [money] NOT NULL, fijo 0 es el que se llenara al mostrar en la tablet o telefono para que llene operador |
39 | 39 | TASIVA: comprobante.itemsFactura.alicuotaIVAAplicable, // [money] NOT NULL, TASA DE IVA DEL ITEM = 21.00 / 10.50 / ETC. |
40 | + gln: comprobante.identificaxSucursalReceptorFactura.glnSucursal, //gln sucursal | |
41 | + codigoBarras: item.codigoUPCEAN13 | |
40 | 42 | }; |
41 | 43 | } |
debo/index.js
... | ... | @@ -7,7 +7,7 @@ module.exports = function(comprobante, entities) { |
7 | 7 | cuerpo: [] |
8 | 8 | } |
9 | 9 | |
10 | - comprobante.itemsFactura.forEach((item, index) => { | |
10 | + comprobante.itemsFactura.forEach((item) => { | |
11 | 11 | |
12 | 12 | objReturn.cuerpo.push(require('./cuerpoDebo')(comprobante, afipTablas, entities, item)); |
13 | 13 | }); |
debo/relaciones.js
... | ... | @@ -28,7 +28,7 @@ module.exports = function(planex, wsServer) { |
28 | 28 | |
29 | 29 | planex.itemsFactura.forEach((item, index) => { |
30 | 30 | |
31 | - if (!values[index]) console.error('No se encontrĂ³ el articulo'); | |
31 | + if (!values[index]) return; console.error('No se encontrĂ³ el articulo'); | |
32 | 32 | |
33 | 33 | item.CodArt = values[index].CodArt; |
34 | 34 | item.CodSec = values[index].CodSec; |
debo/validacion.js
index.js
1 | 1 | config = require('./config/config.json'); |
2 | -module.exports = knex = require('knex')(config.db) | |
2 | + | |
3 | +module.exports = | |
4 | + knex = require('knex')(config.db), | |
5 | + express = require('express'); | |
6 | + app = express(); | |
7 | + wsServer = require('./webSocketServer/index')(); | |
8 | + moment = require('moment'); | |
9 | + | |
10 | +app.listen(config.portWebService); | |
11 | +app.use(express.json({ limit: '50mb' })); | |
3 | 12 | |
4 | 13 | require('./watch/index')(config.dir, onGetFile); |
5 | 14 | |
6 | -const wsServer = require('./webSocketServer/index')(); | |
7 | -var planexArr = [] | |
15 | +app.use(function(req, res, next) { | |
16 | + res.setHeader('Access-Control-Allow-Origin', '*'); | |
17 | + res.setHeader( | |
18 | + 'Access-Control-Allow-Headers', | |
19 | + 'Origin, X-Requested-With, Content-Type, Accept, X-Terminal-Key, X-Nombre-Usuario, X-Punto-Venta' | |
20 | + ); | |
21 | + res.setHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, OPTIONS'); | |
22 | + next(); | |
23 | +}); | |
24 | + | |
25 | +app.use('/gateway-debo', require('./rutas/comprobantes')); | |
26 | +app.use('/gateway-debo', require('./rutas/login')); | |
27 | + | |
28 | +var planexArr = []; | |
8 | 29 | |
9 | 30 | function onGetFile(fileString) { |
10 | 31 | |
... | ... | @@ -17,9 +38,7 @@ function onGetFile(fileString) { |
17 | 38 | // Traigo proveedor, empresa |
18 | 39 | require('./debo/relaciones')(planex, wsServer).then(function(result) { |
19 | 40 | |
20 | - var planex = planexArr.filter(function(p) { | |
21 | - return p.identificaxMensaje.idMensaje == result.planex.identificaxMensaje.idMensaje | |
22 | - })[0]; | |
41 | + var planex = result.planex; | |
23 | 42 | |
24 | 43 | var entities = {}; |
25 | 44 | |
... | ... | @@ -28,7 +47,7 @@ function onGetFile(fileString) { |
28 | 47 | |
29 | 48 | var debo = require('./debo/index')(planex, entities); |
30 | 49 | |
31 | - require('./debo/validacion')(debo, wsServer, planex.identificaxReceptorFactura.glnReceptor).then(function() { | |
50 | + require('./debo/validacion')(debo, wsServer, planex.identificaxSucursalReceptorFactura.glnSucursal).then(function() { | |
32 | 51 | |
33 | 52 | require('./db/index')(debo); |
34 | 53 | }).catch(function(err) { |
... | ... | @@ -36,9 +55,9 @@ function onGetFile(fileString) { |
36 | 55 | console.log(err); |
37 | 56 | }); |
38 | 57 | |
39 | - | |
40 | 58 | }); |
41 | 59 | } |
42 | 60 | |
43 | 61 | console.log('listen websocket port ' + config.port); |
62 | +console.log('listen webservice port ' + config.portWebService); | |
44 | 63 | console.log('Ejecutar programa como administrador...'); |
package.json
... | ... | @@ -4,15 +4,19 @@ |
4 | 4 | "description": "WebSocket Head Office", |
5 | 5 | "main": "index.js", |
6 | 6 | "dependencies": { |
7 | - "chokidar": "^3.0.0", | |
8 | - "express": "^4.16.4", | |
7 | + "chokidar": "^3.0.1", | |
8 | + "express": "^4.17.1", | |
9 | 9 | "knex": "^0.16.5", |
10 | + "moment": "^2.24.0", | |
10 | 11 | "mssql": "^5.1.0", |
11 | 12 | "ws": "^7.0.0" |
12 | 13 | }, |
13 | - "devDependencies": {}, | |
14 | + "devDependencies": { | |
15 | + "nodemon": "^1.19.1" | |
16 | + }, | |
14 | 17 | "scripts": { |
15 | - "test": "echo \"Error: no test specified\" && exit 1" | |
18 | + "test": "echo \"Error: no test specified\" && exit 1", | |
19 | + "dev": "nodemon index.js" | |
16 | 20 | }, |
17 | 21 | "author": "Foca Software", |
18 | 22 | "license": "ISC" |
webSocketServer/index.js
1 | 1 | module.exports = function() { |
2 | 2 | |
3 | -const webSocketServer = require('ws').Server; | |
4 | -var clients = []; | |
3 | + const webSocketServer = require('ws').Server; | |
4 | + var clients = []; | |
5 | 5 | |
6 | -const objWs = {}; | |
6 | + const objWs = {}; | |
7 | 7 | |
8 | -objWs.wsServer = new webSocketServer({ | |
9 | - port: config.port | |
10 | -}); | |
8 | + objWs.wsServer = new webSocketServer({ | |
9 | + port: config.port | |
10 | + }); | |
11 | 11 | |
12 | -objWs.wsServer.on('connection', function connection(ws) { | |
12 | + objWs.wsServer.on('connection', function connection(ws) { | |
13 | 13 | |
14 | - console.log('open socket server'); | |
14 | + console.log('open socket server'); | |
15 | 15 | |
16 | - ws.on('message', function incoming(message) { | |
16 | + ws.on('message', function incoming(message) { | |
17 | 17 | |
18 | - message = JSON.parse(message.toString('utf8')); | |
18 | + message = JSON.parse(message.toString('utf8')); | |
19 | 19 | |
20 | - switch (message.action) { | |
21 | - case 'gln': | |
22 | - clients.push({ws: ws, gln: message.gln}); | |
23 | - break; | |
24 | - default: | |
25 | - // console.log(message.action); | |
26 | - } | |
20 | + switch (message.action) { | |
21 | + case 'gln': | |
22 | + clients.push({ws: ws, gln: message.gln}); | |
23 | + break; | |
24 | + default: | |
25 | + // console.log(message.action); | |
26 | + } | |
27 | + }); | |
27 | 28 | }); |
28 | -}); | |
29 | 29 | |
30 | -objWs.getEntidad = function(gln, tableName, where, queryString) { | |
30 | + objWs.getEntidad = function(gln, tableName, where, queryString) { | |
31 | 31 | |
32 | - return new Promise(function(resolve, reject) { | |
32 | + return new Promise(function(resolve, reject) { | |
33 | 33 | |
34 | - var client = clients.filter(function(client) { | |
35 | - return client.gln == gln | |
36 | - })[0]; | |
34 | + var client = clients.filter(function(client) { | |
35 | + return client.gln == gln | |
36 | + })[0]; | |
37 | + | |
38 | + if (!client) { | |
39 | + reject('No se encuentra el webSocket client'); | |
40 | + } | |
37 | 41 | |
38 | - if (!client) { | |
39 | - reject('No se encuentra el webSocket client'); | |
40 | - } | |
42 | + var idSolicitud = Math.round(Math.random() * 1000); | |
41 | 43 | |
42 | - var idSolicitud = Math.round(Math.random() * 1000); | |
44 | + var enviar = { | |
45 | + action: 'getEntity', | |
46 | + idSolicitud: idSolicitud | |
47 | + }; | |
43 | 48 | |
44 | - var enviar = { | |
45 | - action: 'getEntity', | |
46 | - idSolicitud: idSolicitud | |
47 | - }; | |
49 | + if (queryString) { | |
48 | 50 | |
49 | - if (queryString) { | |
51 | + enviar.queryString = queryString; | |
52 | + } else { | |
53 | + enviar.tableName = tableName; | |
54 | + enviar.where = where || {}; | |
55 | + } | |
50 | 56 | |
51 | - enviar.queryString = queryString; | |
52 | - } else { | |
53 | - enviar.tableName = tableName; | |
54 | - enviar.where = where || {}; | |
55 | - } | |
57 | + client.ws.send(JSON.stringify(enviar)); | |
56 | 58 | |
57 | - client.ws.send(JSON.stringify(enviar)); | |
59 | + client.ws.on('message', function(message) { | |
58 | 60 | |
59 | - client.ws.on('message', function(message) { | |
61 | + message = JSON.parse(message); | |
60 | 62 | |
61 | - message = JSON.parse(message); | |
63 | + if (idSolicitud == message.idSolicitud) { | |
62 | 64 | |
63 | - if (idSolicitud == message.idSolicitud) { | |
65 | + resolve(message.data); | |
66 | + } | |
64 | 67 | |
65 | - resolve(message.data); | |
66 | - } | |
68 | + }); | |
69 | + }); | |
70 | + } | |
67 | 71 | |
72 | + objWs.getClientGln = function(gln) { | |
73 | + return clients.filter(function(client) { | |
74 | + return client.gln = gln; | |
68 | 75 | }); |
69 | - }); | |
70 | -} | |
76 | + } | |
71 | 77 | |
72 | -return objWs; | |
78 | + return objWs; | |
73 | 79 | } |