@tesouro/embedded-components-react 0.5.228 → 0.5.230

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.
Files changed (85) hide show
  1. package/README.md +22 -21
  2. package/dist/index.d.ts +34 -1
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +34 -1
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +1 -1
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index11.js +1 -1
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index5.js +32 -33
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index6.js +34 -32
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index7.js +1 -1
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +120 -52
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +44 -100
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +93 -337
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +356 -211
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +225 -157
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +152 -21
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +18 -221
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +224 -56
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +126 -231
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +53 -298
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +232 -43
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +295 -118
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +38 -145
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +126 -46
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +145 -117
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +38 -91
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +113 -107
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index27.js +94 -27
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index28.js +104 -619
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index29.js +34 -41
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index30.js +635 -34
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index31.js +39 -77
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index32.js +34 -117
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index33.js +75 -318
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index34.js +139 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index35.js +340 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +55 -468
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +443 -97
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +24 -21
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +32 -2
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +205 -84
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +161 -3
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +12 -20
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +23 -40
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +2 -17
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +90 -68
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +3 -20
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +20 -12
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +40 -30
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +14 -7
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +15 -301
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +73 -1
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +17 -45
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +12 -68
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +26 -490
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +294 -95
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +1 -0
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +48 -2
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +72 -4
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index29.js +496 -1
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +121 -27
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index30.js +97 -91
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +2 -236
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +3 -2
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index34.js +1 -249
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index35.js +89 -82
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index36.js +23 -54
  70. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index37.js +223 -340
  71. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index38.js +3 -0
  72. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index39.js +249 -0
  73. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +100 -216
  74. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index40.js +93 -0
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index41.js +59 -0
  76. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index42.js +353 -0
  77. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +35 -29
  78. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +2 -216
  79. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +9 -159
  80. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +27 -14
  81. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +216 -23
  82. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  83. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/index.js +12 -12
  84. package/package.json +1 -1
  85. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index31.js +0 -28
