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 | 3 | var promesas = []; |
| 4 | 4 | |
| ... | ... | @@ -10,7 +10,14 @@ module.exports = function(comprobante) { |
| 10 | 10 | |
| 11 | 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 | 21 | }).catch(function() { |
| 15 | 22 | |
| 16 | 23 | console.log('ERROR AL GUARDAR EL COMPROBANTE'); |
debo/relaciones.js
| ... | ... | @@ -28,7 +28,11 @@ module.exports = function(planex, wsServer) { |
| 28 | 28 | |
| 29 | 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 | 37 | item.CodArt = values[index].CodArt; |
| 34 | 38 | item.CodSec = values[index].CodSec; |
| ... | ... | @@ -44,6 +48,8 @@ module.exports = function(planex, wsServer) { |
| 44 | 48 | |
| 45 | 49 | resolve({planex, values}); |
| 46 | 50 | |
| 51 | + }).catch(function(e) { | |
| 52 | + reject(e); | |
| 47 | 53 | }); |
| 48 | 54 | |
| 49 | 55 | }); |
debo/validacion.js
index.js
| 1 | -config = require('./config/config.json'); | |
| 2 | - | |
| 3 | 1 | module.exports = |
| 2 | + config = require('./config/config.json'); | |
| 4 | 3 | knex = require('knex')(config.db), |
| 5 | 4 | express = require('express'); |
| 6 | 5 | app = express(); |
| 7 | 6 | wsServer = require('./webSocketServer/index')(); |
| 8 | 7 | moment = require('moment'); |
| 8 | + fs = require('fs'); | |
| 9 | + | |
| 9 | 10 | |
| 10 | 11 | app.listen(config.portWebService); |
| 11 | 12 | app.use(express.json({ limit: '50mb' })); |
| ... | ... | @@ -25,16 +26,12 @@ app.use(function(req, res, next) { |
| 25 | 26 | app.use('/gateway-debo', require('./rutas/comprobantes')); |
| 26 | 27 | app.use('/gateway-debo', require('./rutas/login')); |
| 27 | 28 | |
| 28 | -var planexArr = []; | |
| 29 | - | |
| 30 | -function onGetFile(fileString) { | |
| 29 | +function onGetFile(fileString, nameFile) { | |
| 31 | 30 | |
| 32 | 31 | if (!fileString) return; |
| 33 | 32 | |
| 34 | 33 | var planex = require('./planex/index')(fileString); |
| 35 | 34 | |
| 36 | - planexArr.push(planex); | |
| 37 | - | |
| 38 | 35 | // Traigo proveedor, empresa |
| 39 | 36 | require('./debo/relaciones')(planex, wsServer).then(function(result) { |
| 40 | 37 | |
| ... | ... | @@ -47,14 +44,17 @@ function onGetFile(fileString) { |
| 47 | 44 | |
| 48 | 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); | |
| 53 | - }).catch(function(err) { | |
| 50 | + require('./db/index')(debo, nameFile); | |
| 51 | + }).catch(function(err) { | |
| 54 | 52 | |
| 55 | - console.log(err); | |
| 56 | - }); | |
| 53 | + console.log(err); | |
| 54 | + }); | |
| 57 | 55 | |
| 56 | + }).catch(function(e) { | |
| 57 | + console.log(e); | |
| 58 | 58 | }); |
| 59 | 59 | } |
| 60 | 60 |
rutas/comprobantes.js
| ... | ... | @@ -88,7 +88,7 @@ router.post('/comprobante', function(req, res) { |
| 88 | 88 | |
| 89 | 89 | req.body.cuerpo.forEach(cuerpo => { |
| 90 | 90 | |
| 91 | - | |
| 91 | + if (cuerpo.estado == 'rechazado') return; | |
| 92 | 92 | promesas.push(knex('AMOVSTOC').insert({ |
| 93 | 93 | SEC: cuerpo.COD, |
| 94 | 94 | ART: cuerpo.ART, |
| ... | ... | @@ -128,6 +128,9 @@ router.post('/comprobante', function(req, res) { |
| 128 | 128 | delete cuerpo.recibido; |
| 129 | 129 | delete cuerpo.input; |
| 130 | 130 | |
| 131 | + cuerpo.LI0 = cuerpo.LI0.slice(0, 29); | |
| 132 | + cuerpo.TIO = cuerpo.TIO.slice(0, 29); | |
| 133 | + | |
| 131 | 134 | promesas.push(knex('PMOVFACT').insert(cuerpo)); |
| 132 | 135 | |
| 133 | 136 | }); |
| ... | ... | @@ -135,11 +138,32 @@ router.post('/comprobante', function(req, res) { |
| 135 | 138 | Promise.all(promesas) |
| 136 | 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 | 164 | .catch(function(e) { |
| 141 | 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 | 1 | module.exports = function (dir, callback) { |
| 2 | 2 | |
| 3 | - const fs = require('fs'); | |
| 4 | 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 | 7 | watcher.on('add', function(file) { |
| 9 | 8 | |
| ... | ... | @@ -13,7 +12,7 @@ module.exports = function (dir, callback) { |
| 13 | 12 | |
| 14 | 13 | fs.readFile(file, 'utf8', function (err, fileString) { |
| 15 | 14 | |
| 16 | - callback(fileString); | |
| 15 | + callback(fileString, file); | |
| 17 | 16 | }); |
| 18 | 17 | } |
| 19 | 18 |