index.js
4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module.exports = function(comprobante) {
// split por salto de línea
comprobante = comprobante.split(/\r?\n/);
var objReturn = {
identificaxComprobante: {},
identificaxMensaje: {},
comprobantesReferencia: [],
identificaxEmisor: {},
informaxRepresentanteEmisor: {},
identificaxReceptorFactura: {},
identificaxSucursalReceptorFactura: {},
importesTotales: {},
detallesImportesIVA: {},
detallePercepcionesIIBB: {},
descuentosGlobalesFactura: {},
detalleOtrosImpuestosComprobante: {},
itemsFactura: [],
detalleDescuentosItemFactura: [],
detalleImpuestosItemFactura: []
};
function returnFloatByDecimals(parameter, cantDecimal) {
if (!parameter) return;
var beforeSemiColon = parseFloat(parameter.slice(0, parameter.length - cantDecimal));
var afterSemicolon = parameter.slice(parameter.length - cantDecimal, parameter.length);
return parseFloat(beforeSemiColon + '.' + afterSemicolon);
}
comprobante.forEach(sector => {
if (sector.slice(0, 3) == '010') {
objReturn.identificaxComprobante = require('./identificaxComprobante')(sector)// 010
} 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
} else if (sector.slice(0, 3) == '030') {
objReturn.identificaxEmisor = require('./identificaxEmisor')(sector) // 030
} else if (sector.slice(0, 3) == '035') {
objReturn.informaxRepresentanteEmisor = require('./informaxRepresentanteEmisor')(sector) // 035
} else if (sector.slice(0, 3) == '040') {
objReturn.identificaxReceptorFactura = require('./identificaxReceptorFactura')(sector) // 040
} else if (sector.slice(0, 3) == '045') {
objReturn.identificaxSucursalReceptorFactura = require('./identificaxSucursalReceptorFactura')(sector) // 045
} else if (sector.slice(0, 3) == '050') {
objReturn.importesTotales = require('./importesTotales')(sector, returnFloatByDecimals) // 050
} else if (sector.slice(0, 3) == '060') {
objReturn.detallesImportesIVA = require('./detallesImportesIVA')(sector, returnFloatByDecimals) // 060
} else if (sector.slice(0, 3) == '070') {
objReturn.detallePercepcionesIIBB = require('./detallePercepcionesIIBB')(sector, returnFloatByDecimals) // 070
} 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
} 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
} 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;
}
});
return objReturn;
}