@@ -1,115 +1,59 @@
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 "./index6.js";
3
- import { discountFromDraft as s } from "./index10.js";
2
+ import { escapeRegex as t, getNumberSeparators as n, parseLocaleDecimal as r } from "./index6.js";
4
3
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
5
- var c = 1e4;
6
- function l(e, t) {
7
- return Math.round(o(e.price, t) * a(e.quantity));
4
+ function i(t, n) {
5
+ return t === "percentage" ? 2 : e(n);
8
6
  }
9
- function u({ lineItems: e, currency: t, taxRate: n }) {
10
- let r = n ? Math.round(n * 100) : 0, i = 0, a = 0;
11
- for (let n of e) {
12
- let e = l(n, t);
13
- n.taxable ? i += e : a += e;
14
- }
15
- return {
16
- taxableItemsSubtotal: i,
17
- nonTaxableItemsSubtotal: a,
18
- subtotal: i + a,
19
- rateMinorUnits: r
20
- };
7
+ function a(e, r, a, o = n()) {
8
+ let s = `0-9${t(o.digits.join(""))}${t(o.decimal)}${o.group ? t(o.group) : ""}`, c = e.replace(RegExp(`[^${s}]`, "gu"), ""), l = c.indexOf(o.decimal);
9
+ return l === -1 ? c : c.slice(0, l + o.decimal.length) + Array.from(c.slice(l + o.decimal.length).split(o.decimal).join("")).slice(0, i(r, a)).join("");
21
10
  }
22
- function d({ discount: e, subtotal: t }) {
23
- if (!e) return 0;
24
- let n = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / 1e4));
25
- return Math.min(Math.max(n, 0), t);
11
+ function o(e, t, a, o = n()) {
12
+ return Math.round(r(e, o) * 10 ** i(t, a));
26
13
  }
27
- function f({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
- let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
29
- return {
30
- taxableSubtotal: e - i,
31
- nonTaxableSubtotal: t - (n - i)
14
+ function s(e, t, n) {
15
+ let r = i(t, n);
16
+ return new Intl.NumberFormat(void 0, {
17
+ minimumFractionDigits: r,
18
+ maximumFractionDigits: r
19
+ }).format(e / 10 ** r);
20
+ }
21
+ function c(e, t, n) {
22
+ let r = i(t, n), a = {
23
+ minimumFractionDigits: r,
24
+ maximumFractionDigits: r
32
25
  };
33
- }
34
- function p({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: i, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
- if (a <= 0) return 0;
36
- let s = /* @__PURE__ */ new Map();
37
- for (let a of e) {
38
- if (!a.taxable) continue;
39
- let e = r(a, n, i);
40
- s.set(e, (s.get(e) ?? 0) + l(a, t));
41
- }
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);
45
- d -= r, f += r * e;
46
- }), Math.round(f / c);
47
- }
48
- function m({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
49
- let a = u({
50
- lineItems: e,
51
- currency: t,
52
- taxRate: n
53
- }), o = d({
54
- discount: i,
55
- subtotal: a.subtotal
56
- }), { taxableSubtotal: s, nonTaxableSubtotal: c } = f({
26
+ return t === "percentage" ? new Intl.NumberFormat(void 0, {
57
27
  ...a,
58
- discountAmount: o
59
- }), l = p({
60
- lineItems: e,
61
- currency: t,
62
- rateMinorUnits: a.rateMinorUnits,
63
- keepSavedRate: r,
64
- taxableItemsSubtotal: a.taxableItemsSubtotal,
65
- taxableSubtotal: s
66
- }), m = a.subtotal - o;
67
- return {
28
+ style: "percent"
29
+ }).format(e / 10 ** (r + 2)) : new Intl.NumberFormat(void 0, {
68
30
  ...a,
69
- discountAmount: o,
70
- discountedSubtotal: m,
71
- taxableSubtotal: s,
72
- nonTaxableSubtotal: c,
73
- totalTaxes: l,
74
- total: m + l
75
- };
76
- }
77
- function h(e) {
78
- return m({
79
- lineItems: e.lineItems.filter((e) => !t(e)),
80
- currency: e.currency,
81
- taxRate: Number(e.taxRate) || void 0,
82
- keepSavedRate: n(e.taxRate, e.savedTaxRate),
83
- discount: s(e)
84
- });
85
- }
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);
95
- }
96
- function v(t, n, r) {
97
- return new Intl.NumberFormat(void 0, {
98
31
  style: "currency",
99
32
  currency: n,
100
- currencyDisplay: "narrowSymbol",
101
- currencySign: r
102
- }).format(t / 10 ** e(n));
33
+ currencyDisplay: "narrowSymbol"
34
+ }).format(e / 10 ** r);
35
+ }
36
+ function l({ value: e, type: t, currency: n }) {
37
+ return s(o(e, t, n), t, n);
103
38
  }
104
- function y(e, t) {
39
+ function u(e) {
105
40
  return {
106
- subtotal: v(e.subtotal, t),
107
- discount: e.discountAmount > 0 ? v(-e.discountAmount, t, "accounting") : v(0, t),
108
- nonTaxableSubtotal: v(e.nonTaxableSubtotal, t),
109
- taxableSubtotal: v(e.taxableSubtotal, t),
110
- tax: v(e.totalTaxes, t),
111
- total: v(e.total, t)
41
+ discountType: "amount",
42
+ discount: s(0, "amount", e)
112
43
  };
113
44
  }
45
+ function d(e) {
46
+ let t = o(e.discount, e.discountType, e.currency);
47
+ return t > 0 ? {
48
+ type: e.discountType,
49
+ amount: t
50
+ } : null;
51
+ }
52
+ function f(e, t) {
53
+ return e ? {
54
+ discountType: e.type,
55
+ discount: s(e.amount, e.type, t)
56
+ } : u(t);
57
+ }
114
58
  //#endregion
115
- export { c as FULL_PERCENT_MINOR_UNITS, f as allocateDiscount, y as buildFormTotalsView, h as calculateFormTotals, m as calculateInvoiceTotals, u as calculateItemsSubtotals, d as resolveDiscountAmount, g as validateDiscount, _ as validateInvoiceTotals };
59
+ export { l as convertDiscountInput, u as createEmptyDiscount, c as decorateDiscountInput, d as discountFromDraft, o as discountInputToMinorUnits, f as discountToDraft, s as formatDiscountInput, a as sanitizeDiscountInput };
@@ -1,359 +1,115 @@
1
1
  import { minorExponentForCurrency as e } from "../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
- import { parseDateOrTimestamp as t } from "../../../shared/util/dist/lib/parseCalendarDate.js";
3
- import { createLineItem as n, isBlankLineItem as r, keepsSavedTaxRates as i, lineItemToCreatePayload as a, lineItemToUpdatePayload as o, responseLineItemToFormValues as s, summarizeLineItemErrors as c, taxRateFromLineItems as l, validateLineItems as u } from "./index6.js";
4
- import { attachmentFormValuesToPayload as d, receivableToAttachmentFormValues as f } from "./index7.js";
5
- import { createEmptyRecurrenceFields as p } from "./index8.js";
6
- import { buildPaymentTermsPayload as m, buildPaymentTermsUpdatePayload as h, paymentTermsToFormFields as g } from "./index9.js";
7
- import { createEmptyDiscount as _, discountFromDraft as v, discountToDraft as y } from "./index10.js";
8
- import { validateDiscount as b, validateInvoiceTotals as x } from "./index11.js";
2
+ import { isBlankLineItem as t, keepsSavedTaxRates as n, lineItemTaxRateMinorUnits as r, maxAmountLabel as i, parseQuantity as a, priceInputToMinorUnits as o } from "./index6.js";
3
+ import { discountFromDraft as s } from "./index11.js";
9
4
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js
10
- var S = {
11
- to: "",
12
- cc: "",
13
- bcc: "",
14
- subject: "",
15
- body: ""
16
- }, C = {
17
- mode: "full",
18
- amountPaid: "",
19
- paidAt: "",
20
- comment: ""
21
- };
22
- function w() {
5
+ var c = 1e4;
6
+ function l(e, t) {
7
+ return Math.round(o(e.price, t) * a(e.quantity));
8
+ }
9
+ function u({ lineItems: e, currency: t, taxRate: n }) {
10
+ let r = n ? Math.round(n * 100) : 0, i = 0, a = 0;
11
+ for (let n of e) {
12
+ let e = l(n, t);
13
+ n.taxable ? i += e : a += e;
14
+ }
23
15
  return {
24
- type: "invoice",
25
- customerId: "",
26
- currency: "USD",
27
- issueDate: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
28
- dueDate: "",
29
- openingNote: "",
30
- closingNote: "",
31
- paymentTermsId: "",
32
- paymentTermsCustomDate: "",
33
- taxRate: "",
34
- ..._("USD"),
35
- lineItems: [n()],
36
- bankAccountId: "",
37
- bankAccountType: "",
38
- paymentReminderId: "",
39
- overdueReminderId: "",
40
- attachments: [],
41
- ...p()
16
+ taxableItemsSubtotal: i,
17
+ nonTaxableItemsSubtotal: a,
18
+ subtotal: i + a,
19
+ rateMinorUnits: r
42
20
  };
43
21
  }
44
- function T(e) {
45
- return e === "quotes" ? "quote" : e === "credit_notes" ? "credit_note" : "invoice";
46
- }
47
- function E(e) {
48
- return e === "quote" ? "quotes" : e === "credit_note" ? "credit_notes" : "invoices";
49
- }
50
- function D(e) {
51
- return (e?.length ? e : [
52
- "invoices",
53
- "quotes",
54
- "credit_notes"
55
- ]).filter((e, t, n) => [
56
- "invoices",
57
- "quotes",
58
- "credit_notes"
59
- ].includes(e) && n.indexOf(e) === t);
60
- }
61
- function O({ defaultTab: e, enabledTabs: t }) {
62
- return e && t.includes(e) ? e : t[0] ?? "invoices";
22
+ function d({ discount: e, subtotal: t }) {
23
+ if (!e) return 0;
24
+ let n = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / 1e4));
25
+ return Math.min(Math.max(n, 0), t);
63
26
  }
64
- function k(e, n) {
65
- let r = t(e);
66
- return r ? new Intl.DateTimeFormat(void 0, {
67
- day: "numeric",
68
- month: "short",
69
- year: "numeric"
70
- }).format(r) : n;
71
- }
72
- function A({ amount: t, currency: n, fallback: r }) {
73
- return t == null || !n ? r : new Intl.NumberFormat(void 0, {
74
- currency: n,
75
- style: "currency"
76
- }).format(t / 10 ** e(n));
77
- }
78
- function j(t, n) {
79
- let r = Number(t);
80
- if (!Number.isFinite(r)) return;
81
- let i = n ? e(n) : 2;
82
- return Math.round(r * 10 ** i);
83
- }
84
- function M(e, t) {
85
- return e.document_id || t.untitledDocument;
86
- }
87
- function N(e) {
88
- return e === "paid" || e === "accepted" || e === "issued" || e === "recurring" ? "success" : e === "draft" || e === "issuing" ? "neutral" : e === "overdue" || e === "partially_paid" ? "warning" : e === "failed" || e === "declined" || e === "expired" || e === "uncollectible" || e === "canceled" || e === "deleted" ? "danger" : "info";
89
- }
90
- function P(e) {
91
- let t = e.status === "draft", n = e.status === "issued", r = e.type === "invoice", i = e.type === "quote", a = e.type === "credit_note", o = r && [
92
- "issued",
93
- "overdue",
94
- "partially_paid"
95
- ].includes(e.status);
27
+ function f({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
+ let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
96
29
  return {
97
- edit: t && !a,
98
- accept: i && n,
99
- cancel: ![
100
- "paid",
101
- "canceled",
102
- "deleted",
103
- "uncollectible"
104
- ].includes(e.status) && !t,
105
- clone: !a && e.status !== "deleted",
106
- decline: i && n,
107
- delete: t,
108
- issue: t,
109
- markPaid: o,
110
- markUncollectible: o,
111
- recordPayment: o,
112
- send: [
113
- "issued",
114
- "accepted",
115
- "overdue",
116
- "partially_paid"
117
- ].includes(e.status) && !a
30
+ taxableSubtotal: e - i,
31
+ nonTaxableSubtotal: t - (n - i)
118
32
  };
119
33
  }
120
- function F({ receivables: e, messages: t }) {
121
- return e.map((e) => {
122
- let n = e.type === "invoice" ? e.amount_due : void 0;
123
- return {
124
- id: e.id,
125
- type: e.type,
126
- documentLabel: M(e, t),
127
- customerLabel: e.counterpart_name || t.unknownCustomer,
128
- status: e.status,
129
- statusTone: N(e.status),
130
- issueDateLabel: k(e.issue_date, t.notAvailable),
131
- dueDateLabel: k(e.type === "quote" ? e.expiry_date : e.due_date, t.notAvailable),
132
- totalLabel: A({
133
- amount: e.total_amount,
134
- currency: e.currency,
135
- fallback: t.notAvailable
136
- }),
137
- amountDueLabel: A({
138
- amount: n,
139
- currency: e.currency,
140
- fallback: t.notAvailable
141
- }),
142
- actions: P(e)
143
- };
144
- });
145
- }
146
- function I(e) {
147
- if (e.memo || e.footer) return {
148
- opening: e.memo || void 0,
149
- closing: e.footer || void 0
150
- };
151
- }
152
- function L({ values: e, billingAddressId: t, messages: n, willIssue: r = !1, hasStartedRecurrence: i = !1 }) {
153
- let a = {};
154
- e.customerId ? t || (a.customerId = n.customerAddressRequired) : a.customerId = n.customerRequired, e.currency || (a.currency = n.currencyRequired), r && !e.paymentTermsId && (a.paymentTermsId = n.paymentTermsRequired), r && !e.bankAccountId && (a.bankAccountId = n.bankAccountRequired);
155
- let o = u(e.lineItems, {
156
- currency: e.currency,
157
- messages: n,
158
- requireComplete: r || i
159
- }), s = c(o, x(e, n), (r || i) && e.lineItems.length === 0 ? n.lineItemsRequired : void 0);
160
- o && (a.lineItems = o), s && (a.lineItemsSummary = s);
161
- let l = b(e, n);
162
- return l && (a.discount = l), a;
163
- }
164
- function R(e) {
165
- return Object.keys(e).length > 0;
166
- }
167
- function z(e, t) {
168
- return !R(L({
169
- values: H(e),
170
- billingAddressId: e.type === "invoice" ? e.counterpart_billing_address?.id ?? void 0 : void 0,
171
- messages: t,
172
- willIssue: !0
173
- }));
174
- }
175
- function B({ bankAccountId: e, bankAccountType: t }) {
34
+ function p({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: i, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
+ if (a <= 0) return 0;
36
+ let s = /* @__PURE__ */ new Map();
37
+ for (let a of e) {
38
+ if (!a.taxable) continue;
39
+ let e = r(a, n, i);
40
+ s.set(e, (s.get(e) ?? 0) + l(a, t));
41
+ }
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);
45
+ d -= r, f += r * e;
46
+ }), Math.round(f / c);
47
+ }
48
+ function m({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
49
+ let a = u({
50
+ lineItems: e,
51
+ currency: t,
52
+ taxRate: n
53
+ }), o = d({
54
+ discount: i,
55
+ subtotal: a.subtotal
56
+ }), { taxableSubtotal: s, nonTaxableSubtotal: c } = f({
57
+ ...a,
58
+ discountAmount: o
59
+ }), l = p({
60
+ lineItems: e,
61
+ currency: t,
62
+ rateMinorUnits: a.rateMinorUnits,
63
+ keepSavedRate: r,
64
+ taxableItemsSubtotal: a.taxableItemsSubtotal,
65
+ taxableSubtotal: s
66
+ }), m = a.subtotal - o;
176
67
  return {
177
- bank_account_id: e || void 0,
178
- bank_account_type: e && t || void 0
179
- };
180
- }
181
- function V({ values: e, billingAddressId: t, unitNamesById: n }) {
182
- let i = e.lineItems.filter((e) => !r(e)).map((t) => a({
183
- lineItem: t,
184
- currency: e.currency,
185
- taxRate: e.taxRate,
186
- unitNamesById: n
187
- })), o = {
188
- counterpart_billing_address_id: t,
189
- counterpart_id: e.customerId,
190
- currency: e.currency,
191
- line_items: i,
192
- memo: e.openingNote,
193
- footer: e.closingNote,
194
- discount: v(e) ?? void 0,
195
- ...B(e)
196
- };
197
- return e.type === "quote" ? {
198
- ...o,
199
- expiry_date: e.dueDate || void 0,
200
- type: "quote"
201
- } : {
202
- ...o,
203
- ...m(e),
204
- payment_reminder_id: e.paymentReminderId || void 0,
205
- overdue_reminder_id: e.overdueReminderId || void 0,
206
- attachments: d(e.attachments),
207
- type: "invoice"
68
+ ...a,
69
+ discountAmount: o,
70
+ discountedSubtotal: m,
71
+ taxableSubtotal: s,
72
+ nonTaxableSubtotal: c,
73
+ totalTaxes: l,
74
+ total: m + l
208
75
  };
209
76
  }
210
- function H(e, t) {
211
- let r = e.type === "quote" ? "quote" : "invoice", i = l(e.line_items), a = e.type === "invoice" ? e : void 0, o = e.line_items.map((n) => s({
212
- lineItem: n,
213
- currency: e.currency,
214
- units: t
215
- }));
216
- return {
217
- ...w(),
218
- type: r,
219
- customerId: e.counterpart_id,
77
+ function h(e) {
78
+ return m({
79
+ lineItems: e.lineItems.filter((e) => !t(e)),
220
80
  currency: e.currency,
221
- issueDate: q(e.issue_date),
222
- dueDate: e.type === "quote" ? q(e.expiry_date) : "",
223
- openingNote: e.memo ?? "",
224
- closingNote: e.footer ?? "",
225
- ...e.type === "invoice" ? g(e.payment_terms) : {},
226
- taxRate: i,
227
- savedTaxRate: i,
228
- ...y(e.discount, e.currency),
229
- lineItems: o.length > 0 ? o : [n(e.currency)],
230
- bankAccountId: e.bank_account_id ?? "",
231
- bankAccountType: U(e.bank_account_type),
232
- paymentReminderId: a?.payment_reminder_id ?? "",
233
- overdueReminderId: a?.overdue_reminder_id ?? "",
234
- attachments: f(e)
235
- };
81
+ taxRate: Number(e.taxRate) || void 0,
82
+ keepSavedRate: n(e.taxRate, e.savedTaxRate),
83
+ discount: s(e)
84
+ });
236
85
  }
237
- function U(e) {
238
- return e === "BANK_DETAILS" || e === "INTERNAL" || e === "EXTERNAL" ? e : "";
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;
239
89
  }
240
- function W({ values: e, billingAddressId: t, lineItemChanges: n }) {
241
- let r = {
242
- counterpart_billing_address_id: t,
243
- counterpart_id: e.customerId,
244
- currency: e.currency,
245
- issue_date: e.issueDate || void 0,
246
- memo: e.openingNote,
247
- footer: e.closingNote,
248
- discount: v(e),
249
- ...B(e)
250
- };
251
- return e.type === "quote" ? { quote: {
252
- ...r,
253
- ...n ? { line_items: n } : {},
254
- expiry_date: e.dueDate || void 0,
255
- ...h(e)
256
- } } : { invoice: {
257
- ...r,
258
- ...n ? { line_items: n } : {},
259
- ...h(e),
260
- payment_reminder_id: e.paymentReminderId || null,
261
- overdue_reminder_id: e.overdueReminderId || null,
262
- attachments: d(e.attachments) ?? null
263
- } };
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);
264
95
  }
265
- function G({ values: e, originalLineItems: t, originalCurrency: n, unitNamesById: a, units: c }) {
266
- let u = l(t), d = i(e.taxRate, u), f = (e, t, n) => o({
267
- lineItem: e,
268
- currency: t,
269
- taxRate: n,
270
- keepSavedRate: d,
271
- unitNamesById: a
272
- }), p = new Map(t.map((e) => [e.id, JSON.stringify(f(s({
273
- lineItem: e,
96
+ function v(t, n, r) {
97
+ return new Intl.NumberFormat(void 0, {
98
+ style: "currency",
274
99
  currency: n,
275
- units: c
276
- }), n, u))])), m = e.lineItems.filter((e) => !r(e)), h = new Set(m.map((e) => e.id)), g = m.filter((e) => !p.has(e.id)).map((t) => f(t, e.currency, e.taxRate)), _ = m.flatMap((t) => {
277
- let n = p.get(t.id);
278
- if (n === void 0) return [];
279
- let r = f(t, e.currency, e.taxRate);
280
- return n === JSON.stringify(r) ? [] : [{
281
- id: t.id,
282
- data: r
283
- }];
284
- }), v = t.filter((e) => !h.has(e.id)).map((e) => e.id);
285
- if (g.length || _.length || v.length) return {
286
- ...g.length ? { add: g } : {},
287
- ..._.length ? { replace: _ } : {},
288
- ...v.length ? { remove: v } : {}
289
- };
290
- }
291
- function K({ values: e, originalLineItems: t, changes: n }) {
292
- let i = e.lineItems.filter((e) => !r(e)).map((e) => e.id);
293
- if (!t) return { created: i };
294
- let a = new Set(t.map((e) => e.id));
295
- return {
296
- added: i.filter((e) => !a.has(e)),
297
- replaced: n?.replace?.map((e) => e.id) ?? []
298
- };
299
- }
300
- function q(e) {
301
- return e?.slice(0, 10) ?? "";
302
- }
303
- function J(e, t) {
304
- let n = {};
305
- return e.to.trim() || (n.to = t.sendToRequired), e.subject.trim() || (n.subject = t.sendSubjectRequired), e.body.trim() || (n.body = t.sendBodyRequired), n;
306
- }
307
- function Y(e) {
308
- return Object.keys(e).length > 0;
309
- }
310
- function X(e) {
311
- return e.split(",").map((e) => e.trim()).filter(Boolean);
312
- }
313
- function Z(e, t, n) {
314
- let r = {};
315
- if (e.mode === "partial") {
316
- let i = j(e.amountPaid, n);
317
- (!i || i <= 0) && (r.amountPaid = t.paymentAmountInvalid);
318
- }
319
- return r;
320
- }
321
- function Q(e) {
322
- return Object.keys(e).length > 0;
323
- }
324
- function $(e, t) {
325
- return {
326
- ...S,
327
- to: e?.counterpart_contact?.email ?? "",
328
- subject: e?.document_id ? `${t.sendSubjectDefault} ${e.document_id}` : t.sendSubjectDefault,
329
- body: t.sendBodyDefault
330
- };
100
+ currencyDisplay: "narrowSymbol",
101
+ currencySign: r
102
+ }).format(t / 10 ** e(n));
331
103
  }
332
- function ee() {
104
+ function y(e, t) {
333
105
  return {
334
- ...C,
335
- paidAt: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
106
+ subtotal: v(e.subtotal, t),
107
+ discount: e.discountAmount > 0 ? v(-e.discountAmount, t, "accounting") : v(0, t),
108
+ nonTaxableSubtotal: v(e.nonTaxableSubtotal, t),
109
+ taxableSubtotal: v(e.taxableSubtotal, t),
110
+ tax: v(e.totalTaxes, t),
111
+ total: v(e.total, t)
336
112
  };
337
113
  }
338
- function te(e = "all") {
339
- let t = [
340
- "draft",
341
- "issued",
342
- "failed",
343
- "accepted",
344
- "expired",
345
- "declined",
346
- "recurring",
347
- "partially_paid",
348
- "paid",
349
- "overdue",
350
- "uncollectible",
351
- "canceled"
352
- ];
353
- return e !== "all" && !t.includes(e) && t.push(e), t.map((e) => ({
354
- value: e,
355
- label: e.split("_").map((e) => `${e.slice(0, 1).toUpperCase()}${e.slice(1)}`).join(" ")
356
- }));
357
- }
358
114
  //#endregion
359
- export { C as EMPTY_RECEIVABLE_PAYMENT_VALUES, S as EMPTY_RECEIVABLE_SEND_VALUES, P as buildReceivableActions, I as buildReceivableNotesView, F as buildReceivableRows, D as coerceEnabledTabs, w as createEmptyReceivableFormValues, n as createLineItem, ee as defaultPaymentValues, $ as defaultSendValues, k as formatDate, A as formatMoney, j as fromMajorUnits, M as getDocumentTitle, N as getStatusTone, Q as hasPaymentErrors, R as hasReceivableFormErrors, Y as hasSendErrors, z as isReceivableReadyToIssue, V as receivableFormValuesToCreatePayload, G as receivableFormValuesToLineItemChanges, W as receivableFormValuesToUpdatePayload, H as receivableToFormValues, O as resolveInitialTab, X as splitEmailList, te as statusFilterOptions, K as submittedLineItemRows, E as tabForType, T as typeForTab, Z as validatePaymentValues, L as validateReceivableForm, J as validateSendValues };
115
+ export { c as FULL_PERCENT_MINOR_UNITS, f as allocateDiscount, y as buildFormTotalsView, h as calculateFormTotals, m as calculateInvoiceTotals, u as calculateItemsSubtotals, d as resolveDiscountAmount, g as validateDiscount, _ as validateInvoiceTotals };