@tesouro/embedded-components-react 0.7.63 → 0.7.66

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,15 +1,16 @@
1
1
  import { minorExponentForCurrency as e } from "../../../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
- import { isBlankLineItem as t, keepsSavedTaxRates as n, lineItemTaxRateMinorUnits as r, maxAmountLabel as i, parseQuantity as a, priceInputToMinorUnits as o } from "./lineItems.js";
3
- import { discountFromDraft as s } from "./discount.js";
2
+ import { currencyDisplayFor as t } from "./currencyDisplay.js";
3
+ import { isBlankLineItem as n, keepsSavedTaxRates as r, lineItemTaxRateMinorUnits as i, maxAmountLabel as a, parseQuantity as o, priceInputToMinorUnits as s } from "./lineItems.js";
4
+ import { discountFromDraft as c } from "./discount.js";
4
5
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/totals.js
5
- var c = 1e4;
6
- function l(e, t) {
7
- return Math.round(o(e.price, t) * a(e.quantity));
6
+ var l = 1e4;
7
+ function u(e, t) {
8
+ return Math.round(s(e.price, t) * o(e.quantity));
8
9
  }
9
- function u({ lineItems: e, currency: t, taxRate: n }) {
10
+ function d({ lineItems: e, currency: t, taxRate: n }) {
10
11
  let r = n ? Math.round(n * 100) : 0, i = 0, a = 0;
11
12
  for (let n of e) {
12
- let e = l(n, t);
13
+ let e = u(n, t);
13
14
  n.taxable ? i += e : a += e;
14
15
  }
15
16
  return {
@@ -19,84 +20,84 @@ function u({ lineItems: e, currency: t, taxRate: n }) {
19
20
  rateMinorUnits: r
20
21
  };
21
22
  }
22
- function d({ discount: e, subtotal: t }) {
23
+ function f({ discount: e, subtotal: t }) {
23
24
  if (!e) return 0;
24
25
  let n = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / 1e4));
25
26
  return Math.min(Math.max(n, 0), t);
26
27
  }
27
- function f({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
+ function p({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
29
  let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
29
30
  return {
30
31
  taxableSubtotal: e - i,
31
32
  nonTaxableSubtotal: t - (n - i)
32
33
  };
33
34
  }
34
- function p({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: i, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
+ function m({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: r, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
36
  if (a <= 0) return 0;
36
37
  let s = /* @__PURE__ */ new Map();
37
38
  for (let a of e) {
38
39
  if (!a.taxable) continue;
39
- let e = r(a, n, i);
40
- s.set(e, (s.get(e) ?? 0) + l(a, t));
40
+ let e = i(a, n, r);
41
+ s.set(e, (s.get(e) ?? 0) + u(a, t));
41
42
  }
42
- let u = [...s], d = o, f = 0;
43
- return u.forEach(([e, t], n) => {
44
- let r = n === u.length - 1 ? d : Math.round(o * t / a);
43
+ let c = [...s], d = o, f = 0;
44
+ return c.forEach(([e, t], n) => {
45
+ let r = n === c.length - 1 ? d : Math.round(o * t / a);
45
46
  d -= r, f += r * e;
46
- }), Math.round(f / c);
47
+ }), Math.round(f / l);
47
48
  }
48
- function m({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
49
- let a = u({
49
+ function h({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
50
+ let a = d({
50
51
  lineItems: e,
51
52
  currency: t,
52
53
  taxRate: n
53
- }), o = d({
54
+ }), o = f({
54
55
  discount: i,
55
56
  subtotal: a.subtotal
56
- }), { taxableSubtotal: s, nonTaxableSubtotal: c } = f({
57
+ }), { taxableSubtotal: s, nonTaxableSubtotal: c } = p({
57
58
  ...a,
58
59
  discountAmount: o
59
- }), l = p({
60
+ }), l = m({
60
61
  lineItems: e,
61
62
  currency: t,
62
63
  rateMinorUnits: a.rateMinorUnits,
63
64
  keepSavedRate: r,
64
65
  taxableItemsSubtotal: a.taxableItemsSubtotal,
65
66
  taxableSubtotal: s
66
- }), m = a.subtotal - o;
67
+ }), u = a.subtotal - o;
67
68
  return {
68
69
  ...a,
69
70
  discountAmount: o,
70
- discountedSubtotal: m,
71
+ discountedSubtotal: u,
71
72
  taxableSubtotal: s,
72
73
  nonTaxableSubtotal: c,
73
74
  totalTaxes: l,
74
- total: m + l
75
+ total: u + l
75
76
  };
76
77
  }
77
- function h(e) {
78
- return m({
79
- lineItems: e.lineItems.filter((e) => !t(e)),
78
+ function g(e) {
79
+ return h({
80
+ lineItems: e.lineItems.filter((e) => !n(e)),
80
81
  currency: e.currency,
81
82
  taxRate: Number(e.taxRate) || void 0,
82
- keepSavedRate: n(e.taxRate, e.savedTaxRate),
83
- discount: s(e)
83
+ keepSavedRate: r(e.taxRate, e.savedTaxRate),
84
+ discount: c(e)
84
85
  });
85
86
  }
86
- function g(e, t) {
87
- let n = s(e);
88
- if (n) return n.type === "percentage" ? n.amount > 1e4 ? t.discountPercentageTooHigh : void 0 : n.amount > h(e).subtotal ? t.discountExceedsSubtotal : void 0;
89
- }
90
- function _(e, n) {
91
- if (e.lineItems.filter((e) => !t(e)).some((t) => o(t.price, e.currency) > 9e15)) return;
92
- let { subtotal: r, total: a } = h(e), s = i(e.currency);
93
- if (r > 9e15) return n.invoiceSubtotalTooHigh.replace("{maxAmount}", s);
94
- if (a > 9e15) return n.invoiceTotalTooHigh.replace("{maxAmount}", s);
87
+ function _(e, t) {
88
+ let n = c(e);
89
+ if (n) return n.type === "percentage" ? n.amount > 1e4 ? t.discountPercentageTooHigh : void 0 : n.amount > g(e).subtotal ? t.discountExceedsSubtotal : void 0;
95
90
  }
96
91
  function v(e, t) {
97
- return h(e).total > 0 ? void 0 : t.invoiceTotalZero;
92
+ if (e.lineItems.filter((e) => !n(e)).some((t) => s(t.price, e.currency) > 9e15)) return;
93
+ let { subtotal: r, total: i } = g(e), o = a(e.currency);
94
+ if (r > 9e15) return t.invoiceSubtotalTooHigh.replace("{maxAmount}", o);
95
+ if (i > 9e15) return t.invoiceTotalTooHigh.replace("{maxAmount}", o);
98
96
  }
99
97
  function y(e, t) {
98
+ return g(e).total > 0 ? void 0 : t.invoiceTotalZero;
99
+ }
100
+ function b(e, t) {
100
101
  let n = e.formatToParts(t), r = (e) => e.type !== "currency" && e.type !== "literal", i = n.findIndex(r);
101
102
  if (i === -1) return e.format(t);
102
103
  let a = n.length - 1;
@@ -104,23 +105,23 @@ function y(e, t) {
104
105
  let o = (e) => e.map((e) => e.value).join("");
105
106
  return `${o(n.slice(0, i))}(${o(n.slice(i, a + 1))})${o(n.slice(a + 1))}`;
106
107
  }
107
- function b(t, n, r = !1) {
108
- let i = new Intl.NumberFormat(void 0, {
108
+ function x(n, r, i = !1) {
109
+ let a = new Intl.NumberFormat(void 0, {
109
110
  style: "currency",
110
- currency: n,
111
- currencyDisplay: "narrowSymbol"
112
- }), a = t / 10 ** e(n);
113
- return r ? y(i, a) : i.format(a);
111
+ currency: r,
112
+ currencyDisplay: t(r)
113
+ }), o = n / 10 ** e(r);
114
+ return i ? b(a, o) : a.format(o);
114
115
  }
115
- function x(e, t) {
116
+ function S(e, t) {
116
117
  return {
117
- subtotal: b(e.subtotal, t),
118
- discount: e.discountAmount > 0 ? b(e.discountAmount, t, !0) : b(0, t),
119
- nonTaxableSubtotal: b(e.nonTaxableSubtotal, t),
120
- taxableSubtotal: b(e.taxableSubtotal, t),
121
- tax: b(e.totalTaxes, t),
122
- total: b(e.total, t)
118
+ subtotal: x(e.subtotal, t),
119
+ discount: e.discountAmount > 0 ? x(e.discountAmount, t, !0) : x(0, t),
120
+ nonTaxableSubtotal: x(e.nonTaxableSubtotal, t),
121
+ taxableSubtotal: x(e.taxableSubtotal, t),
122
+ tax: x(e.totalTaxes, t),
123
+ total: x(e.total, t)
123
124
  };
124
125
  }
125
126
  //#endregion
126
- export { c as FULL_PERCENT_MINOR_UNITS, f as allocateDiscount, y as bracketAmount, x as buildFormTotalsView, h as calculateFormTotals, m as calculateInvoiceTotals, u as calculateItemsSubtotals, d as resolveDiscountAmount, g as validateDiscount, _ as validateInvoiceTotals, v as validateIssuableTotal };
127
+ export { l as FULL_PERCENT_MINOR_UNITS, p as allocateDiscount, b as bracketAmount, S as buildFormTotalsView, g as calculateFormTotals, h as calculateInvoiceTotals, d as calculateItemsSubtotals, f as resolveDiscountAmount, _ as validateDiscount, v as validateInvoiceTotals, y as validateIssuableTotal };
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.7.63", n = "e47f3b4535cfeb468100c0b2f912924768c6b15f", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.7.66", n = "6104c73d61228502ff326ac8761a846765fe16ee", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-react",
3
- "version": "0.7.63",
3
+ "version": "0.7.66",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": [