@sri-xml-viewer/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +527 -0
- package/dist/index.d.cts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +484 -0
- package/package.json +32 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
TYPE_IDENTITY: () => TYPE_IDENTITY,
|
|
24
|
+
getDataAccessKey: () => getDataAccessKey,
|
|
25
|
+
getDetailsFc: () => getDetailsFc,
|
|
26
|
+
getFullInvoiceDataFromXml: () => getFullInvoiceDataFromXml,
|
|
27
|
+
getInfoAdicional: () => getInfoAdicional,
|
|
28
|
+
getInfoFactura: () => getInfoFactura,
|
|
29
|
+
getInfoTributaria: () => getInfoTributaria,
|
|
30
|
+
getKeyData: () => getKeyData,
|
|
31
|
+
getPagos: () => getPagos,
|
|
32
|
+
getTotals: () => getTotals,
|
|
33
|
+
nameCodeRetention: () => nameCodeRetention,
|
|
34
|
+
parseXml: () => parseXml,
|
|
35
|
+
parseXmlString: () => parseXmlString,
|
|
36
|
+
typeDocument: () => typeDocument,
|
|
37
|
+
typeRtFee: () => typeRtFee,
|
|
38
|
+
typesIvaFee: () => typesIvaFee,
|
|
39
|
+
typesPaymentSRI: () => typesPaymentSRI
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/constants.ts
|
|
44
|
+
var typesIvaFee = [
|
|
45
|
+
{ label: "0%", code: "0", declarationCode: 507, fee: 0, status: true },
|
|
46
|
+
{ label: "12%", code: "2", declarationCode: 500, fee: 12, status: false },
|
|
47
|
+
{ label: "14%", code: "3", declarationCode: 500, fee: 14, status: false },
|
|
48
|
+
{ label: "No Objeto de Impuesto", code: "6", declarationCode: 532, fee: 0, status: true },
|
|
49
|
+
{ label: "Exento de IVA", code: "7", declarationCode: 532, fee: 0, status: true },
|
|
50
|
+
{ label: "13%", code: "10", declarationCode: 500, fee: 13, status: false },
|
|
51
|
+
{ label: "15%", code: "4", declarationCode: 500, fee: 15, status: true },
|
|
52
|
+
{ label: "5%", code: "5", declarationCode: 540, fee: 5, status: true },
|
|
53
|
+
{ label: "Iva Diferenciado", code: "8", declarationCode: 500, fee: 5, status: false }
|
|
54
|
+
];
|
|
55
|
+
var typeRtFee = [
|
|
56
|
+
{ value: "2", code: "1", label: "I_Renta" },
|
|
57
|
+
{ value: "1", code: "2", label: "IVA" },
|
|
58
|
+
{ value: "3", code: "6", label: "ISD" }
|
|
59
|
+
];
|
|
60
|
+
var typeDocument = [
|
|
61
|
+
{ value: "01", label: "FACTURA", shortName: "FAC" },
|
|
62
|
+
{ value: "03", label: "LIQUIDACI\xD3N DE COMPRA DE BIENES Y PRESTACI\xD3N DE SERVICIOS", shortName: "LIQ" },
|
|
63
|
+
{ value: "04", label: "NOTA DE CR\xC9DITO", shortName: "NC" },
|
|
64
|
+
{ value: "05", label: "NOTA DE D\xC9BITO", shortName: "ND" },
|
|
65
|
+
{ value: "06", label: "GU\xCDA DE REMISI\xD3N", shortName: "GR" },
|
|
66
|
+
{ value: "07", label: "RETENCI\xD3N", shortName: "RET" }
|
|
67
|
+
];
|
|
68
|
+
var TYPE_IDENTITY = [
|
|
69
|
+
{ label: "RUC", value: "04", forForm: true },
|
|
70
|
+
{ label: "C\xE9dula", value: "05", forForm: true },
|
|
71
|
+
{ label: "Pasaporte", value: "06", forForm: true },
|
|
72
|
+
{ label: "Consumidor Final", value: "07" },
|
|
73
|
+
{ label: "Identificaci\xF3n del Exterior", value: "08", forForm: true },
|
|
74
|
+
{ label: "Placa", value: "09" }
|
|
75
|
+
];
|
|
76
|
+
var typesPaymentSRI = [
|
|
77
|
+
{ value: "01", label: "SIN UTILIZACI\xD3N DEL SISTEMA FINANCIERO" },
|
|
78
|
+
{ value: "15", label: "COMPENSACI\xD3N DE DEUDAS" },
|
|
79
|
+
{ value: "16", label: "TARJETA DE D\xC9BITO" },
|
|
80
|
+
{ value: "17", label: "DINERO ELECTR\xD3NICO" },
|
|
81
|
+
{ value: "18", label: "TARJETA PREPAGO" },
|
|
82
|
+
{ value: "19", label: "TARJETA DE CR\xC9DITO" },
|
|
83
|
+
{ value: "20", label: "OTROS CON UTILIZACI\xD3N DEL SISTEMA FINANCIERO" },
|
|
84
|
+
{ value: "21", label: "ENDOSO DE T\xCDTULOS" }
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
// src/parser.ts
|
|
88
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
89
|
+
function parseXmlString(xml) {
|
|
90
|
+
if (isBrowser) {
|
|
91
|
+
const parser = new DOMParser();
|
|
92
|
+
const doc = parser.parseFromString(xml, "text/xml");
|
|
93
|
+
if (doc.getElementsByTagName("parsererror").length > 0) {
|
|
94
|
+
throw new Error(doc.getElementsByTagName("parsererror")[0]?.textContent || "Error de parseo de XML");
|
|
95
|
+
}
|
|
96
|
+
return doc;
|
|
97
|
+
} else {
|
|
98
|
+
const GlobalDOMParser = globalThis.DOMParser;
|
|
99
|
+
if (GlobalDOMParser) {
|
|
100
|
+
const parser = new GlobalDOMParser();
|
|
101
|
+
return parser.parseFromString(xml, "text/xml");
|
|
102
|
+
}
|
|
103
|
+
throw new Error("DOMParser no est\xE1 disponible globalmente. Para entornos SSR / Node.js, por favor define globalThis.DOMParser usando una librer\xEDa como @xmldom/xmldom.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function getDataAccessKey(key) {
|
|
107
|
+
let emissionDate = "";
|
|
108
|
+
let identify = "";
|
|
109
|
+
let numero_doc = key.slice(24, 39);
|
|
110
|
+
let type = "";
|
|
111
|
+
let mode = null;
|
|
112
|
+
type = key.slice(8, 10);
|
|
113
|
+
identify = key.slice(10, 23);
|
|
114
|
+
mode = key.slice(23, 24);
|
|
115
|
+
emissionDate = key.slice(0, 8);
|
|
116
|
+
emissionDate = `${emissionDate.slice(0, 2)}/${emissionDate.slice(2, 4)}/${emissionDate.slice(4, 8)}`;
|
|
117
|
+
numero_doc = `${numero_doc.slice(0, 3)}-${numero_doc.slice(3, 6)}-${numero_doc.slice(6, 15)}`;
|
|
118
|
+
const name_doc = typeDocument.find((rs) => rs.value === type)?.label ?? "";
|
|
119
|
+
return {
|
|
120
|
+
emissionDate,
|
|
121
|
+
ruc: identify,
|
|
122
|
+
numberDoc: numero_doc,
|
|
123
|
+
type,
|
|
124
|
+
typeWithName: name_doc,
|
|
125
|
+
typeWithCode: type,
|
|
126
|
+
mode
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function getKeyData(key) {
|
|
130
|
+
return getDataAccessKey(key);
|
|
131
|
+
}
|
|
132
|
+
function getPagos(doc) {
|
|
133
|
+
const result = [];
|
|
134
|
+
const data = doc?.getElementsByTagName("pagos");
|
|
135
|
+
if (!data)
|
|
136
|
+
return result;
|
|
137
|
+
const firstElement = data.item(0)?.children;
|
|
138
|
+
if (!firstElement)
|
|
139
|
+
return result;
|
|
140
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
141
|
+
const child = firstElement[i];
|
|
142
|
+
if (child?.tagName) {
|
|
143
|
+
const codePago = child.getElementsByTagName("formaPago")[0]?.textContent || "";
|
|
144
|
+
const namePago = typesPaymentSRI.find((rs) => rs.value === codePago)?.label || "";
|
|
145
|
+
const obj = {
|
|
146
|
+
formaPago: namePago,
|
|
147
|
+
total: child.getElementsByTagName("total")[0]?.textContent || "",
|
|
148
|
+
plazo: child.getElementsByTagName("plazo")[0]?.textContent || "",
|
|
149
|
+
unidadTiempo: child.getElementsByTagName("unidadTiempo")[0]?.textContent || ""
|
|
150
|
+
};
|
|
151
|
+
result.push(obj);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function getInfoAdicional(doc) {
|
|
157
|
+
const result = [];
|
|
158
|
+
const data = doc?.getElementsByTagName("infoAdicional");
|
|
159
|
+
if (!data)
|
|
160
|
+
return result;
|
|
161
|
+
const firstElement = data.item(0)?.children;
|
|
162
|
+
if (firstElement) {
|
|
163
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
164
|
+
const child = firstElement[i];
|
|
165
|
+
if (child?.tagName) {
|
|
166
|
+
const obj = {
|
|
167
|
+
name: child.getAttribute("nombre") || "",
|
|
168
|
+
value: child.textContent || ""
|
|
169
|
+
};
|
|
170
|
+
result.push(obj);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function getInfoFactura(doc) {
|
|
177
|
+
const data = doc?.getElementsByTagName("infoFactura");
|
|
178
|
+
if (!data)
|
|
179
|
+
return {};
|
|
180
|
+
const result = {};
|
|
181
|
+
const firstElement = data.item(0)?.children;
|
|
182
|
+
if (firstElement) {
|
|
183
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
184
|
+
const child = firstElement[i];
|
|
185
|
+
switch (child?.tagName) {
|
|
186
|
+
case "pagos":
|
|
187
|
+
case "totalConImpuestos":
|
|
188
|
+
continue;
|
|
189
|
+
case void 0:
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
if (child?.tagName)
|
|
193
|
+
result[child.tagName || "na"] = child.textContent || "";
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
function getDetailsFc(doc) {
|
|
201
|
+
const data = doc?.getElementsByTagName("detalles");
|
|
202
|
+
const result = [];
|
|
203
|
+
if (!data)
|
|
204
|
+
return result;
|
|
205
|
+
const firstElement = data.item(0)?.children;
|
|
206
|
+
if (firstElement) {
|
|
207
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
208
|
+
const elementDetail = firstElement[i];
|
|
209
|
+
if (!elementDetail?.children)
|
|
210
|
+
continue;
|
|
211
|
+
const impuestosElement = elementDetail?.getElementsByTagName("impuestos")[0]?.children;
|
|
212
|
+
const impuestos = {
|
|
213
|
+
impuesto: []
|
|
214
|
+
};
|
|
215
|
+
if (impuestosElement) {
|
|
216
|
+
for (let k = 0; k < impuestosElement.length; k++) {
|
|
217
|
+
const impuestoElement = impuestosElement[k];
|
|
218
|
+
const tax = {
|
|
219
|
+
codigo: impuestoElement?.getElementsByTagName("codigo")[0]?.textContent || "",
|
|
220
|
+
codigoPorcentaje: impuestoElement?.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "",
|
|
221
|
+
descuentoAdicional: impuestoElement?.getElementsByTagName("descuentoAdicional")[0]?.textContent || void 0,
|
|
222
|
+
baseImponible: impuestoElement?.getElementsByTagName("baseImponible")[0]?.textContent || "",
|
|
223
|
+
tarifa: impuestoElement?.getElementsByTagName("tarifa")[0]?.textContent || "",
|
|
224
|
+
valor: impuestoElement?.getElementsByTagName("valor")[0]?.textContent || ""
|
|
225
|
+
};
|
|
226
|
+
impuestos.impuesto.push(tax);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const detAdicionalElement = elementDetail?.getElementsByTagName("detallesAdicionales")[0]?.children;
|
|
230
|
+
const detallesAdicionales = {
|
|
231
|
+
detAdicional: []
|
|
232
|
+
};
|
|
233
|
+
if (detAdicionalElement) {
|
|
234
|
+
for (let k = 0; k < detAdicionalElement.length; k++) {
|
|
235
|
+
const detAdicionalElementItem = detAdicionalElement[k];
|
|
236
|
+
const item = {
|
|
237
|
+
"@nombre": detAdicionalElementItem?.getElementsByTagName("nombre")[0]?.textContent || "",
|
|
238
|
+
"@valor": detAdicionalElementItem?.getElementsByTagName("valor")[0]?.textContent || ""
|
|
239
|
+
};
|
|
240
|
+
detallesAdicionales.detAdicional.push(item);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const detail = {
|
|
244
|
+
codigoPrincipal: elementDetail?.getElementsByTagName("codigoPrincipal")[0]?.textContent || "",
|
|
245
|
+
codigoAuxiliar: elementDetail?.getElementsByTagName("codigoAuxiliar")[0]?.textContent || void 0,
|
|
246
|
+
descripcion: elementDetail?.getElementsByTagName("descripcion")[0]?.textContent || "",
|
|
247
|
+
unidadMedida: elementDetail?.getElementsByTagName("unidadMedida")[0]?.textContent || void 0,
|
|
248
|
+
cantidad: elementDetail?.getElementsByTagName("cantidad")[0]?.textContent || "",
|
|
249
|
+
precioUnitario: elementDetail?.getElementsByTagName("precioUnitario")[0]?.textContent || "0",
|
|
250
|
+
precioSinSubsidio: elementDetail?.getElementsByTagName("precioSinSubsidio")[0]?.textContent || void 0,
|
|
251
|
+
descuento: elementDetail?.getElementsByTagName("descuento")[0]?.textContent || "0",
|
|
252
|
+
impuestos,
|
|
253
|
+
detallesAdicionales: detallesAdicionales.detAdicional.length > 0 ? detallesAdicionales : void 0,
|
|
254
|
+
precioTotalSinImpuesto: elementDetail?.getElementsByTagName("precioTotalSinImpuesto")[0]?.textContent || "0"
|
|
255
|
+
};
|
|
256
|
+
result.push(detail);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
function getTotals(doc) {
|
|
262
|
+
const accessKey = doc?.getElementsByTagName("claveAcceso")[0]?.textContent || "";
|
|
263
|
+
const datakey = getDataAccessKey(accessKey);
|
|
264
|
+
if (!datakey)
|
|
265
|
+
return [];
|
|
266
|
+
switch (datakey.type) {
|
|
267
|
+
case "01": {
|
|
268
|
+
return totalF(doc);
|
|
269
|
+
}
|
|
270
|
+
case "04": {
|
|
271
|
+
return totalNC(doc);
|
|
272
|
+
}
|
|
273
|
+
default:
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function getInfoTributaria(doc) {
|
|
278
|
+
const data = doc?.getElementsByTagName("infoTributaria");
|
|
279
|
+
if (!data)
|
|
280
|
+
return {};
|
|
281
|
+
const result = {};
|
|
282
|
+
const firstElement = data.item(0)?.children;
|
|
283
|
+
if (firstElement) {
|
|
284
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
285
|
+
const child = firstElement[i];
|
|
286
|
+
if (child?.tagName) {
|
|
287
|
+
result[child.tagName || "na"] = child.textContent || "";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
function parseXml(xml) {
|
|
294
|
+
if (!xml) {
|
|
295
|
+
throw new Error("No se ha recibido el XML, el xml est\xE1 vac\xEDo");
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const dataOfSri = parseXmlString(xml);
|
|
299
|
+
const fechaAutorizacion = dataOfSri.getElementsByTagName("fechaAutorizacion")[0]?.innerHTML;
|
|
300
|
+
const comprobante = dataOfSri.getElementsByTagName("comprobante")[0];
|
|
301
|
+
let accessKey = "";
|
|
302
|
+
let dataComprobante;
|
|
303
|
+
if (comprobante) {
|
|
304
|
+
const childNodes = comprobante?.childNodes || [];
|
|
305
|
+
let cdataContent = "";
|
|
306
|
+
if (childNodes.length === 0) {
|
|
307
|
+
cdataContent = childNodes[0]?.nodeValue?.trim() || "";
|
|
308
|
+
} else {
|
|
309
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
310
|
+
if (childNodes[i]?.nodeType === 4) {
|
|
311
|
+
cdataContent = childNodes[i]?.nodeValue?.trim() || "";
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
dataComprobante = parseXmlString(cdataContent);
|
|
317
|
+
accessKey = dataComprobante.getElementsByTagName("claveAcceso")[0]?.innerHTML || "";
|
|
318
|
+
} else {
|
|
319
|
+
accessKey = dataOfSri.getElementsByTagName("claveAcceso")[0]?.innerHTML || "";
|
|
320
|
+
dataComprobante = dataOfSri;
|
|
321
|
+
}
|
|
322
|
+
const dataKey = getDataAccessKey(accessKey);
|
|
323
|
+
const data = {
|
|
324
|
+
numAuto: accessKey,
|
|
325
|
+
dateAuto: fechaAutorizacion,
|
|
326
|
+
documentData: dataComprobante,
|
|
327
|
+
numberDocument: dataKey.numberDoc,
|
|
328
|
+
typeDoc: dataKey.type,
|
|
329
|
+
emissionDate: dataKey.emissionDate
|
|
330
|
+
};
|
|
331
|
+
return data;
|
|
332
|
+
} catch (e) {
|
|
333
|
+
throw new TypeError(`Error al parsear el XML: ${e.message}`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function totalF(doc) {
|
|
337
|
+
const dataTable = [];
|
|
338
|
+
const allTypes = typesIvaFee.map((data) => {
|
|
339
|
+
return {
|
|
340
|
+
type: "2",
|
|
341
|
+
code: data.code,
|
|
342
|
+
name: data.label,
|
|
343
|
+
fee: data.fee,
|
|
344
|
+
base: 0,
|
|
345
|
+
totalTax: 0
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
let totalIce = 0;
|
|
349
|
+
let totalIRBPNR = 0;
|
|
350
|
+
let totalDEVOLUCIONIVA = 0;
|
|
351
|
+
const totalConImpuestoElement = doc?.getElementsByTagName("totalConImpuestos")[0];
|
|
352
|
+
if (!totalConImpuestoElement)
|
|
353
|
+
return [];
|
|
354
|
+
for (let i = 0; i < totalConImpuestoElement.children.length; i++) {
|
|
355
|
+
const child = totalConImpuestoElement.children[i];
|
|
356
|
+
if (child?.tagName === "totalImpuesto") {
|
|
357
|
+
const cod = child.getElementsByTagName("codigo")[0]?.textContent || "";
|
|
358
|
+
const codigoPorcentaje = child.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "";
|
|
359
|
+
switch (cod) {
|
|
360
|
+
case "3":
|
|
361
|
+
totalIce += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
362
|
+
break;
|
|
363
|
+
case "5":
|
|
364
|
+
totalIRBPNR += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
365
|
+
break;
|
|
366
|
+
default:
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
const valorDevolucionIva = child.getElementsByTagName("valorDevolucionIva")[0]?.textContent || void 0;
|
|
370
|
+
if (valorDevolucionIva) {
|
|
371
|
+
totalDEVOLUCIONIVA += Number.parseFloat(valorDevolucionIva ?? "0");
|
|
372
|
+
}
|
|
373
|
+
const index = allTypes.findIndex((data) => {
|
|
374
|
+
return data.code === codigoPorcentaje;
|
|
375
|
+
});
|
|
376
|
+
if (index !== -1 && allTypes[index]) {
|
|
377
|
+
const baseImponible = child.getElementsByTagName("baseImponible")[0]?.textContent || "0";
|
|
378
|
+
const valor = child.getElementsByTagName("valor")[0]?.textContent || "0";
|
|
379
|
+
allTypes[index].base = Number.parseFloat(baseImponible);
|
|
380
|
+
allTypes[index].totalTax = Number.parseFloat(valor);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const newAllTypes = allTypes.filter((data) => data.base > 0);
|
|
385
|
+
newAllTypes.forEach((data) => {
|
|
386
|
+
dataTable.push({ name: `SUBTOTAL ${data.fee} %`, valor: data.base });
|
|
387
|
+
});
|
|
388
|
+
const totalSinImpuestos = Number.parseFloat(doc?.getElementsByTagName("totalSinImpuestos")[0]?.textContent || "0");
|
|
389
|
+
dataTable.push({ name: "SUBTOTAL SIN IMPUESTOS", valor: totalSinImpuestos });
|
|
390
|
+
const totalDescuento = Number.parseFloat(doc?.getElementsByTagName("totalDescuento")[0]?.textContent || "0");
|
|
391
|
+
dataTable.push({
|
|
392
|
+
name: "TOTAL DESCUENTO",
|
|
393
|
+
valor: totalDescuento
|
|
394
|
+
});
|
|
395
|
+
dataTable.push({
|
|
396
|
+
name: "ICE",
|
|
397
|
+
valor: totalIce
|
|
398
|
+
});
|
|
399
|
+
newAllTypes.filter((rs) => rs.fee > 0).forEach((data) => {
|
|
400
|
+
dataTable.push({ name: `IVA ${data.fee}`, valor: data.totalTax });
|
|
401
|
+
});
|
|
402
|
+
dataTable.push({ name: "TOTAL DEVOLUCI\xD3N IVA", valor: totalDEVOLUCIONIVA });
|
|
403
|
+
dataTable.push({
|
|
404
|
+
name: "IRBPNR",
|
|
405
|
+
valor: totalIRBPNR
|
|
406
|
+
});
|
|
407
|
+
const importeTotal = Number.parseFloat(doc?.getElementsByTagName("importeTotal")[0]?.textContent || "0");
|
|
408
|
+
dataTable.push({
|
|
409
|
+
name: "VALOR TOTAL",
|
|
410
|
+
valor: importeTotal
|
|
411
|
+
});
|
|
412
|
+
return dataTable;
|
|
413
|
+
}
|
|
414
|
+
function totalNC(doc) {
|
|
415
|
+
const dataTable = [];
|
|
416
|
+
const allTypes = typesIvaFee.map((data) => {
|
|
417
|
+
return {
|
|
418
|
+
type: data.code,
|
|
419
|
+
name: data.label,
|
|
420
|
+
tarifa: data.fee,
|
|
421
|
+
iva: 0,
|
|
422
|
+
total: 0
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
let totalIce = 0;
|
|
426
|
+
let totalIRBPNR = 0;
|
|
427
|
+
const totalConImpuestoElement = doc?.getElementsByTagName("totalConImpuestos")[0];
|
|
428
|
+
if (!totalConImpuestoElement)
|
|
429
|
+
return [];
|
|
430
|
+
for (let i = 0; i < totalConImpuestoElement.children.length; i++) {
|
|
431
|
+
const child = totalConImpuestoElement.children[i];
|
|
432
|
+
if (child?.tagName === "totalImpuesto") {
|
|
433
|
+
const cod = child.getElementsByTagName("codigo")[0]?.textContent || "";
|
|
434
|
+
const codigoPorcentaje = child.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "";
|
|
435
|
+
switch (cod) {
|
|
436
|
+
case "3":
|
|
437
|
+
totalIce += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
438
|
+
break;
|
|
439
|
+
case "5":
|
|
440
|
+
totalIRBPNR += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
441
|
+
break;
|
|
442
|
+
default:
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
const index = allTypes.findIndex((data) => {
|
|
446
|
+
return data.type === codigoPorcentaje;
|
|
447
|
+
});
|
|
448
|
+
if (index !== -1 && allTypes[index]) {
|
|
449
|
+
const baseImponible = child.getElementsByTagName("baseImponible")[0]?.textContent || "0";
|
|
450
|
+
const valor = child.getElementsByTagName("valor")[0]?.textContent || "0";
|
|
451
|
+
allTypes[index].total = Number.parseFloat(baseImponible);
|
|
452
|
+
allTypes[index].iva = Number.parseFloat(valor);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const impuestos = allTypes.filter((data) => data.total > 0);
|
|
457
|
+
const impuestos_0 = allTypes.filter((data) => data.tarifa === 0);
|
|
458
|
+
impuestos.forEach((data) => {
|
|
459
|
+
dataTable.push({ name: `SUBTOTAL ${data.name}`, valor: data.total });
|
|
460
|
+
});
|
|
461
|
+
impuestos_0.forEach((data) => {
|
|
462
|
+
dataTable.push({ name: `SUBTOTAL ${data.name}`, valor: data.total });
|
|
463
|
+
});
|
|
464
|
+
const totalSinImpuestos = Number.parseFloat(doc?.getElementsByTagName("totalSinImpuestos")[0]?.textContent || "0");
|
|
465
|
+
dataTable.push({ name: "SUBTOTAL SIN IMPUESTOS", valor: totalSinImpuestos });
|
|
466
|
+
dataTable.push({
|
|
467
|
+
name: "ICE",
|
|
468
|
+
valor: totalIce
|
|
469
|
+
});
|
|
470
|
+
impuestos.forEach((data) => {
|
|
471
|
+
dataTable.push({ name: `IVA ${data.name}`, valor: data.iva });
|
|
472
|
+
});
|
|
473
|
+
dataTable.push({
|
|
474
|
+
name: "IRBPNR",
|
|
475
|
+
valor: totalIRBPNR
|
|
476
|
+
});
|
|
477
|
+
const valorModificado = Number.parseFloat(doc?.getElementsByTagName("valorModificado")[0]?.textContent || "0");
|
|
478
|
+
dataTable.push({
|
|
479
|
+
name: "VALOR TOTAL",
|
|
480
|
+
valor: valorModificado
|
|
481
|
+
});
|
|
482
|
+
return dataTable;
|
|
483
|
+
}
|
|
484
|
+
function nameCodeRetention(code) {
|
|
485
|
+
return code;
|
|
486
|
+
}
|
|
487
|
+
function getFullInvoiceDataFromXml(xmlString) {
|
|
488
|
+
const parsed = parseXml(xmlString);
|
|
489
|
+
if (!parsed || !parsed.documentData) {
|
|
490
|
+
throw new Error("No se pudo parsear el XML o no contiene datos del comprobante");
|
|
491
|
+
}
|
|
492
|
+
const doc = parsed.documentData;
|
|
493
|
+
return {
|
|
494
|
+
accessKey: parsed.numAuto,
|
|
495
|
+
dateAuthorization: parsed.dateAuto,
|
|
496
|
+
numberDocument: parsed.numberDocument,
|
|
497
|
+
typeDoc: parsed.typeDoc,
|
|
498
|
+
emissionDate: parsed.emissionDate ?? "",
|
|
499
|
+
documentData: doc,
|
|
500
|
+
infoTributaria: getInfoTributaria(doc),
|
|
501
|
+
infoFactura: getInfoFactura(doc),
|
|
502
|
+
details: getDetailsFc(doc),
|
|
503
|
+
totals: getTotals(doc),
|
|
504
|
+
payments: getPagos(doc),
|
|
505
|
+
additionalInfo: getInfoAdicional(doc)
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
509
|
+
0 && (module.exports = {
|
|
510
|
+
TYPE_IDENTITY,
|
|
511
|
+
getDataAccessKey,
|
|
512
|
+
getDetailsFc,
|
|
513
|
+
getFullInvoiceDataFromXml,
|
|
514
|
+
getInfoAdicional,
|
|
515
|
+
getInfoFactura,
|
|
516
|
+
getInfoTributaria,
|
|
517
|
+
getKeyData,
|
|
518
|
+
getPagos,
|
|
519
|
+
getTotals,
|
|
520
|
+
nameCodeRetention,
|
|
521
|
+
parseXml,
|
|
522
|
+
parseXmlString,
|
|
523
|
+
typeDocument,
|
|
524
|
+
typeRtFee,
|
|
525
|
+
typesIvaFee,
|
|
526
|
+
typesPaymentSRI
|
|
527
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
interface IDataKey {
|
|
2
|
+
emissionDate: string;
|
|
3
|
+
ruc: string;
|
|
4
|
+
numberDoc: string;
|
|
5
|
+
type: string;
|
|
6
|
+
typeWithName: string;
|
|
7
|
+
typeWithCode: string;
|
|
8
|
+
mode: string | null;
|
|
9
|
+
}
|
|
10
|
+
interface Tax {
|
|
11
|
+
codigo: string;
|
|
12
|
+
codigoPorcentaje: string;
|
|
13
|
+
descuentoAdicional?: string;
|
|
14
|
+
baseImponible: string;
|
|
15
|
+
tarifa: string;
|
|
16
|
+
valor: string;
|
|
17
|
+
}
|
|
18
|
+
interface Taxes {
|
|
19
|
+
impuesto: Tax[];
|
|
20
|
+
}
|
|
21
|
+
interface AdditionalDetailItem {
|
|
22
|
+
'@nombre': string;
|
|
23
|
+
'@valor': string;
|
|
24
|
+
}
|
|
25
|
+
interface AdditionalDetails {
|
|
26
|
+
detAdicional: AdditionalDetailItem[];
|
|
27
|
+
}
|
|
28
|
+
interface Detail {
|
|
29
|
+
codigoPrincipal: string;
|
|
30
|
+
codigoAuxiliar?: string;
|
|
31
|
+
descripcion: string;
|
|
32
|
+
unidadMedida?: string;
|
|
33
|
+
cantidad: string;
|
|
34
|
+
precioUnitario: string;
|
|
35
|
+
precioSinSubsidio?: string;
|
|
36
|
+
descuento: string;
|
|
37
|
+
impuestos: Taxes;
|
|
38
|
+
detallesAdicionales?: AdditionalDetails;
|
|
39
|
+
precioTotalSinImpuesto: string;
|
|
40
|
+
}
|
|
41
|
+
interface Payment {
|
|
42
|
+
formaPago: string;
|
|
43
|
+
total: string;
|
|
44
|
+
plazo?: string;
|
|
45
|
+
unidadTiempo?: string;
|
|
46
|
+
}
|
|
47
|
+
interface ITotal {
|
|
48
|
+
name: string;
|
|
49
|
+
value: number;
|
|
50
|
+
code: string;
|
|
51
|
+
taxType?: string;
|
|
52
|
+
order?: number;
|
|
53
|
+
}
|
|
54
|
+
interface IFullInvoiceData {
|
|
55
|
+
accessKey: string;
|
|
56
|
+
dateAuthorization?: string;
|
|
57
|
+
numberDocument: string;
|
|
58
|
+
typeDoc: string;
|
|
59
|
+
emissionDate: string;
|
|
60
|
+
documentData: Document;
|
|
61
|
+
infoTributaria: Record<string, string>;
|
|
62
|
+
infoFactura: Record<string, string>;
|
|
63
|
+
details: Detail[];
|
|
64
|
+
totals: {
|
|
65
|
+
name: string;
|
|
66
|
+
valor: string | number;
|
|
67
|
+
}[];
|
|
68
|
+
payments: Payment[];
|
|
69
|
+
additionalInfo: {
|
|
70
|
+
name: string;
|
|
71
|
+
value: string;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare function parseXmlString(xml: string): Document;
|
|
76
|
+
declare function getDataAccessKey(key: string): IDataKey;
|
|
77
|
+
declare function getKeyData(key: string): IDataKey;
|
|
78
|
+
declare function getPagos(doc: Document): Payment[];
|
|
79
|
+
declare function getInfoAdicional(doc: Document): {
|
|
80
|
+
name: string;
|
|
81
|
+
value: string;
|
|
82
|
+
}[];
|
|
83
|
+
declare function getInfoFactura(doc: Document): Record<string, string>;
|
|
84
|
+
declare function getDetailsFc(doc: Document): Detail[];
|
|
85
|
+
declare function getTotals(doc: Document): {
|
|
86
|
+
name: string;
|
|
87
|
+
valor: string | number;
|
|
88
|
+
}[];
|
|
89
|
+
declare function getInfoTributaria(doc: Document): Record<string, string>;
|
|
90
|
+
declare function parseXml(xml: string): {
|
|
91
|
+
numAuto: string;
|
|
92
|
+
dateAuto: string;
|
|
93
|
+
documentData: Document;
|
|
94
|
+
numberDocument: string;
|
|
95
|
+
typeDoc: string;
|
|
96
|
+
emissionDate: string;
|
|
97
|
+
};
|
|
98
|
+
declare function nameCodeRetention(code: string): string;
|
|
99
|
+
declare function getFullInvoiceDataFromXml(xmlString: string): IFullInvoiceData;
|
|
100
|
+
|
|
101
|
+
interface ITypesIvaFee {
|
|
102
|
+
label: string;
|
|
103
|
+
code: string;
|
|
104
|
+
declarationCode: number;
|
|
105
|
+
fee: number;
|
|
106
|
+
status: boolean;
|
|
107
|
+
}
|
|
108
|
+
declare const typesIvaFee: ITypesIvaFee[];
|
|
109
|
+
declare const typeRtFee: {
|
|
110
|
+
value: string;
|
|
111
|
+
code: string;
|
|
112
|
+
label: string;
|
|
113
|
+
}[];
|
|
114
|
+
declare const typeDocument: {
|
|
115
|
+
value: string;
|
|
116
|
+
label: string;
|
|
117
|
+
shortName: string;
|
|
118
|
+
}[];
|
|
119
|
+
declare const TYPE_IDENTITY: ({
|
|
120
|
+
label: string;
|
|
121
|
+
value: string;
|
|
122
|
+
forForm: boolean;
|
|
123
|
+
} | {
|
|
124
|
+
label: string;
|
|
125
|
+
value: string;
|
|
126
|
+
forForm?: undefined;
|
|
127
|
+
})[];
|
|
128
|
+
declare const typesPaymentSRI: {
|
|
129
|
+
value: string;
|
|
130
|
+
label: string;
|
|
131
|
+
}[];
|
|
132
|
+
|
|
133
|
+
export { type AdditionalDetailItem, type AdditionalDetails, type Detail, type IDataKey, type IFullInvoiceData, type ITotal, type ITypesIvaFee, type Payment, TYPE_IDENTITY, type Tax, type Taxes, getDataAccessKey, getDetailsFc, getFullInvoiceDataFromXml, getInfoAdicional, getInfoFactura, getInfoTributaria, getKeyData, getPagos, getTotals, nameCodeRetention, parseXml, parseXmlString, typeDocument, typeRtFee, typesIvaFee, typesPaymentSRI };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
interface IDataKey {
|
|
2
|
+
emissionDate: string;
|
|
3
|
+
ruc: string;
|
|
4
|
+
numberDoc: string;
|
|
5
|
+
type: string;
|
|
6
|
+
typeWithName: string;
|
|
7
|
+
typeWithCode: string;
|
|
8
|
+
mode: string | null;
|
|
9
|
+
}
|
|
10
|
+
interface Tax {
|
|
11
|
+
codigo: string;
|
|
12
|
+
codigoPorcentaje: string;
|
|
13
|
+
descuentoAdicional?: string;
|
|
14
|
+
baseImponible: string;
|
|
15
|
+
tarifa: string;
|
|
16
|
+
valor: string;
|
|
17
|
+
}
|
|
18
|
+
interface Taxes {
|
|
19
|
+
impuesto: Tax[];
|
|
20
|
+
}
|
|
21
|
+
interface AdditionalDetailItem {
|
|
22
|
+
'@nombre': string;
|
|
23
|
+
'@valor': string;
|
|
24
|
+
}
|
|
25
|
+
interface AdditionalDetails {
|
|
26
|
+
detAdicional: AdditionalDetailItem[];
|
|
27
|
+
}
|
|
28
|
+
interface Detail {
|
|
29
|
+
codigoPrincipal: string;
|
|
30
|
+
codigoAuxiliar?: string;
|
|
31
|
+
descripcion: string;
|
|
32
|
+
unidadMedida?: string;
|
|
33
|
+
cantidad: string;
|
|
34
|
+
precioUnitario: string;
|
|
35
|
+
precioSinSubsidio?: string;
|
|
36
|
+
descuento: string;
|
|
37
|
+
impuestos: Taxes;
|
|
38
|
+
detallesAdicionales?: AdditionalDetails;
|
|
39
|
+
precioTotalSinImpuesto: string;
|
|
40
|
+
}
|
|
41
|
+
interface Payment {
|
|
42
|
+
formaPago: string;
|
|
43
|
+
total: string;
|
|
44
|
+
plazo?: string;
|
|
45
|
+
unidadTiempo?: string;
|
|
46
|
+
}
|
|
47
|
+
interface ITotal {
|
|
48
|
+
name: string;
|
|
49
|
+
value: number;
|
|
50
|
+
code: string;
|
|
51
|
+
taxType?: string;
|
|
52
|
+
order?: number;
|
|
53
|
+
}
|
|
54
|
+
interface IFullInvoiceData {
|
|
55
|
+
accessKey: string;
|
|
56
|
+
dateAuthorization?: string;
|
|
57
|
+
numberDocument: string;
|
|
58
|
+
typeDoc: string;
|
|
59
|
+
emissionDate: string;
|
|
60
|
+
documentData: Document;
|
|
61
|
+
infoTributaria: Record<string, string>;
|
|
62
|
+
infoFactura: Record<string, string>;
|
|
63
|
+
details: Detail[];
|
|
64
|
+
totals: {
|
|
65
|
+
name: string;
|
|
66
|
+
valor: string | number;
|
|
67
|
+
}[];
|
|
68
|
+
payments: Payment[];
|
|
69
|
+
additionalInfo: {
|
|
70
|
+
name: string;
|
|
71
|
+
value: string;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare function parseXmlString(xml: string): Document;
|
|
76
|
+
declare function getDataAccessKey(key: string): IDataKey;
|
|
77
|
+
declare function getKeyData(key: string): IDataKey;
|
|
78
|
+
declare function getPagos(doc: Document): Payment[];
|
|
79
|
+
declare function getInfoAdicional(doc: Document): {
|
|
80
|
+
name: string;
|
|
81
|
+
value: string;
|
|
82
|
+
}[];
|
|
83
|
+
declare function getInfoFactura(doc: Document): Record<string, string>;
|
|
84
|
+
declare function getDetailsFc(doc: Document): Detail[];
|
|
85
|
+
declare function getTotals(doc: Document): {
|
|
86
|
+
name: string;
|
|
87
|
+
valor: string | number;
|
|
88
|
+
}[];
|
|
89
|
+
declare function getInfoTributaria(doc: Document): Record<string, string>;
|
|
90
|
+
declare function parseXml(xml: string): {
|
|
91
|
+
numAuto: string;
|
|
92
|
+
dateAuto: string;
|
|
93
|
+
documentData: Document;
|
|
94
|
+
numberDocument: string;
|
|
95
|
+
typeDoc: string;
|
|
96
|
+
emissionDate: string;
|
|
97
|
+
};
|
|
98
|
+
declare function nameCodeRetention(code: string): string;
|
|
99
|
+
declare function getFullInvoiceDataFromXml(xmlString: string): IFullInvoiceData;
|
|
100
|
+
|
|
101
|
+
interface ITypesIvaFee {
|
|
102
|
+
label: string;
|
|
103
|
+
code: string;
|
|
104
|
+
declarationCode: number;
|
|
105
|
+
fee: number;
|
|
106
|
+
status: boolean;
|
|
107
|
+
}
|
|
108
|
+
declare const typesIvaFee: ITypesIvaFee[];
|
|
109
|
+
declare const typeRtFee: {
|
|
110
|
+
value: string;
|
|
111
|
+
code: string;
|
|
112
|
+
label: string;
|
|
113
|
+
}[];
|
|
114
|
+
declare const typeDocument: {
|
|
115
|
+
value: string;
|
|
116
|
+
label: string;
|
|
117
|
+
shortName: string;
|
|
118
|
+
}[];
|
|
119
|
+
declare const TYPE_IDENTITY: ({
|
|
120
|
+
label: string;
|
|
121
|
+
value: string;
|
|
122
|
+
forForm: boolean;
|
|
123
|
+
} | {
|
|
124
|
+
label: string;
|
|
125
|
+
value: string;
|
|
126
|
+
forForm?: undefined;
|
|
127
|
+
})[];
|
|
128
|
+
declare const typesPaymentSRI: {
|
|
129
|
+
value: string;
|
|
130
|
+
label: string;
|
|
131
|
+
}[];
|
|
132
|
+
|
|
133
|
+
export { type AdditionalDetailItem, type AdditionalDetails, type Detail, type IDataKey, type IFullInvoiceData, type ITotal, type ITypesIvaFee, type Payment, TYPE_IDENTITY, type Tax, type Taxes, getDataAccessKey, getDetailsFc, getFullInvoiceDataFromXml, getInfoAdicional, getInfoFactura, getInfoTributaria, getKeyData, getPagos, getTotals, nameCodeRetention, parseXml, parseXmlString, typeDocument, typeRtFee, typesIvaFee, typesPaymentSRI };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var typesIvaFee = [
|
|
3
|
+
{ label: "0%", code: "0", declarationCode: 507, fee: 0, status: true },
|
|
4
|
+
{ label: "12%", code: "2", declarationCode: 500, fee: 12, status: false },
|
|
5
|
+
{ label: "14%", code: "3", declarationCode: 500, fee: 14, status: false },
|
|
6
|
+
{ label: "No Objeto de Impuesto", code: "6", declarationCode: 532, fee: 0, status: true },
|
|
7
|
+
{ label: "Exento de IVA", code: "7", declarationCode: 532, fee: 0, status: true },
|
|
8
|
+
{ label: "13%", code: "10", declarationCode: 500, fee: 13, status: false },
|
|
9
|
+
{ label: "15%", code: "4", declarationCode: 500, fee: 15, status: true },
|
|
10
|
+
{ label: "5%", code: "5", declarationCode: 540, fee: 5, status: true },
|
|
11
|
+
{ label: "Iva Diferenciado", code: "8", declarationCode: 500, fee: 5, status: false }
|
|
12
|
+
];
|
|
13
|
+
var typeRtFee = [
|
|
14
|
+
{ value: "2", code: "1", label: "I_Renta" },
|
|
15
|
+
{ value: "1", code: "2", label: "IVA" },
|
|
16
|
+
{ value: "3", code: "6", label: "ISD" }
|
|
17
|
+
];
|
|
18
|
+
var typeDocument = [
|
|
19
|
+
{ value: "01", label: "FACTURA", shortName: "FAC" },
|
|
20
|
+
{ value: "03", label: "LIQUIDACI\xD3N DE COMPRA DE BIENES Y PRESTACI\xD3N DE SERVICIOS", shortName: "LIQ" },
|
|
21
|
+
{ value: "04", label: "NOTA DE CR\xC9DITO", shortName: "NC" },
|
|
22
|
+
{ value: "05", label: "NOTA DE D\xC9BITO", shortName: "ND" },
|
|
23
|
+
{ value: "06", label: "GU\xCDA DE REMISI\xD3N", shortName: "GR" },
|
|
24
|
+
{ value: "07", label: "RETENCI\xD3N", shortName: "RET" }
|
|
25
|
+
];
|
|
26
|
+
var TYPE_IDENTITY = [
|
|
27
|
+
{ label: "RUC", value: "04", forForm: true },
|
|
28
|
+
{ label: "C\xE9dula", value: "05", forForm: true },
|
|
29
|
+
{ label: "Pasaporte", value: "06", forForm: true },
|
|
30
|
+
{ label: "Consumidor Final", value: "07" },
|
|
31
|
+
{ label: "Identificaci\xF3n del Exterior", value: "08", forForm: true },
|
|
32
|
+
{ label: "Placa", value: "09" }
|
|
33
|
+
];
|
|
34
|
+
var typesPaymentSRI = [
|
|
35
|
+
{ value: "01", label: "SIN UTILIZACI\xD3N DEL SISTEMA FINANCIERO" },
|
|
36
|
+
{ value: "15", label: "COMPENSACI\xD3N DE DEUDAS" },
|
|
37
|
+
{ value: "16", label: "TARJETA DE D\xC9BITO" },
|
|
38
|
+
{ value: "17", label: "DINERO ELECTR\xD3NICO" },
|
|
39
|
+
{ value: "18", label: "TARJETA PREPAGO" },
|
|
40
|
+
{ value: "19", label: "TARJETA DE CR\xC9DITO" },
|
|
41
|
+
{ value: "20", label: "OTROS CON UTILIZACI\xD3N DEL SISTEMA FINANCIERO" },
|
|
42
|
+
{ value: "21", label: "ENDOSO DE T\xCDTULOS" }
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
// src/parser.ts
|
|
46
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
47
|
+
function parseXmlString(xml) {
|
|
48
|
+
if (isBrowser) {
|
|
49
|
+
const parser = new DOMParser();
|
|
50
|
+
const doc = parser.parseFromString(xml, "text/xml");
|
|
51
|
+
if (doc.getElementsByTagName("parsererror").length > 0) {
|
|
52
|
+
throw new Error(doc.getElementsByTagName("parsererror")[0]?.textContent || "Error de parseo de XML");
|
|
53
|
+
}
|
|
54
|
+
return doc;
|
|
55
|
+
} else {
|
|
56
|
+
const GlobalDOMParser = globalThis.DOMParser;
|
|
57
|
+
if (GlobalDOMParser) {
|
|
58
|
+
const parser = new GlobalDOMParser();
|
|
59
|
+
return parser.parseFromString(xml, "text/xml");
|
|
60
|
+
}
|
|
61
|
+
throw new Error("DOMParser no est\xE1 disponible globalmente. Para entornos SSR / Node.js, por favor define globalThis.DOMParser usando una librer\xEDa como @xmldom/xmldom.");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function getDataAccessKey(key) {
|
|
65
|
+
let emissionDate = "";
|
|
66
|
+
let identify = "";
|
|
67
|
+
let numero_doc = key.slice(24, 39);
|
|
68
|
+
let type = "";
|
|
69
|
+
let mode = null;
|
|
70
|
+
type = key.slice(8, 10);
|
|
71
|
+
identify = key.slice(10, 23);
|
|
72
|
+
mode = key.slice(23, 24);
|
|
73
|
+
emissionDate = key.slice(0, 8);
|
|
74
|
+
emissionDate = `${emissionDate.slice(0, 2)}/${emissionDate.slice(2, 4)}/${emissionDate.slice(4, 8)}`;
|
|
75
|
+
numero_doc = `${numero_doc.slice(0, 3)}-${numero_doc.slice(3, 6)}-${numero_doc.slice(6, 15)}`;
|
|
76
|
+
const name_doc = typeDocument.find((rs) => rs.value === type)?.label ?? "";
|
|
77
|
+
return {
|
|
78
|
+
emissionDate,
|
|
79
|
+
ruc: identify,
|
|
80
|
+
numberDoc: numero_doc,
|
|
81
|
+
type,
|
|
82
|
+
typeWithName: name_doc,
|
|
83
|
+
typeWithCode: type,
|
|
84
|
+
mode
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function getKeyData(key) {
|
|
88
|
+
return getDataAccessKey(key);
|
|
89
|
+
}
|
|
90
|
+
function getPagos(doc) {
|
|
91
|
+
const result = [];
|
|
92
|
+
const data = doc?.getElementsByTagName("pagos");
|
|
93
|
+
if (!data)
|
|
94
|
+
return result;
|
|
95
|
+
const firstElement = data.item(0)?.children;
|
|
96
|
+
if (!firstElement)
|
|
97
|
+
return result;
|
|
98
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
99
|
+
const child = firstElement[i];
|
|
100
|
+
if (child?.tagName) {
|
|
101
|
+
const codePago = child.getElementsByTagName("formaPago")[0]?.textContent || "";
|
|
102
|
+
const namePago = typesPaymentSRI.find((rs) => rs.value === codePago)?.label || "";
|
|
103
|
+
const obj = {
|
|
104
|
+
formaPago: namePago,
|
|
105
|
+
total: child.getElementsByTagName("total")[0]?.textContent || "",
|
|
106
|
+
plazo: child.getElementsByTagName("plazo")[0]?.textContent || "",
|
|
107
|
+
unidadTiempo: child.getElementsByTagName("unidadTiempo")[0]?.textContent || ""
|
|
108
|
+
};
|
|
109
|
+
result.push(obj);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
function getInfoAdicional(doc) {
|
|
115
|
+
const result = [];
|
|
116
|
+
const data = doc?.getElementsByTagName("infoAdicional");
|
|
117
|
+
if (!data)
|
|
118
|
+
return result;
|
|
119
|
+
const firstElement = data.item(0)?.children;
|
|
120
|
+
if (firstElement) {
|
|
121
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
122
|
+
const child = firstElement[i];
|
|
123
|
+
if (child?.tagName) {
|
|
124
|
+
const obj = {
|
|
125
|
+
name: child.getAttribute("nombre") || "",
|
|
126
|
+
value: child.textContent || ""
|
|
127
|
+
};
|
|
128
|
+
result.push(obj);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
function getInfoFactura(doc) {
|
|
135
|
+
const data = doc?.getElementsByTagName("infoFactura");
|
|
136
|
+
if (!data)
|
|
137
|
+
return {};
|
|
138
|
+
const result = {};
|
|
139
|
+
const firstElement = data.item(0)?.children;
|
|
140
|
+
if (firstElement) {
|
|
141
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
142
|
+
const child = firstElement[i];
|
|
143
|
+
switch (child?.tagName) {
|
|
144
|
+
case "pagos":
|
|
145
|
+
case "totalConImpuestos":
|
|
146
|
+
continue;
|
|
147
|
+
case void 0:
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
if (child?.tagName)
|
|
151
|
+
result[child.tagName || "na"] = child.textContent || "";
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
function getDetailsFc(doc) {
|
|
159
|
+
const data = doc?.getElementsByTagName("detalles");
|
|
160
|
+
const result = [];
|
|
161
|
+
if (!data)
|
|
162
|
+
return result;
|
|
163
|
+
const firstElement = data.item(0)?.children;
|
|
164
|
+
if (firstElement) {
|
|
165
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
166
|
+
const elementDetail = firstElement[i];
|
|
167
|
+
if (!elementDetail?.children)
|
|
168
|
+
continue;
|
|
169
|
+
const impuestosElement = elementDetail?.getElementsByTagName("impuestos")[0]?.children;
|
|
170
|
+
const impuestos = {
|
|
171
|
+
impuesto: []
|
|
172
|
+
};
|
|
173
|
+
if (impuestosElement) {
|
|
174
|
+
for (let k = 0; k < impuestosElement.length; k++) {
|
|
175
|
+
const impuestoElement = impuestosElement[k];
|
|
176
|
+
const tax = {
|
|
177
|
+
codigo: impuestoElement?.getElementsByTagName("codigo")[0]?.textContent || "",
|
|
178
|
+
codigoPorcentaje: impuestoElement?.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "",
|
|
179
|
+
descuentoAdicional: impuestoElement?.getElementsByTagName("descuentoAdicional")[0]?.textContent || void 0,
|
|
180
|
+
baseImponible: impuestoElement?.getElementsByTagName("baseImponible")[0]?.textContent || "",
|
|
181
|
+
tarifa: impuestoElement?.getElementsByTagName("tarifa")[0]?.textContent || "",
|
|
182
|
+
valor: impuestoElement?.getElementsByTagName("valor")[0]?.textContent || ""
|
|
183
|
+
};
|
|
184
|
+
impuestos.impuesto.push(tax);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const detAdicionalElement = elementDetail?.getElementsByTagName("detallesAdicionales")[0]?.children;
|
|
188
|
+
const detallesAdicionales = {
|
|
189
|
+
detAdicional: []
|
|
190
|
+
};
|
|
191
|
+
if (detAdicionalElement) {
|
|
192
|
+
for (let k = 0; k < detAdicionalElement.length; k++) {
|
|
193
|
+
const detAdicionalElementItem = detAdicionalElement[k];
|
|
194
|
+
const item = {
|
|
195
|
+
"@nombre": detAdicionalElementItem?.getElementsByTagName("nombre")[0]?.textContent || "",
|
|
196
|
+
"@valor": detAdicionalElementItem?.getElementsByTagName("valor")[0]?.textContent || ""
|
|
197
|
+
};
|
|
198
|
+
detallesAdicionales.detAdicional.push(item);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const detail = {
|
|
202
|
+
codigoPrincipal: elementDetail?.getElementsByTagName("codigoPrincipal")[0]?.textContent || "",
|
|
203
|
+
codigoAuxiliar: elementDetail?.getElementsByTagName("codigoAuxiliar")[0]?.textContent || void 0,
|
|
204
|
+
descripcion: elementDetail?.getElementsByTagName("descripcion")[0]?.textContent || "",
|
|
205
|
+
unidadMedida: elementDetail?.getElementsByTagName("unidadMedida")[0]?.textContent || void 0,
|
|
206
|
+
cantidad: elementDetail?.getElementsByTagName("cantidad")[0]?.textContent || "",
|
|
207
|
+
precioUnitario: elementDetail?.getElementsByTagName("precioUnitario")[0]?.textContent || "0",
|
|
208
|
+
precioSinSubsidio: elementDetail?.getElementsByTagName("precioSinSubsidio")[0]?.textContent || void 0,
|
|
209
|
+
descuento: elementDetail?.getElementsByTagName("descuento")[0]?.textContent || "0",
|
|
210
|
+
impuestos,
|
|
211
|
+
detallesAdicionales: detallesAdicionales.detAdicional.length > 0 ? detallesAdicionales : void 0,
|
|
212
|
+
precioTotalSinImpuesto: elementDetail?.getElementsByTagName("precioTotalSinImpuesto")[0]?.textContent || "0"
|
|
213
|
+
};
|
|
214
|
+
result.push(detail);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
function getTotals(doc) {
|
|
220
|
+
const accessKey = doc?.getElementsByTagName("claveAcceso")[0]?.textContent || "";
|
|
221
|
+
const datakey = getDataAccessKey(accessKey);
|
|
222
|
+
if (!datakey)
|
|
223
|
+
return [];
|
|
224
|
+
switch (datakey.type) {
|
|
225
|
+
case "01": {
|
|
226
|
+
return totalF(doc);
|
|
227
|
+
}
|
|
228
|
+
case "04": {
|
|
229
|
+
return totalNC(doc);
|
|
230
|
+
}
|
|
231
|
+
default:
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function getInfoTributaria(doc) {
|
|
236
|
+
const data = doc?.getElementsByTagName("infoTributaria");
|
|
237
|
+
if (!data)
|
|
238
|
+
return {};
|
|
239
|
+
const result = {};
|
|
240
|
+
const firstElement = data.item(0)?.children;
|
|
241
|
+
if (firstElement) {
|
|
242
|
+
for (let i = 0; i < firstElement.length; i++) {
|
|
243
|
+
const child = firstElement[i];
|
|
244
|
+
if (child?.tagName) {
|
|
245
|
+
result[child.tagName || "na"] = child.textContent || "";
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
function parseXml(xml) {
|
|
252
|
+
if (!xml) {
|
|
253
|
+
throw new Error("No se ha recibido el XML, el xml est\xE1 vac\xEDo");
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const dataOfSri = parseXmlString(xml);
|
|
257
|
+
const fechaAutorizacion = dataOfSri.getElementsByTagName("fechaAutorizacion")[0]?.innerHTML;
|
|
258
|
+
const comprobante = dataOfSri.getElementsByTagName("comprobante")[0];
|
|
259
|
+
let accessKey = "";
|
|
260
|
+
let dataComprobante;
|
|
261
|
+
if (comprobante) {
|
|
262
|
+
const childNodes = comprobante?.childNodes || [];
|
|
263
|
+
let cdataContent = "";
|
|
264
|
+
if (childNodes.length === 0) {
|
|
265
|
+
cdataContent = childNodes[0]?.nodeValue?.trim() || "";
|
|
266
|
+
} else {
|
|
267
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
268
|
+
if (childNodes[i]?.nodeType === 4) {
|
|
269
|
+
cdataContent = childNodes[i]?.nodeValue?.trim() || "";
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
dataComprobante = parseXmlString(cdataContent);
|
|
275
|
+
accessKey = dataComprobante.getElementsByTagName("claveAcceso")[0]?.innerHTML || "";
|
|
276
|
+
} else {
|
|
277
|
+
accessKey = dataOfSri.getElementsByTagName("claveAcceso")[0]?.innerHTML || "";
|
|
278
|
+
dataComprobante = dataOfSri;
|
|
279
|
+
}
|
|
280
|
+
const dataKey = getDataAccessKey(accessKey);
|
|
281
|
+
const data = {
|
|
282
|
+
numAuto: accessKey,
|
|
283
|
+
dateAuto: fechaAutorizacion,
|
|
284
|
+
documentData: dataComprobante,
|
|
285
|
+
numberDocument: dataKey.numberDoc,
|
|
286
|
+
typeDoc: dataKey.type,
|
|
287
|
+
emissionDate: dataKey.emissionDate
|
|
288
|
+
};
|
|
289
|
+
return data;
|
|
290
|
+
} catch (e) {
|
|
291
|
+
throw new TypeError(`Error al parsear el XML: ${e.message}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function totalF(doc) {
|
|
295
|
+
const dataTable = [];
|
|
296
|
+
const allTypes = typesIvaFee.map((data) => {
|
|
297
|
+
return {
|
|
298
|
+
type: "2",
|
|
299
|
+
code: data.code,
|
|
300
|
+
name: data.label,
|
|
301
|
+
fee: data.fee,
|
|
302
|
+
base: 0,
|
|
303
|
+
totalTax: 0
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
let totalIce = 0;
|
|
307
|
+
let totalIRBPNR = 0;
|
|
308
|
+
let totalDEVOLUCIONIVA = 0;
|
|
309
|
+
const totalConImpuestoElement = doc?.getElementsByTagName("totalConImpuestos")[0];
|
|
310
|
+
if (!totalConImpuestoElement)
|
|
311
|
+
return [];
|
|
312
|
+
for (let i = 0; i < totalConImpuestoElement.children.length; i++) {
|
|
313
|
+
const child = totalConImpuestoElement.children[i];
|
|
314
|
+
if (child?.tagName === "totalImpuesto") {
|
|
315
|
+
const cod = child.getElementsByTagName("codigo")[0]?.textContent || "";
|
|
316
|
+
const codigoPorcentaje = child.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "";
|
|
317
|
+
switch (cod) {
|
|
318
|
+
case "3":
|
|
319
|
+
totalIce += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
320
|
+
break;
|
|
321
|
+
case "5":
|
|
322
|
+
totalIRBPNR += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
323
|
+
break;
|
|
324
|
+
default:
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
const valorDevolucionIva = child.getElementsByTagName("valorDevolucionIva")[0]?.textContent || void 0;
|
|
328
|
+
if (valorDevolucionIva) {
|
|
329
|
+
totalDEVOLUCIONIVA += Number.parseFloat(valorDevolucionIva ?? "0");
|
|
330
|
+
}
|
|
331
|
+
const index = allTypes.findIndex((data) => {
|
|
332
|
+
return data.code === codigoPorcentaje;
|
|
333
|
+
});
|
|
334
|
+
if (index !== -1 && allTypes[index]) {
|
|
335
|
+
const baseImponible = child.getElementsByTagName("baseImponible")[0]?.textContent || "0";
|
|
336
|
+
const valor = child.getElementsByTagName("valor")[0]?.textContent || "0";
|
|
337
|
+
allTypes[index].base = Number.parseFloat(baseImponible);
|
|
338
|
+
allTypes[index].totalTax = Number.parseFloat(valor);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const newAllTypes = allTypes.filter((data) => data.base > 0);
|
|
343
|
+
newAllTypes.forEach((data) => {
|
|
344
|
+
dataTable.push({ name: `SUBTOTAL ${data.fee} %`, valor: data.base });
|
|
345
|
+
});
|
|
346
|
+
const totalSinImpuestos = Number.parseFloat(doc?.getElementsByTagName("totalSinImpuestos")[0]?.textContent || "0");
|
|
347
|
+
dataTable.push({ name: "SUBTOTAL SIN IMPUESTOS", valor: totalSinImpuestos });
|
|
348
|
+
const totalDescuento = Number.parseFloat(doc?.getElementsByTagName("totalDescuento")[0]?.textContent || "0");
|
|
349
|
+
dataTable.push({
|
|
350
|
+
name: "TOTAL DESCUENTO",
|
|
351
|
+
valor: totalDescuento
|
|
352
|
+
});
|
|
353
|
+
dataTable.push({
|
|
354
|
+
name: "ICE",
|
|
355
|
+
valor: totalIce
|
|
356
|
+
});
|
|
357
|
+
newAllTypes.filter((rs) => rs.fee > 0).forEach((data) => {
|
|
358
|
+
dataTable.push({ name: `IVA ${data.fee}`, valor: data.totalTax });
|
|
359
|
+
});
|
|
360
|
+
dataTable.push({ name: "TOTAL DEVOLUCI\xD3N IVA", valor: totalDEVOLUCIONIVA });
|
|
361
|
+
dataTable.push({
|
|
362
|
+
name: "IRBPNR",
|
|
363
|
+
valor: totalIRBPNR
|
|
364
|
+
});
|
|
365
|
+
const importeTotal = Number.parseFloat(doc?.getElementsByTagName("importeTotal")[0]?.textContent || "0");
|
|
366
|
+
dataTable.push({
|
|
367
|
+
name: "VALOR TOTAL",
|
|
368
|
+
valor: importeTotal
|
|
369
|
+
});
|
|
370
|
+
return dataTable;
|
|
371
|
+
}
|
|
372
|
+
function totalNC(doc) {
|
|
373
|
+
const dataTable = [];
|
|
374
|
+
const allTypes = typesIvaFee.map((data) => {
|
|
375
|
+
return {
|
|
376
|
+
type: data.code,
|
|
377
|
+
name: data.label,
|
|
378
|
+
tarifa: data.fee,
|
|
379
|
+
iva: 0,
|
|
380
|
+
total: 0
|
|
381
|
+
};
|
|
382
|
+
});
|
|
383
|
+
let totalIce = 0;
|
|
384
|
+
let totalIRBPNR = 0;
|
|
385
|
+
const totalConImpuestoElement = doc?.getElementsByTagName("totalConImpuestos")[0];
|
|
386
|
+
if (!totalConImpuestoElement)
|
|
387
|
+
return [];
|
|
388
|
+
for (let i = 0; i < totalConImpuestoElement.children.length; i++) {
|
|
389
|
+
const child = totalConImpuestoElement.children[i];
|
|
390
|
+
if (child?.tagName === "totalImpuesto") {
|
|
391
|
+
const cod = child.getElementsByTagName("codigo")[0]?.textContent || "";
|
|
392
|
+
const codigoPorcentaje = child.getElementsByTagName("codigoPorcentaje")[0]?.textContent || "";
|
|
393
|
+
switch (cod) {
|
|
394
|
+
case "3":
|
|
395
|
+
totalIce += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
396
|
+
break;
|
|
397
|
+
case "5":
|
|
398
|
+
totalIRBPNR += Number.parseFloat(child.getElementsByTagName("valor")[0]?.textContent ?? "0");
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
const index = allTypes.findIndex((data) => {
|
|
404
|
+
return data.type === codigoPorcentaje;
|
|
405
|
+
});
|
|
406
|
+
if (index !== -1 && allTypes[index]) {
|
|
407
|
+
const baseImponible = child.getElementsByTagName("baseImponible")[0]?.textContent || "0";
|
|
408
|
+
const valor = child.getElementsByTagName("valor")[0]?.textContent || "0";
|
|
409
|
+
allTypes[index].total = Number.parseFloat(baseImponible);
|
|
410
|
+
allTypes[index].iva = Number.parseFloat(valor);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const impuestos = allTypes.filter((data) => data.total > 0);
|
|
415
|
+
const impuestos_0 = allTypes.filter((data) => data.tarifa === 0);
|
|
416
|
+
impuestos.forEach((data) => {
|
|
417
|
+
dataTable.push({ name: `SUBTOTAL ${data.name}`, valor: data.total });
|
|
418
|
+
});
|
|
419
|
+
impuestos_0.forEach((data) => {
|
|
420
|
+
dataTable.push({ name: `SUBTOTAL ${data.name}`, valor: data.total });
|
|
421
|
+
});
|
|
422
|
+
const totalSinImpuestos = Number.parseFloat(doc?.getElementsByTagName("totalSinImpuestos")[0]?.textContent || "0");
|
|
423
|
+
dataTable.push({ name: "SUBTOTAL SIN IMPUESTOS", valor: totalSinImpuestos });
|
|
424
|
+
dataTable.push({
|
|
425
|
+
name: "ICE",
|
|
426
|
+
valor: totalIce
|
|
427
|
+
});
|
|
428
|
+
impuestos.forEach((data) => {
|
|
429
|
+
dataTable.push({ name: `IVA ${data.name}`, valor: data.iva });
|
|
430
|
+
});
|
|
431
|
+
dataTable.push({
|
|
432
|
+
name: "IRBPNR",
|
|
433
|
+
valor: totalIRBPNR
|
|
434
|
+
});
|
|
435
|
+
const valorModificado = Number.parseFloat(doc?.getElementsByTagName("valorModificado")[0]?.textContent || "0");
|
|
436
|
+
dataTable.push({
|
|
437
|
+
name: "VALOR TOTAL",
|
|
438
|
+
valor: valorModificado
|
|
439
|
+
});
|
|
440
|
+
return dataTable;
|
|
441
|
+
}
|
|
442
|
+
function nameCodeRetention(code) {
|
|
443
|
+
return code;
|
|
444
|
+
}
|
|
445
|
+
function getFullInvoiceDataFromXml(xmlString) {
|
|
446
|
+
const parsed = parseXml(xmlString);
|
|
447
|
+
if (!parsed || !parsed.documentData) {
|
|
448
|
+
throw new Error("No se pudo parsear el XML o no contiene datos del comprobante");
|
|
449
|
+
}
|
|
450
|
+
const doc = parsed.documentData;
|
|
451
|
+
return {
|
|
452
|
+
accessKey: parsed.numAuto,
|
|
453
|
+
dateAuthorization: parsed.dateAuto,
|
|
454
|
+
numberDocument: parsed.numberDocument,
|
|
455
|
+
typeDoc: parsed.typeDoc,
|
|
456
|
+
emissionDate: parsed.emissionDate ?? "",
|
|
457
|
+
documentData: doc,
|
|
458
|
+
infoTributaria: getInfoTributaria(doc),
|
|
459
|
+
infoFactura: getInfoFactura(doc),
|
|
460
|
+
details: getDetailsFc(doc),
|
|
461
|
+
totals: getTotals(doc),
|
|
462
|
+
payments: getPagos(doc),
|
|
463
|
+
additionalInfo: getInfoAdicional(doc)
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
export {
|
|
467
|
+
TYPE_IDENTITY,
|
|
468
|
+
getDataAccessKey,
|
|
469
|
+
getDetailsFc,
|
|
470
|
+
getFullInvoiceDataFromXml,
|
|
471
|
+
getInfoAdicional,
|
|
472
|
+
getInfoFactura,
|
|
473
|
+
getInfoTributaria,
|
|
474
|
+
getKeyData,
|
|
475
|
+
getPagos,
|
|
476
|
+
getTotals,
|
|
477
|
+
nameCodeRetention,
|
|
478
|
+
parseXml,
|
|
479
|
+
parseXmlString,
|
|
480
|
+
typeDocument,
|
|
481
|
+
typeRtFee,
|
|
482
|
+
typesIvaFee,
|
|
483
|
+
typesPaymentSRI
|
|
484
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sri-xml-viewer/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Parser core for SRI Ecuador XML electronic vouchers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"decimal.js": "^10.4.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.0.0",
|
|
24
|
+
"tsup": "^8.0.0",
|
|
25
|
+
"vitest": "^1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
29
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --clean --watch",
|
|
30
|
+
"test": "vitest run"
|
|
31
|
+
}
|
|
32
|
+
}
|