pangea-server 3.3.9 → 3.3.11
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.
|
@@ -3,10 +3,10 @@ type ArcaConfig = {
|
|
|
3
3
|
cert: string;
|
|
4
4
|
key: string;
|
|
5
5
|
};
|
|
6
|
-
type VoucherType =
|
|
7
|
-
type Concept =
|
|
8
|
-
type DocumentType =
|
|
9
|
-
type VatConditionReceiver =
|
|
6
|
+
type VoucherType = 'invoice_a' | 'invoice_b' | 'invoice_c' | 'debit_note_a' | 'debit_note_b' | 'debit_note_c' | 'credit_note_a' | 'credit_note_b' | 'credit_note_c';
|
|
7
|
+
type Concept = 'products' | 'services' | 'products_and_services';
|
|
8
|
+
type DocumentType = 'cuit' | 'cuil' | 'dni' | 'final_consumer';
|
|
9
|
+
type VatConditionReceiver = 'vat_registered' | 'vat_exempt' | 'final_consumer' | 'monotaxpayer' | 'unclassified' | 'foreign_supplier' | 'foreign_client' | 'vat_exempt_law_19640' | 'social_monotaxpayer' | 'vat_not_applicable' | 'promoted_independent_monotaxpayer';
|
|
10
10
|
type CreateVoucherOptions = {
|
|
11
11
|
pointOfSale: number;
|
|
12
12
|
voucherType: VoucherType;
|
|
@@ -7,42 +7,79 @@ exports.Arca = void 0;
|
|
|
7
7
|
const afip_js_1 = __importDefault(require("@afipsdk/afip.js"));
|
|
8
8
|
// helpers
|
|
9
9
|
const helpers_1 = require("../helpers");
|
|
10
|
+
const voucherTypeMap = {
|
|
11
|
+
invoice_a: 1,
|
|
12
|
+
invoice_b: 6,
|
|
13
|
+
invoice_c: 11,
|
|
14
|
+
debit_note_a: 2,
|
|
15
|
+
debit_note_b: 7,
|
|
16
|
+
debit_note_c: 12,
|
|
17
|
+
credit_note_a: 3,
|
|
18
|
+
credit_note_b: 8,
|
|
19
|
+
credit_note_c: 13,
|
|
20
|
+
};
|
|
21
|
+
const conceptMap = { products: 1, services: 2, products_and_services: 3 };
|
|
22
|
+
const documentTypeMap = { cuit: 80, cuil: 86, dni: 96, final_consumer: 99 };
|
|
23
|
+
const vatConditionReceiverMap = {
|
|
24
|
+
vat_registered: 1,
|
|
25
|
+
vat_exempt: 4,
|
|
26
|
+
final_consumer: 5,
|
|
27
|
+
monotaxpayer: 6,
|
|
28
|
+
unclassified: 7,
|
|
29
|
+
foreign_supplier: 8,
|
|
30
|
+
foreign_client: 9,
|
|
31
|
+
vat_exempt_law_19640: 10,
|
|
32
|
+
social_monotaxpayer: 13,
|
|
33
|
+
vat_not_applicable: 15,
|
|
34
|
+
promoted_independent_monotaxpayer: 16,
|
|
35
|
+
};
|
|
10
36
|
class Arca {
|
|
11
37
|
constructor(config) {
|
|
12
38
|
const { cuit, cert, key } = config;
|
|
13
39
|
this.__afip = new afip_js_1.default({
|
|
14
40
|
access_token: (0, helpers_1.getEnvStr)('AFIP_ACCESS_TOKEN'),
|
|
15
|
-
|
|
41
|
+
CUIT: cuit,
|
|
42
|
+
...(cuit !== 20409378472 ? { cert, key, production: true } : {}),
|
|
16
43
|
});
|
|
17
44
|
}
|
|
18
45
|
async createVoucher(createVoucherOptions) {
|
|
19
46
|
const { pointOfSale, voucherType, concept, documentType, documentNumber, taxableAmount, exemptAmount, vatAmount, vatConditionReceiver, serviceFrom = null, serviceTo = null, paymentDueDate = null, } = createVoucherOptions;
|
|
20
|
-
const
|
|
47
|
+
const afipVoucherType = voucherTypeMap[voucherType];
|
|
48
|
+
const isInvoiceC = voucherType === 'invoice_c' || voucherType === 'credit_note_c' || voucherType === 'debit_note_c';
|
|
49
|
+
const isFinalConsumer = documentType === 'final_consumer';
|
|
50
|
+
const finalDocumentType = isFinalConsumer ? 99 : documentTypeMap[documentType];
|
|
51
|
+
const finalDocumentNumber = isFinalConsumer ? 0 : documentNumber;
|
|
52
|
+
const finalVatAmount = isInvoiceC ? 0 : vatAmount;
|
|
53
|
+
const finalTaxableAmount = isInvoiceC ? 0 : taxableAmount;
|
|
54
|
+
const finalIvaArray = isInvoiceC || finalVatAmount === 0 ? [] : [{ Id: 5, BaseImp: finalTaxableAmount, Importe: finalVatAmount }];
|
|
55
|
+
if (concept !== 'products' && (serviceFrom === null || serviceTo === null || paymentDueDate === null))
|
|
56
|
+
throw new Error('Service dates are required');
|
|
57
|
+
const lastVoucher = await this.__afip.ElectronicBilling.getLastVoucher(pointOfSale, afipVoucherType);
|
|
21
58
|
const voucherNumber = lastVoucher + 1;
|
|
22
59
|
const voucherDate = Number(new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().split('T')[0].replace(/-/g, ''));
|
|
23
60
|
const data = {
|
|
24
61
|
CantReg: 1,
|
|
25
62
|
PtoVta: pointOfSale,
|
|
26
|
-
CbteTipo:
|
|
27
|
-
Concepto: concept,
|
|
28
|
-
DocTipo:
|
|
29
|
-
DocNro:
|
|
63
|
+
CbteTipo: afipVoucherType,
|
|
64
|
+
Concepto: conceptMap[concept],
|
|
65
|
+
DocTipo: finalDocumentType,
|
|
66
|
+
DocNro: finalDocumentNumber,
|
|
30
67
|
CbteDesde: voucherNumber,
|
|
31
68
|
CbteHasta: voucherNumber,
|
|
32
69
|
CbteFch: voucherDate,
|
|
33
|
-
FchServDesde: serviceFrom,
|
|
34
|
-
FchServHasta: serviceTo,
|
|
35
|
-
FchVtoPago: paymentDueDate,
|
|
36
|
-
ImpTotal:
|
|
70
|
+
FchServDesde: concept === 'products' ? null : serviceFrom,
|
|
71
|
+
FchServHasta: concept === 'products' ? null : serviceTo,
|
|
72
|
+
FchVtoPago: concept === 'products' ? null : paymentDueDate,
|
|
73
|
+
ImpTotal: finalTaxableAmount + finalVatAmount + exemptAmount,
|
|
37
74
|
ImpTotConc: 0,
|
|
38
|
-
ImpNeto:
|
|
75
|
+
ImpNeto: finalTaxableAmount,
|
|
39
76
|
ImpOpEx: exemptAmount,
|
|
40
|
-
ImpIVA:
|
|
77
|
+
ImpIVA: finalVatAmount,
|
|
41
78
|
ImpTrib: 0,
|
|
42
79
|
MonId: 'PES',
|
|
43
80
|
MonCotiz: 1,
|
|
44
|
-
CondicionIVAReceptorId: vatConditionReceiver,
|
|
45
|
-
Iva:
|
|
81
|
+
CondicionIVAReceptorId: vatConditionReceiverMap[vatConditionReceiver],
|
|
82
|
+
Iva: finalIvaArray,
|
|
46
83
|
};
|
|
47
84
|
return this.__afip.ElectronicBilling.createVoucher(data);
|
|
48
85
|
}
|