@devlas/dte-sii 2.5.11 → 2.5.12
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/CafSolicitor.js +378 -378
- package/ConsumoFolio.js +376 -376
- package/Envio.js +196 -196
- package/LICENSE +27 -27
- package/README.md +273 -273
- package/SiiCertificacion.js +14 -7
- package/SiiPortalAuth.js +474 -474
- package/cert/CertRunner.js +8 -0
- package/cert/ConfigLoader.js +131 -131
- package/cert/IntercambioCert.js +427 -427
- package/cert/LibroCompras.js +357 -357
- package/cert/LibroGuias.js +169 -169
- package/cert/LibroVentas.js +151 -151
- package/cert/MuestrasImpresas.js +676 -676
- package/cert/SetBase.js +319 -319
- package/cert/SetBasico.js +411 -411
- package/cert/SetCompra.js +470 -470
- package/cert/SetExenta.js +488 -488
- package/cert/SetGuia.js +281 -281
- package/cert/SetParser.js +1182 -1182
- package/cert/SetsProvider.js +497 -497
- package/cert/Simulacion.js +519 -519
- package/cert/comunaOficina.js +458 -458
- package/cert/index.js +122 -122
- package/cert/types.js +328 -328
- package/package.json +49 -49
package/Envio.js
CHANGED
|
@@ -1,196 +1,196 @@
|
|
|
1
|
-
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
-
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
3
|
-
/**
|
|
4
|
-
* Clases de Envío (EnvioBOLETA, EnvioDTE)
|
|
5
|
-
*
|
|
6
|
-
* Sobres para agrupar múltiples DTEs y enviar al SII
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const Signer = require('./Signer');
|
|
10
|
-
const { formatRutSii } = require('./utils/rut');
|
|
11
|
-
|
|
12
|
-
// ============================================
|
|
13
|
-
// CLASE BASE ENVIO
|
|
14
|
-
// ============================================
|
|
15
|
-
|
|
16
|
-
class EnvioBase {
|
|
17
|
-
constructor(config) {
|
|
18
|
-
this.certificado = config.certificado;
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.dtes = [];
|
|
21
|
-
this.caratula = null;
|
|
22
|
-
this.setId = null;
|
|
23
|
-
this.xml = null;
|
|
24
|
-
this.xmlSinFirma = null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Agregar un DTE al sobre
|
|
29
|
-
*/
|
|
30
|
-
agregar(dte) {
|
|
31
|
-
// Auto-generar si tiene certificado/caf guardados
|
|
32
|
-
if (dte._certificado && dte._caf && !dte.xml) {
|
|
33
|
-
dte.generarXML();
|
|
34
|
-
dte.timbrar(dte._caf);
|
|
35
|
-
dte.firmar(dte._certificado);
|
|
36
|
-
}
|
|
37
|
-
this.dtes.push(dte);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Calcular subtotales por tipo de DTE
|
|
43
|
-
*/
|
|
44
|
-
_getSubTotDTE() {
|
|
45
|
-
const tipos = {};
|
|
46
|
-
for (const dte of this.dtes) {
|
|
47
|
-
const tipo = dte.datos.Encabezado.IdDoc.TipoDTE;
|
|
48
|
-
if (!tipos[tipo]) tipos[tipo] = 0;
|
|
49
|
-
tipos[tipo]++;
|
|
50
|
-
}
|
|
51
|
-
return Object.entries(tipos).map(([tipo, cantidad]) => ({
|
|
52
|
-
TpoDTE: parseInt(tipo, 10),
|
|
53
|
-
NroDTE: cantidad,
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Generar timestamp para firma
|
|
59
|
-
*/
|
|
60
|
-
_generateTimestamp() {
|
|
61
|
-
return new Date().toISOString().replace(/\.\d{3}Z$/, '');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Generar SetId con formato específico
|
|
66
|
-
*/
|
|
67
|
-
_generateSetId(prefix) {
|
|
68
|
-
const now = new Date();
|
|
69
|
-
const dd = String(now.getDate()).padStart(2, '0');
|
|
70
|
-
const mm = String(now.getMonth() + 1).padStart(2, '0');
|
|
71
|
-
const yyyy = now.getFullYear();
|
|
72
|
-
const hh = String(now.getHours()).padStart(2, '0');
|
|
73
|
-
const min = String(now.getMinutes()).padStart(2, '0');
|
|
74
|
-
const ss = String(now.getSeconds()).padStart(2, '0');
|
|
75
|
-
return `${prefix}_${dd}_${mm}_${yyyy}_${hh}_${min}_${ss}`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Extraer XML de DTEs sin declaration
|
|
80
|
-
*/
|
|
81
|
-
_extractDTEsXml() {
|
|
82
|
-
return this.dtes.map(dte => {
|
|
83
|
-
return dte.getXML()
|
|
84
|
-
.replace('<?xml version="1.0" encoding="ISO-8859-1"?>', '')
|
|
85
|
-
.replace('<?xml version="1.0"?>', '')
|
|
86
|
-
.trim();
|
|
87
|
-
}).join('\n');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getXML() { return this.xml; }
|
|
91
|
-
getXMLSinFirma() { return this.xmlSinFirma; }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ============================================
|
|
95
|
-
// CLASE ENVIOBOLETA
|
|
96
|
-
// ============================================
|
|
97
|
-
|
|
98
|
-
// DD-MM-YYYY → YYYY-MM-DD (xs:date requerido por EnvioBOLETA_v11.xsd y ConsumoFolios.xsd)
|
|
99
|
-
function _normDateXsd(d) {
|
|
100
|
-
if (!d) return d;
|
|
101
|
-
const m = String(d).match(/^(\d{2})-(\d{2})-(\d{4})$/);
|
|
102
|
-
return m ? `${m[3]}-${m[2]}-${m[1]}` : d;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
class EnvioBOLETA extends EnvioBase {
|
|
106
|
-
setCaratula(caratula) {
|
|
107
|
-
this.setId = this._generateSetId('ENVIOBOLETA');
|
|
108
|
-
const timestamp = caratula.TmstFirmaEnv || this._generateTimestamp();
|
|
109
|
-
|
|
110
|
-
this.caratula = {
|
|
111
|
-
RutEmisor: formatRutSii(caratula.RutEmisor), // sin puntos, maxLength=10
|
|
112
|
-
RutEnvia: formatRutSii(caratula.RutEnvia), // sin puntos
|
|
113
|
-
RutReceptor: '60803000-K', // Siempre SII para boletas
|
|
114
|
-
FchResol: _normDateXsd(caratula.FchResol),
|
|
115
|
-
NroResol: caratula.NroResol,
|
|
116
|
-
TmstFirmaEnv: timestamp,
|
|
117
|
-
SubTotDTE: this._getSubTotDTE(),
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
generar() {
|
|
124
|
-
if (!this.dtes.length) throw new Error('No hay DTEs para enviar');
|
|
125
|
-
if (!this.caratula) throw new Error('Falta carátula');
|
|
126
|
-
|
|
127
|
-
const subTotDTEs = this.caratula.SubTotDTE
|
|
128
|
-
.map(s => `<SubTotDTE><TpoDTE>${s.TpoDTE}</TpoDTE><NroDTE>${s.NroDTE}</NroDTE></SubTotDTE>`)
|
|
129
|
-
.join('');
|
|
130
|
-
|
|
131
|
-
const xmlBase = `<?xml version="1.0" encoding="ISO-8859-1"?>\n<EnvioBOLETA xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd" version="1.0"><SetDTE ID="${this.setId}"><Caratula version="1.0"><RutEmisor>${this.caratula.RutEmisor}</RutEmisor><RutEnvia>${this.caratula.RutEnvia}</RutEnvia><RutReceptor>${this.caratula.RutReceptor}</RutReceptor><FchResol>${this.caratula.FchResol}</FchResol><NroResol>${this.caratula.NroResol}</NroResol><TmstFirmaEnv>${this.caratula.TmstFirmaEnv}</TmstFirmaEnv>${subTotDTEs}</Caratula><!-- DTES_PLACEHOLDER --></SetDTE></EnvioBOLETA>`;
|
|
132
|
-
|
|
133
|
-
const dtesXml = this._extractDTEsXml();
|
|
134
|
-
this.xmlSinFirma = xmlBase.replace('<!-- DTES_PLACEHOLDER -->', dtesXml);
|
|
135
|
-
|
|
136
|
-
const signer = new Signer(this.certificado);
|
|
137
|
-
this.xml = signer.firmarSetDTE(this.xmlSinFirma, this.setId, 'EnvioBOLETA');
|
|
138
|
-
|
|
139
|
-
return this.xml;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ============================================
|
|
144
|
-
// CLASE ENVIODTE
|
|
145
|
-
// ============================================
|
|
146
|
-
|
|
147
|
-
class EnvioDTE extends EnvioBase {
|
|
148
|
-
setCaratula(caratula) {
|
|
149
|
-
this.setId = caratula.SetDTEId || caratula.SetId || this._generateSetId('DTE_SetDoc');
|
|
150
|
-
const timestamp = this._generateTimestamp();
|
|
151
|
-
|
|
152
|
-
// Ordenar subtotales (33, 61, 56 primero)
|
|
153
|
-
const subTotDTE = this._getSubTotDTE().sort((a, b) => {
|
|
154
|
-
const orden = [33, 61, 56];
|
|
155
|
-
const idxA = orden.indexOf(a.TpoDTE);
|
|
156
|
-
const idxB = orden.indexOf(b.TpoDTE);
|
|
157
|
-
if (idxA === -1 && idxB === -1) return a.TpoDTE - b.TpoDTE;
|
|
158
|
-
if (idxA === -1) return 1;
|
|
159
|
-
if (idxB === -1) return -1;
|
|
160
|
-
return idxA - idxB;
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
this.caratula = {
|
|
164
|
-
RutEmisor: caratula.RutEmisor,
|
|
165
|
-
RutEnvia: caratula.RutEnvia,
|
|
166
|
-
RutReceptor: caratula.RutReceptor || '',
|
|
167
|
-
FchResol: caratula.FchResol,
|
|
168
|
-
NroResol: caratula.NroResol,
|
|
169
|
-
TmstFirmaEnv: timestamp,
|
|
170
|
-
SubTotDTE: subTotDTE,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
generar() {
|
|
177
|
-
if (!this.dtes.length) throw new Error('No hay DTEs para enviar');
|
|
178
|
-
if (!this.caratula) throw new Error('Falta carátula');
|
|
179
|
-
|
|
180
|
-
const subTotDTEs = this.caratula.SubTotDTE
|
|
181
|
-
.map(s => `<SubTotDTE><TpoDTE>${s.TpoDTE}</TpoDTE><NroDTE>${s.NroDTE}</NroDTE></SubTotDTE>`)
|
|
182
|
-
.join('');
|
|
183
|
-
|
|
184
|
-
const xmlBase = `<?xml version="1.0" encoding="ISO-8859-1"?>\n<EnvioDTE xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd" version="1.0"><SetDTE ID="${this.setId}"><Caratula version="1.0"><RutEmisor>${this.caratula.RutEmisor}</RutEmisor><RutEnvia>${this.caratula.RutEnvia}</RutEnvia><RutReceptor>${this.caratula.RutReceptor}</RutReceptor><FchResol>${this.caratula.FchResol}</FchResol><NroResol>${this.caratula.NroResol}</NroResol><TmstFirmaEnv>${this.caratula.TmstFirmaEnv}</TmstFirmaEnv>${subTotDTEs}</Caratula><!-- DTES_PLACEHOLDER --></SetDTE></EnvioDTE>`;
|
|
185
|
-
|
|
186
|
-
const dtesXml = this._extractDTEsXml();
|
|
187
|
-
this.xmlSinFirma = xmlBase.replace('<!-- DTES_PLACEHOLDER -->', dtesXml);
|
|
188
|
-
|
|
189
|
-
const signer = new Signer(this.certificado);
|
|
190
|
-
this.xml = signer.firmarSetDTE(this.xmlSinFirma, this.setId, 'EnvioDTE');
|
|
191
|
-
|
|
192
|
-
return this.xml;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = { EnvioBase, EnvioBOLETA, EnvioDTE };
|
|
1
|
+
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
+
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
3
|
+
/**
|
|
4
|
+
* Clases de Envío (EnvioBOLETA, EnvioDTE)
|
|
5
|
+
*
|
|
6
|
+
* Sobres para agrupar múltiples DTEs y enviar al SII
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const Signer = require('./Signer');
|
|
10
|
+
const { formatRutSii } = require('./utils/rut');
|
|
11
|
+
|
|
12
|
+
// ============================================
|
|
13
|
+
// CLASE BASE ENVIO
|
|
14
|
+
// ============================================
|
|
15
|
+
|
|
16
|
+
class EnvioBase {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.certificado = config.certificado;
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.dtes = [];
|
|
21
|
+
this.caratula = null;
|
|
22
|
+
this.setId = null;
|
|
23
|
+
this.xml = null;
|
|
24
|
+
this.xmlSinFirma = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Agregar un DTE al sobre
|
|
29
|
+
*/
|
|
30
|
+
agregar(dte) {
|
|
31
|
+
// Auto-generar si tiene certificado/caf guardados
|
|
32
|
+
if (dte._certificado && dte._caf && !dte.xml) {
|
|
33
|
+
dte.generarXML();
|
|
34
|
+
dte.timbrar(dte._caf);
|
|
35
|
+
dte.firmar(dte._certificado);
|
|
36
|
+
}
|
|
37
|
+
this.dtes.push(dte);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Calcular subtotales por tipo de DTE
|
|
43
|
+
*/
|
|
44
|
+
_getSubTotDTE() {
|
|
45
|
+
const tipos = {};
|
|
46
|
+
for (const dte of this.dtes) {
|
|
47
|
+
const tipo = dte.datos.Encabezado.IdDoc.TipoDTE;
|
|
48
|
+
if (!tipos[tipo]) tipos[tipo] = 0;
|
|
49
|
+
tipos[tipo]++;
|
|
50
|
+
}
|
|
51
|
+
return Object.entries(tipos).map(([tipo, cantidad]) => ({
|
|
52
|
+
TpoDTE: parseInt(tipo, 10),
|
|
53
|
+
NroDTE: cantidad,
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generar timestamp para firma
|
|
59
|
+
*/
|
|
60
|
+
_generateTimestamp() {
|
|
61
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, '');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generar SetId con formato específico
|
|
66
|
+
*/
|
|
67
|
+
_generateSetId(prefix) {
|
|
68
|
+
const now = new Date();
|
|
69
|
+
const dd = String(now.getDate()).padStart(2, '0');
|
|
70
|
+
const mm = String(now.getMonth() + 1).padStart(2, '0');
|
|
71
|
+
const yyyy = now.getFullYear();
|
|
72
|
+
const hh = String(now.getHours()).padStart(2, '0');
|
|
73
|
+
const min = String(now.getMinutes()).padStart(2, '0');
|
|
74
|
+
const ss = String(now.getSeconds()).padStart(2, '0');
|
|
75
|
+
return `${prefix}_${dd}_${mm}_${yyyy}_${hh}_${min}_${ss}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extraer XML de DTEs sin declaration
|
|
80
|
+
*/
|
|
81
|
+
_extractDTEsXml() {
|
|
82
|
+
return this.dtes.map(dte => {
|
|
83
|
+
return dte.getXML()
|
|
84
|
+
.replace('<?xml version="1.0" encoding="ISO-8859-1"?>', '')
|
|
85
|
+
.replace('<?xml version="1.0"?>', '')
|
|
86
|
+
.trim();
|
|
87
|
+
}).join('\n');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getXML() { return this.xml; }
|
|
91
|
+
getXMLSinFirma() { return this.xmlSinFirma; }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ============================================
|
|
95
|
+
// CLASE ENVIOBOLETA
|
|
96
|
+
// ============================================
|
|
97
|
+
|
|
98
|
+
// DD-MM-YYYY → YYYY-MM-DD (xs:date requerido por EnvioBOLETA_v11.xsd y ConsumoFolios.xsd)
|
|
99
|
+
function _normDateXsd(d) {
|
|
100
|
+
if (!d) return d;
|
|
101
|
+
const m = String(d).match(/^(\d{2})-(\d{2})-(\d{4})$/);
|
|
102
|
+
return m ? `${m[3]}-${m[2]}-${m[1]}` : d;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
class EnvioBOLETA extends EnvioBase {
|
|
106
|
+
setCaratula(caratula) {
|
|
107
|
+
this.setId = this._generateSetId('ENVIOBOLETA');
|
|
108
|
+
const timestamp = caratula.TmstFirmaEnv || this._generateTimestamp();
|
|
109
|
+
|
|
110
|
+
this.caratula = {
|
|
111
|
+
RutEmisor: formatRutSii(caratula.RutEmisor), // sin puntos, maxLength=10
|
|
112
|
+
RutEnvia: formatRutSii(caratula.RutEnvia), // sin puntos
|
|
113
|
+
RutReceptor: '60803000-K', // Siempre SII para boletas
|
|
114
|
+
FchResol: _normDateXsd(caratula.FchResol),
|
|
115
|
+
NroResol: caratula.NroResol,
|
|
116
|
+
TmstFirmaEnv: timestamp,
|
|
117
|
+
SubTotDTE: this._getSubTotDTE(),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
generar() {
|
|
124
|
+
if (!this.dtes.length) throw new Error('No hay DTEs para enviar');
|
|
125
|
+
if (!this.caratula) throw new Error('Falta carátula');
|
|
126
|
+
|
|
127
|
+
const subTotDTEs = this.caratula.SubTotDTE
|
|
128
|
+
.map(s => `<SubTotDTE><TpoDTE>${s.TpoDTE}</TpoDTE><NroDTE>${s.NroDTE}</NroDTE></SubTotDTE>`)
|
|
129
|
+
.join('');
|
|
130
|
+
|
|
131
|
+
const xmlBase = `<?xml version="1.0" encoding="ISO-8859-1"?>\n<EnvioBOLETA xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd" version="1.0"><SetDTE ID="${this.setId}"><Caratula version="1.0"><RutEmisor>${this.caratula.RutEmisor}</RutEmisor><RutEnvia>${this.caratula.RutEnvia}</RutEnvia><RutReceptor>${this.caratula.RutReceptor}</RutReceptor><FchResol>${this.caratula.FchResol}</FchResol><NroResol>${this.caratula.NroResol}</NroResol><TmstFirmaEnv>${this.caratula.TmstFirmaEnv}</TmstFirmaEnv>${subTotDTEs}</Caratula><!-- DTES_PLACEHOLDER --></SetDTE></EnvioBOLETA>`;
|
|
132
|
+
|
|
133
|
+
const dtesXml = this._extractDTEsXml();
|
|
134
|
+
this.xmlSinFirma = xmlBase.replace('<!-- DTES_PLACEHOLDER -->', dtesXml);
|
|
135
|
+
|
|
136
|
+
const signer = new Signer(this.certificado);
|
|
137
|
+
this.xml = signer.firmarSetDTE(this.xmlSinFirma, this.setId, 'EnvioBOLETA');
|
|
138
|
+
|
|
139
|
+
return this.xml;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ============================================
|
|
144
|
+
// CLASE ENVIODTE
|
|
145
|
+
// ============================================
|
|
146
|
+
|
|
147
|
+
class EnvioDTE extends EnvioBase {
|
|
148
|
+
setCaratula(caratula) {
|
|
149
|
+
this.setId = caratula.SetDTEId || caratula.SetId || this._generateSetId('DTE_SetDoc');
|
|
150
|
+
const timestamp = this._generateTimestamp();
|
|
151
|
+
|
|
152
|
+
// Ordenar subtotales (33, 61, 56 primero)
|
|
153
|
+
const subTotDTE = this._getSubTotDTE().sort((a, b) => {
|
|
154
|
+
const orden = [33, 61, 56];
|
|
155
|
+
const idxA = orden.indexOf(a.TpoDTE);
|
|
156
|
+
const idxB = orden.indexOf(b.TpoDTE);
|
|
157
|
+
if (idxA === -1 && idxB === -1) return a.TpoDTE - b.TpoDTE;
|
|
158
|
+
if (idxA === -1) return 1;
|
|
159
|
+
if (idxB === -1) return -1;
|
|
160
|
+
return idxA - idxB;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
this.caratula = {
|
|
164
|
+
RutEmisor: caratula.RutEmisor,
|
|
165
|
+
RutEnvia: caratula.RutEnvia,
|
|
166
|
+
RutReceptor: caratula.RutReceptor || '',
|
|
167
|
+
FchResol: caratula.FchResol,
|
|
168
|
+
NroResol: caratula.NroResol,
|
|
169
|
+
TmstFirmaEnv: timestamp,
|
|
170
|
+
SubTotDTE: subTotDTE,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
generar() {
|
|
177
|
+
if (!this.dtes.length) throw new Error('No hay DTEs para enviar');
|
|
178
|
+
if (!this.caratula) throw new Error('Falta carátula');
|
|
179
|
+
|
|
180
|
+
const subTotDTEs = this.caratula.SubTotDTE
|
|
181
|
+
.map(s => `<SubTotDTE><TpoDTE>${s.TpoDTE}</TpoDTE><NroDTE>${s.NroDTE}</NroDTE></SubTotDTE>`)
|
|
182
|
+
.join('');
|
|
183
|
+
|
|
184
|
+
const xmlBase = `<?xml version="1.0" encoding="ISO-8859-1"?>\n<EnvioDTE xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd" version="1.0"><SetDTE ID="${this.setId}"><Caratula version="1.0"><RutEmisor>${this.caratula.RutEmisor}</RutEmisor><RutEnvia>${this.caratula.RutEnvia}</RutEnvia><RutReceptor>${this.caratula.RutReceptor}</RutReceptor><FchResol>${this.caratula.FchResol}</FchResol><NroResol>${this.caratula.NroResol}</NroResol><TmstFirmaEnv>${this.caratula.TmstFirmaEnv}</TmstFirmaEnv>${subTotDTEs}</Caratula><!-- DTES_PLACEHOLDER --></SetDTE></EnvioDTE>`;
|
|
185
|
+
|
|
186
|
+
const dtesXml = this._extractDTEsXml();
|
|
187
|
+
this.xmlSinFirma = xmlBase.replace('<!-- DTES_PLACEHOLDER -->', dtesXml);
|
|
188
|
+
|
|
189
|
+
const signer = new Signer(this.certificado);
|
|
190
|
+
this.xml = signer.firmarSetDTE(this.xmlSinFirma, this.setId, 'EnvioDTE');
|
|
191
|
+
|
|
192
|
+
return this.xml;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = { EnvioBase, EnvioBOLETA, EnvioDTE };
|
package/LICENSE
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
Esta librería implementa el protocolo XML del Servicio de Impuestos Internos (SII)
|
|
26
|
-
de Chile tal como está documentado públicamente por el propio SII.
|
|
27
|
-
Inspirada conceptualmente en LibreDTE de SASCO SpA (https://libredte.cl).
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Esta librería implementa el protocolo XML del Servicio de Impuestos Internos (SII)
|
|
26
|
+
de Chile tal como está documentado públicamente por el propio SII.
|
|
27
|
+
Inspirada conceptualmente en LibreDTE de SASCO SpA (https://libredte.cl).
|