Commit 5eda16ee29cf853020a1fb92901f204d06259ab7
1 parent
25903588b1
Exists in
master
avances debo
Showing
14 changed files
with
162 additions
and
67 deletions
Show diff stats
afip/index.js
... | ... | @@ -33,8 +33,17 @@ module.exports = function(codigo) { |
33 | 33 | } |
34 | 34 | ] |
35 | 35 | |
36 | - return tablaAfip.filter(function(comprobante) { | |
36 | + var result = tablaAfip.filter(function(comprobante) { | |
37 | 37 | return comprobante.codigo == parseInt(codigo) |
38 | 38 | })[0]; |
39 | 39 | |
40 | + if (!result) { | |
41 | + result = { | |
42 | + letraComprobante: 'CIB', | |
43 | + tipoComprobante: 'CI' | |
44 | + } | |
45 | + } | |
46 | + | |
47 | + return result; | |
48 | + | |
40 | 49 | } |
index.js
1 | -const webSocketServer = require('ws').Server; | |
2 | -const fs = require('fs'); | |
3 | -const config = require('./config/config.json'); | |
1 | +config = require('./config/config.json'); | |
4 | 2 | |
5 | -const planex = require('./planex/index')(''); | |
3 | +require('./watch/index')(config.dir, onGetFile); | |
6 | 4 | |
7 | -const debo = require('./debo/index')(planex); | |
5 | +const wsServer = require('./webSocketServer/index')(); | |
8 | 6 | |
9 | -console.log(planex); | |
10 | -console.log(debo); | |
7 | +function onGetFile(event, fileString) { | |
11 | 8 | |
12 | -fs.watch(__dirname, function (event, file) { | |
13 | - console.log(event); | |
14 | - console.log(file); | |
15 | -}); | |
9 | + if (!fileString) return; | |
16 | 10 | |
17 | -const wsServer = new webSocketServer({ | |
18 | - port: config.port | |
19 | -}); | |
11 | + var planex = require('./planex/index')(fileString); | |
20 | 12 | |
21 | -wsServer.on('connection', function connection(ws) { | |
13 | + var entidades = []; | |
22 | 14 | |
23 | - console.log('open socket server'); | |
15 | + wsServer.getEntidad('7790968003283', 'PROVEED').then(function(data) { | |
16 | + entidades.push({ entidad:'proveedores', data: data}) | |
17 | + }); | |
24 | 18 | |
25 | - ws.on('message', function incoming(message) { | |
19 | + console.log(entidades.length); | |
26 | 20 | |
27 | - message = message.toString('utf8'); | |
28 | - console.log(message); | |
21 | + var debo = require('./debo/index')(planex, entidades); | |
29 | 22 | |
30 | - switch (message) { | |
31 | - case message.action == 'gln': | |
32 | - ws.gln = message.gln; | |
33 | - break; | |
34 | - default: | |
35 | - break; | |
36 | - } | |
37 | - }); | |
38 | -}); | |
23 | + // console.log(debo); | |
24 | + | |
25 | +} | |
39 | 26 | |
40 | 27 | console.log('listen websocket port ' + config.port); |
28 | +console.log('Ejecutar programa como administrador...'); |
planex/comprobantesReferencia.js
planex/detallePercepcionesIIBB.js
planex/detallesImportesIVA.js
planex/identificaxComprobante.js
planex/identificaxEmisor.js
planex/identificaxReceptorFactura.js
planex/identificaxSucursalReceptorFactura.js
planex/importesTotales.js
1 | 1 | module.exports = function(comprobante, returnFloatByDecimals) { |
2 | 2 | |
3 | - comprobante = '050;000000000000000;000000000000000;000000000000000;000000000140295;000000000000000;000000000115946;000000 000024349;000000000000000;000000000000000;000000000000000;000000000000000;000000000000000;000000000000000;;PES;00001000000;1;000000000000000;;;' | |
4 | - | |
5 | 3 | var comprobanteArr = comprobante.split(';'); |
6 | 4 | |
7 | 5 | return { |
planex/index.js
1 | 1 | module.exports = function(comprobante) { |
2 | 2 | |
3 | + // split por salto de lรญnea | |
4 | + comprobante = comprobante.split(/\r?\n/); | |
5 | + | |
6 | + var objReturn = { | |
7 | + identificaxComprobante: {}, | |
8 | + identificaxMensaje: {}, | |
9 | + comprobantesReferencia: [], | |
10 | + identificaxEmisor: {}, | |
11 | + informaxRepresentanteEmisor: {}, | |
12 | + identificaxReceptorFactura: {}, | |
13 | + identificaxSucursalReceptorFactura: {}, | |
14 | + importesTotales: {}, | |
15 | + detallesImportesIVA: {}, | |
16 | + detallePercepcionesIIBB: {}, | |
17 | + descuentosGlobalesFactura: {}, | |
18 | + detalleOtrosImpuestosComprobante: {}, | |
19 | + itemsFactura: [], | |
20 | + detalleDescuentosItemFactura: {}, | |
21 | + detalleImpuestosItemFactura: {} | |
22 | + }; | |
3 | 23 | |
4 | 24 | function returnFloatByDecimals(parameter, cantDecimal) { |
5 | 25 | |
6 | 26 | if (!parameter) return; |
7 | 27 | |
8 | - var antesDeLaComa = parseFloat(parameter.slice(0, parameter.length - cantDecimal)); | |
28 | + var beforeSemiColon = parseFloat(parameter.slice(0, parameter.length - cantDecimal)); | |
9 | 29 | |
10 | - var despuesDeLaComa = parameter.slice(parameter.length - cantDecimal, parameter.length); | |
30 | + var afterSemicolon = parameter.slice(parameter.length - cantDecimal, parameter.length); | |
11 | 31 | |
12 | - return parseFloat(antesDeLaComa + '.' + despuesDeLaComa); | |
32 | + return parseFloat(beforeSemiColon + '.' + afterSemicolon); | |
13 | 33 | } |
14 | 34 | |
15 | - return { | |
16 | - identificaxComprobante: require('./identificaxComprobante')(comprobante),// 010 | |
17 | - identificaxMensaje: require('./identificaxMensaje')(comprobante),// 012 | |
18 | - comprobantesReferencia: require('./comprobantesReferencia')(comprobante), // 020 | |
19 | - identificaxEmisor: require('./identificaxEmisor')(comprobante), // 030 | |
20 | - informaxRepresentanteEmisor: require('./informaxRepresentanteEmisor')(comprobante), // 035 | |
21 | - identificaxReceptorFactura: require('./identificaxReceptorFactura')(comprobante), // 040 | |
22 | - identificaxSucursalReceptorFactura: require('./identificaxSucursalReceptorFactura')(comprobante), // 045 | |
23 | - importesTotales: require('./importesTotales')(comprobante, returnFloatByDecimals), // 050 | |
24 | - detallesImportesIVA: require('./detallesImportesIVA')(comprobante, returnFloatByDecimals), // 060 | |
25 | - detallePercepcionesIIBB: require('./detallePercepcionesIIBB')(comprobante, returnFloatByDecimals), // 070 | |
26 | - descuentosGlobalesFactura: require('./descuentosGlobalesFactura')(comprobante, returnFloatByDecimals), // 080 | |
27 | - detalleOtrosImpuestosComprobante: require('./detalleOtrosImpuestosComprobante')(comprobante, returnFloatByDecimals), // 090 | |
28 | - itemsFactura: require('./itemsFactura')(comprobante, returnFloatByDecimals), // 100 | |
29 | - detalleDescuentosItemFactura: require('./detalleDescuentosItemFactura')(comprobante, returnFloatByDecimals), // 110 | |
30 | - detalleImpuestosItemFactura: require('./detalleImpuestosItemFactura')(comprobante, returnFloatByDecimals), // 120 | |
31 | - }; | |
35 | + comprobante.forEach(sector => { | |
36 | + | |
37 | + if (sector.slice(0, 3) == '010') { | |
38 | + objReturn.identificaxComprobante = require('./identificaxComprobante')(sector)// 010 | |
39 | + } else if (sector.slice(0, 3) == '012') { | |
40 | + objReturn.identificaxMensaje = require('./identificaxMensaje')(sector)// 012 | |
41 | + } else if (sector.slice(0, 3) == '020') { | |
42 | + objReturn.comprobantesReferencia.push(require('./comprobantesReferencia')(sector)) // 020 | |
43 | + } else if (sector.slice(0, 3) == '030') { | |
44 | + objReturn.identificaxEmisor = require('./identificaxEmisor')(sector) // 030 | |
45 | + } else if (sector.slice(0, 3) == '035') { | |
46 | + objReturn.informaxRepresentanteEmisor = require('./informaxRepresentanteEmisor')(sector) // 035 | |
47 | + } else if (sector.slice(0, 3) == '040') { | |
48 | + objReturn.identificaxReceptorFactura = require('./identificaxReceptorFactura')(sector) // 040 | |
49 | + } else if (sector.slice(0, 3) == '045') { | |
50 | + objReturn.identificaxSucursalReceptorFactura = require('./identificaxSucursalReceptorFactura')(sector) // 045 | |
51 | + } else if (sector.slice(0, 3) == '050') { | |
52 | + objReturn.importesTotales = require('./importesTotales')(sector, returnFloatByDecimals) // 050 | |
53 | + } else if (sector.slice(0, 3) == '060') { | |
54 | + objReturn.detallesImportesIVA = require('./detallesImportesIVA')(sector, returnFloatByDecimals) // 060 | |
55 | + } else if (sector.slice(0, 3) == '070') { | |
56 | + objReturn.detallePercepcionesIIBB = require('./detallePercepcionesIIBB')(sector, returnFloatByDecimals) // 070 | |
57 | + } else if (sector.slice(0, 3) == '080') { | |
58 | + objReturn.descuentosGlobalesFactura = require('./descuentosGlobalesFactura')(sector, returnFloatByDecimals) // 080 | |
59 | + } else if (sector.slice(0, 3) == '090') { | |
60 | + objReturn.detalleOtrosImpuestosComprobante = require('./detalleOtrosImpuestosComprobante')(sector, returnFloatByDecimals) // 090 | |
61 | + } else if (sector.slice(0, 3) == '100') { | |
62 | + objReturn.itemsFactura.push(require('./itemsFactura')(sector, returnFloatByDecimals)); // 100 | |
63 | + } else if (sector.slice(0, 3) == '110') { | |
64 | + objReturn.detalleDescuentosItemFactura = require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals); // 110 | |
65 | + } else if (sector.slice(0, 3) == '120') { | |
66 | + objReturn.detalleImpuestosItemFactura = require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals); // 120 | |
67 | + } | |
68 | + }); | |
69 | + | |
70 | + return objReturn; | |
32 | 71 | } |
planex/itemsFactura.js
1 | 1 | module.exports = function(comprobante, returnFloatByDecimals) { |
2 | 2 | |
3 | - comprobante = '100;000001;74300;2087455000005;DescripciรณnArticulo;000000000500000;;000000000035500;02100;0000 00000003452;000000000016437;000000000000000;000000000000000;G; ;000000000000100;000000000000100;CR;CU;000000000032873;7798569874125;; '; | |
4 | - | |
5 | 3 | var comprobanteArr = comprobante.split(';'); |
6 | 4 | |
7 | 5 | return { |
watch/index.js
... | ... | @@ -0,0 +1,19 @@ |
1 | +module.exports = function(dir, callback) { | |
2 | + | |
3 | + const fs = require('fs'); | |
4 | + | |
5 | + fs.watch(dir, function(event, file) { | |
6 | + | |
7 | + var extencion = file.split('.')[1]; | |
8 | + | |
9 | + if (extencion == 'plx') { | |
10 | + | |
11 | + fs.readFile(dir + '\\' + file, 'utf8', function(err , fileString) { | |
12 | + | |
13 | + callback(event, fileString); | |
14 | + }) | |
15 | + } | |
16 | + | |
17 | + }); | |
18 | + | |
19 | +}; |
webSocketServer/index.js
... | ... | @@ -0,0 +1,58 @@ |
1 | +module.exports = function() { | |
2 | + | |
3 | +const webSocketServer = require('ws').Server; | |
4 | +var clients = []; | |
5 | + | |
6 | +const objWs = {}; | |
7 | + | |
8 | +objWs.wsServer = new webSocketServer({ | |
9 | + port: config.port | |
10 | +}); | |
11 | + | |
12 | +objWs.wsServer.on('connection', function connection(ws) { | |
13 | + | |
14 | + console.log('open socket server'); | |
15 | + | |
16 | + ws.on('message', function incoming(message) { | |
17 | + | |
18 | + message = JSON.parse(message.toString('utf8')); | |
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 | + } | |
27 | + }); | |
28 | +}); | |
29 | + | |
30 | +objWs.getEntidad = function(gln, tableName, where) { | |
31 | + | |
32 | + return new Promise(function(resolve, reject) { | |
33 | + | |
34 | + clients.forEach(client => { | |
35 | + | |
36 | + if (client.gln == gln) { | |
37 | + | |
38 | + var enviar = { | |
39 | + action: 'getEntity', | |
40 | + tableName: tableName, | |
41 | + where: where | |
42 | + } | |
43 | + | |
44 | + client.ws.send(JSON.stringify(enviar)); | |
45 | + | |
46 | + client.ws.on('message', function(message) { | |
47 | + | |
48 | + console.log(JSON.parse(message)); | |
49 | + | |
50 | + resolve(message.data); | |
51 | + }); | |
52 | + } | |
53 | + }); | |
54 | + }); | |
55 | +} | |
56 | + | |
57 | +return objWs; | |
58 | +} | |
0 | 59 | \ No newline at end of file |