Commit 6710c93dc042eba6c6b4ab39511d83a737fbc66b

Authored by Eric Fernandez
1 parent 1798fe5137
Exists in master

RECADV

1 module.exports = function(comprobante, nameFile) { 1 module.exports = function(comprobante, nameFile) {
2 2
3 var promesas = []; 3 var nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1];
4 4
5 promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera)); 5 knex('planex_transacciones')
6 .insert({
7 archivoRecibido: nameFileDest,
8 estado: 0, // Ingresada
9 GLN: comprobante.cabecera.GLN
10 })
11 .returning('id')
12 .then(saveDebo);
13
14 function saveDebo(id) {
15 comprobante.cabecera.idTransaccion = id;
16 var promesas = [knex('PMAEFACT_TEMP').insert(comprobante.cabecera)];
17
18 comprobante.cuerpo.forEach(cuerpo => {
19 promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo));
20 });
6 21
7 comprobante.cuerpo.forEach(cuerpo => { 22 Promise.all(promesas).then(function() {
8 promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo));
9 });
10 23
11 Promise.all(promesas).then(function() { 24 var pathDest = config.dirDestino + '/' + nameFileDest;
12 25
13 nameFileDest = nameFile.split('\\')[nameFile.split('\\').length - 1]; 26 fs.rename(nameFile, pathDest, function(err) {
14 var pathDest = config.dirDestino + '/' + nameFileDest;
15 27
16 fs.rename(nameFile, pathDest, function(err) { 28 if(err) console.log(err);
29 console.log('COMPROBANTE GUARDADO CON ÉXITO');
30 });
31 }).catch(function() {
17 32
18 if(err) console.log(err); 33 console.log('ERROR AL GUARDAR EL COMPROBANTE');
19 console.log('COMPROBANTE GUARDADO CON ÉXITO');
debo/cabeceraDebo.js
1 module.exports = function(comprobante, afipTablas, entities) { 1 module.exports = function(comprobante, afipTablas, entities) {
2 2
3 return { 3 return {
4 TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M,E) 4 TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M,E)
5 TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND,RE,CI,LP) 5 TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND,RE,CI,LP)
6 SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA 6 SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA
7 NCO: parseInt(comprobante.identificaxComprobante.numero), // [bigint] NOT NULL, NUMERO DE COMPROBANTE 7 NCO: parseInt(comprobante.identificaxComprobante.numero), // [bigint] NOT NULL, NUMERO DE COMPROBANTE
8 COD: entities.proveedores.COD, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2' 8 COD: entities.proveedores.COD, // [int] NOT NULL, CODIGO DEL PROVEEDOR NECESITAS RELACION -- BUSCAR SI ENVIAN EL CUIT DEL PROVEEDOR SELECT COD FROM PROVEED WHERE CUIT= '30-54775125-2'
9 FEC: comprobante.identificaxComprobante.fechaComprobante, // [smalldatetime] NULL, FECHA DEL COMPROBANTE 9 FEC: comprobante.identificaxComprobante.fechaComprobante, // [smalldatetime] NULL, FECHA DEL COMPROBANTE
10 NOM: entities.proveedores.NOM, // [varchar](40) NOT NULL, NOMBRE DEL PROVEEDOR TABLA PROVEED CAMPO NOM 10 NOM: entities.proveedores.NOM, // [varchar](40) NOT NULL, NOMBRE DEL PROVEEDOR TABLA PROVEED CAMPO NOM
11 TIV: entities.proveedores.IVA, // [tinyint] NOT NULL, TIPO DE IVA CAMPO IVA TABLA PROVEED 11 TIV: entities.proveedores.IVA, // [tinyint] NOT NULL, TIPO DE IVA CAMPO IVA TABLA PROVEED
12 CUI: entities.proveedores.CUIT, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION 12 CUI: entities.proveedores.CUIT, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION
13 FPA: entities.proveedores.FPA, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED 13 FPA: entities.proveedores.FPA, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED
14 TCA: 1, // [money] NOT NULL, FIJO 1 14 TCA: 1, // [money] NOT NULL, FIJO 1
15 DTO: comprobante.descuentosGlobalesFactura.importe || 0, // [money] NOT NULL, DESCUENTO TOTAL SUMATORIA DE LOS DTO POR ITEM 15 DTO: comprobante.descuentosGlobalesFactura.importe || 0, // [money] NOT NULL, DESCUENTO TOTAL SUMATORIA DE LOS DTO POR ITEM
16 PDT: 0, // [money] NOT NULL, FIJO 0 16 PDT: 0, // [money] NOT NULL, FIJO 0
17 NET: comprobante.importesTotales.netoGravado, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA <> 0 17 NET: comprobante.importesTotales.netoGravado, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA <> 0
18 NEE: comprobante.importesTotales.importeOperacionesExentas, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA = 0 18 NEE: comprobante.importesTotales.importeOperacionesExentas, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA = 0
19 IRI: comprobante.detallesImportesIVA.importeLiquidado, // [money] NOT NULL, SUMATORIA DE LOS IVA POR ITEM 19 IRI: comprobante.detallesImportesIVA.importeLiquidado, // [money] NOT NULL, SUMATORIA DE LOS IVA POR ITEM
20 IRS: 0, // [money] NOT NULL, FIJO 0 20 IRS: 0, // [money] NOT NULL, FIJO 0
21 IMI: comprobante.importesTotales.importeImpuestosInternos, // [money] NOT NULL, SUMATORIA DE LOS IMPUESTOS INTERNOS POR ITEM 21 IMI: comprobante.importesTotales.importeImpuestosInternos, // [money] NOT NULL, SUMATORIA DE LOS IMPUESTOS INTERNOS POR ITEM
22 RGA: 0, // [money] NOT NULL, IMPORTE RETENCION DE GANANCIAS 22 RGA: 0, // [money] NOT NULL, IMPORTE RETENCION DE GANANCIAS
23 RIB: 0, // [money] NOT NULL, IMPORTE RETENCION DE INGRESOS BRUTOS 23 RIB: 0, // [money] NOT NULL, IMPORTE RETENCION DE INGRESOS BRUTOS
24 PIV: comprobante.detalleOtrosImpuestosComprobante.percepcionIVA ? comprobante.detalleOtrosImpuestosComprobante.percepcionIVA.importeImpuesto : 0, // [money] NOT NULL, IMPORTE PERCEPCION DE IVA, SECTOR 90 C05 24 PIV: comprobante.detalleOtrosImpuestosComprobante.percepcionIVA ? comprobante.detalleOtrosImpuestosComprobante.percepcionIVA.importeImpuesto : 0, // [money] NOT NULL, IMPORTE PERCEPCION DE IVA, SECTOR 90 C05
25 CNG: comprobante.importesTotales.totalConceptosNoNetoGravado, // [money] NULL, IMPORTE DE CONCEPTOS NO GRAVADOS 25 CNG: comprobante.importesTotales.totalConceptosNoNetoGravado, // [money] NULL, IMPORTE DE CONCEPTOS NO GRAVADOS
26 TOT: comprobante.importesTotales.totalOperacion, // [money] NOT NULL, IMPORTE TOTAL DE LA FACTURA 26 TOT: comprobante.importesTotales.totalOperacion, // [money] NOT NULL, IMPORTE TOTAL DE LA FACTURA
27 ZON: entities.empresa.ZON, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP 27 ZON: entities.empresa.ZON, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP
28 FEV: comprobante.identificaxComprobante.fechaVencimiento, // [datetime] NULL, FECHA DE VENCIMIENTO 28 FEV: comprobante.identificaxComprobante.fechaVencimiento, // [datetime] NULL, FECHA DE VENCIMIENTO
29 OCP: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [char](10) NOT NULL, SI VIENE LA ORDEN DE COMPRA FORMATO "0000000000" (DOS PRIMERO PARA PVE Y 8 ULTIMOS EL NUMERO DE LA OC) 29 OCP: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [char](10) NOT NULL, SI VIENE LA ORDEN DE COMPRA FORMATO "0000000000" (DOS PRIMERO PARA PVE Y 8 ULTIMOS EL NUMERO DE LA OC)
30 OPE: 0, // [int] NOT NULL, FIJO 0 30 OPE: 0, // [int] NOT NULL, FIJO 0
31 REC: 0, // [bigint] NOT NULL, FIJO 0 31 REC: 0, // [bigint] NOT NULL, FIJO 0
32 FEP: comprobante.identificaxComprobante.fechaComprobante, // [datetime] NULL, ITEM FECHA FACTURA 32 FEP: comprobante.identificaxComprobante.fechaComprobante, // [datetime] NULL, ITEM FECHA FACTURA
33 NPE: 0, // [bigint] NOT NULL, NOTA DE PEDIDO FIJO 0 33 NPE: 0, // [bigint] NOT NULL, NOTA DE PEDIDO FIJO 0
34 CPA: 0, // [int] NOT NULL, FIJO 0 34 CPA: 0, // [int] NOT NULL, FIJO 0
35 ENV: 0, // [int] NOT NULL, FIJO 0 35 ENV: 0, // [int] NOT NULL, FIJO 0
36 REM: 0, // [bigint] NOT NULL, FIJO 0 36 REM: 0, // [bigint] NOT NULL, FIJO 0
37 PRO: ' ', // [char](1) NOT NULL, FIJO ' ' VACIO NO NULO 37 PRO: ' ', // [char](1) NOT NULL, FIJO ' ' VACIO NO NULO
38 ANU: ' ', // [char](1) NOT NULL, FIJO ' ' VACIO NO NULO 38 ANU: ' ', // [char](1) NOT NULL, FIJO ' ' VACIO NO NULO
39 TUR: 0, // [int] NOT NULL, FIJO 0 39 TUR: 0, // [int] NOT NULL, FIJO 0
40 PLA: 0, // [int] NOT NULL, FIJO 0 40 PLA: 0, // [int] NOT NULL, FIJO 0
41 LUG: 0, // [int] NOT NULL, FIJO 0 41 LUG: 0, // [int] NOT NULL, FIJO 0
42 ATO: 0, // [numeric](18, 0) NOT NULL, FIJO 0 42 ATO: 0, // [numeric](18, 0) NOT NULL, FIJO 0
43 CCO: 0, // [bigint] NOT NULL, FIJO 0 43 CCO: 0, // [bigint] NOT NULL, FIJO 0
44 IMA: 0, // [int] NOT NULL, FIJO 0 44 IMA: 0, // [int] NOT NULL, FIJO 0
45 CCA1: 0, // [int] NOT NULL, FIJO 0 45 CCA1: 0, // [int] NOT NULL, FIJO 0
46 CCA2: 0, // [int] NOT NULL, FIJO 0 46 CCA2: 0, // [int] NOT NULL, FIJO 0
47 CCA3: 0, // [int] NOT NULL, FIJO 0 47 CCA3: 0, // [int] NOT NULL, FIJO 0
48 CCA4: 0, // [int] NOT NULL, FIJO 0 48 CCA4: 0, // [int] NOT NULL, FIJO 0
49 CCA5: 0, // [int] NOT NULL, FIJO 0 49 CCA5: 0, // [int] NOT NULL, FIJO 0
50 CCA6: 0, // [int] NOT NULL, FIJO 0 50 CCA6: 0, // [int] NOT NULL, FIJO 0
51 CCA7: 0, // [int] NOT NULL, FIJO 0 51 CCA7: 0, // [int] NOT NULL, FIJO 0
52 CCA8: 0, // [int] NOT NULL, FIJO 0 52 CCA8: 0, // [int] NOT NULL, FIJO 0
53 CCA0: 0, // [int] NOT NULL, FIJO 0 53 CCA0: 0, // [int] NOT NULL, FIJO 0
54 OBS: comprobante.importesTotales.observaciones, // [varchar](60) NOT NULL, SI VIENEN OBSERVACIONES PONER AQUI SINO VACIO NO NULO 54 OBS: comprobante.importesTotales.observaciones, // [varchar](60) NOT NULL, SI VIENEN OBSERVACIONES PONER AQUI SINO VACIO NO NULO
55 RIV: 0, // [money] NOT NULL, IMPORTE RETENCION DE IVA 55 RIV: 0, // [money] NOT NULL, IMPORTE RETENCION DE IVA
56 FECCAI: comprobante.identificaxComprobante.fechaVencimientoCai, // [smalldatetime] NOT NULL, FECHA DEL CAI 56 FECCAI: comprobante.identificaxComprobante.fechaVencimientoCai, // [smalldatetime] NOT NULL, FECHA DEL CAI
57 CAI: comprobante.identificaxComprobante.cai, // [char](16) NOT NULL, NUMERO DE CAI 57 CAI: comprobante.identificaxComprobante.cai, // [char](16) NOT NULL, NUMERO DE CAI
58 CHO: 0, // [int] NOT NULL, FIJO 0 58 CHO: 0, // [int] NOT NULL, FIJO 0
59 CTR: '', // [char](1) NOT NULL, VACIO NO NULO 59 CTR: '', // [char](1) NOT NULL, VACIO NO NULO
60 PER: comprobante.importesTotales.importeIB, // [money] NOT NULL, IMPORTE DE PERCEPCIONES 60 PER: comprobante.importesTotales.importeIB, // [money] NOT NULL, IMPORTE DE PERCEPCIONES
61 CCA9: 0, // [int] NOT NULL, FIJO 0 61 CCA9: 0, // [int] NOT NULL, FIJO 0
62 FECVEN: comprobante.identificaxComprobante.fechaVencimiento, // [smalldatetime] NOT NULL, FECHA DE VENCIMIENTO DE LA FACTURA 62 FECVEN: comprobante.identificaxComprobante.fechaVencimiento, // [smalldatetime] NOT NULL, FECHA DE VENCIMIENTO DE LA FACTURA
63 CNG2: 0, // [money] NOT NULL, IMPORTE DE CONCEPTOS NO GRAVADOS 2 63 CNG2: 0, // [money] NOT NULL, IMPORTE DE CONCEPTOS NO GRAVADOS 2
64 E_HD: '', // [varchar](8) NOT NULL, VACIO NO NULO 64 E_HD: '', // [varchar](8) NOT NULL, VACIO NO NULO
65 C_HD: '', // [varchar](1) NOT NULL, VACIO NO NULO 65 C_HD: '', // [varchar](1) NOT NULL, VACIO NO NULO
66 RSS: 0, // [money] NOT NULL, IMPORTE RETENCIONS SUSS 66 RSS: 0, // [money] NOT NULL, IMPORTE RETENCIONS SUSS
67 E_HD2: '', // [varchar](12) NOT NULL, VACIO NO NULO 67 E_HD2: '', // [varchar](12) NOT NULL, VACIO NO NULO
68 C_HD2: '', // [varchar](1) NOT NULL, VACIO NO NULO 68 C_HD2: '', // [varchar](1) NOT NULL, VACIO NO NULO
69 DTO2: 0, // [money] NOT NULL, IMPORTE DE OTROS DESCUENTOS 69 DTO2: 0, // [money] NOT NULL, IMPORTE DE OTROS DESCUENTOS
70 ENLP: 0, // [bit] NOT NULL, FIJO 0 70 ENLP: 0, // [bit] NOT NULL, FIJO 0
71 COD_TRANS: comprobante.identificaxComprobante.numeroRegistrado || 0, // [bigint] NOT NULL, VER DE PONER EL NUMERO DE REFERENCIA QUE PUEDA UNIRNOS A LO QUE VIENE DESDE PLANEX 71 COD_TRANS: comprobante.identificaxComprobante.numeroRegistrado || 0, // [bigint] NOT NULL, VER DE PONER EL NUMERO DE REFERENCIA QUE PUEDA UNIRNOS A LO QUE VIENE DESDE PLANEX
72 RETMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE DE RETENCIONES MUNICIPALES 72 RETMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE DE RETENCIONES MUNICIPALES
73 TIPO_OPERACION: 0, // [int] NOT NULL, FIJO 0 73 TIPO_OPERACION: 0, // [int] NOT NULL, FIJO 0
74 IRD: 0, // [money] NOT NULL, FIJO 0 74 IRD: 0, // [money] NOT NULL, FIJO 0
75 AUX1: 0, // [money] NOT NULL, FIJO 0 75 AUX1: 0, // [money] NOT NULL, FIJO 0
76 AUX2: 0, // [money] NOT NULL, FIJO 0 76 AUX2: 0, // [money] NOT NULL, FIJO 0
77 AUX3: 0, // [money] NOT NULL, FIJO 0 77 AUX3: 0, // [money] NOT NULL, FIJO 0
78 AUX4: 0, // [money] NOT NULL, FIJO 0 78 AUX4: 0, // [money] NOT NULL, FIJO 0
79 ARBA: 0, // [money] NOT NULL, IMPORTE RETENCION ARBA 79 ARBA: 0, // [money] NOT NULL, IMPORTE RETENCION ARBA
80 DGR: 0, // [money] NOT NULL, IMPORTE RETENCION DGR 80 DGR: 0, // [money] NOT NULL, IMPORTE RETENCION DGR
81 DTO_PIE: 0, // [money] NOT NULL, IMPORTE DE DESCUENTO AL PIE, NO POR ITEM 81 DTO_PIE: 0, // [money] NOT NULL, IMPORTE DE DESCUENTO AL PIE, NO POR ITEM
82 OPERACIONES_3711: 1, // [int] NOT NULL, FIJO 1 (PORQUE SON BIENES) 82 OPERACIONES_3711: 1, // [int] NOT NULL, FIJO 1 (PORQUE SON BIENES)
83 ORC: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA 83 ORC: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA
84 NC_ES_NP: 0, // [bit] NOT NULL, FIJO 0 84 NC_ES_NP: 0, // [bit] NOT NULL, FIJO 0
85 CABA: 0, // [money] NOT NULL, IMPORTE RETENCION CABA 85 CABA: 0, // [money] NOT NULL, IMPORTE RETENCION CABA
86 ARBA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION ARBA 86 ARBA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION ARBA
87 CABA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION CABA 87 CABA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION CABA
88 PERMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE PERCEPCIONES MUNICIPALES 88 PERMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE PERCEPCIONES MUNICIPALES
89 IMI2: 0, // [money] NOT NULL, FIJO 0 89 IMI2: 0, // [money] NOT NULL, FIJO 0
90 gln: comprobante.identificaxSucursalReceptorFactura.glnSucursal 90 GLN: comprobante.identificaxSucursalReceptorFactura.glnSucursal
91 }; 91 };
92 } 92 }
93 93
File was created 1 // Update with your config settings.
2
3 module.exports = {
4
5 development: {
6 client: 'mssql',
7 connection: {
8 host: '10.231.45.211',
9 user: 'sa',
10 password: 'xxzza',
11 database: 'UNITYOIL_28082017'
12 }
13 },
14
15 staging: {
16 client: 'postgresql',
17 connection: {
18 database: 'my_db',
19 user: 'username',
20 password: 'password'
21 },
22 pool: {
23 min: 2,
24 max: 10
25 },
26 migrations: {
27 tableName: 'knex_migrations'
28 }
29 },
30
31 production: {
32 client: 'postgresql',
33 connection: {
34 database: 'my_db',
35 user: 'username',
36 password: 'password'
37 },
38 pool: {
39 min: 2,
40 max: 10
41 },
42 migrations: {
43 tableName: 'knex_migrations'
44 }
45 }
46
47 };
48
migrations/20190626112130_v0.0.1.js
File was created 1
2 exports.up = function(knex, Promise) {
3 return Promise.all([
4 knex.schema
5 .createTable('planex_transacciones', function(table) {
6
7 table.increments();
8 table.string('archivoRecibido', 1024);
9 table.string('archivoEnviado', 1024);
10 // 0: insertado, 1 enviado
11 table.integer('estado');
12 table.string('apies');
13 table.string('GLN');
14 })
15 .table('PMAEFACT_TEMP', function(table) {
16
17 table.string('GLN');
18 table.bigInteger('idTransaccion');
19 })
20 .table('PMOVFACT_TEMP', function(table) {
21
22 table.string('GLN');
23 table.bigInteger('codigoBarras');
24 })
25 ]);
26 };
27
28 exports.down = function(knex, Promise) {
29 return Promise.all([
30 knex.schema
31 .dropTable('planex_transacciones')
32 .table('PMAEFACT_TEMP', function(table) {
33
34 table.dropColumns('GLN', 'idTransaccion');
35 })
36 ]);
37 };
38
1 { 1 {
2 "name": "websocketho", 2 "name": "websocketho",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "WebSocket Head Office", 4 "description": "WebSocket Head Office",
5 "main": "index.js", 5 "main": "index.js",
6 "dependencies": { 6 "dependencies": {
7 "chokidar": "^3.0.1", 7 "chokidar": "^3.0.1",
8 "express": "^4.17.1", 8 "express": "^4.17.1",
9 "knex": "^0.16.5", 9 "knex": "^0.16.5",
10 "moment": "^2.24.0", 10 "moment": "^2.24.0",
11 "mssql": "^5.1.0",
12 "ws": "^7.0.0" 11 "ws": "^7.0.0"
13 }, 12 },
14 "devDependencies": { 13 "devDependencies": {
14 "mssql": "^5.1.0",
15 "nodemon": "^1.19.1" 15 "nodemon": "^1.19.1"
16 }, 16 },
17 "scripts": { 17 "scripts": {
18 "test": "echo \"Error: no test specified\" && exit 1", 18 "test": "echo \"Error: no test specified\" && exit 1",
19 "dev": "nodemon index.js" 19 "dev": "nodemon index.js"
20 }, 20 },
21 "author": "Foca Software", 21 "author": "Foca Software",
22 "license": "ISC" 22 "license": "ISC"
23 } 23 }
recadv/datosArticulos.js
File was created 1 module.exports = function(cuerpo, index, parseToFijo) {
2
3 return '110;' +
4 index + ';' +
5 cuerpo.codigoBarras + ';' +
6 cuerpo.COD + '-' + cuerpo.ART + ';;' +
7 cuerpo.TIO + ';' +
8 parseToFijo(cuerpo.PUN, 4, 15) + ';' +
9 moment().format('YYYYMMDD') + ';;';
10 }
11
recadv/datosCabecera.js
File was created 1 module.exports = function(comprobante, idTransaccion) {
2
3 return '010;' +
4 idTransaccion + ';' +
5 9 + ';' +
6 moment().format('YYYYMMDD') + ';' +
7 moment().format('YYYYMMDD') + ';';
8 }
9
recadv/datosCantidadArticulos.js
File was created 1 module.exports = function(cuerpo, index) {
2
3 cuerpo.estado == 'rechazado' ? cuerpo.CAN = 0 : false;
4
5 var cantidadRecibida = cuerpo.recibido ? cuerpo.recibido : cuerpo.CAN;
6
7 return '111;' +
8 index + ';' +
9 45 + ';' +
10 cantidadRecibida + ';';
11 }
12
recadv/datosComprador.js
File was created 1 module.exports = function(comprobante) {
2
3 return '030;' + comprobante.identificaxSucursalReceptorFactura.glnSucursal + ';' +
4 comprobante.identificaxSucursalReceptorFactura.numeroDocumento + ';;;;;;;;;;;';//TODO si se requieren mas datos
5 }
6
recadv/datosIndentificacionMensaje.js
File was created 1 module.exports = function(comprobante) {
2
3 return '000;RECADV;' +
4 comprobante.identificaxEmisor.glnEmisor + ';' +
5 comprobante.identificaxReceptorFactura.glnReceptor + ';' +
6 comprobante.identificaxMensaje.idMensaje;
7 }
8
recadv/datosProveedor.js
File was created 1 module.exports = function(comprobante) {
2
3 return '040;' + comprobante.identificaxEmisor.glnEmisor + ';' +
4 comprobante.identificaxEmisor.glnEmisor + ';;;;;;;;;;;;'
5 }
6
File was created 1 module.exports = function(comprobante, cuerpos) {
2
3 var idTransaccion = comprobante.idTransaccion;
4
5 knex('planex_transacciones')
6 .where({ id: idTransaccion } )
7 .then(function(transax) {
8
9 transax = transax[0];
10
11 fs.readFile(config.dirDestino + '\\' + transax.archivoRecibido, 'utf8', function(err, fileString) {
12
13 if (err) {
14 console.log(err);
15 return;
16 }
17
18 var planex = require('../planex')(fileString);
19
20 var result = require('./todos')(planex, cuerpos, fileString, idTransaccion);
21
22 var nombreRecadv = 'RECADV_' + planex.identificaxMensaje.idMensaje + '.txt';
23
24 fs.writeFile(config.dirRecadv + '/' + nombreRecadv, result, function(err) {
25
26 if (err) return console.log(err);
27
28 knex('planex_transacciones')
29 .where({ id: idTransaccion })
30 .update({ archivoEnviado: nombreRecadv, estado: 1 })
31 .then(function() {
32
33 console.log('Archivo Pruebas guardado');
34 });
35
36 });
37
38 });
39
40 });
41 }
42
File was created 1 module.exports = function(planex, cuerpos, fileString, idTransaccion) {
2
3 var result = require('./datosIndentificacionMensaje')(planex) + '\r\n';
4
5 result += require('./datosCabecera')(planex, idTransaccion) + '\r\n';
6
7 fileString = fileString.split(/\r?\n/);
8
9 fileString.forEach(bloque => {
10
11 if (bloque.slice(0, 3) == '020') {
12 result += bloque + '\r\n';
13 }
14
15 });
16
17 result += require('./datosComprador')(planex);
18 result += require('./datosProveedor')(planex);
19
20 cuerpos.forEach((cuerpo, index) => {
21 result += require('./datosArticulos')(cuerpo, index, decimalToFijo) + '\r\n';
22 });
23
24 cuerpos.forEach((cuerpo, index) => {
25 result += require('./datosCantidadArticulos')(cuerpo, index) + '\r\n';
26 });
27
28 result += require('./totalControl')(cuerpos.length);
29
30 return result;
31 };
32
33 function decimalToFijo(decimal, cantidadDecimales, fijo) {
34
35 decimal = decimal.toString().split('.');
36
37 decimal[1] = rellenar(decimal[1] || '0', cantidadDecimales, false);
38
39 decimal = rellenar(decimal[0] + decimal[1], fijo, true);
40
41 function rellenar(aRellenar, cantidad, left) {
42
43 for (let i = 0; i <= cantidad - aRellenar.length; i++) {
44 left ? aRellenar = '0' + aRellenar : aRellenar = aRellenar + '0';
45 }
46
47 return aRellenar;
48 }
49
50 return decimal;
51 }
52
53
recadv/totalControl.js
File was created 1 module.exports = function(totalLineas) {
2
3 return '140;' + totalLineas;
4 }
5
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
47 require('../recadv')(
48 JSON.parse(JSON.stringify(req.body.cabecera)),
49 JSON.parse(JSON.stringify(req.body.cuerpo)));
50
51 delete req.body.cabecera.idTransaccion;
52 delete req.body.cabecera.GLN;
47 delete req.body.cabecera.C_HD2; 53 delete req.body.cabecera.C_HD2;
48 delete req.body.cabecera.E_HD2; 54 delete req.body.cabecera.E_HD2;
49 55
50 //smalldatetime 56 //smalldatetime
51 req.body.cabecera.FEC = new Date(req.body.cabecera.FEC).toISOString().slice(0, 19).replace('T', ' '); 57 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', ' '); 58 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', ' '); 59 req.body.cabecera.FECVEN = new Date(req.body.cabecera.FECVEN).toISOString().slice(0, 19).replace('T', ' ');
54 60
55 //datetime 61 //datetime
56 req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD'); 62 req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD');
57 req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD'); 63 req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD');
58 64
59 var promesas = [ 65 var promesas = [
60 knex('PMAEFACT').insert(req.body.cabecera), 66 knex('PMAEFACT').insert(req.body.cabecera),
61 knex('PCOBYPAG').insert({ 67 knex('PCOBYPAG').insert({
62 COD: req.body.cabecera.COD, 68 COD: req.body.cabecera.COD,
63 FEP: req.body.cabecera.FEC, 69 FEP: req.body.cabecera.FEC,
64 TIP: req.body.cabecera.TIP, 70 TIP: req.body.cabecera.TIP,
65 TCO: req.body.cabecera.TCO, 71 TCO: req.body.cabecera.TCO,
66 SUC: req.body.cabecera.SUC, 72 SUC: req.body.cabecera.SUC,
67 NCO: req.body.cabecera.NCO, 73 NCO: req.body.cabecera.NCO,
68 IPA: req.body.cabecera.TOT, 74 IPA: req.body.cabecera.TOT,
69 SAL: 0, 75 SAL: 0,
70 TCA: 1, 76 TCA: 1,
71 ZONA: req.body.cabecera.ZON, 77 ZONA: req.body.cabecera.ZON,
72 FPA: req.body.cabecera.FPA, 78 FPA: req.body.cabecera.FPA,
73 REC: 0, 79 REC: 0,
74 FER: '19000101 00:00', 80 FER: '19000101 00:00',
75 PRO: '', 81 PRO: '',
76 FEV: req.body.cabecera.FEV, 82 FEV: req.body.cabecera.FEV,
77 ANU: '', 83 ANU: '',
78 PLA: 0, 84 PLA: 0,
79 LUG: 0, 85 LUG: 0,
80 RES: 0, 86 RES: 0,
81 CCU: 0, 87 CCU: 0,
82 UCU: 0, 88 UCU: 0,
83 HOS: '', 89 HOS: '',
84 E_HD: '', 90 E_HD: '',
85 C_HD: '' 91 C_HD: ''
86 }) 92 })
87 ]; 93 ];
88 94
89 req.body.cuerpo.forEach(cuerpo => { 95 req.body.cuerpo.forEach(cuerpo => {
90 96
91 if (cuerpo.estado = 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0 && cuerpo.RUB == 0)) { 97 if (cuerpo.estado = 'rechazado' && !(cuerpo.COD == 0 && cuerpo.ART == 0 && cuerpo.RUB == 0)) {
92 98
93 promesas.push(knex('AMOVSTOC').insert({ 99 promesas.push(knex('AMOVSTOC').insert({
94 SEC: cuerpo.COD, 100 SEC: cuerpo.COD,
95 ART: cuerpo.ART, 101 ART: cuerpo.ART,
96 FEC: req.body.cabecera.FEC, 102 FEC: req.body.cabecera.FEC,
97 CYV: 'C', 103 CYV: 'C',
98 TIP: req.body.cabecera.TIP, 104 TIP: req.body.cabecera.TIP,
99 TCO: req.body.cabecera.TCO, 105 TCO: req.body.cabecera.TCO,
100 PVE: req.body.cabecera.SUC, 106 PVE: req.body.cabecera.SUC,
101 NCO: req.body.cabecera.NCO, 107 NCO: req.body.cabecera.NCO,
102 ORD: cuerpo.ORD, 108 ORD: cuerpo.ORD,
103 CAN: cuerpo.recibido || cuerpo.CAN, 109 CAN: cuerpo.recibido || cuerpo.CAN,
104 PUN: cuerpo.PUN, 110 PUN: cuerpo.PUN,
105 COD: req.body.cabecera.COD, 111 COD: req.body.cabecera.COD,
106 DTO: cuerpo.DTO, 112 DTO: cuerpo.DTO,
107 IMI: cuerpo.IMI, 113 IMI: cuerpo.IMI,
108 PLA: 0, 114 PLA: 0,
109 LUG: 0, 115 LUG: 0,
110 ANU: '', 116 ANU: '',
111 TIM: 'Co', 117 TIM: 'Co',
112 OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario 118 OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario
113 IMI2: cuerpo.IMI2, 119 IMI2: cuerpo.IMI2,
114 E_HD: '', 120 E_HD: '',
115 C_HD: '', 121 C_HD: '',
116 JUS: 'PLANEX', 122 JUS: 'PLANEX',
117 NLC: 0, 123 NLC: 0,
118 IMI3: cuerpo.IMI3, 124 IMI3: cuerpo.IMI3,
119 JJN: '', 125 JJN: '',
120 JDJ: '', 126 JDJ: '',
121 ID_MOTIVO_NANB: 0 127 ID_MOTIVO_NANB: 0
122 })); 128 }));
123 }; 129 };
124 130
125 cuerpo.estado == 'rechazado' ? cuerpo.CAN = 0 : false; 131 cuerpo.estado == 'rechazado' ? cuerpo.CAN = 0 : false;
126 132
127 delete cuerpo.gln; 133 delete cuerpo.GLN;
128 delete cuerpo.C_HD2; 134 delete cuerpo.C_HD2;
129 delete cuerpo.E_HD2; 135 delete cuerpo.E_HD2;
130 delete cuerpo.codigoBarras; 136 delete cuerpo.codigoBarras;
131 delete cuerpo.estado; 137 delete cuerpo.estado;
132 delete cuerpo.recibido; 138 delete cuerpo.recibido;
133 delete cuerpo.input; 139 delete cuerpo.input;
134 delete cuerpo.tempRecibido; 140 delete cuerpo.tempRecibido;
135 141
136 cuerpo.LI0 = cuerpo.LI0.slice(0, 29); 142 cuerpo.LI0 = cuerpo.LI0.slice(0, 29);
137 cuerpo.TIO = cuerpo.TIO.slice(0, 29); 143 cuerpo.TIO = cuerpo.TIO.slice(0, 29);
138 144
139 promesas.push(knex('PMOVFACT').insert(cuerpo)); 145 promesas.push(knex('PMOVFACT').insert(cuerpo));
140 146
141 }); 147 });
142 148
143 Promise.all(promesas) 149 Promise.all(promesas)
144 .then(function() { 150 .then(function() {
145 151
146 Promise.all([ 152 Promise.all([
147 knex('PMAEFACT_TEMP').where({ 153 knex('PMAEFACT_TEMP').where({
148 TIP: req.body.cabecera.TIP, 154 TIP: req.body.cabecera.TIP,
149 TCO: req.body.cabecera.TCO, 155 TCO: req.body.cabecera.TCO,
150 SUC: req.body.cabecera.SUC, 156 SUC: req.body.cabecera.SUC,
151 NCO: req.body.cabecera.NCO, 157 NCO: req.body.cabecera.NCO,
152 COD: req.body.cabecera.COD 158 COD: req.body.cabecera.COD
153 }) 159 })
154 .del(), 160 .del(),
155 knex('PMOVFACT_TEMP').where({ 161 knex('PMOVFACT_TEMP').where({
156 TIP: req.body.cabecera.TIP, 162 TIP: req.body.cabecera.TIP,
157 TCO: req.body.cabecera.TCO, 163 TCO: req.body.cabecera.TCO,
158 SUC: req.body.cabecera.SUC, 164 SUC: req.body.cabecera.SUC,
159 NCO: req.body.cabecera.NCO 165 NCO: req.body.cabecera.NCO
160 }) 166 })
161 .del() 167 .del()
162 ]).then(function() { 168 ]).then(function() {
163 169
164 console.log('comprobantes guardados con éxito'); 170 console.log('comprobantes guardados con éxito');
165 res.status(201).send(); 171 res.status(201).send();
166 }) 172 })
167 173
168 }) 174 })
169 .catch(function(e) { 175 .catch(function(e) {
170 console.log(e); 176 console.log(e);
171 res.status(500).send(e); 177 res.status(500).send(e);
172 }); 178 });
173 179
174 }); 180 });
175 181