pangea-server 3.3.125 → 3.3.126

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.
@@ -1,69 +1,10 @@
1
- type ArcaConfig = {
2
- cuit: number;
3
- cert: string;
4
- key: string;
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;
10
- type Concept = '1_products' | '2_services' | '3_products_and_services';
11
- type DocumentType = '80_cuit' | '86_cuil' | '96_dni' | '99_final_consumer';
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
- };
40
- type CreateInvoiceCOptions = {
41
- pointOfSale: number;
42
- receiver: {
43
- documentType: '99_final_consumer';
44
- } | {
45
- documentType: Exclude<DocumentType, '99_final_consumer'>;
46
- documentNumber: number;
47
- vatCondition: VatConditionReceiver;
48
- };
49
- concept: Concept;
50
- amount: number;
51
- service?: {
52
- from: string;
53
- to: string;
54
- paymentDueDate: string;
55
- };
56
- };
57
- type CreateVoucherRes = {
58
- voucherNumber: number;
59
- cae: string;
60
- caeExpirationDate: string;
61
- };
1
+ import type { ArcaConfig, ArcaVoucherType, ArcaVoucherInfo, ArcaCreateInvoiceCOptions, ArcaCreateVoucherRes } from '../types/arca.types';
62
2
  export declare class Arca {
3
+ private __cuit;
4
+ private __issuer;
63
5
  private __afip;
64
6
  constructor(config: ArcaConfig);
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>;
7
+ getLastVoucher(pointOfSale: number, voucherType: ArcaVoucherType): Promise<number>;
8
+ getVoucherInfo(voucherNumber: number, pointOfSale: number, voucherType: ArcaVoucherType): Promise<ArcaVoucherInfo | null>;
9
+ createInvoiceC(options: ArcaCreateInvoiceCOptions): Promise<ArcaCreateVoucherRes>;
68
10
  }
69
- export {};
@@ -38,9 +38,24 @@ const vatConditionReceiverIds = {
38
38
  '15_vat_not_applicable': 15,
39
39
  '16_promoted_independent_monotaxpayer': 16,
40
40
  };
