From e528eadf15749ca48786bf5c60697078e5b9cc07 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Mon, 26 Aug 2019 11:42:12 -0300 Subject: [PATCH] guardo pmae antes de todo --- data/index.js | 179 ++++++++++++++++++++++++++++++---------------------------- index.js | 4 +- 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/data/index.js b/data/index.js index 47bc473..b72bac8 100644 --- a/data/index.js +++ b/data/index.js @@ -34,7 +34,7 @@ module.exports = function(config) { delete body.cabecera.GLN; delete body.cabecera.C_HD2; delete body.cabecera.E_HD2; - + //smalldatetime body.cabecera.FEC = new Date(body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); body.cabecera.FECCAI = new Date(body.cabecera.FECCAI).toISOString().slice(0, 19).replace('T', ' '); @@ -42,102 +42,107 @@ module.exports = function(config) { //datetime body.cabecera.FEV = moment(body.cabecera.FEV).format('YYYYMMDD'); body.cabecera.FEP = moment(body.cabecera.FEP).format('YYYYMMDD'); - - var promesas = [ - knex('PMAEFACT').insert(body.cabecera), - knex('PCOBYPAG').insert({ - COD: body.cabecera.COD, - FEP: body.cabecera.FEC, - TIP: body.cabecera.TIP, - TCO: body.cabecera.TCO, - SUC: body.cabecera.SUC, - NCO: body.cabecera.NCO, - IPA: body.cabecera.TOT, - SAL: 0, - TCA: 1, - ZONA: body.cabecera.ZON, - FPA: body.cabecera.FPA, - REC: 0, - FER: '19000101 00:00', - PRO: '', - FEV: body.cabecera.FEV, - ANU: '', - PLA: 0, - LUG: 0, - RES: 0, - CCU: 0, - UCU: 0, - HOS: '', - E_HD: '', - C_HD: '' - }), - ]; - - body.cuerpo.forEach(cuerpo => { - - if (cuerpo.estado != 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0)) { - - promesas.push(knex('AMOVSTOC').insert({ - SEC: cuerpo.COD, - ART: cuerpo.ART, - FEC: body.cabecera.FEC, - CYV: 'C', + + knex('PMAEFACT').insert(body.cabecera).then(() => { + + var promesas = [ + knex('PCOBYPAG').insert({ + COD: body.cabecera.COD, + FEP: body.cabecera.FEC, TIP: body.cabecera.TIP, TCO: body.cabecera.TCO, - PVE: body.cabecera.SUC, + SUC: body.cabecera.SUC, NCO: body.cabecera.NCO, - ORD: cuerpo.ORD, - CAN: cuerpo.cantidadRecibida, - PUN: cuerpo.PUN, - COD: body.cabecera.COD, - DTO: cuerpo.DTO, - IMI: cuerpo.IMI, + IPA: body.cabecera.TOT, + SAL: 0, + TCA: 1, + ZONA: body.cabecera.ZON, + FPA: body.cabecera.FPA, + REC: 0, + FER: '19000101 00:00', + PRO: '', + FEV: body.cabecera.FEV, + ANU: '', PLA: 0, LUG: 0, - ANU: '', - TIM: 'Co', - OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario - IMI2: cuerpo.IMI2, + RES: 0, + CCU: 0, + UCU: 0, + HOS: '', E_HD: '', - C_HD: '', - JUS: 'PLANEX', - NLC: 0, - IMI3: cuerpo.IMI3, - JJN: '', - JDJ: '', - ID_MOTIVO_NANB: 0 - })); - }; - - cuerpo.estado == 'rechazado' ? cuerpo.cantidadRecibida = 0 : false; - - delete cuerpo.GLN; - delete cuerpo.C_HD2; - delete cuerpo.E_HD2; - delete cuerpo.codigoBarras; - delete cuerpo.estado; - delete cuerpo.recibido; - delete cuerpo.input; - delete cuerpo.tempRecibido; - - cuerpo.LI0 = cuerpo.LI0.slice(0, 29); - cuerpo.TIO = cuerpo.TIO.slice(0, 29); - - promesas.push(knex('PMOVFACT').insert(cuerpo)); + C_HD: '' + }), + ]; + + body.cuerpo.forEach(cuerpo => { + + if (cuerpo.estado != 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0)) { + + promesas.push(knex('AMOVSTOC').insert({ + SEC: cuerpo.COD, + ART: cuerpo.ART, + FEC: body.cabecera.FEC, + CYV: 'C', + TIP: body.cabecera.TIP, + TCO: body.cabecera.TCO, + PVE: body.cabecera.SUC, + NCO: body.cabecera.NCO, + ORD: cuerpo.ORD, + CAN: cuerpo.cantidadRecibida, + PUN: cuerpo.PUN, + COD: body.cabecera.COD, + DTO: cuerpo.DTO, + IMI: cuerpo.IMI, + PLA: 0, + LUG: 0, + ANU: '', + TIM: 'Co', + OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario + IMI2: cuerpo.IMI2, + E_HD: '', + C_HD: '', + JUS: 'PLANEX', + NLC: 0, + IMI3: cuerpo.IMI3, + JJN: '', + JDJ: '', + ID_MOTIVO_NANB: 0 + })); + }; + + cuerpo.estado == 'rechazado' ? cuerpo.cantidadRecibida = 0 : false; + + delete cuerpo.GLN; + delete cuerpo.C_HD2; + delete cuerpo.E_HD2; + delete cuerpo.codigoBarras; + delete cuerpo.estado; + delete cuerpo.recibido; + delete cuerpo.input; + delete cuerpo.tempRecibido; + + cuerpo.LI0 = cuerpo.LI0.slice(0, 29); + cuerpo.TIO = cuerpo.TIO.slice(0, 29); + + promesas.push(knex('PMOVFACT').insert(cuerpo)); - }); + }); - Promise.all(promesas) - .then(function() { + Promise.all(promesas) + .then(function() { - console.log('comprobantes guardados con éxito'); - resolve(); + console.log('comprobantes guardados con éxito'); + resolve(); + + }) + .catch(function(e) { + console.log(e); + reject('Ocurrió un error'); + }); + + }) + .catch(reject); - }) - .catch(function(e) { - console.log(e); - reject('Ocurrió un error'); - }); }); } } diff --git a/index.js b/index.js index f919112..a75b871 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ client.on('open', function open() { switch (message.action) { case 'getEntity': - + data.getEntity(message).then(function(message) { client.send(JSON.stringify(message)); @@ -62,7 +62,7 @@ client.on('close', function clear() { function heartbeat() { console.log('recibiendo ping'); - console.log(`tiempo vivo desde ${tiempoVivo}`); + console.log(`tiempo vivo desde ${tiempoVivo}, ${new Date()}`); clearTimeout(pingTimeout); -- 1.9.1