From f1a1cc95984cfcf6f39fc7a786656f2e15adab46 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Mon, 27 May 2019 15:47:04 -0300 Subject: [PATCH] =?UTF-8?q?primera=20versi=C3=B3n=20estable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debo/cabeceraDebo.js | 10 +++---- debo/cuerpoDebo.js | 2 +- index.js | 6 +++- package.json | 2 ++ planex/comprobantesReferencia.js | 8 ++++-- planex/detalleImpuestosItemFactura.js | 35 ++++++++++++++++++++++-- planex/detalleOtrosImpuestosComprobante.js | 40 +++++++++++++++++++++++++-- planex/index.js | 44 ++++-------------------------- watch/index.js | 4 +-- 9 files changed, 96 insertions(+), 55 deletions(-) diff --git a/debo/cabeceraDebo.js b/debo/cabeceraDebo.js index e79d7f3..e9cf146 100644 --- a/debo/cabeceraDebo.js +++ b/debo/cabeceraDebo.js @@ -12,7 +12,7 @@ module.exports = function(comprobante, afipTablas, entities) { CUI: entities.proveedores.CUIT, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION FPA: entities.proveedores.FPA, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED TCA: 1, // [money] NOT NULL, FIJO 1 - DTO: comprobante.descuentosGlobalesFactura.importe, // [money] NOT NULL, DESCUENTO TOTAL SUMATORIA DE LOS DTO POR ITEM + DTO: comprobante.descuentosGlobalesFactura.importe || 0, // [money] NOT NULL, DESCUENTO TOTAL SUMATORIA DE LOS DTO POR ITEM PDT: 0, // [money] NOT NULL, FIJO 0 NET: comprobante.importesTotales.netoGravado, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA <> 0 NEE: comprobante.importesTotales.importeOperacionesExentas, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA = 0 @@ -21,12 +21,12 @@ module.exports = function(comprobante, afipTablas, entities) { IMI: comprobante.importesTotales.importeImpuestosInternos, // [money] NOT NULL, SUMATORIA DE LOS IMPUESTOS INTERNOS POR ITEM RGA: 0, // [money] NOT NULL, IMPORTE RETENCION DE GANANCIAS RIB: 0, // [money] NOT NULL, IMPORTE RETENCION DE INGRESOS BRUTOS - PIV: null, // [money] NOT NULL, IMPORTE PERCEPCION DE IVA, SECTOR 90 C05 + PIV: comprobante.detalleOtrosImpuestosComprobante.percepcionIVA ? comprobante.detalleOtrosImpuestosComprobante.percepcionIVA.importeImpuesto : 0, // [money] NOT NULL, IMPORTE PERCEPCION DE IVA, SECTOR 90 C05 CNG: comprobante.importesTotales.totalConceptosNoNetoGravado, // [money] NULL, IMPORTE DE CONCEPTOS NO GRAVADOS TOT: comprobante.importesTotales.totalOperacion, // [money] NOT NULL, IMPORTE TOTAL DE LA FACTURA ZON: entities.empresa.ZON, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP FEV: comprobante.identificaxComprobante.fechaVencimiento, // [datetime] NULL, FECHA DE VENCIMIENTO - OCP: comprobante.comprobantesReferencia[0].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) + 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) OPE: 0, // [int] NOT NULL, FIJO 0 REC: 0, // [bigint] NOT NULL, FIJO 0 FEP: comprobante.identificaxComprobante.fechaComprobante, // [datetime] NULL, ITEM FECHA FACTURA @@ -68,7 +68,7 @@ module.exports = function(comprobante, afipTablas, entities) { C_HD2: '', // [varchar](1) NOT NULL, VACIO NO NULO DTO2: 0, // [money] NOT NULL, IMPORTE DE OTROS DESCUENTOS ENLP: 0, // [bit] NOT NULL, FIJO 0 - COD_TRANS: comprobante.identificaxComprobante.numeroRegistrado, // [bigint] NOT NULL, VER DE PONER EL NUMERO DE REFERENCIA QUE PUEDA UNIRNOS A LO QUE VIENE DESDE PLANEX + 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 RETMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE DE RETENCIONES MUNICIPALES TIPO_OPERACION: 0, // [int] NOT NULL, FIJO 0 IRD: 0, // [money] NOT NULL, FIJO 0 @@ -80,7 +80,7 @@ module.exports = function(comprobante, afipTablas, entities) { DGR: 0, // [money] NOT NULL, IMPORTE RETENCION DGR DTO_PIE: 0, // [money] NOT NULL, IMPORTE DE DESCUENTO AL PIE, NO POR ITEM OPERACIONES_3711: 1, // [int] NOT NULL, FIJO 1 (PORQUE SON BIENES) - ORC: 'TODO: comprobantesReferencia CUANDO ES PC', // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA + ORC: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA NC_ES_NP: 0, // [bit] NOT NULL, FIJO 0 CABA: 0, // [money] NOT NULL, IMPORTE RETENCION CABA ARBA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION ARBA diff --git a/debo/cuerpoDebo.js b/debo/cuerpoDebo.js index eb444e7..b4fb59c 100644 --- a/debo/cuerpoDebo.js +++ b/debo/cuerpoDebo.js @@ -27,7 +27,7 @@ module.exports = function(comprobante, afipTablas, entities, item) { CCO: 0, // [bigint] NOT NULL, FIJO 0 E_HD: '', // [varchar](8) NOT NULL, FIJO '' VACIO NO NULO C_HD: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO - DTO: comprobante.detalleDescuentosItemFactura.importeDescuento, // [money] NOT NULL, IMPORTE DESCUENTO DE LA FACTURA + DTO: 0, // Comprobante.detalleDescuentosItemFactura.importeDescuento; [money] NOT NULL, IMPORTE DESCUENTO DE LA FACTURA PTA: 0, // [int] NOT NULL, FIJO 0 SUBM: 0, // [int] NOT NULL, FIJO 0 E_HD2: '', // [varchar](12) NOT NULL, FIJO '' VACIO NO NULO diff --git a/index.js b/index.js index 68a3fc6..58dc9ff 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ config = require('./config/config.json'); +module.exports = knex = require('knex')(config.db) require('./watch/index')(config.dir, onGetFile); @@ -36,6 +37,9 @@ function onGetFile(event, fileString) { Promise.all(promesasArticulo).then(function(values) { planex.itemsFactura.forEach((item, index) => { + + if (!values[index]) console.error('No se encontrĂ³ el articulo'); + item.CodArt = values[index].CodArt; item.CodSec = values[index].CodSec; item.CodRub = values[index].CodRub; @@ -49,7 +53,7 @@ function onGetFile(event, fileString) { var debo = require('./debo/index')(planex, entities); - console.log(debo); + require('./db/index')(debo); }); }); } diff --git a/package.json b/package.json index 832f15a..c0ff3e0 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "main": "index.js", "dependencies": { "express": "^4.16.4", + "knex": "^0.16.5", + "mssql": "^5.1.0", "ws": "^7.0.0" }, "devDependencies": {}, diff --git a/planex/comprobantesReferencia.js b/planex/comprobantesReferencia.js index d8861c5..387df24 100644 --- a/planex/comprobantesReferencia.js +++ b/planex/comprobantesReferencia.js @@ -1,12 +1,16 @@ -module.exports = function(comprobante) { +module.exports = function(comprobante, result) { var comprobanteArr = comprobante.split(';'); - return { + var comprobanteReferencia = { tipoDocumentoReferencia: comprobanteArr[1], puntoVentaReferencia: parseInt(comprobanteArr[2]), numeroDocumentoReferencia: parseInt(comprobanteArr[3]), fechaComprobanteReferencia: comprobanteArr[4], cuitEmisorComprobanteAsociado: comprobanteArr[5] } + + result.comprobantesReferencia[comprobanteReferencia.tipoDocumentoReferencia] = comprobanteReferencia; + + return; } diff --git a/planex/detalleImpuestosItemFactura.js b/planex/detalleImpuestosItemFactura.js index 6cde925..513c940 100644 --- a/planex/detalleImpuestosItemFactura.js +++ b/planex/detalleImpuestosItemFactura.js @@ -1,12 +1,41 @@ -module.exports = function(comprobante, returnFloatByDecimals) { +module.exports = function(comprobante, returnFloatByDecimals, result) { var comprobanteArr = comprobante.split(';'); - return { + var detalleDescuentos = { numeroLinea: comprobanteArr[1], descripcionImpuesto: comprobanteArr[2], procentajeImpuesto: returnFloatByDecimals(comprobanteArr[3], 2), importeBase: returnFloatByDecimals(comprobanteArr[4], 2), - importeImpuesto: returnFloatByDecimals(comprobanteArr[5, 2]) + importeImpuesto: returnFloatByDecimals(comprobanteArr[5], 2) }; + + var item = result.itemsFactura.filter(function(item) { + return detalleDescuentos.numeroLinea == item.numeroLinea; + })[0]; + + switch (detalleDescuentos.descripcionImpuesto) { + case 'C05': + item.percepcionIVA = detalleDescuentos; + break; + case 'C06': + item.percepcionIIBB = detalleDescuentos; + break; + case 'C07': + item.impuestoInterno = detalleDescuentos; + break; + case 'C08': + item.impuestoAbasto = detalleDescuentos; + break; + case 'ITC': + item.impuestoTransferenciaCombustibles = detalleDescuentos; + break; + case 'C10': + item.percepcionImpuestosMunicipales = detalleDescuentos; + break; + default: + break; + } + + return detalleDescuentos; } diff --git a/planex/detalleOtrosImpuestosComprobante.js b/planex/detalleOtrosImpuestosComprobante.js index e45ff25..0cd73d3 100644 --- a/planex/detalleOtrosImpuestosComprobante.js +++ b/planex/detalleOtrosImpuestosComprobante.js @@ -1,8 +1,8 @@ -module.exports = function(comprobante, returnFloatByDecimals) { +module.exports = function(comprobante, returnFloatByDecimals, result) { var comprobanteArr = comprobante.split(';'); - return { + var detalleOtrosImpuestos = { descripcionImpuesto: comprobanteArr[1], porcentaje: returnFloatByDecimals(comprobanteArr[2], 2), importeBase: returnFloatByDecimals(comprobanteArr[3], 2), @@ -10,4 +10,40 @@ module.exports = function(comprobante, returnFloatByDecimals) { codigoArancelImpuestoOCuota: comprobanteArr[5], jurisdiccion: comprobanteArr[6] }; + + switch (detalleOtrosImpuestos.codigoArancelImpuestoOCuota) { + case 'C05': + + result.detalleOtrosImpuestosComprobante.percepcionIVA = detalleOtrosImpuestos; + break; + + case 'C07': + + result.detalleOtrosImpuestosComprobante.impuestoInterno = detalleOtrosImpuestos; + break; + + case 'C08': + + result.detalleOtrosImpuestosComprobante.impuestoAbasto = detalleOtrosImpuestos; + break; + + case 'C09': + + result.detalleOtrosImpuestosComprobante.impuestoVideo = detalleOtrosImpuestos; + break; + + case 'ITC': + + result.detalleOtrosImpuestosComprobante.impuestoTransferenciaCombustibles = detalleOtrosImpuestos; + break; + + case 'C12': + + result.detalleOtrosImpuestosComprobante.percepcionNoCategorizadosORNI = detalleOtrosImpuestos; + break; + default: + break; + } + + return; } diff --git a/planex/index.js b/planex/index.js index 36e15c8..8fc698f 100644 --- a/planex/index.js +++ b/planex/index.js @@ -6,7 +6,7 @@ module.exports = function(comprobante) { var objReturn = { identificaxComprobante: {}, identificaxMensaje: {}, - comprobantesReferencia: [], + comprobantesReferencia: {}, identificaxEmisor: {}, informaxRepresentanteEmisor: {}, identificaxReceptorFactura: {}, @@ -39,7 +39,7 @@ module.exports = function(comprobante) { } else if (sector.slice(0, 3) == '012') { objReturn.identificaxMensaje = require('./identificaxMensaje')(sector)// 012 } else if (sector.slice(0, 3) == '020') { - objReturn.comprobantesReferencia.push(require('./comprobantesReferencia')(sector)) // 020 + require('./comprobantesReferencia')(sector, objReturn) // 020 } else if (sector.slice(0, 3) == '030') { objReturn.identificaxEmisor = require('./identificaxEmisor')(sector) // 030 } else if (sector.slice(0, 3) == '035') { @@ -57,47 +57,13 @@ module.exports = function(comprobante) { } else if (sector.slice(0, 3) == '080') { objReturn.descuentosGlobalesFactura = require('./descuentosGlobalesFactura')(sector, returnFloatByDecimals) // 080 } else if (sector.slice(0, 3) == '090') { - objReturn.detalleOtrosImpuestosComprobante = require('./detalleOtrosImpuestosComprobante')(sector, returnFloatByDecimals) // 090 + require('./detalleOtrosImpuestosComprobante')(sector, returnFloatByDecimals, objReturn) // 090 } else if (sector.slice(0, 3) == '100') { objReturn.itemsFactura.push(require('./itemsFactura')(sector, returnFloatByDecimals)); // 100 } else if (sector.slice(0, 3) == '110') { - objReturn.detalleDescuentosItemFactura = require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals); // 110 + objReturn.detalleDescuentosItemFactura.push(require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals)); // 110 } else if (sector.slice(0, 3) == '120') { - objReturn.detalleImpuestosItemFactura.push(require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals)); // 120 - } - }); - - if (!objReturn.detalleImpuestosItemFactura.length) { - return objReturn; - } - - objReturn.itemsFactura.forEach(item => { - - var detalleDescuentos = objReturn.detalleImpuestosItemFactura.filter(function(descuento) { - return descuento.numeroLinea == item.numeroLinea; - })[0]; - - switch (detalleDescuentos.descripcionImpuesto) { - case 'c05': - item.percepcionIVA = detalleDescuentos; - break; - case 'c06': - item.percepcionIIBB = detalleDescuentos; - break; - case 'c07': - item.impuestoInterno = detalleDescuentos; - break; - case 'c08': - item.impuestoAbasto = detalleDescuentos; - break; - case 'ITC': - item.impuestoTransferenciaCombustibles = detalleDescuentos; - break; - case 'c10': - item.percepcionImpuestosMunicipales = detalleDescuentos; - break; - default: - break; + objReturn.detalleImpuestosItemFactura.push(require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals, objReturn)); // 120 } }); diff --git a/watch/index.js b/watch/index.js index 4643e54..3e316e7 100644 --- a/watch/index.js +++ b/watch/index.js @@ -6,12 +6,12 @@ module.exports = function(dir, callback) { var extencion = file.split('.')[1]; - if (extencion == 'plx' && event == 'change') { + if (extencion == 'txt' && event == 'change') { fs.readFile(dir + '\\' + file, 'utf8', function(err , fileString) { callback(event, fileString); - }) + }); } }); -- 1.9.1