Commit f1a1cc95984cfcf6f39fc7a786656f2e15adab46
1 parent
585772b1bb
Exists in
master
primera versión estable
Showing
9 changed files
with
96 additions
and
55 deletions
Show diff stats
debo/cabeceraDebo.js
| ... | ... | @@ -12,7 +12,7 @@ module.exports = function(comprobante, afipTablas, entities) { |
| 12 | 12 | CUI: entities.proveedores.CUIT, // [char](13) NOT NULL, CUIT DEL PROVEEDOR CAMPO CUIT DEL PROVEEDOR O EL QUE VIENE EN LA COMUNICACION |
| 13 | 13 | FPA: entities.proveedores.FPA, // [tinyint] NOT NULL, FORMA DE PAGO CAMPO FPA TABLA PROVEED |
| 14 | 14 | TCA: 1, // [money] NOT NULL, FIJO 1 |
| 15 | - DTO: comprobante.descuentosGlobalesFactura.importe, // [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 | 16 | PDT: 0, // [money] NOT NULL, FIJO 0 |
| 17 | 17 | NET: comprobante.importesTotales.netoGravado, // [money] NOT NULL, SUMATORIA DE LOS NETOS POR ITEM QUE TIENEN IVA <> 0 |
| 18 | 18 | 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) { |
| 21 | 21 | IMI: comprobante.importesTotales.importeImpuestosInternos, // [money] NOT NULL, SUMATORIA DE LOS IMPUESTOS INTERNOS POR ITEM |
| 22 | 22 | RGA: 0, // [money] NOT NULL, IMPORTE RETENCION DE GANANCIAS |
| 23 | 23 | RIB: 0, // [money] NOT NULL, IMPORTE RETENCION DE INGRESOS BRUTOS |
| 24 | - PIV: null, // [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 | 25 | CNG: comprobante.importesTotales.totalConceptosNoNetoGravado, // [money] NULL, IMPORTE DE CONCEPTOS NO GRAVADOS |
| 26 | 26 | TOT: comprobante.importesTotales.totalOperacion, // [money] NOT NULL, IMPORTE TOTAL DE LA FACTURA |
| 27 | 27 | ZON: entities.empresa.ZON, // [int] NOT NULL, NUMERO DE LA EMPRESA SELECT ZON FROM APAREMP |
| 28 | 28 | FEV: comprobante.identificaxComprobante.fechaVencimiento, // [datetime] NULL, FECHA DE VENCIMIENTO |
| 29 | - 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) | |
| 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 | 30 | OPE: 0, // [int] NOT NULL, FIJO 0 |
| 31 | 31 | REC: 0, // [bigint] NOT NULL, FIJO 0 |
| 32 | 32 | FEP: comprobante.identificaxComprobante.fechaComprobante, // [datetime] NULL, ITEM FECHA FACTURA |
| ... | ... | @@ -68,7 +68,7 @@ module.exports = function(comprobante, afipTablas, entities) { |
| 68 | 68 | C_HD2: '', // [varchar](1) NOT NULL, VACIO NO NULO |
| 69 | 69 | DTO2: 0, // [money] NOT NULL, IMPORTE DE OTROS DESCUENTOS |
| 70 | 70 | ENLP: 0, // [bit] NOT NULL, FIJO 0 |
| 71 | - COD_TRANS: comprobante.identificaxComprobante.numeroRegistrado, // [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 | 72 | RETMUN: comprobante.importesTotales.importeImpuestosMunicipales, // [money] NOT NULL, IMPORTE DE RETENCIONES MUNICIPALES |
| 73 | 73 | TIPO_OPERACION: 0, // [int] NOT NULL, FIJO 0 |
| 74 | 74 | IRD: 0, // [money] NOT NULL, FIJO 0 |
| ... | ... | @@ -80,7 +80,7 @@ module.exports = function(comprobante, afipTablas, entities) { |
| 80 | 80 | DGR: 0, // [money] NOT NULL, IMPORTE RETENCION DGR |
| 81 | 81 | DTO_PIE: 0, // [money] NOT NULL, IMPORTE DE DESCUENTO AL PIE, NO POR ITEM |
| 82 | 82 | OPERACIONES_3711: 1, // [int] NOT NULL, FIJO 1 (PORQUE SON BIENES) |
| 83 | - ORC: 'TODO: comprobantesReferencia CUANDO ES PC', // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA | |
| 83 | + ORC: comprobante.comprobantesReferencia.PC.numeroDocumentoReferencia, // [bigint] NOT NULL, NUMERO DE ORDEN DE COMPRA | |
| 84 | 84 | NC_ES_NP: 0, // [bit] NOT NULL, FIJO 0 |
| 85 | 85 | CABA: 0, // [money] NOT NULL, IMPORTE RETENCION CABA |
| 86 | 86 | ARBA_PER: 0, // [money] NOT NULL, IMPORTE PERCEPCION ARBA |
debo/cuerpoDebo.js
| ... | ... | @@ -27,7 +27,7 @@ module.exports = function(comprobante, afipTablas, entities, item) { |
| 27 | 27 | CCO: 0, // [bigint] NOT NULL, FIJO 0 |
| 28 | 28 | E_HD: '', // [varchar](8) NOT NULL, FIJO '' VACIO NO NULO |
| 29 | 29 | C_HD: '', // [varchar](1) NOT NULL, FIJO '' VACIO NO NULO |
| 30 | - DTO: 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 | 31 | PTA: 0, // [int] NOT NULL, FIJO 0 |
| 32 | 32 | SUBM: 0, // [int] NOT NULL, FIJO 0 |
| 33 | 33 | E_HD2: '', // [varchar](12) NOT NULL, FIJO '' VACIO NO NULO |
index.js
| 1 | 1 | config = require('./config/config.json'); |
| 2 | +module.exports = knex = require('knex')(config.db) | |
| 2 | 3 | |
| 3 | 4 | require('./watch/index')(config.dir, onGetFile); |
| 4 | 5 | |
| ... | ... | @@ -36,6 +37,9 @@ function onGetFile(event, fileString) { |
| 36 | 37 | Promise.all(promesasArticulo).then(function(values) { |
| 37 | 38 | |
| 38 | 39 | planex.itemsFactura.forEach((item, index) => { |
| 40 | + | |
| 41 | + if (!values[index]) console.error('No se encontró el articulo'); | |
| 42 | + | |
| 39 | 43 | item.CodArt = values[index].CodArt; |
| 40 | 44 | item.CodSec = values[index].CodSec; |
| 41 | 45 | item.CodRub = values[index].CodRub; |
| ... | ... | @@ -49,7 +53,7 @@ function onGetFile(event, fileString) { |
| 49 | 53 | |
| 50 | 54 | var debo = require('./debo/index')(planex, entities); |
| 51 | 55 | |
| 52 | - console.log(debo); | |
| 56 | + require('./db/index')(debo); | |
| 53 | 57 | }); |
| 54 | 58 | }); |
| 55 | 59 | } |
package.json
planex/comprobantesReferencia.js
| 1 | -module.exports = function(comprobante) { | |
| 1 | +module.exports = function(comprobante, result) { | |
| 2 | 2 | |
| 3 | 3 | var comprobanteArr = comprobante.split(';'); |
| 4 | 4 | |
| 5 | - return { | |
| 5 | + var comprobanteReferencia = { | |
| 6 | 6 | tipoDocumentoReferencia: comprobanteArr[1], |
| 7 | 7 | puntoVentaReferencia: parseInt(comprobanteArr[2]), |
| 8 | 8 | numeroDocumentoReferencia: parseInt(comprobanteArr[3]), |
| 9 | 9 | fechaComprobanteReferencia: comprobanteArr[4], |
| 10 | 10 | cuitEmisorComprobanteAsociado: comprobanteArr[5] |
| 11 | 11 | } |
| 12 | + | |
| 13 | + result.comprobantesReferencia[comprobanteReferencia.tipoDocumentoReferencia] = comprobanteReferencia; | |
| 14 | + | |
| 15 | + return; | |
| 12 | 16 | } |
planex/detalleImpuestosItemFactura.js
| 1 | -module.exports = function(comprobante, returnFloatByDecimals) { | |
| 1 | +module.exports = function(comprobante, returnFloatByDecimals, result) { | |
| 2 | 2 | |
| 3 | 3 | var comprobanteArr = comprobante.split(';'); |
| 4 | 4 | |
| 5 | - return { | |
| 5 | + var detalleDescuentos = { | |
| 6 | 6 | numeroLinea: comprobanteArr[1], |
| 7 | 7 | descripcionImpuesto: comprobanteArr[2], |
| 8 | 8 | procentajeImpuesto: returnFloatByDecimals(comprobanteArr[3], 2), |
| 9 | 9 | importeBase: returnFloatByDecimals(comprobanteArr[4], 2), |
| 10 | - importeImpuesto: returnFloatByDecimals(comprobanteArr[5, 2]) | |
| 10 | + importeImpuesto: returnFloatByDecimals(comprobanteArr[5], 2) | |
| 11 | 11 | }; |
| 12 | + | |
| 13 | + var item = result.itemsFactura.filter(function(item) { | |
| 14 | + return detalleDescuentos.numeroLinea == item.numeroLinea; | |
| 15 | + })[0]; | |
| 16 | + | |
| 17 | + switch (detalleDescuentos.descripcionImpuesto) { | |
| 18 | + case 'C05': | |
| 19 | + item.percepcionIVA = detalleDescuentos; | |
| 20 | + break; | |
| 21 | + case 'C06': | |
| 22 | + item.percepcionIIBB = detalleDescuentos; | |
| 23 | + break; | |
| 24 | + case 'C07': | |
| 25 | + item.impuestoInterno = detalleDescuentos; | |
| 26 | + break; | |
| 27 | + case 'C08': | |
| 28 | + item.impuestoAbasto = detalleDescuentos; | |
| 29 | + break; | |
| 30 | + case 'ITC': | |
| 31 | + item.impuestoTransferenciaCombustibles = detalleDescuentos; | |
| 32 | + break; | |
| 33 | + case 'C10': | |
| 34 | + item.percepcionImpuestosMunicipales = detalleDescuentos; | |
| 35 | + break; | |
| 36 | + default: | |
| 37 | + break; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return detalleDescuentos; | |
| 12 | 41 | } |
planex/detalleOtrosImpuestosComprobante.js
| 1 | -module.exports = function(comprobante, returnFloatByDecimals) { | |
| 1 | +module.exports = function(comprobante, returnFloatByDecimals, result) { | |
| 2 | 2 | |
| 3 | 3 | var comprobanteArr = comprobante.split(';'); |
| 4 | 4 | |
| 5 | - return { | |
| 5 | + var detalleOtrosImpuestos = { | |
| 6 | 6 | descripcionImpuesto: comprobanteArr[1], |
| 7 | 7 | porcentaje: returnFloatByDecimals(comprobanteArr[2], 2), |
| 8 | 8 | importeBase: returnFloatByDecimals(comprobanteArr[3], 2), |
| ... | ... | @@ -10,4 +10,40 @@ module.exports = function(comprobante, returnFloatByDecimals) { |
| 10 | 10 | codigoArancelImpuestoOCuota: comprobanteArr[5], |
| 11 | 11 | jurisdiccion: comprobanteArr[6] |
| 12 | 12 | }; |
| 13 | + | |
| 14 | + switch (detalleOtrosImpuestos.codigoArancelImpuestoOCuota) { | |
| 15 | + case 'C05': | |
| 16 | + | |
| 17 | + result.detalleOtrosImpuestosComprobante.percepcionIVA = detalleOtrosImpuestos; | |
| 18 | + break; | |
| 19 | + | |
| 20 | + case 'C07': | |
| 21 | + | |
| 22 | + result.detalleOtrosImpuestosComprobante.impuestoInterno = detalleOtrosImpuestos; | |
| 23 | + break; | |
| 24 | + | |
| 25 | + case 'C08': | |
| 26 | + | |
| 27 | + result.detalleOtrosImpuestosComprobante.impuestoAbasto = detalleOtrosImpuestos; | |
| 28 | + break; | |
| 29 | + | |
| 30 | + case 'C09': | |
| 31 | + | |
| 32 | + result.detalleOtrosImpuestosComprobante.impuestoVideo = detalleOtrosImpuestos; | |
| 33 | + break; | |
| 34 | + | |
| 35 | + case 'ITC': | |
| 36 | + | |
| 37 | + result.detalleOtrosImpuestosComprobante.impuestoTransferenciaCombustibles = detalleOtrosImpuestos; | |
| 38 | + break; | |
| 39 | + | |
| 40 | + case 'C12': | |
| 41 | + | |
| 42 | + result.detalleOtrosImpuestosComprobante.percepcionNoCategorizadosORNI = detalleOtrosImpuestos; | |
| 43 | + break; | |
| 44 | + default: | |
| 45 | + break; | |
| 46 | + } | |
| 47 | + | |
| 48 | + return; | |
| 13 | 49 | } |
planex/index.js
| ... | ... | @@ -6,7 +6,7 @@ module.exports = function(comprobante) { |
| 6 | 6 | var objReturn = { |
| 7 | 7 | identificaxComprobante: {}, |
| 8 | 8 | identificaxMensaje: {}, |
| 9 | - comprobantesReferencia: [], | |
| 9 | + comprobantesReferencia: {}, | |
| 10 | 10 | identificaxEmisor: {}, |
| 11 | 11 | informaxRepresentanteEmisor: {}, |
| 12 | 12 | identificaxReceptorFactura: {}, |
| ... | ... | @@ -39,7 +39,7 @@ module.exports = function(comprobante) { |
| 39 | 39 | } else if (sector.slice(0, 3) == '012') { |
| 40 | 40 | objReturn.identificaxMensaje = require('./identificaxMensaje')(sector)// 012 |
| 41 | 41 | } else if (sector.slice(0, 3) == '020') { |
| 42 | - objReturn.comprobantesReferencia.push(require('./comprobantesReferencia')(sector)) // 020 | |
| 42 | + require('./comprobantesReferencia')(sector, objReturn) // 020 | |
| 43 | 43 | } else if (sector.slice(0, 3) == '030') { |
| 44 | 44 | objReturn.identificaxEmisor = require('./identificaxEmisor')(sector) // 030 |
| 45 | 45 | } else if (sector.slice(0, 3) == '035') { |
| ... | ... | @@ -57,47 +57,13 @@ module.exports = function(comprobante) { |
| 57 | 57 | } else if (sector.slice(0, 3) == '080') { |
| 58 | 58 | objReturn.descuentosGlobalesFactura = require('./descuentosGlobalesFactura')(sector, returnFloatByDecimals) // 080 |
| 59 | 59 | } else if (sector.slice(0, 3) == '090') { |
| 60 | - objReturn.detalleOtrosImpuestosComprobante = require('./detalleOtrosImpuestosComprobante')(sector, returnFloatByDecimals) // 090 | |
| 60 | + require('./detalleOtrosImpuestosComprobante')(sector, returnFloatByDecimals, objReturn) // 090 | |
| 61 | 61 | } else if (sector.slice(0, 3) == '100') { |
| 62 | 62 | objReturn.itemsFactura.push(require('./itemsFactura')(sector, returnFloatByDecimals)); // 100 |
| 63 | 63 | } else if (sector.slice(0, 3) == '110') { |
| 64 | - objReturn.detalleDescuentosItemFactura = require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals); // 110 | |
| 64 | + objReturn.detalleDescuentosItemFactura.push(require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals)); // 110 | |
| 65 | 65 | } else if (sector.slice(0, 3) == '120') { |
| 66 | - objReturn.detalleImpuestosItemFactura.push(require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals)); // 120 | |
| 67 | - } | |
| 68 | - }); | |
| 69 | - | |
| 70 | - if (!objReturn.detalleImpuestosItemFactura.length) { | |
| 71 | - return objReturn; | |
| 72 | - } | |
| 73 | - | |
| 74 | - objReturn.itemsFactura.forEach(item => { | |
| 75 | - | |
| 76 | - var detalleDescuentos = objReturn.detalleImpuestosItemFactura.filter(function(descuento) { | |
| 77 | - return descuento.numeroLinea == item.numeroLinea; | |
| 78 | - })[0]; | |
| 79 | - | |
| 80 | - switch (detalleDescuentos.descripcionImpuesto) { | |
| 81 | - case 'c05': | |
| 82 | - item.percepcionIVA = detalleDescuentos; | |
| 83 | - break; | |
| 84 | - case 'c06': | |
| 85 | - item.percepcionIIBB = detalleDescuentos; | |
| 86 | - break; | |
| 87 | - case 'c07': | |
| 88 | - item.impuestoInterno = detalleDescuentos; | |
| 89 | - break; | |
| 90 | - case 'c08': | |
| 91 | - item.impuestoAbasto = detalleDescuentos; | |
| 92 | - break; | |
| 93 | - case 'ITC': | |
| 94 | - item.impuestoTransferenciaCombustibles = detalleDescuentos; | |
| 95 | - break; | |
| 96 | - case 'c10': | |
| 97 | - item.percepcionImpuestosMunicipales = detalleDescuentos; | |
| 98 | - break; | |
| 99 | - default: | |
| 100 | - break; | |
| 66 | + objReturn.detalleImpuestosItemFactura.push(require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals, objReturn)); // 120 | |
| 101 | 67 | } |
| 102 | 68 | }); |
| 103 | 69 |
watch/index.js
| ... | ... | @@ -6,12 +6,12 @@ module.exports = function(dir, callback) { |
| 6 | 6 | |
| 7 | 7 | var extencion = file.split('.')[1]; |
| 8 | 8 | |
| 9 | - if (extencion == 'plx' && event == 'change') { | |
| 9 | + if (extencion == 'txt' && event == 'change') { | |
| 10 | 10 | |
| 11 | 11 | fs.readFile(dir + '\\' + file, 'utf8', function(err , fileString) { |
| 12 | 12 | |
| 13 | 13 | callback(event, fileString); |
| 14 | - }) | |
| 14 | + }); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | }); |