pangea-server 3.3.10 → 3.3.12

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.
@@ -38,38 +38,54 @@ class Arca {
38
38
  const { cuit, cert, key } = config;
39
39
  this.__afip = new afip_js_1.default({
40
40
  access_token: (0, helpers_1.getEnvStr)('AFIP_ACCESS_TOKEN'),
41
- ...(cuit === 20409378472 ? { cuit } : { cuit, cert, key, production: true }),
41
+ CUIT: cuit,
42
+ ...(cuit !== 20409378472 ? { cert, key, production: true } : {}),
42
43
  });
43
44
  }
44
45
  async createVoucher(createVoucherOptions) {
45
46
  const { pointOfSale, voucherType, concept, documentType, documentNumber, taxableAmount, exemptAmount, vatAmount, vatConditionReceiver, serviceFrom = null, serviceTo = null, paymentDueDate = null, } = createVoucherOptions;
46
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');
47
57
  const lastVoucher = await this.__afip.ElectronicBilling.getLastVoucher(pointOfSale, afipVoucherType);
58
+ let voucherDate = Number(new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().split('T')[0].replace(/-/g, ''));
59
+ if (lastVoucher !== 0) {
60
+ const lastVoucherInfo = await this.__afip.ElectronicBilling.getVoucherInfo(lastVoucher, pointOfSale, afipVoucherType);
61
+ if (lastVoucherInfo && Number(lastVoucherInfo.CbteFch) > voucherDate) {
62
+ voucherDate = Number(lastVoucherInfo.CbteFch);
63
+ }
64
+ }
48
65
  const voucherNumber = lastVoucher + 1;
49
- const voucherDate = Number(new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString().split('T')[0].replace(/-/g, ''));
50
66
  const data = {
51
67
  CantReg: 1,
52
68
  PtoVta: pointOfSale,
53
69
  CbteTipo: afipVoucherType,
54
70
  Concepto: conceptMap[concept],
55
- DocTipo: documentTypeMap[documentType],
56
- DocNro: documentNumber,
71
+ DocTipo: finalDocumentType,
72
+ DocNro: finalDocumentNumber,
57
73
  CbteDesde: voucherNumber,
58
74
  CbteHasta: voucherNumber,
59
75
  CbteFch: voucherDate,
60
- FchServDesde: serviceFrom,
61
- FchServHasta: serviceTo,
62
- FchVtoPago: paymentDueDate,
63
- ImpTotal: taxableAmount + vatAmount + exemptAmount,
76
+ FchServDesde: concept === 'products' ? null : serviceFrom,
77
+ FchServHasta: concept === 'products' ? null : serviceTo,
78
+ FchVtoPago: concept === 'products' ? null : paymentDueDate,
79
+ ImpTotal: finalTaxableAmount + finalVatAmount + exemptAmount,
64
80
  ImpTotConc: 0,
65
- ImpNeto: taxableAmount,
81
+ ImpNeto: finalTaxableAmount,
66
82
  ImpOpEx: exemptAmount,
67
- ImpIVA: vatAmount,
83
+ ImpIVA: finalVatAmount,
68
84
  ImpTrib: 0,
69
85
  MonId: 'PES',
70
86
  MonCotiz: 1,
71
87
  CondicionIVAReceptorId: vatConditionReceiverMap[vatConditionReceiver],
72
- Iva: vatAmount > 0 ? [{ Id: 5, BaseImp: taxableAmount, Importe: vatAmount }] : [],
88
+ Iva: finalIvaArray,
73
89
  };
74
90
  return this.__afip.ElectronicBilling.createVoucher(data);
75
91
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.10",
4
+ "version": "3.3.12",
5
5
  "files": [
6
6
  "dist"
7
7
  ],