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
... | ... | @@ -4,57 +4,39 @@ module.exports = knex = require('knex')(config.db) |
4 | 4 | require('./watch/index')(config.dir, onGetFile); |
5 | 5 | |
6 | 6 | const wsServer = require('./webSocketServer/index')(); |
7 | +var planexArr = [] | |
7 | 8 | |
8 | -function onGetFile(event, fileString) { | |
9 | +function onGetFile(fileString) { | |
9 | 10 | |
10 | 11 | if (!fileString) return; |
11 | 12 | |
12 | 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); | |
19 | - var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | |
20 | + var planex = planexArr.filter(function(p) { | |
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}); | |
24 | - var promiseEmp = wsServer.getEntidad('7790968003283', 'APAREMP'); | |
26 | + entities.proveedores = result.values[0]; | |
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 ' + | |
31 | - 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + | |
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'); | |
33 | + require('./db/index')(debo); | |
34 | + }).catch(function(err) { | |
42 | 35 | |
43 | - item.CodArt = values[index].CodArt; | |
44 | - item.CodSec = values[index].CodSec; | |
45 | - item.CodRub = values[index].CodRub; | |
46 | - item.DET_LAR = values[index].DET_LAR; | |
36 | + console.log(err); | |
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
watch/index.js
1 | -module.exports = function(dir, callback) { | |
1 | +module.exports = function (dir, callback) { | |
2 | 2 | |
3 | 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 | 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 |