@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,7 +1,8 @@
1
1
  import { minorExponentForCurrency as e } from "../../../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
+ import { currencyDisplayFor as t } from "./currencyDisplay.js";
2
3
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/lineItems.js
3
- var t = 9e15;
4
- function n(e) {
4
+ var n = 9e15;
5
+ function r(e) {
5
6
  let t = new Intl.NumberFormat(e), n = t.formatToParts(12345.67);
6
7
  return {
7
8
  decimal: n.find((e) => e.type === "decimal")?.value ?? ".",
@@ -9,91 +10,92 @@ function n(e) {
9
10
  digits: Array.from({ length: 10 }, (e, n) => t.format(n))
10
11
  };
11
12
  }
12
- function r(e) {
13
+ function i(e) {
13
14
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14
15
  }
15
- function i(e) {
16
+ function a(e) {
16
17
  let t = e.replace(/[^0-9.]/g, ""), n = t.indexOf(".");
17
18
  return n !== -1 && (t = t.slice(0, n + 1) + t.slice(n + 1).replace(/\./g, ""), t = t.slice(0, n + 3)), t;
18
19
  }
19
- function a(e) {
20
+ function o(e) {
20
21
  return e === "" || e === "." ? 0 : Number(e) || 0;
21
22
  }
22
- var o = (e) => Math.round(e * 100) / 100;
23
- function s(t, n) {
23
+ var s = (e) => Math.round(e * 100) / 100;
24
+ function c(t, n) {
24
25
  let r = e(n);
25
26
  return new Intl.NumberFormat(void 0, {
26
27
  minimumFractionDigits: r,
27
28
  maximumFractionDigits: r
28
29
  }).format(t / 10 ** r);
29
30
  }
30
- function c(t, r, i = n()) {
31
- return Math.round(l(t, i) * 10 ** e(r));
31
+ function l(t, n, i = r()) {
32
+ return Math.round(u(t, i) * 10 ** e(n));
32
33
  }
33
- function l(e, t = n()) {
34
+ function u(e, t = r()) {
34
35
  if (e.trim() === "") return 0;
35
- let i = Array.from(e, (e) => {
36
+ let n = Array.from(e, (e) => {
36
37
  let n = t.digits.indexOf(e);
37
38
  return n === -1 ? e : String(n);
38
39
  }).join("");
39
- t.group && (i = i.replace(new RegExp(r(t.group), "g"), "")), i = i.replace(t.decimal, ".");
40
- let a = parseFloat(i);
40
+ t.group && (n = n.replace(new RegExp(i(t.group), "g"), "")), n = n.replace(t.decimal, ".");
41
+ let a = parseFloat(n);
41
42
  return Number.isNaN(a) ? 0 : a;
42
43
  }
43
- function u(t, r, i, a = n()) {
44
- let o = c(t, r, a) / 10 ** e(r);
45
- return s(Math.round(o * 10 ** e(i)), i);
44
+ function d(t, n, i, a = r()) {
45
+ let o = l(t, n, a) / 10 ** e(n);
46
+ return c(Math.round(o * 10 ** e(i)), i);
46
47
  }
47
- function d(e) {
48
- let t = i(e);
48
+ function f(e) {
49
+ let t = a(e);
49
50
  return t.length > 1 && t.startsWith("0") && t[1] !== "." && (t = t.replace(/^0+/, "") || "0"), t === "" || t === "." ? t : Number(t) > 100 ? "100" : t;
50
51
  }
51
- function f(e) {
52
+ function p(e) {
52
53
  return e.endsWith(".") ? e.slice(0, -1) : e;
53
54
  }
54
- function p(e) {
55
+ function m(e) {
55
56
  return Math.round((Number(e) || 0) * 100);
56
57
  }
57
- function m(e, t) {
58
- return t !== void 0 && p(e) === p(t);
58
+ function h(e, t) {
59
+ return t !== void 0 && m(e) === m(t);
59
60
  }
60
- function h(e, t, n) {
61
- return n && e.savedTaxRate !== void 0 && g(e.savedTaxStatus) ? e.savedTaxRate : t;
61
+ function g(e, t, n) {
62
+ return n && e.savedTaxRate !== void 0 && _(e.savedTaxStatus) ? e.savedTaxRate : t;
62
63
  }
63
- function g(e) {
64
+ function _(e) {
64
65
  return (e ?? "taxable") === "taxable";
65
66
  }
66
- function _(e) {
67
- let t = e.find((e) => g(e.tax_status))?.product.tax_rate?.value;
67
+ function v(e) {
68
+ let t = e.find((e) => _(e.tax_status))?.product.tax_rate?.value;
68
69
  return t === void 0 ? "" : String(t / 100);
69
70
  }
70
- function v(e) {
71
+ function y(e) {
71
72
  try {
72
73
  return new Intl.NumberFormat(void 0, {
73
74
  style: "currency",
74
- currency: e
75
+ currency: e,
76
+ currencyDisplay: t(e)
75
77
  }).formatToParts(0).find((e) => e.type === "currency")?.value ?? e;
76
78
  } catch {
77
79
  return e;
78
80
  }
79
81
  }
80
- function y() {
82
+ function b() {
81
83
  return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(16).slice(2)}`;
82
84
  }
83
- function b(e = "USD") {
85
+ function x(e = "USD") {
84
86
  return {
85
- id: y(),
87
+ id: b(),
86
88
  productId: "",
87
89
  name: "",
88
90
  quantity: "1",
89
- price: s(0, e),
91
+ price: c(0, e),
90
92
  measureUnitId: "",
91
93
  measureUnitName: "",
92
94
  productType: "product",
93
95
  taxable: !0
94
96
  };
95
97
  }
96
- function x({ id: e, name: t, quantity: n, price: r, measureUnitId: i, taxable: a }) {
98
+ function S({ id: e, name: t, quantity: n, price: r, measureUnitId: i, taxable: a }) {
97
99
  return {
98
100
  id: e,
99
101
  name: t,
@@ -103,13 +105,13 @@ function x({ id: e, name: t, quantity: n, price: r, measureUnitId: i, taxable: a
103
105
  taxable: a
104
106
  };
105
107
  }
106
- function S(e) {
108
+ function C(e) {
107
109
  return !e.name.trim();
108
110
  }
109
- function C(e, t) {
111
+ function w(e, t) {
110
112
  let n = 0;
111
113
  return e.map((e) => {
112
- if (S(e)) return e;
114
+ if (C(e)) return e;
113
115
  let r = t[n++]?.id;
114
116
  return r ? {
115
117
  ...e,
@@ -117,17 +119,17 @@ function C(e, t) {
117
119
  } : e;
118
120
  });
119
121
  }
120
- function w(e) {
121
- let t = e.filter((e) => !S(e));
122
+ function T(e) {
123
+ let t = e.filter((e) => !C(e));
122
124
  return t.length > 0 ? t : e.slice(0, 1);
123
125
  }
124
- function T({ product: e, currency: t, unitNamesById: n }) {
126
+ function E({ product: e, currency: t, unitNamesById: n }) {
125
127
  let r = e.measure_unit_id ?? "";
126
128
  return {
127
129
  productId: e.id,
128
130
  name: e.name,
129
131
  quantity: String(e.smallest_amount || 1),
130
- price: s(e.price?.value ?? 0, t),
132
+ price: c(e.price?.value ?? 0, t),
131
133
  productType: "product",
132
134
  ...r && n[r] ? {
133
135
  measureUnitId: r,
@@ -135,19 +137,19 @@ function T({ product: e, currency: t, unitNamesById: n }) {
135
137
  } : {}
136
138
  };
137
139
  }
138
- function E(e) {
140
+ function D(e) {
139
141
  return e.quantity === void 0 ? e : {
140
142
  ...e,
141
- quantity: i(e.quantity)
143
+ quantity: a(e.quantity)
142
144
  };
143
145
  }
144
- function D({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n() }) {
146
+ function O({ lineItem: e, field: t, rowCount: n, currency: i, separators: u = r() }) {
145
147
  if (t === "price") return {
146
148
  kind: "update",
147
- patch: { price: s(c(e.price, l, u), l) }
149
+ patch: { price: c(l(e.price, i, u), i) }
148
150
  };
149
- let d = o(a(i(e.quantity)));
150
- return d <= 0 ? r > 1 ? { kind: "remove" } : {
151
+ let d = s(o(a(e.quantity)));
152
+ return d <= 0 ? n > 1 ? { kind: "remove" } : {
151
153
  kind: "update",
152
154
  patch: { quantity: "1" }
153
155
  } : {
@@ -155,42 +157,42 @@ function D({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n(
155
157
  patch: { quantity: String(d) }
156
158
  };
157
159
  }
158
- function O({ lineItem: e, step: t, rowCount: n }) {
159
- if (S(e)) return;
160
- let r = o(Math.max(0, a(e.quantity)) + t);
160
+ function k({ lineItem: e, step: t, rowCount: n }) {
161
+ if (C(e)) return;
162
+ let r = s(Math.max(0, o(e.quantity)) + t);
161
163
  return r <= 0 && n > 1 ? { kind: "remove" } : {
162
164
  kind: "update",
163
165
  patch: { quantity: String(Math.max(n > 1 ? 0 : 1, r)) }
164
166
  };
165
167
  }
166
- function k(e) {
168
+ function A(e) {
167
169
  return Object.fromEntries(e.map((t) => {
168
- let n = !S(t), r = a(t.quantity);
170
+ let n = !C(t), r = o(t.quantity);
169
171
  return [t.id, {
170
172
  canDecreaseQuantity: n && (e.length > 1 || r > 1),
171
173
  canIncreaseQuantity: n
172
174
  }];
173
175
  }));
174
176
  }
175
- function A(e, t, n = !1) {
177
+ function j(e, t, n = !1) {
176
178
  return e.taxable ? {
177
179
  tax_status: "taxable",
178
- tax_rate_value: h(e, p(t), n)
180
+ tax_rate_value: g(e, m(t), n)
179
181
  } : {
180
182
  tax_status: e.savedTaxStatus === "exempt" ? "exempt" : "non_taxable",
181
183
  tax_rate_value: void 0
182
184
  };
183
185
  }
184
- function j({ lineItem: e, currency: t, taxRate: n, unitNamesById: r }) {
185
- let i = e.measureUnitId ? r[e.measureUnitId] : void 0, { tax_status: o, tax_rate_value: s } = A(e, n);
186
+ function M({ lineItem: e, currency: t, taxRate: n, unitNamesById: r }) {
187
+ let i = e.measureUnitId ? r[e.measureUnitId] : void 0, { tax_status: a, tax_rate_value: s } = j(e, n);
186
188
  return {
187
- quantity: a(e.quantity),
188
- tax_status: o,
189
+ quantity: o(e.quantity),
190
+ tax_status: a,
189
191
  product: {
190
192
  name: e.name,
191
193
  price: {
192
194
  currency: t,
193
- value: c(e.price, t)
195
+ value: l(e.price, t)
194
196
  },
195
197
  measure_unit: i ? { name: i } : void 0,
196
198
  type: "product"
@@ -198,52 +200,52 @@ function j({ lineItem: e, currency: t, taxRate: n, unitNamesById: r }) {
198
200
  tax_rate_value: s
199
201
  };
200
202
  }
201
- function M({ lineItem: e, currency: t, taxRate: n, keepSavedRate: r, unitNamesById: i }) {
202
- let o = e.measureUnitId && i[e.measureUnitId] || e.measureUnitName || void 0, { tax_status: s, tax_rate_value: l } = A(e, n, r);
203
+ function N({ lineItem: e, currency: t, taxRate: n, keepSavedRate: r, unitNamesById: i }) {
204
+ let a = e.measureUnitId && i[e.measureUnitId] || e.measureUnitName || void 0, { tax_status: s, tax_rate_value: c } = j(e, n, r);
203
205
  return {
204
- quantity: a(e.quantity),
206
+ quantity: o(e.quantity),
205
207
  tax_status: s,
206
208
  product: {
207
209
  name: e.name,
208
210
  type: e.productType,
209
- measure_unit: o ? { name: o } : void 0,
211
+ measure_unit: a ? { name: a } : void 0,
210
212
  price: {
211
213
  currency: t,
212
- value: c(e.price, t)
214
+ value: l(e.price, t)
213
215
  }
214
216
  },
215
- tax_rate_value: l,
217
+ tax_rate_value: c,
216
218
  discount: e.savedDiscount
217
219
  };
218
220
  }
219
- function N({ lineItem: e, currency: t, units: n }) {
221
+ function P({ lineItem: e, currency: t, units: n }) {
220
222
  let r = e.product.measure_unit;
221
223
  return {
222
224
  id: e.id,
223
225
  productId: e.product.id,
224
226
  name: e.product.name,
225
227
  quantity: String(e.quantity),
226
- price: s(e.product.price?.value ?? 0, t),
227
- measureUnitId: F(r?.id ?? "", r?.name ?? "", n),
228
+ price: c(e.product.price?.value ?? 0, t),
229
+ measureUnitId: I(r?.id ?? "", r?.name ?? "", n),
228
230
  measureUnitName: r?.name ?? "",
229
231
  productType: e.product.type ?? "product",
230
- taxable: g(e.tax_status),
232
+ taxable: _(e.tax_status),
231
233
  savedTaxStatus: e.tax_status,
232
234
  savedTaxRate: e.product.tax_rate?.value,
233
235
  savedDiscount: e.discount ?? void 0
234
236
  };
235
237
  }
236
- function P(e, t) {
238
+ function F(e, t) {
237
239
  if (!t) return;
238
240
  let n = t.toLowerCase();
239
241
  return e.find((e) => e.name.toLowerCase() === n);
240
242
  }
241
- function F(e, t, n) {
242
- return n?.length ? ((e ? n.find((t) => t.id === e) : void 0) ?? P(n, t))?.id ?? (t ? "" : e) : e;
243
+ function I(e, t, n) {
244
+ return n?.length ? ((e ? n.find((t) => t.id === e) : void 0) ?? F(n, t))?.id ?? (t ? "" : e) : e;
243
245
  }
244
- function I(e, t) {
246
+ function L(e, t) {
245
247
  let n = !1, r = e.map((e) => {
246
- let r = F(e.measureUnitId, e.measureUnitName, t);
248
+ let r = I(e.measureUnitId, e.measureUnitName, t);
247
249
  return r === e.measureUnitId ? e : (n = !0, {
248
250
  ...e,
249
251
  measureUnitId: r
@@ -251,19 +253,19 @@ function I(e, t) {
251
253
  });
252
254
  return n ? r : e;
253
255
  }
254
- function L(n) {
255
- return new Intl.NumberFormat().format(t / 10 ** e(n));
256
+ function R(t) {
257
+ return new Intl.NumberFormat().format(n / 10 ** e(t));
256
258
  }
257
- var R = .1;
258
- function z(e, { currency: t, messages: n, requireComplete: r = !1 }) {
259
+ var z = .1;
260
+ function B(e, { currency: t, messages: n, requireComplete: r = !1 }) {
259
261
  let i = {};
260
- for (let o of e) {
262
+ for (let a of e) {
261
263
  let e = {};
262
- r && S(o) && (e.name = n.lineItemNameRequired), r && a(o.quantity) < R && (e.quantity = n.lineItemQuantityRequired), o.name.length > 100 && (e.name = n.lineItemNameTooLong), c(o.price, t) > 9e15 && (e.price = n.lineItemPriceTooHigh.replace("{maxAmount}", L(t))), Object.keys(e).length > 0 && (i[o.id] = e);
264
+ r && C(a) && (e.name = n.lineItemNameRequired), r && o(a.quantity) < z && (e.quantity = n.lineItemQuantityRequired), a.name.length > 100 && (e.name = n.lineItemNameTooLong), l(a.price, t) > 9e15 && (e.price = n.lineItemPriceTooHigh.replace("{maxAmount}", R(t))), Object.keys(e).length > 0 && (i[a.id] = e);
263
265
  }
264
266
  return Object.keys(i).length > 0 ? i : void 0;
265
267
  }
266
- function B(e, t, n) {
268
+ function V(e, t, n) {
267
269
  let r = Object.values(e ?? {}), i = [
268
270
  n,
269
271
  t,
@@ -277,4 +279,4 @@ function B(e, t, n) {
277
279
  return i.length > 0 ? i : void 0;
278
280
  }
279
281
  //#endregion
280
- export { t as MAX_AMOUNT_MINOR_UNITS, k as buildLineItemControls, D as commitLineItemField, f as commitTaxRateInput, u as convertPriceInput, b as createLineItem, r as escapeRegex, s as formatPriceInput, v as getCurrencySymbol, n as getNumberSeparators, S as isBlankLineItem, g as isLineItemTaxable, m as keepsSavedTaxRates, T as lineItemFromProduct, h as lineItemTaxRateMinorUnits, j as lineItemToCreatePayload, M as lineItemToUpdatePayload, L as maxAmountLabel, l as parseLocaleDecimal, a as parseQuantity, c as priceInputToMinorUnits, C as reconcileLineItemIds, I as reconcileMeasureUnits, N as responseLineItemToFormValues, E as sanitizeLineItemPatch, i as sanitizeQuantityInput, d as sanitizeTaxRateInput, O as stepLineItemQuantity, w as stripBlankLineItems, B as summarizeLineItemErrors, _ as taxRateFromLineItems, p as taxRateToMinorUnits, x as toSheetLineItem, z as validateLineItems };
282
+ export { n as MAX_AMOUNT_MINOR_UNITS, A as buildLineItemControls, O as commitLineItemField, p as commitTaxRateInput, d as convertPriceInput, x as createLineItem, i as escapeRegex, c as formatPriceInput, y as getCurrencySymbol, r as getNumberSeparators, C as isBlankLineItem, _ as isLineItemTaxable, h as keepsSavedTaxRates, E as lineItemFromProduct, g as lineItemTaxRateMinorUnits, M as lineItemToCreatePayload, N as lineItemToUpdatePayload, R as maxAmountLabel, u as parseLocaleDecimal, o as parseQuantity, l as priceInputToMinorUnits, w as reconcileLineItemIds, L as reconcileMeasureUnits, P as responseLineItemToFormValues, D as sanitizeLineItemPatch, a as sanitizeQuantityInput, f as sanitizeTaxRateInput, k as stepLineItemQuantity, T as stripBlankLineItems, V as summarizeLineItemErrors, v as taxRateFromLineItems, m as taxRateToMinorUnits, S as toSheetLineItem, B as validateLineItems };
@@ -1,97 +1,98 @@
1
1
  import { minorExponentForCurrency as e } from "../../../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
2
  import "../../../../ui/dist/index20.js";
3
3
  import "../../../../ui/dist/index.js";
4
- import { isBlankLineItem as t, keepsSavedTaxRates as n, lineItemTaxRateMinorUnits as r, parseQuantity as i, priceInputToMinorUnits as a, taxRateToMinorUnits as o } from "./lineItems.js";
5
- import { formatPreviewDate as s, resolveIssueDate as c, termDueDate as l } from "./paymentTerms.js";
6
- import { bracketAmount as u } from "./totals.js";
7
- import { formatMoney as d } from "./helpers.js";
8
- import { differenceInCalendarDays as f, parseISO as p } from "date-fns";
4
+ import { currencyDisplayFor as t } from "./currencyDisplay.js";
5
+ import { isBlankLineItem as n, keepsSavedTaxRates as r, lineItemTaxRateMinorUnits as i, parseQuantity as a, priceInputToMinorUnits as o, taxRateToMinorUnits as s } from "./lineItems.js";
6
+ import { formatPreviewDate as c, resolveIssueDate as l, termDueDate as u } from "./paymentTerms.js";
7
+ import { bracketAmount as d } from "./totals.js";
8
+ import { formatMoney as f } from "./helpers.js";
9
+ import { differenceInCalendarDays as p, parseISO as m } from "date-fns";
9
10
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/preview.js
10
- var m = "US", h = 100;
11
- function g(e) {
12
- return (e ?? []).filter(({ status: e, direction: t }) => e === "active" && t === "receive");
13
- }
11
+ var h = "US", g = 100;
14
12
  function _(e) {
15
- return g(e).length > 0;
13
+ return (e ?? []).filter(({ status: e, direction: t }) => e === "active" && t === "receive");
16
14
  }
17
15
  function v(e) {
18
- return e?.invoice?.display_organization_bank_account ?? e?.display_organization_bank_account ?? !0;
16
+ return _(e).length > 0;
19
17
  }
20
18
  function y(e) {
19
+ return e?.invoice?.display_organization_bank_account ?? e?.display_organization_bank_account ?? !0;
20
+ }
21
+ function b(e) {
21
22
  try {
22
23
  return new Intl.DisplayNames(void 0, { type: "region" }).of(e) ?? e;
23
24
  } catch {
24
25
  return e;
25
26
  }
26
27
  }
27
- function b({ address: e, issuerCountry: t, formatCountry: n = y }) {
28
+ function x({ address: e, issuerCountry: t, formatCountry: n = b }) {
28
29
  if (!e) return [];
29
- let r = [e.city, e.state].filter(Boolean).join(", "), i = e.country === m && t === m;
30
+ let r = [e.city, e.state].filter(Boolean).join(", "), i = e.country === h && t === h;
30
31
  return [
31
32
  [e.line1, e.line2].filter(Boolean).join(" "),
32
33
  [r, e.postal_code].filter(Boolean).join(" "),
33
34
  e.country && !i ? n(e.country) : ""
34
35
  ].filter(Boolean);
35
36
  }
36
- var x = { kind: "pending" }, S = (e) => ({
37
+ var S = { kind: "pending" }, C = (e) => ({
37
38
  kind: "text",
38
39
  lines: e
39
40
  });
40
- function C(e, t) {
41
+ function w(e, t) {
41
42
  return e.previewNetDays.replace("{days}", String(t));
42
43
  }
43
- function w(e, t) {
44
+ function T(e, t) {
44
45
  let n = e.previewEarlyPaymentDays.replace("{days}", String(t.number_of_days));
45
- return t.discount ? `${n}, ${e.previewEarlyPaymentDiscount.replace("{rate}", String(t.discount / h))}` : n;
46
+ return t.discount ? `${n}, ${e.previewEarlyPaymentDiscount.replace("{rate}", String(t.discount / g))}` : n;
46
47
  }
47
- function T({ paymentTermsId: e, paymentTermsCustomDate: t, paymentTerms: n, issueDate: r, messages: i }) {
48
+ function E({ paymentTermsId: e, paymentTermsCustomDate: t, paymentTerms: n, issueDate: r, messages: i }) {
48
49
  let a = {
49
- dueDate: x,
50
- paymentTerms: x
50
+ dueDate: S,
51
+ paymentTerms: S
51
52
  };
52
53
  if (e === "custom") {
53
54
  if (!t) return a;
54
- let e = p(t), n = Math.max(0, f(e, r));
55
+ let e = m(t), n = Math.max(0, p(e, r));
55
56
  return {
56
- dueDate: S([s(e)]),
57
- paymentTerms: S([C(i, n)])
57
+ dueDate: C([c(e)]),
58
+ paymentTerms: C([w(i, n)])
58
59
  };
59
60
  }
60
61
  if (e === "receipt_due") return {
61
- dueDate: S([s(r)]),
62
- paymentTerms: S([i.previewDueOnReceipt])
62
+ dueDate: C([c(r)]),
63
+ paymentTerms: C([i.previewDueOnReceipt])
63
64
  };
64
65
  let o = n?.find((t) => t.id === e);
65
66
  if (!o) return a;
66
- let c = l(o, r), u = [
67
- o.term_1 && w(i, o.term_1),
68
- o.term_2 && w(i, o.term_2),
69
- o.term_final && C(i, o.term_final.number_of_days)
67
+ let s = u(o, r), l = [
68
+ o.term_1 && T(i, o.term_1),
69
+ o.term_2 && T(i, o.term_2),
70
+ o.term_final && w(i, o.term_final.number_of_days)
70
71
  ].filter((e) => !!e);
71
72
  return {
72
- dueDate: c ? S([s(c)]) : x,
73
- paymentTerms: u.length > 0 ? S(u) : x
73
+ dueDate: s ? C([c(s)]) : S,
74
+ paymentTerms: l.length > 0 ? C(l) : S
74
75
  };
75
76
  }
76
- function E(e, t) {
77
+ function D(e, t) {
77
78
  return t ? e.previewTaxId.replace("{taxId}", t) : void 0;
78
79
  }
79
- function D(e) {
80
+ function O(e) {
80
81
  return e.length > 0 ? e : void 0;
81
82
  }
82
- function O(e, t) {
83
+ function k(e, t) {
83
84
  return e ? {
84
85
  name: e.type === "organization" ? e.organization.legal_name : void 0,
85
- addressLines: D(b({
86
+ addressLines: O(x({
86
87
  address: e.address,
87
88
  issuerCountry: e.address?.country
88
89
  })),
89
- taxIdLine: E(t, e.tax_id),
90
+ taxIdLine: D(t, e.tax_id),
90
91
  email: e.email ?? void 0,
91
92
  phone: e.phone ?? void 0
92
93
  } : {};
93
94
  }
94
- function k(e) {
95
+ function A(e) {
95
96
  let t = "organization" in e ? e.organization : e.individual;
96
97
  return {
97
98
  name: "organization" in e ? e.organization.legal_name : [e.individual.first_name, e.individual.last_name].filter(Boolean).join(" "),
@@ -99,56 +100,57 @@ function k(e) {
99
100
  phone: t.phone
100
101
  };
101
102
  }
102
- function A({ counterpart: e, billingAddress: t, issuerCountry: n, messages: r }) {
103
+ function j({ counterpart: e, billingAddress: t, issuerCountry: n, messages: r }) {
103
104
  if (!e) return { kind: "pending" };
104
- let { name: i, email: a, phone: o } = k(e);
105
+ let { name: i, email: a, phone: o } = A(e);
105
106
  return i ? {
106
107
  kind: "party",
107
108
  name: i,
108
- addressLines: D(b({
109
+ addressLines: O(x({
109
110
  address: t,
110
111
  issuerCountry: n
111
112
  })),
112
- taxIdLine: E(r, e.tax_id),
113
+ taxIdLine: D(r, e.tax_id),
113
114
  email: a || void 0,
114
115
  phone: o || void 0
115
116
  } : { kind: "pending" };
116
117
  }
117
- function j({ lineItems: e, currency: n, unitNamesById: r, messages: o }) {
118
- return e.filter((e) => !t(e)).map((e) => {
119
- let t = a(e.price, n), s = i(e.quantity), c = r[e.measureUnitId] || e.measureUnitName;
118
+ function M({ lineItems: e, currency: t, unitNamesById: r, messages: i }) {
119
+ return e.filter((e) => !n(e)).map((e) => {
120
+ let n = o(e.price, t), s = a(e.quantity), c = r[e.measureUnitId] || e.measureUnitName;
120
121
  return {
121
122
  id: e.id,
122
123
  name: e.name,
123
124
  quantity: String(s),
124
- price: d({
125
- amount: t,
126
- currency: n,
125
+ price: f({
126
+ amount: n,
127
+ currency: t,
127
128
  fallback: ""
128
129
  }),
129
130
  ...c ? { unit: c } : {},
130
- taxable: e.taxable ? o.previewTaxableYes : o.previewTaxableNo,
131
- amount: d({
132
- amount: Math.round(t * s),
133
- currency: n,
131
+ taxable: e.taxable ? i.previewTaxableYes : i.previewTaxableNo,
132
+ amount: f({
133
+ amount: Math.round(n * s),
134
+ currency: t,
134
135
  fallback: ""
135
136
  })
136
137
  };
137
138
  });
138
139
  }
139
- function M(t, n) {
140
- return n ? u(new Intl.NumberFormat(void 0, {
140
+ function N(n, r) {
141
+ return r ? d(new Intl.NumberFormat(void 0, {
141
142
  style: "currency",
142
- currency: n
143
- }), t / 10 ** e(n)) : "";
143
+ currency: r,
144
+ currencyDisplay: t(r)
145
+ }), n / 10 ** e(r)) : "";
144
146
  }
145
- function N(e, i) {
146
- if (!e.taxRate) return i.previewTax;
147
- let a = o(e.taxRate), s = n(e.taxRate, e.savedTaxRate);
148
- return new Set(e.lineItems.filter((e) => e.taxable && !t(e)).map((e) => r(e, a, s))).size > 1 ? i.previewTax : i.previewTaxWithRate.replace("{rate}", String(a / h));
147
+ function P(e, t) {
148
+ if (!e.taxRate) return t.previewTax;
149
+ let a = s(e.taxRate), o = r(e.taxRate, e.savedTaxRate);
150
+ return new Set(e.lineItems.filter((e) => e.taxable && !n(e)).map((e) => i(e, a, o))).size > 1 ? t.previewTax : t.previewTaxWithRate.replace("{rate}", String(a / g));
149
151
  }
150
- function P({ totals: e, currency: t, taxLabel: n, messages: r }) {
151
- let i = (e) => d({
152
+ function F({ totals: e, currency: t, taxLabel: n, messages: r }) {
153
+ let i = (e) => f({
152
154
  amount: e,
153
155
  currency: t,
154
156
  fallback: ""
@@ -160,7 +162,7 @@ function P({ totals: e, currency: t, taxLabel: n, messages: r }) {
160
162
  return a && c.push({
161
163
  id: "discount",
162
164
  label: r.previewDiscount,
163
- value: M(e.discountAmount, t)
165
+ value: N(e.discountAmount, t)
164
166
  }), s && (o || a) && c.push({
165
167
  id: "nonTaxableSubtotal",
166
168
  label: r.previewNonTaxableSubtotal,
@@ -183,7 +185,7 @@ function P({ totals: e, currency: t, taxLabel: n, messages: r }) {
183
185
  }
184
186
  };
185
187
  }
186
- function F({ bankDetails: e, canReceivePayments: t, messages: n }) {
188
+ function I({ bankDetails: e, canReceivePayments: t, messages: n }) {
187
189
  let r = e ? [
188
190
  [n.previewAccountHolderName, e.accountHolderName],
189
191
  [n.previewRoutingNumber, e.routingNumber],
@@ -194,13 +196,13 @@ function F({ bankDetails: e, canReceivePayments: t, messages: n }) {
194
196
  bankLines: r
195
197
  };
196
198
  }
197
- function I({ values: e, totals: t, entity: n, counterpart: r, billingAddress: i, paymentTerms: a, unitNamesById: o, bankDetails: l, canReceivePayments: u = !1, messages: d, today: f = /* @__PURE__ */ new Date() }) {
198
- let p = j({
199
+ function L({ values: e, totals: t, entity: n, counterpart: r, billingAddress: i, paymentTerms: a, unitNamesById: o, bankDetails: s, canReceivePayments: u = !1, messages: d, today: f = /* @__PURE__ */ new Date() }) {
200
+ let p = M({
199
201
  lineItems: e.lineItems,
200
202
  currency: e.currency,
201
203
  unitNamesById: o,
202
204
  messages: d
203
- }), m = n?.logo?.url, h = O(n, d), g = c(e.issueDate, f);
205
+ }), m = n?.logo?.url, h = k(n, d), g = l(e.issueDate, f);
204
206
  return {
205
207
  issuer: h,
206
208
  logo: m ? {
@@ -208,15 +210,15 @@ function I({ values: e, totals: t, entity: n, counterpart: r, billingAddress: i,
208
210
  src: m,
209
211
  alt: h.name ? d.previewLogoAlt.replace("{name}", h.name) : d.previewLogoAltNoName
210
212
  } : { kind: "placeholder" },
211
- billTo: A({
213
+ billTo: j({
212
214
  counterpart: r,
213
215
  billingAddress: i,
214
216
  issuerCountry: n?.address?.country,
215
217
  messages: d
216
218
  }),
217
- invoiceNumber: x,
218
- issueDate: s(g),
219
- ...T({
219
+ invoiceNumber: S,
220
+ issueDate: c(g),
221
+ ...E({
220
222
  paymentTermsId: e.paymentTermsId,
221
223
  paymentTermsCustomDate: e.paymentTermsCustomDate,
222
224
  paymentTerms: a,
@@ -229,19 +231,19 @@ function I({ values: e, totals: t, entity: n, counterpart: r, billingAddress: i,
229
231
  kind: "rows",
230
232
  rows: p
231
233
  } : { kind: "empty" },
232
- totals: p.length > 0 ? P({
234
+ totals: p.length > 0 ? F({
233
235
  totals: t,
234
236
  currency: e.currency,
235
- taxLabel: N(e, d),
237
+ taxLabel: P(e, d),
236
238
  messages: d
237
239
  }) : void 0,
238
240
  closingNote: e.closingNote || void 0,
239
- payment: F({
240
- bankDetails: l,
241
+ payment: I({
242
+ bankDetails: s,
241
243
  canReceivePayments: u,
242
244
  messages: d
243
245
  })
244
246
  };
245
247
  }
246
248
  //#endregion
247
- export { b as buildPreviewAddressLines, T as buildPreviewPaymentTerms, I as buildReceivablePreviewView, v as displaysBankAccount, y as formatCountryName, M as formatDeduction, g as getReceivePaymentMethods, _ as hasReceivePaymentMethod };
249
+ export { x as buildPreviewAddressLines, E as buildPreviewPaymentTerms, L as buildReceivablePreviewView, y as displaysBankAccount, b as formatCountryName, N as formatDeduction, _ as getReceivePaymentMethods, v as hasReceivePaymentMethod };