index.js
3.22 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
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') {
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') {
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') {
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.push(require('./detalleDescuentosItemFactura')(sector, returnFloatByDecimals)); // 110
} else if (sector.slice(0, 3) == '120') {
objReturn.detalleImpuestosItemFactura.push(require('./detalleImpuestosItemFactura')(sector, returnFloatByDecimals, objReturn)); // 120
}
});
return objReturn;
}