@facturacr/atv-sdk 2.0.12-alpha → 2.0.14-alpha
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/__tests__/stubs/createDocument.data.ts +34 -0
- package/__tests__/tests/ATV/create-document.test.ts +34 -1
- package/dist/src/ATV/core/CreateDocFactory.js +5 -2
- package/dist/src/ATV/core/CreateDocFactory.js.map +1 -1
- package/dist/src/ATV/mappers/billDocToAtv.js +44 -57
- package/dist/src/ATV/mappers/billDocToAtv.js.map +1 -1
- package/examples/README.md +5 -0
- package/examples/createAndSendFEC.ts +94 -0
- package/package.json +2 -2
- package/src/ATV/core/CreateDocFactory.ts +6 -2
- package/src/ATV/mappers/billDocToAtv.ts +39 -34
|
@@ -108,3 +108,37 @@ export const TEInputExample: CreateDocumentInput['document'] = {
|
|
|
108
108
|
paymentMethod: '03',
|
|
109
109
|
conditionSale: '01'
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
export const FECInputExample: CreateDocumentInput['document'] = {
|
|
113
|
+
consecutiveIdentifier: '2',
|
|
114
|
+
activityCode: '729001',
|
|
115
|
+
providerId: emitterStub.identifier.id,
|
|
116
|
+
documentName: 'FacturaElectronicaCompra',
|
|
117
|
+
branch: '1',
|
|
118
|
+
terminal: '1',
|
|
119
|
+
ceSituation: '1',
|
|
120
|
+
countryCode: '506',
|
|
121
|
+
emitter: {
|
|
122
|
+
fullName: 'Airbnb',
|
|
123
|
+
commercialName: 'Airbnb',
|
|
124
|
+
activityCode: '729001',
|
|
125
|
+
identifier: {
|
|
126
|
+
type: '05',
|
|
127
|
+
id: '000000000001'
|
|
128
|
+
},
|
|
129
|
+
foreignAddress: 'Proveedor extranjero no domiciliado',
|
|
130
|
+
email: 'no-reply@airbnb.com'
|
|
131
|
+
},
|
|
132
|
+
receiver: receiverStub,
|
|
133
|
+
orderLines,
|
|
134
|
+
securityCode: '1',
|
|
135
|
+
paymentMethod: '04',
|
|
136
|
+
conditionSale: '01',
|
|
137
|
+
referenceInfo: {
|
|
138
|
+
docType: '16',
|
|
139
|
+
refNumber: 'HMX5HK4SNQ',
|
|
140
|
+
issueDate: new Date(),
|
|
141
|
+
code: '11',
|
|
142
|
+
reason: 'Proveedor no domiciliado - comision Airbnb'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import { ATV } from '@src/ATV'
|
|
3
3
|
import 'jest-xml-matcher'
|
|
4
|
-
import { FEInputExample } from '@test/stubs/createDocument.data'
|
|
4
|
+
import { FECInputExample, FEInputExample } from '@test/stubs/createDocument.data'
|
|
5
5
|
const fakePem = fs.readFileSync('__tests__/stubs/dummyKeys/client-identity.p12', 'binary')
|
|
6
6
|
const fakePassword = '1234'
|
|
7
7
|
const expectXml = fs.readFileSync('__tests__/stubs/commonExpectedXml.xml', 'utf-8')
|
|
@@ -56,4 +56,37 @@ describe('Create Document (Invoice)', () => {
|
|
|
56
56
|
})
|
|
57
57
|
expect(createdDoc.extraData.xml).toEqualXML(expectXml)
|
|
58
58
|
})
|
|
59
|
+
|
|
60
|
+
it('should create a purchase invoice without factory-assumed tax fields', async () => {
|
|
61
|
+
const atv = new ATV({}, 'stg')
|
|
62
|
+
const createdDoc = await atv.createDocumentCommand({
|
|
63
|
+
document: FECInputExample,
|
|
64
|
+
token: 'fake-token',
|
|
65
|
+
// @ts-expect-error only for testing
|
|
66
|
+
signatureOptions: undefined
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
expect(createdDoc.extraData.xml).toContain('<FacturaElectronicaCompra')
|
|
70
|
+
expect(createdDoc.extraData.xml).toContain('<ImpuestoNeto>')
|
|
71
|
+
expect(createdDoc.extraData.xml).not.toContain('<ImpuestoAsumidoEmisorFabrica>')
|
|
72
|
+
expect(createdDoc.extraData.xml).not.toContain('<TotalImpAsumEmisorFabrica>')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should create a purchase invoice key and activity from the signing receiver', async () => {
|
|
76
|
+
const receiver = FECInputExample.receiver
|
|
77
|
+
if (!receiver) throw new Error('FECInputExample.receiver is required')
|
|
78
|
+
|
|
79
|
+
const atv = new ATV({}, 'stg')
|
|
80
|
+
const createdDoc = await atv.createDocumentCommand({
|
|
81
|
+
document: FECInputExample,
|
|
82
|
+
token: 'fake-token',
|
|
83
|
+
// @ts-expect-error only for testing
|
|
84
|
+
signatureOptions: undefined
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
expect(createdDoc.command.data.clave).toContain(receiver.identifier.id.padStart(12, '0'))
|
|
88
|
+
expect(createdDoc.extraData.xml).toContain(`<CodigoActividadEmisor>${receiver.activityCode.padStart(6, '0')}</CodigoActividadEmisor>`)
|
|
89
|
+
expect(createdDoc.extraData.xml).toContain(`<Numero>${FECInputExample.emitter.identifier.id}</Numero>`)
|
|
90
|
+
expect(createdDoc.extraData.xml).toContain(`<Numero>${receiver.identifier.id}</Numero>`)
|
|
91
|
+
})
|
|
59
92
|
})
|
|
@@ -52,14 +52,17 @@ class CreateDocFactory {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
createClave(dto, docType) {
|
|
55
|
+
const keyPerson = dto.documentName === 'FacturaElectronicaCompra' && dto.receiver
|
|
56
|
+
? dto.receiver
|
|
57
|
+
: dto.emitter;
|
|
55
58
|
return Clave_1.Clave.create({
|
|
56
59
|
branch: dto.branch,
|
|
57
60
|
ceSituation: dto.ceSituation,
|
|
58
61
|
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
59
62
|
countryCode: dto.countryCode,
|
|
60
63
|
docKeyType: docType.value,
|
|
61
|
-
emitterIdentifier:
|
|
62
|
-
identifierType:
|
|
64
|
+
emitterIdentifier: keyPerson.identifier.id,
|
|
65
|
+
identifierType: keyPerson.identifier.type || '01',
|
|
63
66
|
securityCode: dto.securityCode,
|
|
64
67
|
terminal: dto.terminal
|
|
65
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
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qB;YAChD,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,UAAU,EAAE,OAAO,CAAC,KAAK;YACzB,iBAAiB,EAAE,SAAS,CAAC,UAAU,CAAC,EAAE;YAC1C,cAAc,EAAE,SAAS,CAAC,UAAU,CAAC,IAAI,IAAI,IAAI;YACjD,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAA;IACJ,CAAC;CACF;AA/DD,4CA+DC"}
|
|
@@ -4,11 +4,12 @@ exports.mapReceptorMessageToAtvFormat = exports.mapDocumentToAtvFormat = void 0;
|
|
|
4
4
|
const parseAtvMoneyFormat = (amount) => {
|
|
5
5
|
return parseFloat(amount.toFixed(5));
|
|
6
6
|
};
|
|
7
|
-
const
|
|
7
|
+
const isPurchaseInvoice = (docName) => docName === 'FacturaElectronicaCompra';
|
|
8
|
+
const mapOrderLinesToAtvFormat = (orderLines, docName) => {
|
|
8
9
|
const LineaDetalle = orderLines.map((orderLine) => {
|
|
9
10
|
var _a;
|
|
10
11
|
const impuestoMonto = orderLine.tax ? parseAtvMoneyFormat((_a = orderLine.tax.amount) !== null && _a !== void 0 ? _a : 0) : 0;
|
|
11
|
-
return Object.assign(Object.assign({ NumeroLinea: orderLine.lineNumber, CodigoCABYS: orderLine.code,
|
|
12
|
+
return Object.assign(Object.assign(Object.assign({ NumeroLinea: orderLine.lineNumber, CodigoCABYS: orderLine.code,
|
|
12
13
|
// CodigoComercial
|
|
13
14
|
Cantidad: orderLine.quantity, UnidadMedida: orderLine.measureUnit,
|
|
14
15
|
// UnidadMedidaComercial
|
|
@@ -22,13 +23,15 @@ const mapOrderLinesToAtvFormat = (orderLines) => {
|
|
|
22
23
|
Monto: impuestoMonto
|
|
23
24
|
// Exoneracion is explicitly excluded here
|
|
24
25
|
}
|
|
25
|
-
})),
|
|
26
|
+
})), (!isPurchaseInvoice(docName) && {
|
|
27
|
+
ImpuestoAsumidoEmisorFabrica: 0
|
|
28
|
+
})), {
|
|
26
29
|
// @ts-expect-error pending-to-fix
|
|
27
30
|
ImpuestoNeto: parseAtvMoneyFormat(orderLine.tax.amount), MontoTotalLinea: parseAtvMoneyFormat(orderLine.totalOrderLineAmount), exchangeRate: orderLine.exchangeRate, currency: orderLine.currency });
|
|
28
31
|
});
|
|
29
32
|
return { LineaDetalle };
|
|
30
33
|
};
|
|
31
|
-
const mapSummaryInvoice = (document) => {
|
|
34
|
+
const mapSummaryInvoice = (document, docName) => {
|
|
32
35
|
const summaryInvoice = document.summaryInvoice;
|
|
33
36
|
const orderLines = document.orderLines; // Still need access to order lines for breakdown
|
|
34
37
|
// --- Lógica para TotalDesgloseImpuesto (sin considerar exoneraciones) ---
|
|
@@ -50,76 +53,57 @@ const mapSummaryInvoice = (document) => {
|
|
|
50
53
|
TotalMontoImpuesto: parseAtvMoneyFormat(totalMonto)
|
|
51
54
|
};
|
|
52
55
|
});
|
|
53
|
-
return {
|
|
54
|
-
CodigoTipoMoneda: {
|
|
56
|
+
return Object.assign(Object.assign({ CodigoTipoMoneda: {
|
|
55
57
|
// @ts-expect-error pending-to-fix
|
|
56
58
|
CodigoMoneda: summaryInvoice.currency.code,
|
|
57
59
|
// @ts-expect-error pending-to-fix
|
|
58
60
|
TipoCambio: summaryInvoice.currency.exchangeRate
|
|
59
|
-
},
|
|
60
|
-
TotalServGravados: parseAtvMoneyFormat(summaryInvoice.totalEncumberedServices),
|
|
61
|
-
TotalServExentos: parseAtvMoneyFormat(summaryInvoice.totalExemptServices),
|
|
62
|
-
TotalServNoSujeto: parseAtvMoneyFormat(summaryInvoice.totalNonTaxableServices), // Moved here
|
|
61
|
+
}, TotalServGravados: parseAtvMoneyFormat(summaryInvoice.totalEncumberedServices), TotalServExentos: parseAtvMoneyFormat(summaryInvoice.totalExemptServices), TotalServNoSujeto: parseAtvMoneyFormat(summaryInvoice.totalNonTaxableServices),
|
|
63
62
|
// @ts-expect-error pending-to-fix
|
|
64
|
-
TotalMercanciasGravadas: parseAtvMoneyFormat(summaryInvoice.totalEncumberedMerchandise),
|
|
63
|
+
TotalMercanciasGravadas: parseAtvMoneyFormat(summaryInvoice.totalEncumberedMerchandise),
|
|
65
64
|
// @ts-expect-error pending-to-fix
|
|
66
|
-
TotalMercanciasExentas: parseAtvMoneyFormat(summaryInvoice.totalExemptMerchandise),
|
|
67
|
-
TotalMercNoSujeta: parseAtvMoneyFormat(summaryInvoice.totalNonTaxableMerchandise), // Moved here
|
|
68
|
-
TotalGravado: parseAtvMoneyFormat(summaryInvoice.totalEncumbered),
|
|
69
|
-
TotalExento: parseAtvMoneyFormat(summaryInvoice.totalExempt),
|
|
70
|
-
TotalExonerado: parseAtvMoneyFormat(summaryInvoice.totalExonerated),
|
|
71
|
-
TotalNoSujeto: parseAtvMoneyFormat(summaryInvoice.totalNonTaxable), // Moved here
|
|
72
|
-
TotalVenta: parseAtvMoneyFormat(summaryInvoice.totalSale),
|
|
65
|
+
TotalMercanciasExentas: parseAtvMoneyFormat(summaryInvoice.totalExemptMerchandise), TotalMercNoSujeta: parseAtvMoneyFormat(summaryInvoice.totalNonTaxableMerchandise), TotalGravado: parseAtvMoneyFormat(summaryInvoice.totalEncumbered), TotalExento: parseAtvMoneyFormat(summaryInvoice.totalExempt), TotalExonerado: parseAtvMoneyFormat(summaryInvoice.totalExonerated), TotalNoSujeto: parseAtvMoneyFormat(summaryInvoice.totalNonTaxable), TotalVenta: parseAtvMoneyFormat(summaryInvoice.totalSale),
|
|
73
66
|
// @ts-expect-error pending-to-fix
|
|
74
|
-
TotalDescuentos: parseAtvMoneyFormat(summaryInvoice.totalDiscounts),
|
|
67
|
+
TotalDescuentos: parseAtvMoneyFormat(summaryInvoice.totalDiscounts),
|
|
75
68
|
// @ts-expect-error pending-to-fix
|
|
76
|
-
TotalVentaNeta: parseAtvMoneyFormat(summaryInvoice.totalNetSale),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
TotalImpAsumEmisorFabrica: 0,
|
|
80
|
-
TotalOtrosCargos: 0,
|
|
81
|
-
MedioPago: {
|
|
69
|
+
TotalVentaNeta: parseAtvMoneyFormat(summaryInvoice.totalNetSale), TotalDesgloseImpuesto, TotalImpuesto: parseAtvMoneyFormat(summaryInvoice.totalTaxes) }, (!isPurchaseInvoice(docName) && {
|
|
70
|
+
TotalImpAsumEmisorFabrica: 0
|
|
71
|
+
})), { TotalOtrosCargos: 0, MedioPago: {
|
|
82
72
|
// @ts-expect-error pending-to-fix
|
|
83
73
|
TipoMedioPago: document.paymentMethod
|
|
84
|
-
},
|
|
85
|
-
TotalComprobante: parseAtvMoneyFormat(summaryInvoice.totalVoucher)
|
|
86
|
-
};
|
|
74
|
+
}, TotalComprobante: parseAtvMoneyFormat(summaryInvoice.totalVoucher) });
|
|
87
75
|
};
|
|
88
76
|
const mapPerson = (person) => {
|
|
89
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
77
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
90
78
|
const atvPerson = {
|
|
91
79
|
Nombre: person.fullName,
|
|
92
80
|
Identificacion: {
|
|
93
81
|
Tipo: person.identifierType,
|
|
94
82
|
Numero: person.identifierId
|
|
95
83
|
},
|
|
96
|
-
NombreComercial: person.commercialName
|
|
97
|
-
Ubicacion: undefined,
|
|
98
|
-
OtrasSenasExtranjero: undefined,
|
|
99
|
-
Telefono: undefined,
|
|
100
|
-
CorreoElectronico: undefined
|
|
84
|
+
NombreComercial: person.commercialName
|
|
101
85
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
86
|
+
if (((_a = person.location) === null || _a === void 0 ? void 0 : _a.province) && ((_b = person.location) === null || _b === void 0 ? void 0 : _b.canton) && ((_c = person.location) === null || _c === void 0 ? void 0 : _c.district)) {
|
|
87
|
+
atvPerson.Ubicacion = {
|
|
88
|
+
Provincia: (_d = person.location) === null || _d === void 0 ? void 0 : _d.province,
|
|
89
|
+
Canton: (_f = (_e = person.location) === null || _e === void 0 ? void 0 : _e.canton) === null || _f === void 0 ? void 0 : _f.padStart(2, '0'),
|
|
90
|
+
Distrito: (_h = (_g = person.location) === null || _g === void 0 ? void 0 : _g.district) === null || _h === void 0 ? void 0 : _h.padStart(2, '0'),
|
|
91
|
+
Barrio: (_k = (_j = person.location) === null || _j === void 0 ? void 0 : _j.neighborhood) === null || _k === void 0 ? void 0 : _k.padStart(5, '0'),
|
|
92
|
+
OtrasSenas: (_l = person.location) === null || _l === void 0 ? void 0 : _l.details
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (person.foreignAddress) {
|
|
96
|
+
atvPerson.OtrasSenasExtranjero = person.foreignAddress;
|
|
97
|
+
}
|
|
98
|
+
if (((_m = person.phone) === null || _m === void 0 ? void 0 : _m.countryCode) && ((_o = person.phone) === null || _o === void 0 ? void 0 : _o.number)) {
|
|
99
|
+
atvPerson.Telefono = {
|
|
100
|
+
CodigoPais: (_p = person.phone) === null || _p === void 0 ? void 0 : _p.countryCode,
|
|
101
|
+
NumTelefono: (_q = person.phone) === null || _q === void 0 ? void 0 : _q.number
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (person.email) {
|
|
105
|
+
atvPerson.CorreoElectronico = person.email;
|
|
106
|
+
}
|
|
123
107
|
return atvPerson;
|
|
124
108
|
};
|
|
125
109
|
const mapReferenceInformation = (referenceInfo) => {
|
|
@@ -134,11 +118,14 @@ const mapReferenceInformation = (referenceInfo) => {
|
|
|
134
118
|
const mapDocumentToAtvFormat = (docName, document) => {
|
|
135
119
|
var _a, _b;
|
|
136
120
|
const key = docName;
|
|
137
|
-
const
|
|
121
|
+
const activitySource = isPurchaseInvoice(docName) && document.receiver
|
|
122
|
+
? document.receiver
|
|
123
|
+
: document.emitter;
|
|
124
|
+
const doc = Object.assign(Object.assign(Object.assign(Object.assign({ Clave: document.clave, ProveedorSistemas: document.providerId, CodigoActividadEmisor: activitySource.activityCode.padStart(6, '0') }, (document.receiver && {
|
|
138
125
|
CodigoActividadReceptor: (_b = (_a = document.receiver) === null || _a === void 0 ? void 0 : _a.activityCode) === null || _b === void 0 ? void 0 : _b.padStart(6, '0')
|
|
139
126
|
})), { NumeroConsecutivo: document.fullConsecutive, FechaEmision: document.issueDate.toISOString(), Emisor: mapPerson(document.emitter) }), (document.receiver && {
|
|
140
127
|
Receptor: mapPerson(document.receiver)
|
|
141
|
-
})), { CondicionVenta: document.conditionSale, PlazoCredito: document.deadlineCredit, DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines), ResumenFactura: mapSummaryInvoice(document), Otros: document.others });
|
|
128
|
+
})), { CondicionVenta: document.conditionSale, PlazoCredito: document.deadlineCredit, DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines, docName), ResumenFactura: mapSummaryInvoice(document, docName), Otros: document.others });
|
|
142
129
|
if (document.referenceInformation) {
|
|
143
130
|
doc.InformacionReferencia = mapReferenceInformation(document.referenceInformation);
|
|
144
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billDocToAtv.js","sourceRoot":"","sources":["../../../../src/ATV/mappers/billDocToAtv.ts"],"names":[],"mappings":";;;AASA,MAAM,mBAAmB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,UAAuB,EAAmB,EAAE;
|
|
1
|
+
{"version":3,"file":"billDocToAtv.js","sourceRoot":"","sources":["../../../../src/ATV/mappers/billDocToAtv.ts"],"names":[],"mappings":";;;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AK,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,qDAAqD;YAChG,cAAc,EAAE,KAAK,CAAC,uBAAuB;YAC7C,kBAAkB,EAAE,KAAK,CAAC,UAAU;YACpC,eAAe,EAAE,KAAK,CAAC,YAAY;YACnC,iBAAiB,EAAE,KAAK,CAAC,YAAY;YACrC,0BAA0B,EAAE,KAAK,CAAC,SAAS,EAAE,yEAAyE;YACtH,YAAY,EAAE,KAAK,CAAC,SAAS,EAAE,yCAAyC;YACxE,oBAAoB,EAAE,KAAK,CAAC,kBAAkB;YAC9C,yBAAyB,EAAE,KAAK,CAAC,mBAAmB;SACrD;KACF,CAAA;AACH,CAAC,CAAA;AAjBY,QAAA,6BAA6B,iCAiBzC"}
|
package/examples/README.md
CHANGED
|
@@ -11,6 +11,11 @@ Para probar crear y enviar tiquete electronico. Ejemplo:
|
|
|
11
11
|
yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSendTE.ts 1
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
Para probar crear y enviar factura electronica de compra. Ejemplo:
|
|
15
|
+
```
|
|
16
|
+
yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSendFEC.ts 1
|
|
17
|
+
```
|
|
18
|
+
|
|
14
19
|
Para aceptar una factura. Ejemplo:
|
|
15
20
|
```
|
|
16
21
|
yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/atvAccept.ts
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { FECInputExample } from '@test/stubs/createDocument.data'
|
|
3
|
+
import { ATV } from '../dist/src'
|
|
4
|
+
import { PersonProps } from 'dist/src/ATV/core/Person'
|
|
5
|
+
|
|
6
|
+
const getRequiredEnv = (key: string): string => {
|
|
7
|
+
const value = process.env[key]
|
|
8
|
+
if (!value) {
|
|
9
|
+
throw new Error(`Missing required environment variable: ${key}`)
|
|
10
|
+
}
|
|
11
|
+
return value
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const USERNAME_TEST = getRequiredEnv('USERNAME_TEST')
|
|
15
|
+
const PASSWORD_TEST = getRequiredEnv('PASSWORD_TEST')
|
|
16
|
+
const EMITTER_IDENTIFIER_ID = getRequiredEnv('EMITTER_IDENTIFIER_ID')
|
|
17
|
+
const EMITTER_IDENTIFIER_TYPE = getRequiredEnv('EMITTER_IDENTIFIER_TYPE') as PersonProps['identifier']['type']
|
|
18
|
+
|
|
19
|
+
const SOURCE_P12_URI = getRequiredEnv('SOURCE_P12_URI')
|
|
20
|
+
const SOURCE_P12_PASSPORT = getRequiredEnv('SOURCE_P12_PASSPORT')
|
|
21
|
+
|
|
22
|
+
const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
|
|
23
|
+
|
|
24
|
+
const paramConsecutive = process.argv[2]
|
|
25
|
+
const consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
|
|
26
|
+
console.log('paramConsecutive', paramConsecutive)
|
|
27
|
+
|
|
28
|
+
// In FacturaElectronicaCompra the non-domiciled supplier is XML Emisor,
|
|
29
|
+
// and the local taxpayer/business that signs is XML Receptor.
|
|
30
|
+
const receiver = FECInputExample.receiver
|
|
31
|
+
if (!receiver) {
|
|
32
|
+
throw new Error('FECInputExample.receiver is required')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!consecutiveIdentifier) {
|
|
36
|
+
throw new Error('Missing consecutiveIdentifier. Pass it as argument or set TEST_CONSECUTIVE.')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
FECInputExample.consecutiveIdentifier = consecutiveIdentifier
|
|
40
|
+
receiver.identifier.id = EMITTER_IDENTIFIER_ID
|
|
41
|
+
receiver.identifier.type = EMITTER_IDENTIFIER_TYPE
|
|
42
|
+
FECInputExample.providerId = EMITTER_IDENTIFIER_ID
|
|
43
|
+
|
|
44
|
+
console.log('requestStub consecutivo', FECInputExample.consecutiveIdentifier)
|
|
45
|
+
|
|
46
|
+
function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<Awaited<ReturnType<ATV['sendConfirmation']>>> {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
console.log('location', location)
|
|
50
|
+
atv.sendConfirmation({
|
|
51
|
+
url: location,
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
Authorization: 'bearer ' + token
|
|
55
|
+
}
|
|
56
|
+
}).then(data => resolve(data))
|
|
57
|
+
.catch(err => reject(err))
|
|
58
|
+
}, ms)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function main(): Promise<void> {
|
|
63
|
+
const atv = new ATV({}, 'stg')
|
|
64
|
+
const tokenData = await atv.getToken({
|
|
65
|
+
username: USERNAME_TEST,
|
|
66
|
+
password: PASSWORD_TEST
|
|
67
|
+
})
|
|
68
|
+
const { command, extraData } = await atv.createDocumentCommand({
|
|
69
|
+
document: FECInputExample,
|
|
70
|
+
token: tokenData.accessToken,
|
|
71
|
+
signatureOptions: {
|
|
72
|
+
buffer: pem,
|
|
73
|
+
password: SOURCE_P12_PASSPORT
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
console.log({
|
|
77
|
+
clave: command.data.clave,
|
|
78
|
+
emisor: command.data.emisor,
|
|
79
|
+
receptor: command.data.receptor,
|
|
80
|
+
hasImpuestoAsumidoEmisorFabrica: extraData.xml.includes('ImpuestoAsumidoEmisorFabrica')
|
|
81
|
+
})
|
|
82
|
+
const response = await atv.sendDocument(command)
|
|
83
|
+
if (response.errorCause) {
|
|
84
|
+
console.log('error response', response)
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
if (!response.location) {
|
|
88
|
+
throw new Error('No confirmation location returned by Hacienda.')
|
|
89
|
+
}
|
|
90
|
+
const confirmationResponse = await getConfimation(atv, tokenData.accessToken, response.location, 3500)
|
|
91
|
+
console.log({ MensajeHacienda: confirmationResponse.confirmation })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@facturacr/atv-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14-alpha",
|
|
4
4
|
"description": "Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -71,4 +71,4 @@
|
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": ">=18"
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|
|
@@ -119,14 +119,18 @@ export class CreateDocFactory {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
private createClave(dto: CreateDocumentInput['document'], docType: DocumentType): Clave {
|
|
122
|
+
const keyPerson = dto.documentName === 'FacturaElectronicaCompra' && dto.receiver
|
|
123
|
+
? dto.receiver
|
|
124
|
+
: dto.emitter
|
|
125
|
+
|
|
122
126
|
return Clave.create({
|
|
123
127
|
branch: dto.branch,
|
|
124
128
|
ceSituation: dto.ceSituation,
|
|
125
129
|
consecutiveIdentifier: dto.consecutiveIdentifier,
|
|
126
130
|
countryCode: dto.countryCode,
|
|
127
131
|
docKeyType: docType.value,
|
|
128
|
-
emitterIdentifier:
|
|
129
|
-
identifierType:
|
|
132
|
+
emitterIdentifier: keyPerson.identifier.id,
|
|
133
|
+
identifierType: keyPerson.identifier.type || '01',
|
|
130
134
|
securityCode: dto.securityCode,
|
|
131
135
|
terminal: dto.terminal
|
|
132
136
|
})
|
|
@@ -11,7 +11,9 @@ const parseAtvMoneyFormat = (amount: number) => {
|
|
|
11
11
|
return parseFloat(amount.toFixed(5))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const isPurchaseInvoice = (docName: string) => docName === 'FacturaElectronicaCompra'
|
|
15
|
+
|
|
16
|
+
const mapOrderLinesToAtvFormat = (orderLines: OrderLine[], docName: string): DetalleServicio => {
|
|
15
17
|
const LineaDetalle = orderLines.map<DetalleServicio['LineaDetalle'][0]>((orderLine) => {
|
|
16
18
|
const impuestoMonto = orderLine.tax ? parseAtvMoneyFormat(orderLine.tax.amount ?? 0) : 0
|
|
17
19
|
return {
|
|
@@ -36,7 +38,9 @@ const mapOrderLinesToAtvFormat = (orderLines: OrderLine[]): DetalleServicio => {
|
|
|
36
38
|
// Exoneracion is explicitly excluded here
|
|
37
39
|
}
|
|
38
40
|
}),
|
|
39
|
-
|
|
41
|
+
...(!isPurchaseInvoice(docName) && {
|
|
42
|
+
ImpuestoAsumidoEmisorFabrica: 0
|
|
43
|
+
}),
|
|
40
44
|
// @ts-expect-error pending-to-fix
|
|
41
45
|
ImpuestoNeto: parseAtvMoneyFormat(orderLine.tax.amount),
|
|
42
46
|
MontoTotalLinea: parseAtvMoneyFormat(orderLine.totalOrderLineAmount),
|
|
@@ -47,7 +51,7 @@ const mapOrderLinesToAtvFormat = (orderLines: OrderLine[]): DetalleServicio => {
|
|
|
47
51
|
return { LineaDetalle }
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
const mapSummaryInvoice = (document: DomainDocument): Resumen => {
|
|
54
|
+
const mapSummaryInvoice = (document: DomainDocument, docName: string): Resumen => {
|
|
51
55
|
const summaryInvoice = document.summaryInvoice
|
|
52
56
|
const orderLines = document.orderLines // Still need access to order lines for breakdown
|
|
53
57
|
|
|
@@ -97,7 +101,9 @@ const mapSummaryInvoice = (document: DomainDocument): Resumen => {
|
|
|
97
101
|
TotalVentaNeta: parseAtvMoneyFormat(summaryInvoice.totalNetSale),
|
|
98
102
|
TotalDesgloseImpuesto,
|
|
99
103
|
TotalImpuesto: parseAtvMoneyFormat(summaryInvoice.totalTaxes),
|
|
100
|
-
|
|
104
|
+
...(!isPurchaseInvoice(docName) && {
|
|
105
|
+
TotalImpAsumEmisorFabrica: 0
|
|
106
|
+
}),
|
|
101
107
|
TotalOtrosCargos: 0,
|
|
102
108
|
MedioPago: {
|
|
103
109
|
// @ts-expect-error pending-to-fix
|
|
@@ -108,39 +114,35 @@ const mapSummaryInvoice = (document: DomainDocument): Resumen => {
|
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
const mapPerson = (person: Person): Persona => {
|
|
111
|
-
const atvPerson = {
|
|
117
|
+
const atvPerson: Persona = {
|
|
112
118
|
Nombre: person.fullName,
|
|
113
119
|
Identificacion: {
|
|
114
120
|
Tipo: person.identifierType,
|
|
115
121
|
Numero: person.identifierId
|
|
116
122
|
},
|
|
117
|
-
NombreComercial: person.commercialName
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
NombreComercial: person.commercialName
|
|
124
|
+
}
|
|
125
|
+
if (person.location?.province && person.location?.canton && person.location?.district) {
|
|
126
|
+
atvPerson.Ubicacion = {
|
|
127
|
+
Provincia: person.location?.province,
|
|
128
|
+
Canton: person.location?.canton?.padStart(2, '0'),
|
|
129
|
+
Distrito: person.location?.district?.padStart(2, '0'),
|
|
130
|
+
Barrio: person.location?.neighborhood?.padStart(5, '0'),
|
|
131
|
+
OtrasSenas: person.location?.details
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (person.foreignAddress) {
|
|
135
|
+
atvPerson.OtrasSenasExtranjero = person.foreignAddress
|
|
136
|
+
}
|
|
137
|
+
if (person.phone?.countryCode && person.phone?.number) {
|
|
138
|
+
atvPerson.Telefono = {
|
|
139
|
+
CodigoPais: person.phone?.countryCode,
|
|
140
|
+
NumTelefono: person.phone?.number
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (person.email) {
|
|
144
|
+
atvPerson.CorreoElectronico = person.email
|
|
122
145
|
}
|
|
123
|
-
// @ts-expect-error pending-to-fix
|
|
124
|
-
atvPerson.Ubicacion = person.location
|
|
125
|
-
? {
|
|
126
|
-
Provincia: person.location?.province,
|
|
127
|
-
Canton: person.location?.canton?.padStart(2, '0'),
|
|
128
|
-
Distrito: person.location?.district?.padStart(2, '0'),
|
|
129
|
-
Barrio: person.location?.neighborhood?.padStart(5, '0'),
|
|
130
|
-
OtrasSenas: person.location?.details
|
|
131
|
-
}
|
|
132
|
-
: undefined
|
|
133
|
-
// @ts-expect-error pending-to-fix
|
|
134
|
-
atvPerson.OtrasSenasExtranjero = person.foreignAddress
|
|
135
|
-
// @ts-expect-error pending-to-fix
|
|
136
|
-
atvPerson.Telefono = person.phone
|
|
137
|
-
? {
|
|
138
|
-
CodigoPais: person.phone?.countryCode,
|
|
139
|
-
NumTelefono: person.phone?.number
|
|
140
|
-
}
|
|
141
|
-
: undefined
|
|
142
|
-
// @ts-expect-error pending-to-fix
|
|
143
|
-
atvPerson.CorreoElectronico = person.email
|
|
144
146
|
|
|
145
147
|
return atvPerson
|
|
146
148
|
}
|
|
@@ -157,10 +159,13 @@ const mapReferenceInformation = (referenceInfo: ReferenceInformation): Informaci
|
|
|
157
159
|
|
|
158
160
|
export const mapDocumentToAtvFormat = (docName: string, document: DomainDocument): AtvFormat => {
|
|
159
161
|
const key = docName
|
|
162
|
+
const activitySource = isPurchaseInvoice(docName) && document.receiver
|
|
163
|
+
? document.receiver
|
|
164
|
+
: document.emitter
|
|
160
165
|
const doc: AtvDocument = {
|
|
161
166
|
Clave: document.clave,
|
|
162
167
|
ProveedorSistemas: document.providerId,
|
|
163
|
-
CodigoActividadEmisor:
|
|
168
|
+
CodigoActividadEmisor: activitySource.activityCode.padStart(6, '0'),
|
|
164
169
|
...(document.receiver && { // TODO add && document.name === 'FacturaElectronica'
|
|
165
170
|
CodigoActividadReceptor: document.receiver?.activityCode?.padStart(6, '0')
|
|
166
171
|
}),
|
|
@@ -172,8 +177,8 @@ export const mapDocumentToAtvFormat = (docName: string, document: DomainDocument
|
|
|
172
177
|
}),
|
|
173
178
|
CondicionVenta: document.conditionSale,
|
|
174
179
|
PlazoCredito: document.deadlineCredit,
|
|
175
|
-
DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines),
|
|
176
|
-
ResumenFactura: mapSummaryInvoice(document),
|
|
180
|
+
DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines, docName),
|
|
181
|
+
ResumenFactura: mapSummaryInvoice(document, docName),
|
|
177
182
|
Otros: document.others
|
|
178
183
|
}
|
|
179
184
|
if (document.referenceInformation) {
|