Merge Request #6

Merged
Created by Eric Fernandez

Master(efernandez)

Assignee: Eric Fernandez
Milestone: None

Merged by Eric Fernandez

Commits (5)
1 participants
File was created 1 module.exports = function(comprobante) {
2
3 var promesas = [];
4
5 promesas.push(knex('PMAEFACT_TEMP').insert(comprobante.cabecera));
6
7 comprobante.cuerpo.forEach(cuerpo => {
8 promesas.push(knex('PMOVFACT_TEMP').insert(cuerpo));
9 });
10
11 Promise.all(promesas).then(function() {
12
13 console.log('COMPROBANTE GUARDADO CON ÉXITO');
14 }).catch(function() {
15
16 console.log('ERROR AL GUARDAR EL COMPROBANTE');
17 });
18 }
1 module.exports = function(comprobante) { 19
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
1 module.exports = function(comprobante, afipTablas, entities, item) { 1 module.exports = function(comprobante, afipTablas, entities, item) {
2 2
3 return { 3 return {
4 TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M) 4 TIP: afipTablas(comprobante.identificaxComprobante.tipo).letraComprobante, // [char](1) NOT NULL, LETRA DEL COMPROBANTE (A,B,C,M)
5 TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND) 5 TCO: afipTablas(comprobante.identificaxComprobante.tipo).tipoComprobante, // [char](2) NOT NULL, TIPO DE COMPROBANTE (FT,NC,ND)
6 SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA DE LA FACTURA 6 SUC: parseInt(comprobante.identificaxComprobante.puntoVenta), // [int] NOT NULL, PUNTO DE VENTA DE LA FACTURA
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 PRO: 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 PRO: 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 ORD: parseInt(item.numeroLinea), // [int] NOT NULL, ORDEN DEL ITEM, EMPIEZA EN 1 Y SUMA DE A 1 POR CADA REGISTRO DE MOVIMIENTO 9 ORD: parseInt(item.numeroLinea), // [int] NOT NULL, ORDEN DEL ITEM, EMPIEZA EN 1 Y SUMA DE A 1 POR CADA REGISTRO DE MOVIMIENTO
10 COD: item.CodSec, // [int] NOT NULL, SECTOR DEBO DEL PRODUCTO 10 COD: item.CodSec, // [int] NOT NULL, SECTOR DEBO DEL PRODUCTO
11 ART: item.CodArt, // [int] NOT NULL, ARTICULO DEBO DEL PRODUCTO ESTOS 2 SE OBTIENEN A PARTIR DEL CODIGO DE BARRAS: SELECT CodSec AS SECTOR,CodArt AS ARTICULO FROM CODBAR WHERE CODBAR='03239210540' 11 ART: item.CodArt, // [int] NOT NULL, ARTICULO DEBO DEL PRODUCTO ESTOS 2 SE OBTIENEN A PARTIR DEL CODIGO DE BARRAS: SELECT CodSec AS SECTOR,CodArt AS ARTICULO FROM CODBAR WHERE CODBAR='03239210540'
12 RUB: item.CodRub, // [int] NOT NULL, CODIGO DE RUBRO SE OBTIENE DE LA TABLA ARTICULOS SELECT DET_LAR,CODRUB FROM ARTICULOS WHERE CODSEC=SECTOR AND CODART=ARTICULO (DATOS OBTENIDOS EN NOTA ANTERIOR 12 RUB: item.CodRub, // [int] NOT NULL, CODIGO DE RUBRO SE OBTIENE DE LA TABLA ARTICULOS SELECT DET_LAR,CODRUB FROM ARTICULOS WHERE CODSEC=SECTOR AND CODART=ARTICULO (DATOS OBTENIDOS EN NOTA ANTERIOR
13 TIO: item.DET_LAR, // [varchar](60) NOT NULL DESCRIPCION DEL PRODUCTO DEL PUNTO ANTERIOR DET_LAR 13 TIO: item.DET_LAR, // [varchar](60) NOT NULL DESCRIPCION DEL PRODUCTO DEL PUNTO ANTERIOR DET_LAR
14 LI0: item.descripcion, // [varchar](60) NOT NULL, DESCRIPCION ENVIADA POR EL PROVEEDOR 14 LI0: item.descripcion, // [varchar](60) NOT NULL, DESCRIPCION ENVIADA POR EL PROVEEDOR
15 CAN: item.cantidad, // [money] NOT NULL, CANTIDAD DEL ITEM 15 CAN: item.cantidad, // [money] NOT NULL, CANTIDAD DEL ITEM
16 PUN: item.precioUnitario, // [decimal](20, 8) NOT NULL PRECIO UNITARIO DEL PRODUCTO ITEM 16 PUN: item.precioUnitario, // [decimal](20, 8) NOT NULL PRECIO UNITARIO DEL PRODUCTO ITEM
17 IMI: item.impuestoInterno ? item.impuestoInterno.importeImpuesto : 0, // [money] NOT NULL, IMPORTE IMPUESTOS INTERNOS DEL ITEM 17 IMI: item.impuestoInterno ? item.impuestoInterno.importeImpuesto : 0, // [money] NOT NULL, IMPORTE IMPUESTOS INTERNOS DEL ITEM
18 IVA: item.importeIVA, // [money] NOT NULL, IMPORTE IVA DEL ITEM 18 IVA: item.importeIVA, // [money] NOT NULL, IMPORTE IVA DEL ITEM
19 PUT: item.precioUnitario, // [money] NOT NULL, IGUAL AL PUN 19 PUT: item.precioUnitario, // [money] NOT NULL, IGUAL AL PUN
20 LEG: 0, // [int] NOT NULL, FIJO 0 20 LEG: 0, // [int] NOT NULL, FIJO 0
21 CMF: 0, // [int] NOT NULL, FIJO 0 21 CMF: 0, // [int] NOT NULL, FIJO 0
22 TUR: 0, // [int] NOT NULL, FIJO 0 22 TUR: 0, // [int] NOT NULL, FIJO 0
23 PLA: 0, // [int] NOT NULL, FIJO 0 23 PLA: 0, // [int] NOT NULL, FIJO 0
24 LUG: 0, // [int] NOT NULL, FIJO 0 24 LUG: 0, // [int] NOT NULL, FIJO 0
25 ESC: 0, // [bit] NOT NULL, FIJO 0 25 ESC: 0, // [bit] NOT NULL, FIJO 0
26 TAN: 0, // [int] NOT NULL, FIJO 0 26 TAN: 0, // [int] NOT NULL, FIJO 0
27 CCO: 0, // [bigint] NOT NULL, FIJO 0 27 CCO: 0, // [bigint] NOT NULL, FIJO 0
28 E_HD: '', // [varchar](8) NOT NULL, FIJO '' VACIO NO NULO 28 E_HD: '', // [varchar](8) NOT NULL, FIJO '' VACIO NO NULO
29 C_HD: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO 29 C_HD: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO
30 DTO: 0, // Comprobante.detalleDescuentosItemFactura.importeDescuento; [money] NOT NULL, IMPORTE DESCUENTO DE LA FACTURA 30 DTO: 0, // Comprobante.detalleDescuentosItemFactura.importeDescuento; [money] NOT NULL, IMPORTE DESCUENTO DE LA FACTURA
31 PTA: 0, // [int] NOT NULL, FIJO 0 31 PTA: 0, // [int] NOT NULL, FIJO 0
32 SUBM: 0, // [int] NOT NULL, FIJO 0 32 SUBM: 0, // [int] NOT NULL, FIJO 0
33 E_HD2: '', // [varchar](12) NOT NULL, FIJO '' VACIO NO NULO 33 E_HD2: '', // [varchar](12) NOT NULL, FIJO '' VACIO NO NULO
34 C_HD2: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO 34 C_HD2: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO
35 COMISION: 0, // [money] NOT NULL, FIJO 0 35 COMISION: 0, // [money] NOT NULL, FIJO 0
36 LIQ_VTA: '', // [varchar](20) NOT NULL, FIJO '' VACIO NO NULO 36 LIQ_VTA: '', // [varchar](20) NOT NULL, FIJO '' VACIO NO NULO
37 COSTO_PMOV: comprobante.itemsFactura.precioUnitario, // [money] NOT NULL, IGUAL AL PUN 37 COSTO_PMOV: comprobante.itemsFactura.precioUnitario, // [money] NOT NULL, IGUAL AL PUN
38 SAL_ITEM: 0, // [money] NOT NULL, fijo 0 es el que se llenara al mostrar en la tablet o telefono para que llene operador 38 SAL_ITEM: 0, // [money] NOT NULL, fijo 0 es el que se llenara al mostrar en la tablet o telefono para que llene operador
39 TASIVA: comprobante.itemsFactura.alicuotaIVAAplicable, // [money] NOT NULL, TASA DE IVA DEL ITEM = 21.00 / 10.50 / ETC. 39 TASIVA: comprobante.itemsFactura.alicuotaIVAAplicable, // [money] NOT NULL, TASA DE IVA DEL ITEM = 21.00 / 10.50 / ETC.
40 gln: comprobante.identificaxSucursalReceptorFactura.glnSucursal, //gln sucursal
41 codigoBarras: item.codigoUPCEAN13
40 gln: comprobante.identificaxSucursalReceptorFactura.glnSucursal, //gln sucursal 42 };
41 codigoBarras: item.codigoUPCEAN13 43 }
42 }; 44
1 module.exports = function(comprobante, entities) { 1 module.exports = function(comprobante, entities) {
2 2
3 var afipTablas = require('../afip/index'); 3 var afipTablas = require('../afip/index');
4 4
5 var objReturn = { 5 var objReturn = {
6 cabecera: require('./cabeceraDebo')(comprobante, afipTablas, entities), 6 cabecera: require('./cabeceraDebo')(comprobante, afipTablas, entities),
7 cuerpo: [] 7 cuerpo: []
8 } 8 }
9 9
10 comprobante.itemsFactura.forEach((item) => { 10 comprobante.itemsFactura.forEach((item) => {
11 11
12 objReturn.cuerpo.push(require('./cuerpoDebo')(comprobante, afipTablas, entities, item)); 12 objReturn.cuerpo.push(require('./cuerpoDebo')(comprobante, afipTablas, entities, item));
13 }); 13 });
14 14
15 return objReturn; 15 return objReturn;
16 } 16 }
17 17
File was created 1 module.exports = function(planex, wsServer) {
2
3 return new Promise(function(resolve, reject) {
4
5 var promesasArticulo = [];
6
7 var tipoCuit = planex.identificaxEmisor.cuit.slice(0, 2);
8 var digitoVerificador = planex.identificaxEmisor.cuit[planex.identificaxEmisor.cuit.length - 1];
9 var cuitToDebo = tipoCuit + '-' + planex.identificaxEmisor.cuit.slice(2, 10) + '-' + digitoVerificador;
10
11 var promiseProveedores = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'PROVEED', {CUIT: cuitToDebo});
12 var promiseEmp = wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, 'APAREMP');
13
14 planex.itemsFactura.forEach(item => {
15
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 = \'' +
18 item.codigoUPCEAN13 + '\'';
19
20 promesasArticulo.push(
21 wsServer.getEntidad(planex.identificaxReceptorFactura.glnReceptor, null, {}, queryString)
22 );
23 });
24
25 promesas = promesasArticulo.concat([promiseProveedores, promiseEmp]);
26
27 Promise.all(promesas).then(function(values) {
28
29 planex.itemsFactura.forEach((item, index) => {
30
31 if (!values[index]) return; console.error('No se encontró el articulo');
32
33 item.CodArt = values[index].CodArt;
34 item.CodSec = values[index].CodSec;
35 item.CodRub = values[index].CodRub;
36 item.DET_LAR = values[index].DET_LAR;
37
38 delete values[index];
39 });
40
41 values = values.filter(function(p) {
42 return p;
43 });
44
45 resolve({planex, values});
46
47 });
48
49 });
50 }
1 module.exports = function(planex, wsServer) { 51
File was created 1 module.exports = function(debo, wsServer, gln) {
2
3 return new Promise(function(resolve, reject) {
4
5 wsServer
6 .getEntidad(gln, 'PMAEFACT_TEMP', {
7 TIP: debo.cabecera.TIP,
8 TCO: debo.cabecera.TCO,
9 SUC: debo.cabecera.SUC,
10 NCO: debo.cabecera.NCO,
11 COD: debo.cabecera.COD
12 }).then(function(values) {
13
14 if (values) {
15 reject('Ya existe el comprobante', values);
16 } else {
17 resolve();
18 }
19 });
20 });
21 }
1 module.exports = function(debo, wsServer, gln) { 22
1 config = require('./config/config.json'); 1 config = require('./config/config.json');
2
3 module.exports = 2
4 knex = require('knex')(config.db), 3 module.exports =
4 knex = require('knex')(config.db),
5 express = require('express');
6 app = express();
7 wsServer = require('./webSocketServer/index')();
8 moment = require('moment');
5 express = require('express'); 9
6 app = express(); 10 app.listen(config.portWebService);
11 app.use(express.json({ limit: '50mb' }));
7 wsServer = require('./webSocketServer/index')(); 12
8 moment = require('moment'); 13 require('./watch/index')(config.dir, onGetFile);
9 14
10 app.listen(config.portWebService); 15 app.use(function(req, res, next) {
16 res.setHeader('Access-Control-Allow-Origin', '*');
17 res.setHeader(
18 'Access-Control-Allow-Headers',
19 'Origin, X-Requested-With, Content-Type, Accept, X-Terminal-Key, X-Nombre-Usuario, X-Punto-Venta'
20 );
21 res.setHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, OPTIONS');
22 next();
23 });
11 app.use(express.json({ limit: '50mb' })); 24
12 25 app.use('/gateway-debo', require('./rutas/comprobantes'));
26 app.use('/gateway-debo', require('./rutas/login'));
13 require('./watch/index')(config.dir, onGetFile); 27
14 28 var planexArr = [];
15 app.use(function(req, res, next) { 29
16 res.setHeader('Access-Control-Allow-Origin', '*'); 30 function onGetFile(fileString) {
17 res.setHeader( 31
18 'Access-Control-Allow-Headers', 32 if (!fileString) return;
19 'Origin, X-Requested-With, Content-Type, Accept, X-Terminal-Key, X-Nombre-Usuario, X-Punto-Venta'
20 ); 33
21 res.setHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, OPTIONS'); 34 var planex = require('./planex/index')(fileString);
22 next(); 35
23 }); 36 planexArr.push(planex);
24
25 app.use('/gateway-debo', require('./rutas/comprobantes')); 37
26 app.use('/gateway-debo', require('./rutas/login')); 38 // Traigo proveedor, empresa
39 require('./debo/relaciones')(planex, wsServer).then(function(result) {
27 40
28 var planexArr = []; 41 var planex = result.planex;
29 42
30 function onGetFile(fileString) { 43 var entities = {};
31
32 if (!fileString) return;
33 44
34 var planex = require('./planex/index')(fileString); 45 entities.proveedores = result.values[0];
35 46 entities.empresa = result.values[1];
36 planexArr.push(planex); 47
37 48 var debo = require('./debo/index')(planex, entities);
38 // Traigo proveedor, empresa 49
39 require('./debo/relaciones')(planex, wsServer).then(function(result) { 50 require('./debo/validacion')(debo, wsServer, planex.identificaxSucursalReceptorFactura.glnSucursal).then(function() {
40 51
41 var planex = result.planex; 52 require('./db/index')(debo);
53 }).catch(function(err) {
42 54
43 var entities = {}; 55 console.log(err);
44
45 entities.proveedores = result.values[0];
46 entities.empresa = result.values[1];
47 56 });
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",
10 "moment": "^2.24.0",
9 "knex": "^0.16.5", 11 "mssql": "^5.1.0",
10 "moment": "^2.24.0", 12 "ws": "^7.0.0"
11 "mssql": "^5.1.0", 13 },
12 "ws": "^7.0.0" 14 "devDependencies": {
15 "nodemon": "^1.19.1"
16 },
13 }, 17 "scripts": {
14 "devDependencies": { 18 "test": "echo \"Error: no test specified\" && exit 1",
19 "dev": "nodemon index.js"
15 "nodemon": "^1.19.1" 20 },
16 }, 21 "author": "Foca Software",
17 "scripts": { 22 "license": "ISC"
18 "test": "echo \"Error: no test specified\" && exit 1", 23 }
19 "dev": "nodemon index.js" 24
rutas/comprobantes.js
File was created 1 module.exports = router = express.Router();
2
3 router.get('/comprobantes/:gln*?', function(req, res) {
4
5 var cabecera = knex('PMAEFACT_TEMP')
6 .where(function(qb) {
7 if (req.params.gln) {
8 qb.where({gln: req.params.gln});
9 }
10 })
11 .select('*');
12
13 var cuerpo = knex('PMOVFACT_TEMP')
14 .where(function(qb) {
15 if (req.params.gln) {
16 qb.where({gln: req.params.gln});
17 }
18 })
19 .select('*');
20
21 Promise.all([cabecera, cuerpo]).then(function(data) {
22
23 var result = [];
24 data[0].forEach((cabecera) => {
25
26 let idCabecera = cabecera.TIP + cabecera.TCO + cabecera.SUC + cabecera.NCO;
27
28 var cuerpos = data[1].filter((cuerpo) => {
29 let idCuerpo = cuerpo.TIP + cuerpo.TCO + cuerpo.SUC + cuerpo.NCO;
30 return idCuerpo == idCabecera
31 });
32
33 result.push({
34 cabecera: cabecera,
35 cuerpo: cuerpos
36 });
37 });
38
39 res.status(200).send(result);
40 });
41 });
42
43 router.post('/comprobante', function(req, res) {
44
45 console.log(req.body);
46 delete req.body.cabecera.gln;
47 delete req.body.cabecera.C_HD2;
48 delete req.body.cabecera.E_HD2;
49
50 //smalldatetime
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', ' ');
53 req.body.cabecera.FECVEN = new Date(req.body.cabecera.FECVEN).toISOString().slice(0, 19).replace('T', ' ');
54
55 //datetime
56 req.body.cabecera.FEV = moment(req.body.cabecera.FEV).format('YYYYMMDD');
57 req.body.cabecera.FEP = moment(req.body.cabecera.FEP).format('YYYYMMDD');
58
59 var promesas = [
60 knex('PMAEFACT').insert(req.body.cabecera),
61 knex('PCOBYPAG').insert({
62 COD: req.body.cabecera.COD,
63 FEP: req.body.cabecera.FEC,
64 TIP: req.body.cabecera.TIP,
65 TCO: req.body.cabecera.TCO,
66 SUC: req.body.cabecera.SUC,
67 NCO: req.body.cabecera.NCO,
68 IPA: req.body.cabecera.TOT,
69 SAL: 0,
70 TCA: 1,
71 ZONA: req.body.cabecera.ZON,
72 FPA: req.body.cabecera.FPA,
73 REC: 0,
74 FER: '19000101 00:00',
75 PRO: '',
76 FEV: req.body.cabecera.FEV,
77 ANU: '',
78 PLA: 0,
79 LUG: 0,
80 RES: 0,
81 CCU: 0,
82 UCU: 0,
83 HOS: '',
84 E_HD: '',
85 C_HD: ''
86 })
87 ];
88
89 req.body.cuerpo.forEach(cuerpo => {
90
91
92 promesas.push(knex('AMOVSTOC').insert({
93 SEC: cuerpo.COD,
94 ART: cuerpo.ART,
95 FEC: req.body.cabecera.FEC,
96 CYV: 'C',
97 TIP: req.body.cabecera.TIP,
98 TCO: req.body.cabecera.TCO,
99 PVE: req.body.cabecera.SUC,
100 NCO: req.body.cabecera.NCO,
101 ORD: cuerpo.ORD,
102 CAN: cuerpo.recibido || cuerpo.CAN,
103 PUN: cuerpo.PUN,
104 COD: req.body.cabecera.COD,
105 DTO: cuerpo.DTO,
106 IMI: cuerpo.IMI,
107 PLA: 0,
108 LUG: 0,
109 ANU: '',
110 TIM: 'Co',
111 OPE: -888, // <= TODO: Cuando se haga el login poner codigo operario
112 IMI2: cuerpo.IMI2,
113 E_HD: '',
114 C_HD: '',
115 JUS: 'PLANEX',
116 NLC: 0,
117 IMI3: cuerpo.IMI3,
118 JJN: '',
119 JDJ: '',
120 ID_MOTIVO_NANB: 0
121 }));
122
123 delete cuerpo.gln;
124 delete cuerpo.C_HD2;
125 delete cuerpo.E_HD2;
126 delete cuerpo.codigoBarras;
127 delete cuerpo.estado;
128 delete cuerpo.recibido;
129 delete cuerpo.input;
130
131 promesas.push(knex('PMOVFACT').insert(cuerpo));
132
133 });
134
135 Promise.all(promesas)
136 .then(function() {
137
138 console.log('comprobantes guardados con éxito');
139 })
140 .catch(function(e) {
141 console.log(e);
142 });
143
144 res.status(201).send('ok');
145 });
1 module.exports = router = express.Router(); 146
File was created 1 module.exports = router = express.Router();
2
3 router.post('/login', function(req, res) {
4
5 if (wsServer.getClientGln(req.body.gln).length) {
6
7 res.status(200).send({data: 'ok'});
8 } else {
9 res.status(200).send({data: 'No existe el cliente'});
10 }
11 });
1 module.exports = router = express.Router(); 12
1 module.exports = function (dir, callback) { 1 module.exports = function (dir, callback) {
2 2
3 const fs = require('fs'); 3 const fs = require('fs');
4 const chokidar = require('chokidar');
4 const chokidar = require('chokidar'); 5
5 6 const watcher = chokidar.watch(dir);
7
8 watcher.on('add', function(file) {
6 const watcher = chokidar.watch(dir); 9
7 10 var extencion = file.split('.')[1];
8 watcher.on('add', function(file) { 11
9 12 if (extencion == 'txt') {
10 var extencion = file.split('.')[1]; 13
11 14 fs.readFile(file, 'utf8', function (err, fileString) {
12 if (extencion == 'txt') { 15
13 16 callback(fileString);
14 fs.readFile(file, 'utf8', function (err, fileString) { 17 });
15 18 }
16 callback(fileString); 19
17 }); 20 });
18 } 21
19 22 };
20 }); 23
webSocketServer/index.js
1 module.exports = function() { 1 module.exports = function() {
2 2
3 const webSocketServer = require('ws').Server; 3 const webSocketServer = require('ws').Server;
4 var clients = []; 4 var clients = [];
5 5
6 const objWs = {}; 6 const objWs = {};
7 7
8 objWs.wsServer = new webSocketServer({ 8 objWs.wsServer = new webSocketServer({
9 port: config.port 9 port: config.port
10 }); 10 });
11 11
12 objWs.wsServer.on('connection', function connection(ws) { 12 objWs.wsServer.on('connection', function connection(ws) {
13 13
14 console.log('open socket server'); 14 console.log('open socket server');
15 15
16 ws.on('message', function incoming(message) { 16 ws.on('message', function incoming(message) {
17 17
18 message = JSON.parse(message.toString('utf8')); 18 message = JSON.parse(message.toString('utf8'));
19 19
20 switch (message.action) { 20 switch (message.action) {
21 case 'gln': 21 case 'gln':
22 clients.push({ws: ws, gln: message.gln}); 22 clients.push({ws: ws, gln: message.gln});
23 break; 23 break;
24 default: 24 default:
25 // console.log(message.action); 25 // console.log(message.action);
26 } 26 }
27 });
27 }); 28 });
28 });
29 29
30 objWs.getEntidad = function(gln, tableName, where, queryString) { 30 objWs.getEntidad = function(gln, tableName, where, queryString) {
31 31
32 return new Promise(function(resolve, reject) { 32 return new Promise(function(resolve, reject) {
33 33
34 var client = clients.filter(function(client) { 34 var client = clients.filter(function(client) {
35 return client.gln == gln 35 return client.gln == gln
36 })[0]; 36 })[0];
37
38 if (!client) {
39 reject('No se encuentra el webSocket client');
40 }
37 41
38 if (!client) { 42 var idSolicitud = Math.round(Math.random() * 1000);
39 reject('No se encuentra el webSocket client');
40 }
41 43
42 var idSolicitud = Math.round(Math.random() * 1000); 44 var enviar = {
45 action: 'getEntity',
46 idSolicitud: idSolicitud
47 };
43 48
44 var enviar = { 49 if (queryString) {
45 action: 'getEntity',
46 idSolicitud: idSolicitud
47 };
48 50
49 if (queryString) { 51 enviar.queryString = queryString;
52 } else {
53 enviar.tableName = tableName;
54 enviar.where = where || {};
55 }
50 56
51 enviar.queryString = queryString; 57 client.ws.send(JSON.stringify(enviar));
52 } else {
53 enviar.tableName = tableName;
54 enviar.where = where || {};
55 }
56 58
57 client.ws.send(JSON.stringify(enviar)); 59 client.ws.on('message', function(message) {
58 60
59 client.ws.on('message', function(message) { 61 message = JSON.parse(message);
60 62
61 message = JSON.parse(message); 63 if (idSolicitud == message.idSolicitud) {
62 64
63 if (idSolicitud == message.idSolicitud) { 65 resolve(message.data);
66 }
64 67
65 resolve(message.data); 68 });
66 } 69 });
70 }