Commit ba68e26e4497367a2ececbbf21493af42804cf20
1 parent
f1a1cc9598
Exists in
master
get entities and arts
Showing
3 changed files
with
25 additions
and
39 deletions
Show diff stats
index.js
| 1 | config = require('./config/config.json'); | 1 | config = require('./config/config.json'); |
| 2 | module.exports = knex = require('knex')(config.db) | 2 | module.exports = knex = require('knex')(config.db) |
| 3 | 3 | ||
| 4 | require('./watch/index')(config.dir, onGetFile); | 4 | require('./watch/index')(config.dir, onGetFile); |
| 5 | 5 | ||
| 6 | const wsServer = require('./webSocketServer/index')(); | 6 | const wsServer = require('./webSocketServer/index')(); |
| 7 | var planexArr = [] | ||
| 7 | 8 | ||
| 8 | function onGetFile(event, fileString) { | 9 | function onGetFile(fileString) { |
| 9 | 10 | ||
| 10 | if (!fileString) return; | 11 | if (!fileString) return; |
| 11 | 12 | ||
| 12 | var planex = require('./planex/index')(fileString); | 13 | var planex = require('./planex/index')(fileString); |
| 13 | 14 | ||
| 14 | console.log(planex); | 15 | planexArr.push(planex); |
| 15 | 16 | ||
| 16 | var entities = {}; | 17 | // Traigo proveedor, empresa |
| 18 | require('./debo/relaciones')(planex, wsServer).then(function(result) { | ||
| 17 | 19 | ||
| 18 | var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); | 20 | var planex = planexArr.filter(function(p) { |
| 19 | var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | 21 | return p.identificaxMensaje.idMensaje == result.planex.identificaxMensaje.idMensaje |
| 22 | })[0]; | ||
| 20 | 23 | ||
| 21 | var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; | 24 | var entities = {}; |
| 22 | 25 | ||
| 23 | var promiseProveedores = wsServer.getEntidad('7790968003283', 'PROVEED', {CUIT: cuitToDebo}); | 26 | entities.proveedores = result.values[0]; |
| 24 | var promiseEmp = wsServer.getEntidad('7790968003283', 'APAREMP'); | 27 | entities.empresa = result.values[1]; |
| 25 | 28 | ||
| 26 | var promesasArticulo = []; | 29 | var debo = require('./debo/index')(planex, entities); |
| 27 | 30 | ||
| 28 | planex.itemsFactura.forEach(item => { | 31 | require('./debo/validacion')(debo, wsServer, planex.identificaxReceptorFactura.glnReceptor).then(function() { |
| 29 | 32 | ||
| 30 | var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + | 33 | require('./db/index')(debo); |
| 31 | 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + | 34 | }).catch(function(err) { |
| 32 | item.codigoUPCEAN13 + '\''; | ||
| 33 | |||
| 34 | promesasArticulo.push(wsServer.getEntidad('7790968003283', null, {}, queryString)); | ||
| 35 | }); | ||
| 36 | |||
| 37 | Promise.all(promesasArticulo).then(function(values) { | ||
| 38 | |||
| 39 | planex.itemsFactura.forEach((item, index) => { | ||
| 40 | |||
| 41 | if (!values[index]) console.error('No se encontró el articulo'); | ||
| 42 | 35 | ||
| 43 | item.CodArt = values[index].CodArt; | 36 | console.log(err); |
| 44 | item.CodSec = values[index].CodSec; | ||
| 45 | item.CodRub = values[index].CodRub; | ||
| 46 | item.DET_LAR = values[index].DET_LAR; | ||
| 47 | }); | 37 | }); |
| 48 | 38 | ||
| 49 | Promise.all([promiseProveedores, promiseEmp]).then(function(data) { | ||
| 50 | |||
| 51 | entities.proveedores = data[0]; | ||
| 52 | entities.empresa = data[1]; | ||
| 53 | |||
| 54 | var debo = require('./debo/index')(planex, entities); | ||
| 55 | 39 | ||
| 56 | require('./db/index')(debo); | ||
| 57 | }); | ||
| 58 | }); | 40 | }); |
| 59 | } | 41 | } |
| 60 | 42 |
package.json
| 1 | { | 1 | { |
| 2 | "name": "websocketho", | 2 | "name": "websocketho", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "WebSocket Head Office", | 4 | "description": "WebSocket Head Office", |
| 5 | "main": "index.js", | 5 | "main": "index.js", |
| 6 | "dependencies": { | 6 | "dependencies": { |
| 7 | "chokidar": "^3.0.0", | ||
| 7 | "express": "^4.16.4", | 8 | "express": "^4.16.4", |
| 8 | "knex": "^0.16.5", | 9 | "knex": "^0.16.5", |
| 9 | "mssql": "^5.1.0", | 10 | "mssql": "^5.1.0", |
| 10 | "ws": "^7.0.0" | 11 | "ws": "^7.0.0" |
| 11 | }, | 12 | }, |
| 12 | "devDependencies": {}, | 13 | "devDependencies": {}, |
| 13 | "scripts": { | 14 | "scripts": { |
| 14 | "test": "echo \"Error: no test specified\" && exit 1" | 15 | "test": "echo \"Error: no test specified\" && exit 1" |
| 15 | }, | 16 | }, |
| 16 | "author": "Foca Software", | 17 | "author": "Foca Software", |
| 17 | "license": "ISC" | 18 | "license": "ISC" |
| 18 | } | 19 | } |
| 19 | 20 |
watch/index.js
| 1 | module.exports = function(dir, callback) { | 1 | module.exports = function (dir, callback) { |
| 2 | 2 | ||
| 3 | const fs = require('fs'); | 3 | const fs = require('fs'); |
| 4 | const chokidar = require('chokidar'); | ||
| 4 | 5 | ||
| 5 | fs.watch(dir, function(event, file) { | 6 | const watcher = chokidar.watch(dir); |
| 7 | |||
| 8 | watcher.on('add', function(file) { | ||
| 6 | 9 | ||
| 7 | var extencion = file.split('.')[1]; | 10 | var extencion = file.split('.')[1]; |
| 8 | 11 | ||
| 9 | if (extencion == 'txt' && event == 'change') { | 12 | if (extencion == 'txt') { |
| 10 | 13 | ||
| 11 | fs.readFile(dir + '\\' + file, 'utf8', function(err , fileString) { | 14 | fs.readFile(file, 'utf8', function (err, fileString) { |
| 12 | 15 | ||
| 13 | callback(event, fileString); | 16 | callback(fileString); |
| 14 | }); | 17 | }); |
| 15 | } | 18 | } |
| 16 | 19 | ||
| 17 | }); | 20 | }); |
| 18 | 21 | ||
| 19 | }; | 22 | }; |
| 20 | 23 |