@facturacr/atv-sdk 1.2.14 → 2.0.0-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 +4 -1
- package/dist/src/ATV/core/CreateDocFactory.d.ts +2 -1
- package/dist/src/ATV/core/CreateDocFactory.js +1 -1
- package/dist/src/ATV/core/CreateDocFactory.js.map +1 -1
- package/dist/src/ATV/core/Document.d.ts +2 -1
- package/dist/src/ATV/core/Document.js +4 -1
- package/dist/src/ATV/core/Document.js.map +1 -1
- package/dist/src/ATV/core/Person.d.ts +2 -0
- package/dist/src/ATV/core/Person.js +3 -0
- package/dist/src/ATV/core/Person.js.map +1 -1
- package/dist/src/ATV/mappers/billDocToAtv.js +15 -15
- package/dist/src/ATV/mappers/billDocToAtv.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/lib/genXML/sigXML/index.js +2 -1
- package/dist/src/lib/genXML/sigXML/index.js.map +1 -1
- package/dist/src/lib/genXML/xmlConfig.d.ts +25 -24
- package/dist/src/lib/genXML/xmlConfig.js +25 -20
- package/dist/src/lib/genXML/xmlConfig.js.map +1 -1
- package/dist/src/types/facturaInterfaces.d.ts +10 -6
- package/doc/atv-structures/4.4/breaking-changes-ai-generated.md +53 -0
- package/doc/atv-structures/4.4/supported.md +12 -0
- package/examples/README.md +7 -2
- package/examples/createAndSend.ts +4 -3
- package/package.json +1 -1
- package/src/ATV/core/CreateDocFactory.ts +70 -70
- package/src/ATV/core/Document.ts +6 -2
- package/src/ATV/core/Person.ts +5 -0
- package/src/ATV/mappers/billDocToAtv.ts +20 -19
- package/src/index.ts +2 -2
- package/src/lib/genXML/sigXML/index.ts +2 -1
- package/src/lib/genXML/xmlConfig.ts +27 -33
- package/src/types/facturaInterfaces.ts +11 -6
- package/dist/src/confirmXML.d.ts +0 -8
- package/dist/src/confirmXML.js +0 -44
- package/dist/src/confirmXML.js.map +0 -1
- package/dist/src/creditNote.d.ts +0 -14
- package/dist/src/creditNote.js +0 -77
- package/dist/src/creditNote.js.map +0 -1
- package/dist/src/electronicBill.d.ts +0 -3
- package/dist/src/electronicBill.js +0 -61
- package/dist/src/electronicBill.js.map +0 -1
- package/dist/src/lib/genJSON/confirmXML.d.ts +0 -7
- package/dist/src/lib/genJSON/confirmXML.js +0 -46
- package/dist/src/lib/genJSON/confirmXML.js.map +0 -1
- package/dist/src/lib/genJSON/index.d.ts +0 -5
- package/dist/src/lib/genJSON/index.js +0 -135
- package/dist/src/lib/genJSON/index.js.map +0 -1
- package/examples/genBasicXML.ts +0 -31
- package/src/confirmXML.ts +0 -40
- package/src/creditNote.ts +0 -93
- package/src/electronicBill.ts +0 -57
- package/src/lib/genJSON/confirmXML.ts +0 -47
- package/src/lib/genJSON/index.ts +0 -131
package/src/lib/genJSON/index.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { ClientPayload } from '@src/types/globalInterfaces'
|
|
2
|
-
import { InvoiceDocumentContainer, Resumen, Persona, Impuesto, LineaDetalle } from '@src/types/facturaInterfaces'
|
|
3
|
-
import { genXML } from '@src/lib/genXML'
|
|
4
|
-
|
|
5
|
-
// Default XML Values
|
|
6
|
-
const DEFAULT_VALUES = {
|
|
7
|
-
key: 0,
|
|
8
|
-
message: 'Default msj',
|
|
9
|
-
detailsMessage: 'Default details msj',
|
|
10
|
-
tipoIdentificacion: '01' as Persona['Identificacion']['Tipo']
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function sumLines(lines: LineaDetalle[]): any {
|
|
14
|
-
return lines.reduce((accumulator: any, currentValue: any) => {
|
|
15
|
-
const prevTotal = accumulator.MontoTotal || 0
|
|
16
|
-
const prevTax = accumulator.Impuesto || { Impuesto: { Monto: 0 } }
|
|
17
|
-
return {
|
|
18
|
-
total: prevTotal + currentValue.MontoTotal,
|
|
19
|
-
taxes: prevTax.Impuesto.Monto + currentValue.Impuesto.Monto
|
|
20
|
-
}
|
|
21
|
-
}, 0)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getBillResum(lines: LineaDetalle[]): Resumen {
|
|
25
|
-
const sum = sumLines(lines)
|
|
26
|
-
return {
|
|
27
|
-
CodigoTipoMoneda: {
|
|
28
|
-
CodigoMoneda: 'CRC',
|
|
29
|
-
TipoCambio: '585.69'
|
|
30
|
-
},
|
|
31
|
-
TotalServGravados: 0,
|
|
32
|
-
TotalServExentos: 0,
|
|
33
|
-
// TotalServExonerado: 0,
|
|
34
|
-
TotalMercanciasGravadas: sum.total,
|
|
35
|
-
TotalMercanciasExentas: 0,
|
|
36
|
-
TotalGravado: sum.total,
|
|
37
|
-
TotalExento: 0,
|
|
38
|
-
TotalExonerado: 0,
|
|
39
|
-
TotalVenta: sum.total,
|
|
40
|
-
TotalDescuentos: 0,
|
|
41
|
-
TotalVentaNeta: sum.total,
|
|
42
|
-
TotalImpuesto: sum.taxes,
|
|
43
|
-
TotalComprobante: sum.total + sum.taxes
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getSender(frontEndRequest: ClientPayload): Persona {
|
|
48
|
-
const sender = frontEndRequest.Emisor
|
|
49
|
-
return {
|
|
50
|
-
Nombre: sender.Nombre,
|
|
51
|
-
Identificacion: {
|
|
52
|
-
Tipo: sender.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
53
|
-
Numero: sender.Identificacion.Numero
|
|
54
|
-
},
|
|
55
|
-
NombreComercial: sender.NombreComercial,
|
|
56
|
-
Ubicacion: sender.Ubicacion,
|
|
57
|
-
Telefono: sender.Telefono,
|
|
58
|
-
Fax: sender.Fax,
|
|
59
|
-
CorreoElectronico: sender.CorreoElectronico
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function setTaxObj(subtotal: number, taxObj: Impuesto): Impuesto {
|
|
64
|
-
const tax = typeof taxObj.Tarifa === 'number' ? taxObj.Tarifa : 13
|
|
65
|
-
return {
|
|
66
|
-
Codigo: taxObj.Codigo,
|
|
67
|
-
CodigoTarifa: taxObj.CodigoTarifa,
|
|
68
|
-
Tarifa: tax,
|
|
69
|
-
Monto: subtotal * (tax / 100)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function setLinesDefaults(lines: LineaDetalle[]): LineaDetalle[] {
|
|
74
|
-
return lines.map((line, index) => {
|
|
75
|
-
const quantity = line.Cantidad || 1
|
|
76
|
-
const total = line.PrecioUnitario * quantity
|
|
77
|
-
const subtotal = total // restar descuentos
|
|
78
|
-
const taxObj = setTaxObj(subtotal, line.Impuesto)
|
|
79
|
-
return {
|
|
80
|
-
NumeroLinea: (index + 1).toString(),
|
|
81
|
-
Codigo: line.Codigo,
|
|
82
|
-
Cantidad: quantity,
|
|
83
|
-
UnidadMedida: line.UnidadMedida || 'Sp',
|
|
84
|
-
Detalle: line.Detalle,
|
|
85
|
-
PrecioUnitario: line.PrecioUnitario,
|
|
86
|
-
MontoTotal: total,
|
|
87
|
-
SubTotal: subtotal,
|
|
88
|
-
Impuesto: taxObj,
|
|
89
|
-
MontoTotalLinea: subtotal + taxObj.Monto
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function getReceiver(frontEndRequest: ClientPayload): Persona {
|
|
95
|
-
const receiver = frontEndRequest.Receptor
|
|
96
|
-
return {
|
|
97
|
-
Nombre: receiver.Nombre,
|
|
98
|
-
Identificacion: {
|
|
99
|
-
Tipo: receiver.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
100
|
-
Numero: receiver.Identificacion.Numero
|
|
101
|
-
},
|
|
102
|
-
NombreComercial: receiver.NombreComercial,
|
|
103
|
-
Ubicacion: receiver.Ubicacion
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default async (frontEndRequest: ClientPayload, date: any, clave: string, consecutivo: string, options: any): Promise<any> => {
|
|
108
|
-
const receiver = getReceiver(frontEndRequest)
|
|
109
|
-
const sender = getSender(frontEndRequest)
|
|
110
|
-
const lines = setLinesDefaults(frontEndRequest.LineasDetalle)
|
|
111
|
-
const key = frontEndRequest.facturaElectronicaType || 'FacturaElectronica'
|
|
112
|
-
const body = {
|
|
113
|
-
Clave: clave,
|
|
114
|
-
CodigoActividad: frontEndRequest.actividad.padStart(6, '0'),
|
|
115
|
-
NumeroConsecutivo: consecutivo,
|
|
116
|
-
FechaEmision: date,
|
|
117
|
-
Emisor: sender,
|
|
118
|
-
Receptor: receiver,
|
|
119
|
-
CondicionVenta: '01',
|
|
120
|
-
MedioPago: '03',
|
|
121
|
-
DetalleServicio: {
|
|
122
|
-
LineaDetalle: lines
|
|
123
|
-
},
|
|
124
|
-
ResumenFactura: getBillResum(lines)
|
|
125
|
-
}
|
|
126
|
-
const factura: InvoiceDocumentContainer = {
|
|
127
|
-
[key]: body
|
|
128
|
-
}
|
|
129
|
-
const XML = await genXML(key, factura, options)
|
|
130
|
-
return XML
|
|
131
|
-
}
|