pangea-server 3.3.16 → 3.3.17
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,9 +3,40 @@ type ArcaConfig = {
|
|
|
3
3
|
cert: string;
|
|
4
4
|
key: string;
|
|
5
5
|
};
|
|
6
|
+
type VoucherTypeA = '1_invoice_a' | '2_debit_note_a' | '3_credit_note_a';
|
|
7
|
+
type VoucherTypeB = '6_invoice_b' | '7_debit_note_b' | '8_credit_note_b';
|
|
8
|
+
type VoucherTypeC = '11_invoice_c' | '12_debit_note_c' | '13_credit_note_c';
|
|
9
|
+
type VoucherType = VoucherTypeA | VoucherTypeB | VoucherTypeC;
|
|
6
10
|
type Concept = '1_products' | '2_services' | '3_products_and_services';
|
|
7
11
|
type DocumentType = '80_cuit' | '86_cuil' | '96_dni' | '99_final_consumer';
|
|
8
12
|
type VatConditionReceiver = '1_vat_registered' | '4_vat_exempt' | '5_final_consumer' | '6_monotaxpayer' | '7_unclassified' | '8_foreign_supplier' | '9_foreign_client' | '10_vat_exempt_law_19640' | '13_social_monotaxpayer' | '15_vat_not_applicable' | '16_promoted_independent_monotaxpayer';
|
|
13
|
+
type VoucherInfo = {
|
|
14
|
+
pointOfSale: number;
|
|
15
|
+
voucherTypeId: number;
|
|
16
|
+
voucherFrom: number;
|
|
17
|
+
voucherTo: number;
|
|
18
|
+
voucherDate: string;
|
|
19
|
+
documentTypeId: number;
|
|
20
|
+
documentNumber: number;
|
|
21
|
+
receiverVatConditionId: number;
|
|
22
|
+
conceptId: number;
|
|
23
|
+
totalAmount: number;
|
|
24
|
+
nonTaxedAmount: number;
|
|
25
|
+
netAmount: number;
|
|
26
|
+
exemptAmount: number;
|
|
27
|
+
tributeAmount: number;
|
|
28
|
+
vatAmount: number;
|
|
29
|
+
currencyId: string;
|
|
30
|
+
currencyRate: number;
|
|
31
|
+
serviceFromDate: string | null;
|
|
32
|
+
serviceToDate: string | null;
|
|
33
|
+
paymentDueDate: string | null;
|
|
34
|
+
result: 'approved' | 'rejected';
|
|
35
|
+
processDate: string;
|
|
36
|
+
authorizationType: 'CAE';
|
|
37
|
+
authorizationCode: string;
|
|
38
|
+
authorizationExpirationDate: string;
|
|
39
|
+
};
|
|
9
40
|
type CreateInvoiceCOptions = {
|
|
10
41
|
pointOfSale: number;
|
|
11
42
|
receiver: {
|
|
@@ -23,15 +54,16 @@ type CreateInvoiceCOptions = {
|
|
|
23
54
|
paymentDueDate: string;
|
|
24
55
|
};
|
|
25
56
|
};
|
|
26
|
-
type
|
|
57
|
+
type CreateVoucherRes = {
|
|
58
|
+
voucherNumber: number;
|
|
27
59
|
cae: string;
|
|
28
60
|
caeExpirationDate: string;
|
|
29
61
|
};
|
|
30
62
|
export declare class Arca {
|
|
31
63
|
private __afip;
|
|
32
64
|
constructor(config: ArcaConfig);
|
|
33
|
-
getLastVoucher(pointOfSale: number,
|
|
34
|
-
getVoucherInfo(
|
|
35
|
-
createInvoiceC(options: CreateInvoiceCOptions): Promise<
|
|
65
|
+
getLastVoucher(pointOfSale: number, voucherType: VoucherType): Promise<number>;
|
|
66
|
+
getVoucherInfo(voucherNumber: number, pointOfSale: number, voucherType: VoucherType): Promise<VoucherInfo | null>;
|
|
67
|
+
createInvoiceC(options: CreateInvoiceCOptions): Promise<CreateVoucherRes>;
|
|
36
68
|
}
|
|
37
69
|
export {};
|
|
@@ -47,41 +47,67 @@ class Arca {
|
|
|
47
47
|
...(cuit !== 20409378472 ? { cert, key, production: true } : {}),
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
getLastVoucher(pointOfSale,
|
|
50
|
+
getLastVoucher(pointOfSale, voucherType) {
|
|
51
|
+
const voucherTypeId = voucherTypeIds[voucherType];
|
|
51
52
|
return this.__afip.ElectronicBilling.getLastVoucher(pointOfSale, voucherTypeId);
|
|
52
53
|
}
|
|
53
|
-
getVoucherInfo(
|
|
54
|
-
|
|
54
|
+
async getVoucherInfo(voucherNumber, pointOfSale, voucherType) {
|
|
55
|
+
const voucherTypeId = voucherTypeIds[voucherType];
|
|
56
|
+
const res = await this.__afip.ElectronicBilling.getVoucherInfo(voucherNumber, pointOfSale, voucherTypeId);
|
|
57
|
+
if (!res)
|
|
58
|
+
return null;
|
|
59
|
+
return {
|
|
60
|
+
pointOfSale: res.PtoVta,
|
|
61
|
+
voucherTypeId: res.CbteTipo,
|
|
62
|
+
voucherFrom: res.CbteDesde,
|
|
63
|
+
voucherTo: res.CbteHasta,
|
|
64
|
+
voucherDate: res.CbteFch,
|
|
65
|
+
documentTypeId: res.DocTipo,
|
|
66
|
+
documentNumber: res.DocNro,
|
|
67
|
+
receiverVatConditionId: res.CondicionIVAReceptorId,
|
|
68
|
+
conceptId: res.Concepto,
|
|
69
|
+
totalAmount: res.ImpTotal,
|
|
70
|
+
nonTaxedAmount: res.ImpTotConc,
|
|
71
|
+
netAmount: res.ImpNeto,
|
|
72
|
+
exemptAmount: res.ImpOpEx,
|
|
73
|
+
tributeAmount: res.ImpTrib,
|
|
74
|
+
vatAmount: res.ImpIVA,
|
|
75
|
+
currencyId: res.MonId,
|
|
76
|
+
currencyRate: res.MonCotiz,
|
|
77
|
+
serviceFromDate: res.FchServDesde,
|
|
78
|
+
serviceToDate: res.FchServHasta,
|
|
79
|
+
paymentDueDate: res.FchVtoPago,
|
|
80
|
+
result: res.Resultado === 'A' ? 'approved' : 'rejected',
|
|
81
|
+
processDate: res.FchProceso,
|
|
82
|
+
authorizationType: res.EmisionTipo,
|
|
83
|
+
authorizationCode: res.CodAutorizacion,
|
|
84
|
+
authorizationExpirationDate: res.FchVto,
|
|
85
|
+
};
|
|
55
86
|
}
|
|
56
87
|
async createInvoiceC(options) {
|
|
57
88
|
const { pointOfSale, receiver, concept, amount, service } = options;
|
|
89
|
+
const voucherType = '11_invoice_c';
|
|
58
90
|
const isConceptProducts = concept === '1_products';
|
|
59
91
|
if (!isConceptProducts && !service)
|
|
60
92
|
throw new Error('Service dates are required');
|
|
61
|
-
const
|
|
62
|
-
const lastVoucherNumber = await this.getLastVoucher(pointOfSale, voucherTypeId);
|
|
63
|
-
console.log('lastVoucherNumber: ', lastVoucherNumber);
|
|
93
|
+
const lastVoucherNumber = await this.getLastVoucher(pointOfSale, voucherType);
|
|
64
94
|
const voucherNumber = lastVoucherNumber + 1;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
console.log('toISOString: ', localDate.toISOString());
|
|
95
|
+
const timezone = -3;
|
|
96
|
+
const localDate = new Date(Date.now() + timezone * 60 * 60000);
|
|
68
97
|
const voucherDate = Number(localDate.toISOString().split('T')[0].replace(/-/g, ''));
|
|
69
|
-
console.log('voucherDate: ', voucherDate);
|
|
70
98
|
const isFinalConsumer = receiver.documentType === '99_final_consumer';
|
|
71
99
|
const finalVatCondition = isFinalConsumer ? '5_final_consumer' : receiver.vatCondition;
|
|
72
|
-
const
|
|
73
|
-
CantReg: 1,
|
|
100
|
+
const params = {
|
|
74
101
|
PtoVta: pointOfSale,
|
|
75
|
-
CbteTipo:
|
|
76
|
-
|
|
77
|
-
DocTipo: documentTypeIds[receiver.documentType],
|
|
78
|
-
DocNro: isFinalConsumer ? 0 : receiver.documentNumber,
|
|
102
|
+
CbteTipo: voucherTypeIds[voucherType],
|
|
103
|
+
CantReg: 1,
|
|
79
104
|
CbteDesde: voucherNumber,
|
|
80
105
|
CbteHasta: voucherNumber,
|
|
81
106
|
CbteFch: voucherDate,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
DocTipo: documentTypeIds[receiver.documentType],
|
|
108
|
+
DocNro: isFinalConsumer ? 0 : receiver.documentNumber,
|
|
109
|
+
CondicionIVAReceptorId: vatConditionReceiverIds[finalVatCondition],
|
|
110
|
+
Concepto: conceptIds[concept],
|
|
85
111
|
ImpTotal: amount,
|
|
86
112
|
ImpTotConc: 0,
|
|
87
113
|
ImpNeto: amount,
|
|
@@ -90,10 +116,12 @@ class Arca {
|
|
|
90
116
|
ImpTrib: 0,
|
|
91
117
|
MonId: 'PES',
|
|
92
118
|
MonCotiz: 1,
|
|
93
|
-
|
|
119
|
+
FchServDesde: isConceptProducts ? null : Number(service.from.replace(/-/g, '')),
|
|
120
|
+
FchServHasta: isConceptProducts ? null : Number(service.to.replace(/-/g, '')),
|
|
121
|
+
FchVtoPago: isConceptProducts ? null : Number(service.paymentDueDate.replace(/-/g, '')),
|
|
94
122
|
};
|
|
95
|
-
const res = await this.__afip.ElectronicBilling.createVoucher(
|
|
96
|
-
return { cae: res.CAE, caeExpirationDate: res.CAEFchVto };
|
|
123
|
+
const res = await this.__afip.ElectronicBilling.createVoucher(params);
|
|
124
|
+
return { voucherNumber, cae: res.CAE, caeExpirationDate: res.CAEFchVto };
|
|
97
125
|
}
|
|
98
126
|
}
|
|
99
127
|
exports.Arca = Arca;
|