41
+ const vatConditionReceiverDescriptions = {
42
+ '1_vat_registered': 'IVA Responsable Inscripto',
43
+ '4_vat_exempt': 'IVA Sujeto Exento',
44
+ '5_final_consumer': 'Consumidor Final',
45
+ '6_monotaxpayer': 'Responsable Monotributo',
46
+ '7_unclassified': 'Sujeto No Categorizado',
47
+ '8_foreign_supplier': 'Proveedor del Exterior',
48
+ '9_foreign_client': 'Cliente del Exterior',
49
+ '10_vat_exempt_law_19640': 'IVA Liberado – Ley N° 19.640',
50
+ '13_social_monotaxpayer': 'Monotributista Social',
51
+ '15_vat_not_applicable': 'IVA No Alcanzado',
52
+ '16_promoted_independent_monotaxpayer': 'Monotributo Trabajador Independiente Promovido',
53
+ };
41
54
  class Arca {
42
55
  constructor(config) {
43
- const { cuit, cert, key } = config;
56
+ const { cuit, cert, key, issuer } = config;
57
+ this.__cuit = cuit;
58
+ this.__issuer = issuer;
44
59
  this.__afip = new afip_js_1.default({
45
60
  access_token: (0, helpers_1.getEnvStr)('AFIP_ACCESS_TOKEN'),
46
61
  CUIT: cuit,
@@ -85,7 +100,7 @@ class Arca {
85
100
  };
86
101
  }
87
102
  async createInvoiceC(options) {
88
- const { pointOfSale, receiver, concept, amount, service } = options;
103
+ const { pointOfSale, receiver, concept, items, amount, service, pdf } = options;
89
104
  const voucherType = '11_invoice_c';
90
105
  const isConceptProducts = concept === '1_products';
91
106
  if (!isConceptProducts && !service)
@@ -95,8 +110,6 @@ class Arca {
95
110
  const timezone = -3;
96
111
  const localDate = new Date(Date.now() + timezone * 60 * 60000);
97
112
  const voucherDate = Number(localDate.toISOString().split('T')[0].replace(/-/g, ''));
98
- const isFinalConsumer = receiver.documentType === '99_final_consumer';
99
- const finalVatCondition = isFinalConsumer ? '5_final_consumer' : receiver.vatCondition;
100
113
  const params = {
101
114
  PtoVta: pointOfSale,
102
115
  CbteTipo: voucherTypeIds[voucherType],
@@ -105,8 +118,8 @@ class Arca {
105
118
  CbteHasta: voucherNumber,
106
119
  CbteFch: voucherDate,
107
120
  DocTipo: documentTypeIds[receiver.documentType],
108
- DocNro: isFinalConsumer ? 0 : receiver.documentNumber,
109
- CondicionIVAReceptorId: vatConditionReceiverIds[finalVatCondition],
121
+ DocNro: receiver.documentType === '99_final_consumer' ? 0 : receiver.documentNumber || 0,
122
+ CondicionIVAReceptorId: vatConditionReceiverIds[receiver.vatCondition || '5_final_consumer'],
110
123
  Concepto: conceptIds[concept],
111
124
  ImpTotal: amount,
112
125
  ImpTotConc: 0,
@@ -123,6 +136,71 @@ class Arca {
123
136
  try {
124
137
  const res = await this.__afip.ElectronicBilling.createVoucher(params);
125
138
  const finalRes = { voucherNumber, cae: res.CAE, caeExpirationDate: res.CAEFchVto };
139
+ try {
140
+ const day = String(localDate.getDate()).padStart(2, '0');
141
+ const month = String(localDate.getMonth() + 1).padStart(2, '0');
142
+ const year = localDate.getFullYear();
143
+ const issueDate = `${day}/${month}/${year}`;
144
+ const caeDueDate = `${res.CAEFchVto.slice(6, 8)}/${res.CAEFchVto.slice(4, 6)}/${res.CAEFchVto.slice(0, 4)}`;
145
+ const timestamp = localDate
146
+ .toISOString()
147
+ .replace(/[-:T.]/g, '')
148
+ .slice(0, 14);
149
+ const clientName = receiver.name?.replace(/\s+/g, '_').toLowerCase() || 'consumidor_final';
150
+ const fileName = `${timestamp}_${clientName}.pdf`;
151
+ const pdfData = {
152
+ file_name: fileName,
153
+ send_to: pdf?.sendTo,
154
+ template: {
155
+ name: 'invoice-c',
156
+ params: {
157
+ voucher_number: voucherNumber,
158
+ sales_point: pointOfSale,
159
+ issue_date: issueDate,
160
+ cae_due_date: caeDueDate,
161
+ issuer_cuit: this.__cuit,
162
+ cae: res.CAE,
163
+ issuer_business_name: this.__issuer.businessName,
164
+ issuer_address: this.__issuer.address,
165
+ issuer_iva_condition: this.__issuer.ivaCondition,
166
+ issuer_gross_income: this.__issuer.grossIncome,
167
+ issuer_activity_start_date: this.__issuer.activityStartDate,
168
+ receiver_name: receiver.name || 'CONSUMIDOR FINAL',
169
+ receiver_address: receiver.address || '-',
170
+ receiver_document_type: documentTypeIds[receiver.documentType],
171
+ receiver_document_number: receiver.documentType === '99_final_consumer' ? 0 : receiver.documentNumber || 0,
172
+ receiver_iva_condition: vatConditionReceiverDescriptions[receiver.vatCondition || '5_final_consumer'],
173
+ sale_condition: 'Contado',
174
+ currency_id: 'ARS',
175
+ currency_rate: 1,
176
+ concept: conceptIds[concept],
177
+ items: items.map((item) => ({
178
+ code: item.code,
179
+ description: item.description,
180
+ quantity: item.quantity,
181
+ unit_price: item.unitPrice,
182
+ subtotal: item.quantity * item.unitPrice,
183
+ })),
184
+ vat_amount: 0,
185
+ tributes_amount: 0,
186
+ total_amount: amount,
187
+ billing_from: isConceptProducts ? '' : service.from.split('-').reverse().join('/'),
188
+ billing_to: isConceptProducts ? '' : service.to.split('-').reverse().join('/'),
189
+ payment_due_date: isConceptProducts ? '' : service.paymentDueDate.split('-').reverse().join('/'),
190
+ net_amount_taxed: amount,
191
+ net_amount_untaxed: 0,
192
+ exempt_amount: 0,
193
+ invoice_footer_note: pdf?.footerNote,
194
+ },
195
+ },
196
+ };
197
+ const pdfRes = await this.__afip.ElectronicBilling.createPDF(pdfData);
198
+ finalRes.file = pdfRes.file;
199
+ }
200
+ catch (pdfErr) {
201
+ (0, helpers_1.printDanger)('arca', 'Error creating PDF (voucher was created)');
202
+ console.log(pdfErr);
203
+ }
126
204
  (0, helpers_1.printSuccess)('arca', 'Voucher created successfully');
127
205
  console.log('params:');
128
206
  console.log(params);
@@ -0,0 +1,80 @@
1
+ export type ArcaIssuer = {
2
+ businessName: string;
3
+ address: string;
4
+ ivaCondition: string;
5
+ grossIncome: string;
6
+ activityStartDate: string;
7
+ };
8
+ export type ArcaConfig = {
9
+ cuit: number;
10
+ cert: string;
11
+ key: string;
12
+ issuer: ArcaIssuer;
13
+ };
14
+ export type ArcaVoucherTypeA = '1_invoice_a' | '2_debit_note_a' | '3_credit_note_a';
15
+ export type ArcaVoucherTypeB = '6_invoice_b' | '7_debit_note_b' | '8_credit_note_b';
16
+ export type ArcaVoucherTypeC = '11_invoice_c' | '12_debit_note_c' | '13_credit_note_c';
17
+ export type ArcaVoucherType = ArcaVoucherTypeA | ArcaVoucherTypeB | ArcaVoucherTypeC;
18
+ export type ArcaConcept = '1_products' | '2_services' | '3_products_and_services';
19
+ export type ArcaDocumentType = '80_cuit' | '86_cuil' | '96_dni' | '99_final_consumer';
20
+ export type ArcaVatConditionReceiver = '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';
21
+ export type ArcaVoucherInfo = {
22
+ pointOfSale: number;
23
+ voucherTypeId: number;
24
+ voucherFrom: number;
25
+ voucherTo: number;
26
+ voucherDate: string;
27
+ documentTypeId: number;
28
+ documentNumber: number;
29
+ receiverVatConditionId: number;
30
+ conceptId: number;
31
+ totalAmount: number;
32
+ nonTaxedAmount: number;
33
+ netAmount: number;
34
+ exemptAmount: number;
35
+ tributeAmount: number;
36
+ vatAmount: number;
37
+ currencyId: string;
38
+ currencyRate: number;
39
+ serviceFromDate: string | null;
40
+ serviceToDate: string | null;
41
+ paymentDueDate: string | null;
42
+ result: 'approved' | 'rejected';
43
+ processDate: string;
44
+ authorizationType: 'CAE';
45
+ authorizationCode: string;
46
+ authorizationExpirationDate: string;
47
+ };
48
+ export type ArcaCreateInvoiceCOptions = {
49
+ pointOfSale: number;
50
+ receiver: {
51
+ documentType: ArcaDocumentType;
52
+ documentNumber?: number;
53
+ vatCondition?: ArcaVatConditionReceiver;
54
+ name?: string;
55
+ address?: string;
56
+ };
57
+ concept: ArcaConcept;
58
+ items: {
59
+ code: string;
60
+ description: string;
61
+ quantity: number;
62
+ unitPrice: number;
63
+ }[];
64
+ amount: number;
65
+ service?: {
66
+ from: string;
67
+ to: string;
68
+ paymentDueDate: string;
69
+ };
70
+ pdf?: {
71
+ sendTo?: string;
72
+ footerNote?: string;
73
+ };
74
+ };
75
+ export type ArcaCreateVoucherRes = {
76
+ voucherNumber: number;
77
+ cae: string;
78
+ caeExpirationDate: string;
79
+ file?: string;
80
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
+ import './arca.types';
1
2
  import './global.types';
@@ -1,3 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./arca.types");
3
4
  require("./global.types");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.125",
4
+ "version": "3.3.126",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "homepage": "https://github.com/GianfrancoRaselli/pangea-server#readme",
34
34
  "dependencies": {
35
- "@afipsdk/afip.js": "1.2.2",
35
+ "@afipsdk/afip.js": "1.2.3",
36
36
  "@google/genai": "1.34.0",
37
37
  "aws-sdk": "2.1692.0",
38
38
  "bcrypt": "5.1.1",