pangea-server 3.3.13 → 3.3.14

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,31 +3,35 @@ type ArcaConfig = {
3
3
  cert: string;
4
4
  key: string;
5
5
  };
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
6
  type Concept = 'products' | 'services' | 'products_and_services';
8
7
  type DocumentType = 'cuit' | 'cuil' | 'dni' | 'final_consumer';
9
8
  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
- type CreateVoucherOptions = {
9
+ type CreateInvoiceCOptions = {
11
10
  pointOfSale: number;
12
- voucherType: VoucherType;
11
+ receiver: {
12
+ documentType: 'final_consumer';
13
+ } | {
14
+ documentType: Exclude<DocumentType, 'final_consumer'>;
15
+ documentNumber: number;
16
+ vatCondition: VatConditionReceiver;
17
+ };
13
18
  concept: Concept;
14
- documentType: DocumentType;
15
- documentNumber: number;
16
- taxableAmount: number;
17
- exemptAmount: number;
18
- vatAmount: number;
19
- vatConditionReceiver: VatConditionReceiver;
20
- serviceFrom?: number | null;
21
- serviceTo?: number | null;
22
- paymentDueDate?: number | null;
19
+ amount: number;
20
+ service?: {
21
+ from: string;
22
+ to: string;
23
+ paymentDueDate: string;
24
+ };
23
25
  };
24
- type CreateVoucherRes = {
26
+ type CreateVoucherCRes = {
25
27
  cae: string;
26
28
  caeExpirationDate: string;
27
29
  };
28
30
  export declare class Arca {
29
31
  private __afip;
30
32
  constructor(config: ArcaConfig);
31
- createVoucher(createVoucherOptions: CreateVoucherOptions): Promise<CreateVoucherRes>;
33
+ getLastVoucher(pointOfSale: number, voucherTypeId: number): Promise<number>;
34
+ getVoucherInfo(lastVoucherNumber: number, pointOfSale: number, voucherTypeId: number): Promise<any>;
35
+ createInvoiceC(options: CreateInvoiceCOptions): Promise<CreateVoucherCRes>;
32
36
  }
33
37
  export {};
@@ -7,7 +7,7 @@ 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 = {
10
+ const voucherTypeIds = {
11
11
  invoice_a: 1,
12
12
  invoice_b: 6,
13
13
  invoice_c: 11,
@@ -18,9 +18,9 @@ const voucherTypeMap = {
18
18
  credit_note_b: 8,
19
19
  credit_note_c: 13,
20
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 = {
21
+ const conceptIds = { products: 1, services: 2, products_and_services: 3 };
22
+ const documentTypeIds = { cuit: 80, cuil: 86, dni: 96, final_consumer: 99 };
23
+ const vatConditionReceiverIds = {
24
24
  vat_registered: 1,
25
25
  vat_exempt: 4,
26
26
  final_consumer: 5,
@@ -42,51 +42,48 @@ class Arca {
42
42
  ...(cuit !== 20409378472 ? { cert, key, production: true } : {}),
43
43
  });
44
44
  }
45
- async createVoucher(createVoucherOptions) {
46
- const { pointOfSale, voucherType, concept, documentType, documentNumber, taxableAmount, exemptAmount, vatAmount, vatConditionReceiver, serviceFrom = null, serviceTo = null, paymentDueDate = null, } = createVoucherOptions;
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)) {
45
+ getLastVoucher(pointOfSale, voucherTypeId) {
46
+ return this.__afip.ElectronicBilling.getLastVoucher(pointOfSale, voucherTypeId);
47
+ }
48
+ getVoucherInfo(lastVoucherNumber, pointOfSale, voucherTypeId) {
49
+ return this.__afip.ElectronicBilling.getVoucherInfo(lastVoucherNumber, pointOfSale, voucherTypeId);
50
+ }
51
+ async createInvoiceC(options) {
52
+ const { pointOfSale, receiver, concept, amount, service } = options;
53
+ if (concept !== 'products' && !service)
56
54
  throw new Error('Service dates are required');
57
- }
58
- const lastVoucher = await this.__afip.ElectronicBilling.getLastVoucher(pointOfSale, afipVoucherType);
59
- let voucherDate = Number(new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().split('T')[0].replace(/-/g, ''));
60
- if (lastVoucher !== 0) {
61
- const lastVoucherInfo = await this.__afip.ElectronicBilling.getVoucherInfo(lastVoucher, pointOfSale, afipVoucherType);
62
- if (lastVoucherInfo && Number(lastVoucherInfo.CbteFch) > voucherDate) {
63
- voucherDate = Number(lastVoucherInfo.CbteFch);
64
- }
65
- }
66
- const voucherNumber = lastVoucher + 1;
55
+ const voucherTypeId = voucherTypeIds['invoice_c'];
56
+ const lastVoucherNumber = await this.getLastVoucher(pointOfSale, voucherTypeId);
57
+ console.log('lastVoucherNumber: ', lastVoucherNumber);
58
+ const voucherNumber = lastVoucherNumber + 1;
59
+ const localDate = new Date(Date.now() - new Date().getTimezoneOffset() * 60000);
60
+ console.log('localDate: ', localDate);
61
+ console.log('toISOString: ', localDate.toISOString());
62
+ const voucherDate = Number(localDate.toISOString().split('T')[0].replace(/-/g, ''));
63
+ console.log('voucherDate: ', voucherDate);
64
+ const finalVatCondition = receiver.documentType === 'final_consumer' ? 'final_consumer' : receiver.vatCondition;
67
65
  const data = {
68
66
  CantReg: 1,
69
67
  PtoVta: pointOfSale,
70
- CbteTipo: afipVoucherType,
71
- Concepto: conceptMap[concept],
72
- DocTipo: finalDocumentType,
73
- DocNro: finalDocumentNumber,
68
+ CbteTipo: voucherTypeId,
69
+ Concepto: conceptIds[concept],
70
+ DocTipo: documentTypeIds[receiver.documentType],
71
+ DocNro: receiver.documentType === 'final_consumer' ? 0 : receiver.documentNumber,
74
72
  CbteDesde: voucherNumber,
75
73
  CbteHasta: voucherNumber,
76
74
  CbteFch: voucherDate,
77
- FchServDesde: concept === 'products' ? null : serviceFrom,
78
- FchServHasta: concept === 'products' ? null : serviceTo,
79
- FchVtoPago: concept === 'products' ? null : paymentDueDate,
80
- ImpTotal: finalTaxableAmount + finalVatAmount + exemptAmount,
75
+ FchServDesde: concept === 'products' ? null : Number(service.from.replace(/-/g, '')),
76
+ FchServHasta: concept === 'products' ? null : Number(service.to.replace(/-/g, '')),
77
+ FchVtoPago: concept === 'products' ? null : Number(service.paymentDueDate.replace(/-/g, '')),
78
+ ImpTotal: amount,
81
79
  ImpTotConc: 0,
82
- ImpNeto: finalTaxableAmount,
83
- ImpOpEx: exemptAmount,
84
- ImpIVA: finalVatAmount,
80
+ ImpNeto: amount,
81
+ ImpOpEx: 0,
82
+ ImpIVA: 0,
85
83
  ImpTrib: 0,
86
84
  MonId: 'PES',
87
85
  MonCotiz: 1,
88
- CondicionIVAReceptorId: vatConditionReceiverMap[vatConditionReceiver],
89
- Iva: finalIvaArray,
86
+ CondicionIVAReceptorId: vatConditionReceiverIds[finalVatCondition],
90
87
  };
91
88
  const res = await this.__afip.ElectronicBilling.createVoucher(data);
92
89
  return { cae: res.CAE, caeExpirationDate: res.CAEFchVto };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.13",
4
+ "version": "3.3.14",
5
5
  "files": [
6
6
  "dist"
7
7
  ],