Commit f5a48826030b5132cdf016dea959dd68bfd095d7
1 parent
248a10673f
Exists in
master
delete pmae pmov temp
Showing
6 changed files
with
58 additions
and
22 deletions
Show diff stats
db/index.js
| 1 | module.exports = function(comprobante) { | 1 | module.exports = function(comprobante, nameFile) { |
| 2 | 2 | ||
| 3 | var promesas = []; | 3 | var promesas = []; |
| 4 | 4 | ||
| 5 | promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera)); | 5 | promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera)); |
| 6 | 6 | ||
| 7 | comprobante.cuerpo.forEach(cuerpo => { | 7 | comprobante.cuerpo.forEach(cuerpo => { |
| 8 | promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo)); | 8 | promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo)); |
| 9 | }); | 9 | }); |
| 10 | 10 | ||
| 11 | Promise.all(promesas).then(function() { | 11 | Promise.all(promesas).then(function() { |
| 12 | 12 | ||
| 13 | console.log('COMPROBANTE GUARDADO CON ÉXITO'); | 13 | nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1]; |
| 14 | var pathDest = config.dirDestino + '/' + nameFileDest; | ||
| 15 | |||
| 16 | fs.rename(nameFile, pathDest, function(err) { | ||
| 17 | |||
| 18 | if(err) console.log(err); | ||
| 19 | console.log('COMPROBANTE GUARDADO CON ÉXITO'); | ||
| 20 | }); | ||
| 14 | }).catch(function() { | 21 | }).catch(function() { |
| 15 | 22 | ||
| 16 | console.log('ERROR AL GUARDAR EL COMPROBANTE'); | 23 | console.log('ERROR AL GUARDAR EL COMPROBANTE'); |
| 17 | }); | 24 | }); |
| 18 | } | 25 | } |
| 19 | 26 |
debo/relaciones.js
| 1 | module.exports = function(planex, wsServer) { | 1 | module.exports = function(planex, wsServer) { |
| 2 | 2 | ||
| 3 | return new Promise(function(resolve, reject) { | 3 | return new Promise(function(resolve, reject) { |
| 4 | 4 | ||
| 5 | var promesasArticulo = []; | 5 | var promesasArticulo = []; |
| 6 | 6 | ||
| 7 | var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); | 7 | var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2); |
| 8 | var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; | 8 | var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1]; |
| 9 | var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; | 9 | var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador; |
| 10 | 10 | ||
| 11 | var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo}); | 11 | var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo}); |
| 12 | var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP'); | 12 | var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP'); |
| 13 | 13 | ||
| 14 | planex.itemsFactura.forEach(item => { | 14 | planex.itemsFactura.forEach(item => { |
| 15 | 15 | ||
| 16 | var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + | 16 | var queryString = 'select cb.*, art.CodRub, art.DET_LAR from CODBAR cb ' + |
| 17 | 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + | 17 | 'join ARTICULOS art on cb.CodArt = art.CodArt and cb.CodSec = art.CodSec where cb.CodBar = \'' + |
| 18 | item.codigoUPCEAN13 + '\''; | 18 | item.codigoUPCEAN13 + '\''; |
| 19 | 19 | ||
| 20 | promesasArticulo.push( | 20 | promesasArticulo.push( |
| 21 | wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString) | 21 | wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString) |
| 22 | ); | 22 | ); |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]); | 25 | promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]); |
| 26 | 26 | ||
| 27 | Promise.all(promesas).then(function(values) { | 27 | Promise.all(promesas).then(function(values) { |
| 28 | 28 | ||
| 29 | planex.itemsFactura.forEach((item, index) => { | 29 | planex.itemsFactura.forEach((item, index) => { |
| 30 | 30 | ||
| 31 | if (!values[index]) return; console.error('No se encontró el articulo'); | 31 | if (!values[index]) { |
| 32 | |||
| 33 | console.error('No se encontró el articulo Código de barras = ' + item.codigoUPCEAN13); | ||
| 34 | return; | ||
| 35 | } | ||
| 32 | 36 | ||
| 33 | item.CodArt = values[index].CodArt; | 37 | item.CodArt = values[index].CodArt; |
| 34 | item.CodSec = values[index].CodSec; | 38 | item.CodSec = values[index].CodSec; |
| 35 | item.CodRub = values[index].CodRub; | 39 | item.CodRub = values[index].CodRub; |
| 36 | item.DET_LAR = values[index].DET_LAR; | 40 | item.DET_LAR = values[index].DET_LAR; |
| 37 | 41 | ||
| 38 | delete values[index]; | 42 | delete values[index]; |
| 39 | }); | 43 | }); |
| 40 | 44 | ||
| 41 | values = values.filter(function(p) { | 45 | values = values.filter(function(p) { |
| 42 | return p; | 46 | return p; |
| 43 | }); | 47 | }); |
| 44 | 48 | ||
| 45 | resolve({planex, values}); | 49 | resolve({planex, values}); |
| 46 | 50 | ||
| 51 | }).catch(function(e) { | ||
| 52 | reject(e); | ||
| 47 | }); | 53 | }); |
| 48 | 54 | ||
| 49 | }); | 55 | }); |
| 50 | } | 56 | } |
| 51 | 57 |
debo/validacion.js
| 1 | module.exports = function(debo, wsServer, gln) { | 1 | module.exports = function(debo, wsServer, gln) { |
| 2 | 2 | ||
| 3 | return new Promise(function(resolve, reject) { | 3 | return new Promise(function(resolve, reject) { |
| 4 | 4 | ||
| 5 | wsServer | 5 | wsServer |
| 6 | .getEntidad(gln, 'PMAEFACT_TEMP', { | 6 | .getEntidad(gln, 'PMAEFACT_TEMP', { |
| 7 | TIP: debo.cabecera.TIP, | 7 | TIP: debo.cabecera.TIP, |
| 8 | TCO: debo.cabecera.TCO, | 8 | TCO: debo.cabecera.TCO, |
| 9 | SUC: debo.cabecera.SUC, | 9 | SUC: debo.cabecera.SUC, |
| 10 | NCO: debo.cabecera.NCO, | 10 | NCO: debo.cabecera.NCO, |
| 11 | COD: debo.cabecera.COD | 11 | COD: debo.cabecera.COD |
| 12 | }).then(function(values) { | 12 | }).then(function(values) { |
| 13 | 13 | ||
| 14 | if (values) { | 14 | if (values) { |
| 15 | reject('Ya existe el comprobante', values); | 15 | reject('Ya existe el comprobante', values); |
| 16 | } else { | 16 | } else { |
| 17 | resolve(); | 17 | resolve(debo); |
| 18 | } | 18 | } |
| 19 | }); | 19 | }); |
| 20 | }); | 20 | }); |
| 21 | } | 21 | } |
| 22 | 22 |
index.js
| 1 | config = require('./config/config.json'); | ||
| 2 | |||
| 3 | module.exports = | 1 | module.exports = |
| 2 | config = require('./config/config.json'); | ||
| 4 | knex = require('knex')(config.db), | 3 | knex = require('knex')(config.db), |
| 5 | express = require('express'); | 4 | express = require('express'); |
| 6 | app = express(); | 5 | app = express(); |
| 7 | wsServer = require('./webSocketServer/index')(); | 6 | wsServer = require('./webSocketServer/index')(); |
| 8 | moment = require('moment'); | 7 | moment = require('moment'); |
| 8 | fs = require('fs'); | ||
| 9 | |||
| 9 | 10 | ||
| 10 | app.listen(config.portWebService); | 11 | app.listen(config.portWebService); |
| 11 | app.use(express.json({ limit: '50mb' })); | 12 | app.use(express.json({ limit: '50mb' })); |
| 12 | 13 | ||
| 13 | require('./watch/index')(config.dir, onGetFile); | 14 | require('./watch/index')(config.dir, onGetFile); |
| 14 | 15 | ||
| 15 | app.use(function(req, res, next) { | 16 | app.use(function(req, res, next) { |
| 16 | res.setHeader('Access-Control-Allow-Origin', '*'); | 17 | res.setHeader('Access-Control-Allow-Origin', '*'); |
| 17 | res.setHeader( | 18 | res.setHeader( |
| 18 | 'Access-Control-Allow-Headers', | 19 | 'Access-Control-Allow-Headers', |
| 19 | 'Origin, X-Requested-With, Content-Type, Accept, X-Terminal-Key, X-Nombre-Usuario, X-Punto-Venta' | 20 | 'Origin, X-Requested-With, Content-Type, Accept, X-Terminal-Key, X-Nombre-Usuario, X-Punto-Venta' |
| 20 | ); | 21 | ); |
| 21 | res.setHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, OPTIONS'); | 22 | res.setHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, OPTIONS'); |
| 22 | next(); | 23 | next(); |
| 23 | }); | 24 | }); |
| 24 | 25 | ||
| 25 | app.use('/gateway-debo', require('./rutas/comprobantes')); | 26 | app.use('/gateway-debo', require('./rutas/comprobantes')); |
| 26 | app.use('/gateway-debo', require('./rutas/login')); | 27 | app.use('/gateway-debo', require('./rutas/login')); |
| 27 | 28 | ||
| 28 | var planexArr = []; | 29 | function onGetFile(fileString, nameFile) { |
| 29 | |||
| 30 | function onGetFile(fileString) { | ||
| 31 | 30 | ||
| 32 | if (!fileString) return; | 31 | if (!fileString) return; |
| 33 | 32 | ||
| 34 | var planex = require('./planex/index')(fileString); | 33 | var planex = require('./planex/index')(fileString); |
| 35 | 34 | ||
| 36 | planexArr.push(planex); | ||
| 37 | |||
| 38 | // Traigo proveedor, empresa | 35 | // Traigo proveedor, empresa |
| 39 | require('./debo/relaciones')(planex, wsServer).then(function(result) { | 36 | require('./debo/relaciones')(planex, wsServer).then(function(result) { |
| 40 | 37 | ||
| 41 | var planex = result.planex; | 38 | var planex = result.planex; |
| 42 | 39 | ||
| 43 | var entities = {}; | 40 | var entities = {}; |
| 44 | 41 | ||
| 45 | entities.proveedores = result.values[0]; | 42 | entities.proveedores = result.values[0]; |
| 46 | entities.empresa = result.values[1]; | 43 | entities.empresa = result.values[1]; |
| 47 | 44 | ||
| 48 | var debo = require('./debo/index')(planex, entities); | 45 | var debo = require('./debo/index')(planex, entities); |
| 49 | 46 | ||
| 50 | require('./debo/validacion')(debo, wsServer, planex.identificaxSucursalReceptorFactura.glnSucursal).then(function() { | 47 | require('./debo/validacion')(debo, wsServer, planex.identificaxSucursalReceptorFactura.glnSucursal) |
| 48 | .then(function(debo) { | ||
| 51 | 49 | ||
| 52 | require('./db/index')(debo); | 50 | require('./db/index')(debo, nameFile); |
| 53 | }).catch(function(err) { | 51 | }).catch(function(err) { |
| 54 | 52 | ||
| 55 | console.log(err); | 53 | console.log(err); |
| 56 | }); | 54 | }); |
| 57 | 55 | ||
| 56 | }).catch(function(e) { | ||
| 57 | console.log(e); | ||
| 58 | }); | 58 | }); |
rutas/comprobantes.js
| 1 | module.exports = router = express.Router(); | 1 | module.exports = router = express.Router(); |
| 2 | 2 | ||
| 3 | router.get('/comprobantes/:gln*?', function(req, res) { | 3 | router.get('/comprobantes/:gln*?', function(req, res) { |
| 4 | 4 | ||
| 5 | var cabecera = knex('PMAEFACT_TEMP') | 5 | var cabecera = knex('PMAEFACT_TEMP') |
| 6 | .where(function(qb) { | 6 | .where(function(qb) { |
| 7 | if (req.params.gln) { | 7 | if (req.params.gln) { |
| 8 | qb.where({gln: req.params.gln}); | 8 | qb.where({gln: req.params.gln}); |
| 9 | } | 9 | } |
| 10 | }) | 10 | }) |
| 11 | .select('*'); | 11 | .select('*'); |
| 12 | 12 | ||
| 13 | var cuerpo = knex('PMOVFACT_TEMP') | 13 | var cuerpo = knex('PMOVFACT_TEMP') |
| 14 | .where(function(qb) { | 14 | .where(function(qb) { |
| 15 | if (req.params.gln) { | 15 | if (req.params.gln) { |
| 16 | qb.where({gln: req.params.gln}); | 16 | qb.where({gln: req.params.gln}); |
| 17 | } | 17 | } |
| 18 | }) | 18 | }) |
| 19 | .select('*'); | 19 | .select('*'); |
| 20 | 20 | ||
| 21 | Promise.all([cabecera, cuerpo]).then(function(data) { | 21 | Promise.all([cabecera, cuerpo]).then(function(data) { |
| 22 | 22 | ||
| 23 | var result = []; | 23 | var result = []; |
| 24 | data[0].forEach((cabecera) => { | 24 | data[0].forEach((cabecera) => { |
| 25 | 25 | ||
| 26 | let idCabecera = cabecera.TIP + cabecera.TCO + cabecera.SUC + cabecera.NCO; | 26 | let idCabecera = cabecera.TIP + cabecera.TCO + cabecera.SUC + cabecera.NCO; |
| 27 | 27 | ||
| 28 | var cuerpos = data[1].filter((cuerpo) => { | 28 | var cuerpos = data[1].filter((cuerpo) => { |
| 29 | let idCuerpo = cuerpo.TIP + cuerpo.TCO + cuerpo.SUC + cuerpo.NCO; | 29 | let idCuerpo = cuerpo.TIP + cuerpo.TCO + cuerpo.SUC + cuerpo.NCO; |
| 30 | return idCuerpo == idCabecera | 30 | return idCuerpo == idCabecera |
| 31 | }); | 31 | }); |
| 32 | 32 | ||
| 33 | result.push({ | 33 | result.push({ |
| 34 | cabecera: cabecera, | 34 | cabecera: cabecera, |
| 35 | cuerpo: cuerpos | 35 | cuerpo: cuerpos |
| 36 | }); | 36 | }); |
| 37 | }); | 37 | }); |
| 38 | 38 | ||
| 39 | res.status(200).send(result); | 39 | res.status(200).send(result); |
| 40 | }); | 40 | }); |
| 41 | }); | 41 | }); |
| 42 | 42 | ||
| 43 | router.post('/comprobante', function(req, res) { | 43 | router.post('/comprobante', function(req, res) { |
| 44 | 44 | ||
| 45 | console.log(req.body); | 45 | console.log(req.body); |
| 46 | delete req.body.cabecera.gln; | 46 | delete req.body.cabecera.gln; |
| 47 | delete req.body.cabecera.C_HD2; | 47 | delete req.body.cabecera.C_HD2; |
| 48 | delete req.body.cabecera.E_HD2; | 48 | delete req.body.cabecera.E_HD2; |
| 49 | 49 | ||
| 50 | //smalldatetime | 50 | //smalldatetime |
| 51 | req.body.cabecera.FEC = new Date(req.body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); | 51 | req.body.cabecera.FEC = new Date(req.body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); |
| 52 | req.body.cabecera.FECCAI = new Date(req.body.cabecera.FECCAI).toISOString().slice(0, 19).replace('T', ' '); | 52 | req.body.cabecera.FECCAI = new Date(req.body.cabecera.FECCAI).toISOString().slice(0, 19).replace('T', ' '); |
| 53 | req.body.cabecera.FECVEN = new Date(req.body.cabecera.FECVEN).toISOString().slice(0, 19).replace('T', ' '); | 53 | req.body.cabecera.FECVEN = new Date(req.body.cabecera.FECVEN).toISOString().slice(0, 19).replace('T', ' '); |
| 54 | 54 | ||
| 55 | //datetime | 55 | //datetime |
| 56 | req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD'); | 56 | req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD'); |
| 57 | req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD'); | 57 | req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD'); |
| 58 | 58 | ||
| 59 | var promesas = [ | 59 | var promesas = [ |
| 60 | knex('PMAEFACT').insert(req.body.cabecera), | 60 | knex('PMAEFACT').insert(req.body.cabecera), |
| 61 | knex('PCOBYPAG').insert({ | 61 | knex('PCOBYPAG').insert({ |
| 62 | COD: req.body.cabecera.COD, | 62 | COD: req.body.cabecera.COD, |
| 63 | FEP: req.body.cabecera.FEC, | 63 | FEP: req.body.cabecera.FEC, |
| 64 | TIP: req.body.cabecera.TIP, | 64 | TIP: req.body.cabecera.TIP, |
| 65 | TCO: req.body.cabecera.TCO, | 65 | TCO: req.body.cabecera.TCO, |
| 66 | SUC: req.body.cabecera.SUC, | 66 | SUC: req.body.cabecera.SUC, |
| 67 | NCO: req.body.cabecera.NCO, | 67 | NCO: req.body.cabecera.NCO, |
| 68 | IPA: req.body.cabecera.TOT, | 68 | IPA: req.body.cabecera.TOT, |
| 69 | SAL: 0, | 69 | SAL: 0, |
| 70 | TCA: 1, | 70 | TCA: 1, |
| 71 | ZONA: req.body.cabecera.ZON, | 71 | ZONA: req.body.cabecera.ZON, |
| 72 | FPA: req.body.cabecera.FPA, | 72 | FPA: req.body.cabecera.FPA, |
| 73 | REC: 0, | 73 | REC: 0, |
| 74 | FER: '19000101 00:00', | 74 | FER: '19000101 00:00', |
| 75 | PRO: '', | 75 | PRO: '', |
| 76 | FEV: req.body.cabecera.FEV, | 76 | FEV: req.body.cabecera.FEV, |
| 77 | ANU: '', | 77 | ANU: '', |
| 78 | PLA: 0, | 78 | PLA: 0, |
| 79 | LUG: 0, | 79 | LUG: 0, |
| 80 | RES: 0, | 80 | RES: 0, |
| 81 | CCU: 0, | 81 | CCU: 0, |
| 82 | UCU: 0, | 82 | UCU: 0, |
| 83 | HOS: '', | 83 | HOS: '', |
| 84 | E_HD: '', | 84 | E_HD: '', |
| 85 | C_HD: '' | 85 | C_HD: '' |
| 86 | }) | 86 | }) |
| 87 | ]; | 87 | ]; |
| 88 | 88 | ||
| 89 | req.body.cuerpo.forEach(cuerpo => { | 89 | req.body.cuerpo.forEach(cuerpo => { |
| 90 | 90 | ||
| 91 | 91 | if (cuerpo.estado == 'rechazado') return; | |
| 92 | promesas.push(knex('AMOVSTOC').insert({ | 92 | promesas.push(knex('AMOVSTOC').insert({ |
| 93 | SEC: cuerpo.COD, | 93 | SEC: cuerpo.COD, |
| 94 | ART: cuerpo.ART, | 94 | ART: cuerpo.ART, |
| 95 | FEC: req.body.cabecera.FEC, | 95 | FEC: req.body.cabecera.FEC, |
| 96 | CYV: 'C', | 96 | CYV: 'C', |
| 97 | TIP: req.body.cabecera.TIP, | 97 | TIP: req.body.cabecera.TIP, |
| 98 | TCO: req.body.cabecera.TCO, | 98 | TCO: req.body.cabecera.TCO, |
| 99 | PVE: req.body.cabecera.SUC, | 99 | PVE: req.body.cabecera.SUC, |
| 100 | NCO: req.body.cabecera.NCO, | 100 | NCO: req.body.cabecera.NCO, |
| 101 | ORD: cuerpo.ORD, | 101 | ORD: cuerpo.ORD, |
| 102 | CAN: cuerpo.recibido || cuerpo.CAN, | 102 | CAN: cuerpo.recibido || cuerpo.CAN, |
| 103 | PUN: cuerpo.PUN, | 103 | PUN: cuerpo.PUN, |
| 104 | COD: req.body.cabecera.COD, | 104 | COD: req.body.cabecera.COD, |
| 105 | DTO: cuerpo.DTO, | 105 | DTO: cuerpo.DTO, |
| 106 | IMI: cuerpo.IMI, | 106 | IMI: cuerpo.IMI, |
| 107 | PLA: 0, | 107 | PLA: 0, |
| 108 | LUG: 0, | 108 | LUG: 0, |
| 109 | ANU: '', | 109 | ANU: '', |
| 110 | TIM: 'Co', | 110 | TIM: 'Co', |
| 111 | OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario | 111 | OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario |
| 112 | IMI2: cuerpo.IMI2, | 112 | IMI2: cuerpo.IMI2, |
| 113 | E_HD: '', | 113 | E_HD: '', |
| 114 | C_HD: '', | 114 | C_HD: '', |
| 115 | JUS: 'PLANEX', | 115 | JUS: 'PLANEX', |
| 116 | NLC: 0, | 116 | NLC: 0, |
| 117 | IMI3: cuerpo.IMI3, | 117 | IMI3: cuerpo.IMI3, |
| 118 | JJN: '', | 118 | JJN: '', |
| 119 | JDJ: '', | 119 | JDJ: '', |
| 120 | ID_MOTIVO_NANB: 0 | 120 | ID_MOTIVO_NANB: 0 |
| 121 | })); | 121 | })); |
| 122 | 122 | ||
| 123 | delete cuerpo.gln; | 123 | delete cuerpo.gln; |
| 124 | delete cuerpo.C_HD2; | 124 | delete cuerpo.C_HD2; |
| 125 | delete cuerpo.E_HD2; | 125 | delete cuerpo.E_HD2; |
| 126 | delete cuerpo.codigoBarras; | 126 | delete cuerpo.codigoBarras; |
| 127 | delete cuerpo.estado; | 127 | delete cuerpo.estado; |
| 128 | delete cuerpo.recibido; | 128 | delete cuerpo.recibido; |
| 129 | delete cuerpo.input; | 129 | delete cuerpo.input; |
| 130 | 130 | ||
| 131 | cuerpo.LI0 = cuerpo.LI0.slice(0, 29); | ||
| 132 | cuerpo.TIO = cuerpo.TIO.slice(0, 29); | ||
| 133 | |||
| 131 | promesas.push(knex('PMOVFACT').insert(cuerpo)); | 134 | promesas.push(knex('PMOVFACT').insert(cuerpo)); |
| 132 | 135 | ||
| 133 | }); | 136 | }); |
| 134 | 137 | ||
| 135 | Promise.all(promesas) | 138 | Promise.all(promesas) |
| 136 | .then(function() { | 139 | .then(function() { |
| 137 | 140 | ||
| 138 | console.log('comprobantes guardados con éxito'); | 141 | Promise.all([ |
| 142 | knex('PMAEFACT_TEMP').where({ | ||
| 143 | TIP: req.body.cabecera.TIP, | ||
| 144 | TCO: req.body.cabecera.TCO, | ||
| 145 | SUC: req.body.cabecera.SUC, | ||
| 146 | NCO: req.body.cabecera.NCO, | ||
| 147 | COD: req.body.cabecera.COD | ||
| 148 | }) | ||
| 149 | .del(), | ||
| 150 | knex('PMOVFACT_TEMP').where({ | ||
| 151 | TIP: req.body.cabecera.TIP, | ||
| 152 | TCO: req.body.cabecera.TCO, | ||
| 153 | SUC: req.body.cabecera.SUC, | ||
| 154 | NCO: req.body.cabecera.NCO | ||
| 155 | }) | ||
| 156 | .del() | ||
| 157 | ]).then(function() { | ||
| 158 | |||
| 159 | console.log('comprobantes guardados con éxito'); | ||
| 160 | res.status(201).send(); | ||
| 161 | }) | ||
| 162 | |||
| 139 | }) | 163 | }) |
| 140 | .catch(function(e) { | 164 | .catch(function(e) { |
| 141 | console.log(e); | 165 | console.log(e); |
| 166 | res.status(500).send(e); | ||
| 142 | }); | 167 | }); |
| 143 | 168 | ||
| 144 | res.status(201).send('ok'); | ||
| 145 | }); | 169 | }); |
watch/index.js
| 1 | module.exports = function (dir, callback) { | 1 | module.exports = function (dir, callback) { |
| 2 | 2 | ||
| 3 | const fs = require('fs'); | ||
| 4 | const chokidar = require('chokidar'); | 3 | const chokidar = require('chokidar'); |
| 5 | 4 | ||
| 6 | const watcher = chokidar.watch(dir); | 5 | const watcher = chokidar.watch(dir, { ignored: config.dirDestino }); |
| 7 | 6 | ||
| 8 | watcher.on('add', function(file) { | 7 | watcher.on('add', function(file) { |
| 9 | 8 | ||
| 10 | var extencion = file.split('.')[1]; | 9 | var extencion = file.split('.')[1]; |
| 11 | 10 | ||
| 12 | if (extencion == 'txt') { | 11 | if (extencion == 'txt') { |
| 13 | 12 | ||
| 14 | fs.readFile(file, 'utf8', function (err, fileString) { | 13 | fs.readFile(file, 'utf8', function (err, fileString) { |
| 15 | 14 | ||
| 16 | callback(fileString); | 15 | callback(fileString, file); |
| 17 | }); | 16 | }); |
| 18 | } | 17 | } |
| 19 | 18 | ||
| 20 | }); | 19 | }); |
| 21 | 20 | ||
| 22 | }; | 21 | }; |
| 23 | 22 |