Commit e528eadf15749ca48786bf5c60697078e5b9cc07
1 parent
c2a1db4112
Exists in
master
guardo pmae antes de todo
Showing
2 changed files
with
94 additions
and
89 deletions
Show diff stats
data/index.js
| ... | ... | @@ -34,7 +34,7 @@ module.exports = function(config) { |
| 34 | 34 | delete body.cabecera.GLN; |
| 35 | 35 | delete body.cabecera.C_HD2; |
| 36 | 36 | delete body.cabecera.E_HD2; |
| 37 | - | |
| 37 | + | |
| 38 | 38 | //smalldatetime |
| 39 | 39 | body.cabecera.FEC = new Date(body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); |
| 40 | 40 | body.cabecera.FECCAI = new Date(body.cabecera.FECCAI).toISOString().slice(0, 19).replace('T', ' '); |
| ... | ... | @@ -42,102 +42,107 @@ module.exports = function(config) { |
| 42 | 42 | //datetime |
| 43 | 43 | body.cabecera.FEV = moment(body.cabecera.FEV).format('YYYYMMDD'); |
| 44 | 44 | body.cabecera.FEP = moment(body.cabecera.FEP).format('YYYYMMDD'); |
| 45 | - | |
| 46 | - var promesas = [ | |
| 47 | - knex('PMAEFACT').insert(body.cabecera), | |
| 48 | - knex('PCOBYPAG').insert({ | |
| 49 | - COD: body.cabecera.COD, | |
| 50 | - FEP: body.cabecera.FEC, | |
| 51 | - TIP: body.cabecera.TIP, | |
| 52 | - TCO: body.cabecera.TCO, | |
| 53 | - SUC: body.cabecera.SUC, | |
| 54 | - NCO: body.cabecera.NCO, | |
| 55 | - IPA: body.cabecera.TOT, | |
| 56 | - SAL: 0, | |
| 57 | - TCA: 1, | |
| 58 | - ZONA: body.cabecera.ZON, | |
| 59 | - FPA: body.cabecera.FPA, | |
| 60 | - REC: 0, | |
| 61 | - FER: '19000101 00:00', | |
| 62 | - PRO: '', | |
| 63 | - FEV: body.cabecera.FEV, | |
| 64 | - ANU: '', | |
| 65 | - PLA: 0, | |
| 66 | - LUG: 0, | |
| 67 | - RES: 0, | |
| 68 | - CCU: 0, | |
| 69 | - UCU: 0, | |
| 70 | - HOS: '', | |
| 71 | - E_HD: '', | |
| 72 | - C_HD: '' | |
| 73 | - }), | |
| 74 | - ]; | |
| 75 | - | |
| 76 | - body.cuerpo.forEach(cuerpo => { | |
| 77 | - | |
| 78 | - if (cuerpo.estado != 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0)) { | |
| 79 | - | |
| 80 | - promesas.push(knex('AMOVSTOC').insert({ | |
| 81 | - SEC: cuerpo.COD, | |
| 82 | - ART: cuerpo.ART, | |
| 83 | - FEC: body.cabecera.FEC, | |
| 84 | - CYV: 'C', | |
| 45 | + | |
| 46 | + knex('PMAEFACT').insert(body.cabecera).then(() => { | |
| 47 | + | |
| 48 | + var promesas = [ | |
| 49 | + knex('PCOBYPAG').insert({ | |
| 50 | + COD: body.cabecera.COD, | |
| 51 | + FEP: body.cabecera.FEC, | |
| 85 | 52 | TIP: body.cabecera.TIP, |
| 86 | 53 | TCO: body.cabecera.TCO, |
| 87 | - PVE: body.cabecera.SUC, | |
| 54 | + SUC: body.cabecera.SUC, | |
| 88 | 55 | NCO: body.cabecera.NCO, |
| 89 | - ORD: cuerpo.ORD, | |
| 90 | - CAN: cuerpo.cantidadRecibida, | |
| 91 | - PUN: cuerpo.PUN, | |
| 92 | - COD: body.cabecera.COD, | |
| 93 | - DTO: cuerpo.DTO, | |
| 94 | - IMI: cuerpo.IMI, | |
| 56 | + IPA: body.cabecera.TOT, | |
| 57 | + SAL: 0, | |
| 58 | + TCA: 1, | |
| 59 | + ZONA: body.cabecera.ZON, | |
| 60 | + FPA: body.cabecera.FPA, | |
| 61 | + REC: 0, | |
| 62 | + FER: '19000101 00:00', | |
| 63 | + PRO: '', | |
| 64 | + FEV: body.cabecera.FEV, | |
| 65 | + ANU: '', | |
| 95 | 66 | PLA: 0, |
| 96 | 67 | LUG: 0, |
| 97 | - ANU: '', | |
| 98 | - TIM: 'Co', | |
| 99 | - OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario | |
| 100 | - IMI2: cuerpo.IMI2, | |
| 68 | + RES: 0, | |
| 69 | + CCU: 0, | |
| 70 | + UCU: 0, | |
| 71 | + HOS: '', | |
| 101 | 72 | E_HD: '', |
| 102 | - C_HD: '', | |
| 103 | - JUS: 'PLANEX', | |
| 104 | - NLC: 0, | |
| 105 | - IMI3: cuerpo.IMI3, | |
| 106 | - JJN: '', | |
| 107 | - JDJ: '', | |
| 108 | - ID_MOTIVO_NANB: 0 | |
| 109 | - })); | |
| 110 | - }; | |
| 111 | - | |
| 112 | - cuerpo.estado == 'rechazado' ? cuerpo.cantidadRecibida = 0 : false; | |
| 113 | - | |
| 114 | - delete cuerpo.GLN; | |
| 115 | - delete cuerpo.C_HD2; | |
| 116 | - delete cuerpo.E_HD2; | |
| 117 | - delete cuerpo.codigoBarras; | |
| 118 | - delete cuerpo.estado; | |
| 119 | - delete cuerpo.recibido; | |
| 120 | - delete cuerpo.input; | |
| 121 | - delete cuerpo.tempRecibido; | |
| 122 | - | |
| 123 | - cuerpo.LI0 = cuerpo.LI0.slice(0, 29); | |
| 124 | - cuerpo.TIO = cuerpo.TIO.slice(0, 29); | |
| 125 | - | |
| 126 | - promesas.push(knex('PMOVFACT').insert(cuerpo)); | |
| 73 | + C_HD: '' | |
| 74 | + }), | |
| 75 | + ]; | |
| 76 | + | |
| 77 | + body.cuerpo.forEach(cuerpo => { | |
| 78 | + | |
| 79 | + if (cuerpo.estado != 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0)) { | |
| 80 | + | |
| 81 | + promesas.push(knex('AMOVSTOC').insert({ | |
| 82 | + SEC: cuerpo.COD, | |
| 83 | + ART: cuerpo.ART, | |
| 84 | + FEC: body.cabecera.FEC, | |
| 85 | + CYV: 'C', | |
| 86 | + TIP: body.cabecera.TIP, | |
| 87 | + TCO: body.cabecera.TCO, | |
| 88 | + PVE: body.cabecera.SUC, | |
| 89 | + NCO: body.cabecera.NCO, | |
| 90 | + ORD: cuerpo.ORD, | |
| 91 | + CAN: cuerpo.cantidadRecibida, | |
| 92 | + PUN: cuerpo.PUN, | |
| 93 | + COD: body.cabecera.COD, | |
| 94 | + DTO: cuerpo.DTO, | |
| 95 | + IMI: cuerpo.IMI, | |
| 96 | + PLA: 0, | |
| 97 | + LUG: 0, | |
| 98 | + ANU: '', | |
| 99 | + TIM: 'Co', | |
| 100 | + OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario | |
| 101 | + IMI2: cuerpo.IMI2, | |
| 102 | + E_HD: '', | |
| 103 | + C_HD: '', | |
| 104 | + JUS: 'PLANEX', | |
| 105 | + NLC: 0, | |
| 106 | + IMI3: cuerpo.IMI3, | |
| 107 | + JJN: '', | |
| 108 | + JDJ: '', | |
| 109 | + ID_MOTIVO_NANB: 0 | |
| 110 | + })); | |
| 111 | + }; | |
| 112 | + | |
| 113 | + cuerpo.estado == 'rechazado' ? cuerpo.cantidadRecibida = 0 : false; | |
| 114 | + | |
| 115 | + delete cuerpo.GLN; | |
| 116 | + delete cuerpo.C_HD2; | |
| 117 | + delete cuerpo.E_HD2; | |
| 118 | + delete cuerpo.codigoBarras; | |
| 119 | + delete cuerpo.estado; | |
| 120 | + delete cuerpo.recibido; | |
| 121 | + delete cuerpo.input; | |
| 122 | + delete cuerpo.tempRecibido; | |
| 123 | + | |
| 124 | + cuerpo.LI0 = cuerpo.LI0.slice(0, 29); | |
| 125 | + cuerpo.TIO = cuerpo.TIO.slice(0, 29); | |
| 126 | + | |
| 127 | + promesas.push(knex('PMOVFACT').insert(cuerpo)); | |
| 127 | 128 | |
| 128 | - }); | |
| 129 | + }); | |
| 129 | 130 | |
| 130 | - Promise.all(promesas) | |
| 131 | - .then(function() { | |
| 131 | + Promise.all(promesas) | |
| 132 | + .then(function() { | |
| 132 | 133 | |
| 133 | - console.log('comprobantes guardados con éxito'); | |
| 134 | - resolve(); | |
| 134 | + console.log('comprobantes guardados con éxito'); | |
| 135 | + resolve(); | |
| 136 | + | |
| 137 | + }) | |
| 138 | + .catch(function(e) { | |
| 139 | + console.log(e); | |
| 140 | + reject('Ocurrió un error'); | |
| 141 | + }); | |
| 142 | + | |
| 143 | + }) | |
| 144 | + .catch(reject); | |
| 135 | 145 | |
| 136 | - }) | |
| 137 | - .catch(function(e) { | |
| 138 | - console.log(e); | |
| 139 | - reject('Ocurrió un error'); | |
| 140 | - }); | |
| 141 | 146 | }); |
| 142 | 147 | } |
| 143 | 148 | } |
index.js
| ... | ... | @@ -21,7 +21,7 @@ client.on('open', function open() { |
| 21 | 21 | |
| 22 | 22 | switch (message.action) { |
| 23 | 23 | case 'getEntity': |
| 24 | - | |
| 24 | + | |
| 25 | 25 | data.getEntity(message).then(function(message) { |
| 26 | 26 | |
| 27 | 27 | client.send(JSON.stringify(message)); |
| ... | ... | @@ -62,7 +62,7 @@ client.on('close', function clear() { |
| 62 | 62 | |
| 63 | 63 | function heartbeat() { |
| 64 | 64 | console.log('recibiendo ping'); |
| 65 | - console.log(`tiempo vivo desde ${tiempoVivo}`); | |
| 65 | + console.log(`tiempo vivo desde ${tiempoVivo}, ${new Date()}`); | |
| 66 | 66 | |
| 67 | 67 | clearTimeout(pingTimeout); |
| 68 | 68 |