facturas 0.12.1 → 0.12.3

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.
@@ -23,7 +23,7 @@ import {
23
23
  } from "./chunk-GX5ERXT6.mjs";
24
24
  import {
25
25
  createWsmtxcaService
26
- } from "./chunk-D5ZWXTCV.mjs";
26
+ } from "./chunk-ZPVXXSUC.mjs";
27
27
  import {
28
28
  ArcaConfigurationError,
29
29
  ArcaError,
@@ -1882,6 +1882,10 @@ function wsmtxcaRequest(data, number) {
1882
1882
  "Item totals must equal the voucher total excluding tributes"
1883
1883
  );
1884
1884
  }
1885
+ const tributes = data.taxes?.length ? data.taxes : void 0;
1886
+ if (tributes === void 0 && normalizeArcaAmountToMinorUnits(data.taxAmount, "taxes") !== 0n) {
1887
+ invalid("taxes", "Tribute amount requires tribute details");
1888
+ }
1885
1889
  return {
1886
1890
  comprobanteCAERequest: {
1887
1891
  codigoTipoComprobante: data.voucherType,
@@ -1897,7 +1901,7 @@ function wsmtxcaRequest(data, number) {
1897
1901
  importeSubtotal: Number(
1898
1902
  normalizeArcaAmountToMinorUnits(data.netAmount, "net") + normalizeArcaAmountToMinorUnits(data.nonTaxableAmount, "untaxed") + normalizeArcaAmountToMinorUnits(data.exemptAmount, "exempt")
1899
1903
  ) / 100,
1900
- importeOtrosTributos: data.taxAmount,
1904
+ ...tributes === void 0 ? {} : { importeOtrosTributos: data.taxAmount },
1901
1905
  importeTotal: data.totalAmount,
1902
1906
  codigoMoneda: data.currencyId,
1903
1907
  cotizacionMoneda: data.exchangeRate,
@@ -1928,14 +1932,16 @@ function wsmtxcaRequest(data, number) {
1928
1932
  porcentaje: b.percentage
1929
1933
  }))
1930
1934
  } : void 0,
1931
- arrayOtrosTributos: data.taxes?.length ? {
1932
- otroTributo: data.taxes.map((t) => ({
1933
- codigo: t.id,
1934
- descripcion: t.description,
1935
- baseImponible: t.baseAmount,
1936
- importe: t.amount
1937
- }))
1938
- } : void 0,
1935
+ ...tributes ? {
1936
+ arrayOtrosTributos: {
1937
+ otroTributo: tributes.map((t) => ({
1938
+ codigo: t.id,
1939
+ descripcion: t.description,
1940
+ baseImponible: t.baseAmount,
1941
+ importe: t.amount
1942
+ }))
1943
+ }
1944
+ } : {},
1939
1945
  arrayItems: { item: items },
1940
1946
  arraySubtotalesIVA: data.vatRates?.length ? {
1941
1947
  subtotalIVA: data.vatRates.map((v) => ({
@@ -3108,7 +3114,8 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3108
3114
  select ?? (() => wsfe),
3109
3115
  stored,
3110
3116
  readSettledRecord(recorded),
3111
- options
3117
+ options,
3118
+ (other) => storeCall(() => store.get(settledKey(environment, taxId, other)))
3112
3119
  );
3113
3120
  }
3114
3121
  return await settle(
@@ -3171,24 +3178,40 @@ function readSettledRecord(json) {
3171
3178
  );
3172
3179
  }
3173
3180
  }
3174
- async function settledOutcome(select, reservation, settled, options) {
3181
+ async function settledOutcome(select, reservation, settled, options, settledFor) {
3175
3182
  if (settled.kind === "conflict") {
3176
3183
  return settledConflict(settled, reservation);
3177
3184
  }
3178
3185
  const outcome = await consultReservation(select, reservation, options, true);
3179
- if (outcome.kind === "indeterminate" && outcome.lookup.kind === "not_found") {
3180
- return {
3181
- kind: "indeterminate",
3182
- attempted: {
3183
- salesPoint: reservation.salesPoint,
3184
- voucherType: reservation.voucherType,
3185
- number: settled.number
3186
- },
3187
- attempt: replayEvidence(reservation.service),
3188
- lookup: { kind: "superseded", by: settled.by }
3189
- };
3186
+ const empty = outcome.kind === "indeterminate" && outcome.lookup.kind === "not_found";
3187
+ if (!empty && (outcome.kind !== "conflict" || await successionDisputed(settled.by, settledFor))) {
3188
+ return outcome;
3190
3189
  }
3191
- return outcome;
3190
+ return {
3191
+ kind: "indeterminate",
3192
+ attempted: {
3193
+ salesPoint: reservation.salesPoint,
3194
+ voucherType: reservation.voucherType,
3195
+ number: settled.number
3196
+ },
3197
+ attempt: replayEvidence(reservation.service),
3198
+ lookup: { kind: "superseded", by: settled.by }
3199
+ };
3200
+ }
3201
+ async function successionDisputed(key, settledFor) {
3202
+ let next = key;
3203
+ for (let hop = 0; hop < 16; hop += 1) {
3204
+ const json = await settledFor(next);
3205
+ if (json === null) {
3206
+ return false;
3207
+ }
3208
+ const record = readSettledRecord(json);
3209
+ if (record.kind === "conflict") {
3210
+ return true;
3211
+ }
3212
+ next = record.by;
3213
+ }
3214
+ return true;
3192
3215
  }
3193
3216
  function settledConflict(settled, reservation) {
3194
3217
  return {
@@ -3769,7 +3792,16 @@ async function recoverOperation(select, key, inputOptions, context) {
3769
3792
  select,
3770
3793
  record,
3771
3794
  readSettledRecord(recorded),
3772
- options
3795
+ options,
3796
+ (other) => storeCall(
3797
+ () => store.get(
3798
+ settledKey(
3799
+ context.environment,
3800
+ context.taxId,
3801
+ other
3802
+ )
3803
+ )
3804
+ )
3773
3805
  );
3774
3806
  }
3775
3807
  return await recordConflict(
@@ -4246,4 +4278,4 @@ export {
4246
4278
  withLease,
4247
4279
  createFileStore
4248
4280
  };
4249
- //# sourceMappingURL=chunk-2PYF5JFG.mjs.map
4281
+ //# sourceMappingURL=chunk-G7BWMDFT.mjs.map