@tesouro/embedded-components-react 0.5.214 → 0.5.216

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 (123) hide show
  1. package/dist/index.d.ts +144 -3
  2. package/dist/index.js +14 -13
  3. package/dist/lib/BankAccountOnboardingWidget.d.ts +56 -2
  4. package/dist/lib/BankAccountOnboardingWidget.js +4 -3
  5. package/dist/lib/MarketingWidget.js +1 -1
  6. package/dist/lib/ReceivablesWidget.d.ts +88 -1
  7. package/dist/lib/ReceivablesWidget.js +1 -1
  8. package/dist/lib/WidgetSuite.d.ts +53 -0
  9. package/dist/libs/shared/util-validation/dist/index5.js +7 -0
  10. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index.js +3 -2
  11. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index11.js +72 -72
  12. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index12.js +4 -1
  13. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index13.js +15 -15
  14. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index14.js +60 -60
  15. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index15.js +12 -12
  16. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index16.js +16 -16
  17. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index18.js +11 -11
  18. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index21.js +8 -8
  19. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index22.js +71 -5
  20. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index23.js +95 -33
  21. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index24.js +6 -17
  22. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index25.js +16 -616
  23. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index26.js +669 -0
  24. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index.js +15 -13
  25. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index10.js +52 -37
  26. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index11.js +31 -37
  27. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index12.js +33 -89
  28. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index13.js +39 -12
  29. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index14.js +98 -2
  30. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index15.js +14 -4
  31. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index16.js +2 -185
  32. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index17.js +4 -30
  33. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index18.js +183 -21
  34. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index19.js +26 -66
  35. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index20.js +21 -233
  36. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index21.js +66 -27
  37. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index22.js +233 -26
  38. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index23.js +27 -72
  39. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index24.js +26 -85
  40. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index25.js +74 -8
  41. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index26.js +83 -55
  42. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index27.js +6 -7
  43. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index28.js +37 -42
  44. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index29.js +11 -0
  45. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index30.js +64 -0
  46. package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/ui/dist/index9.js +7 -33
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +7 -7
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +63 -67
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index11.js +160 -1
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index12.js +6 -0
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +32 -25
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index6.js +25 -200
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index7.js +175 -1
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index8.js +1 -101
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index9.js +92 -71
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +44 -100
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +93 -421
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +442 -112
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +166 -157
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +150 -204
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +202 -31
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +32 -145
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +145 -37
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +44 -58
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +113 -87
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +58 -116
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +83 -357
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +111 -65
  70. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +449 -99
  71. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +68 -281
  72. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +115 -0
  73. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +314 -0
  74. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +34 -23
  76. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +444 -92
  77. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +113 -52
  78. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +18 -14
  79. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +2 -92
  80. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +95 -3
  81. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +3 -24
  82. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +24 -1
  83. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +1 -3
  84. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +1 -1
  85. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +3 -18
  86. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +18 -1
  87. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +0 -3
  88. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +0 -8
  89. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +11 -0
  90. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +1 -264
  91. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +258 -42
  92. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +38 -62
  93. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +61 -463
  94. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +457 -89
  95. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +91 -234
  96. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +89 -82
  97. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +22 -338
  98. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index29.js +236 -0
  99. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +26 -204
  100. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index30.js +3 -0
  101. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index31.js +249 -0
  102. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +93 -0
  103. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +344 -0
  104. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +208 -32
  105. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +29 -202
  106. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +183 -137
  107. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +157 -12
  108. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +10 -19
  109. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +23 -2
  110. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index.js +1 -1
  111. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index5.js +16 -19
  112. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index6.js +157 -16
  113. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +40 -40
  114. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/onboardingSuppressionReason.js +3 -1
  115. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +167 -156
  116. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +66 -34
  117. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/index.js +2 -1
  118. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  119. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/application/bankAccountApplication.js +26 -0
  120. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index16.js +1 -1
  121. package/dist/packages/shared-ui-shadcn/dist/index.js +13 -13
  122. package/package.json +1 -1
  123. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index7.js +0 -161
@@ -1,443 +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 { buildPaymentTermsPayload as p, buildPaymentTermsUpdatePayload as m, paymentTermsToFormFields as h } from "./index8.js";
6
- import { createEmptyDiscount as g, discountFromDraft as _, discountToDraft as v } from "./index9.js";
7
- import { validateDiscount as y, validateInvoiceTotals as b } from "./index10.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";
8
4
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
9
- var x = {
10
- to: "",
11
- cc: "",
12
- bcc: "",
13
- subject: "",
14
- body: ""
15
- }, S = {
16
- mode: "full",
17
- amountPaid: "",
18
- paidAt: "",
19
- comment: ""
20
- };
21
- function C() {
22
- return {
23
- type: "invoice",
24
- customerId: "",
25
- currency: "USD",
26
- issueDate: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
27
- dueDate: "",
28
- openingNote: "",
29
- closingNote: "",
30
- paymentTermsId: "",
31
- paymentTermsCustomDate: "",
32
- taxRate: "",
33
- ...g("USD"),
34
- lineItems: [n()],
35
- bankAccountId: "",
36
- bankAccountType: "",
37
- paymentReminderId: "",
38
- overdueReminderId: "",
39
- attachments: []
40
- };
41
- }
42
- function w(e) {
43
- return e === "quotes" ? "quote" : e === "credit_notes" ? "credit_note" : "invoice";
44
- }
45
- function T(e) {
46
- return e === "quote" ? "quotes" : e === "credit_note" ? "credit_notes" : "invoices";
47
- }
48
- function E(e) {
49
- return (e?.length ? e : [
50
- "invoices",
51
- "quotes",
52
- "credit_notes"
53
- ]).filter((e, t, n) => [
54
- "invoices",
55
- "quotes",
56
- "credit_notes"
57
- ].includes(e) && n.indexOf(e) === t);
58
- }
59
- function D({ defaultTab: e, enabledTabs: t }) {
60
- return e && t.includes(e) ? e : t[0] ?? "invoices";
61
- }
62
- function O(e, n) {
63
- let r = t(e);
64
- return r ? new Intl.DateTimeFormat(void 0, {
65
- day: "numeric",
66
- month: "short",
67
- year: "numeric"
68
- }).format(r) : n;
69
- }
70
- function k({ amount: t, currency: n, fallback: r }) {
71
- return t == null || !n ? r : new Intl.NumberFormat(void 0, {
72
- currency: n,
73
- style: "currency"
74
- }).format(t / 10 ** e(n));
75
- }
76
- function A(t, n) {
77
- let r = Number(t);
78
- if (!Number.isFinite(r)) return;
79
- let i = n ? e(n) : 2;
80
- return Math.round(r * 10 ** i);
81
- }
82
- function j(e, t) {
83
- return e.document_id || t.untitledDocument;
84
- }
85
- function M(e, t) {
86
- return e === "quote" ? t.quoteType : e === "credit_note" ? t.creditNoteType : t.invoiceType;
87
- }
88
- function N(e) {
89
- 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";
90
- }
91
- function P(e) {
92
- let t = e.status === "draft", n = e.status === "issued", r = e.type === "invoice", i = e.type === "quote", a = e.type === "credit_note", o = r && [
93
- "issued",
94
- "overdue",
95
- "partially_paid"
96
- ].includes(e.status);
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
+ }
97
15
  return {
98
- edit: t && !a,
99
- accept: i && n,
100
- cancel: ![
101
- "paid",
102
- "canceled",
103
- "deleted",
104
- "uncollectible"
105
- ].includes(e.status) && !t,
106
- clone: !a && e.status !== "deleted",
107
- decline: i && n,
108
- delete: t,
109
- issue: t,
110
- markPaid: o,
111
- markUncollectible: o,
112
- recordPayment: o,
113
- send: [
114
- "issued",
115
- "accepted",
116
- "overdue",
117
- "partially_paid"
118
- ].includes(e.status) && !a
16
+ taxableItemsSubtotal: i,
17
+ nonTaxableItemsSubtotal: a,
18
+ subtotal: i + a,
19
+ rateMinorUnits: r
119
20
  };
120
21
  }
121
- function F({ receivables: e, messages: t }) {
122
- return e.map((e) => {
123
- let n = e.type === "invoice" ? e.amount_due : void 0;
124
- return {
125
- id: e.id,
126
- type: e.type,
127
- documentLabel: j(e, t),
128
- customerLabel: e.counterpart_name || t.unknownCustomer,
129
- status: e.status,
130
- statusTone: N(e.status),
131
- issueDateLabel: O(e.issue_date, t.notAvailable),
132
- dueDateLabel: O(e.type === "quote" ? e.expiry_date : e.due_date, t.notAvailable),
133
- totalLabel: k({
134
- amount: e.total_amount,
135
- currency: e.currency,
136
- fallback: t.notAvailable
137
- }),
138
- amountDueLabel: k({
139
- amount: n,
140
- currency: e.currency,
141
- fallback: t.notAvailable
142
- }),
143
- actions: P(e)
144
- };
145
- });
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);
146
26
  }
147
- function I({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
148
- if (!e) return;
149
- let a = e.type === "invoice" ? e.amount_due : void 0, o = e.type === "quote" ? e.expiry_date : e.due_date;
27
+ function f({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
+ let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
150
29
  return {
151
- id: e.id,
152
- type: e.type,
153
- title: j(e, i),
154
- customerLabel: e.counterpart_name || i.unknownCustomer,
155
- status: e.status,
156
- statusTone: N(e.status),
157
- totalLabel: k({
158
- amount: e.total_amount,
159
- currency: e.currency,
160
- fallback: i.notAvailable
161
- }),
162
- amountDueLabel: k({
163
- amount: a,
164
- currency: e.currency,
165
- fallback: i.notAvailable
166
- }),
167
- pdfUrl: r || e.file_url || e.original_file_url || void 0,
168
- summaryItems: [
169
- {
170
- label: i.summaryDocumentType,
171
- value: M(e.type, i)
172
- },
173
- {
174
- label: i.summaryDocumentNumber,
175
- value: j(e, i)
176
- },
177
- {
178
- label: i.summaryCustomer,
179
- value: e.counterpart_name || i.unknownCustomer
180
- },
181
- {
182
- label: i.summaryIssued,
183
- value: O(e.issue_date, i.notAvailable)
184
- },
185
- {
186
- label: i.summaryDue,
187
- value: O(o, i.notAvailable)
188
- },
189
- {
190
- label: i.summaryCreated,
191
- value: O(e.created_at, i.notAvailable)
192
- },
193
- {
194
- label: i.summaryUpdated,
195
- value: O(e.updated_at, i.notAvailable)
196
- },
197
- {
198
- label: i.summaryTotal,
199
- value: k({
200
- amount: e.total_amount,
201
- currency: e.currency,
202
- fallback: i.notAvailable
203
- })
204
- },
205
- {
206
- label: i.summaryAmountDue,
207
- value: k({
208
- amount: a,
209
- currency: e.currency,
210
- fallback: i.notAvailable
211
- })
212
- }
213
- ],
214
- lineItems: e.line_items.map((t, n) => ({
215
- id: t.product.id || String(n),
216
- name: t.product.name,
217
- quantityLabel: String(t.quantity),
218
- unitPriceLabel: k({
219
- amount: t.product.price?.value,
220
- currency: t.product.price?.currency || e.currency,
221
- fallback: i.notAvailable
222
- }),
223
- totalLabel: k({
224
- amount: t.total_after_tax ?? t.total_before_tax,
225
- currency: e.currency,
226
- fallback: i.notAvailable
227
- })
228
- })),
229
- activityItems: t.map((e) => ({
230
- id: e.id,
231
- title: L(e.event_type, i),
232
- description: e.event_type,
233
- timestampLabel: O(e.timestamp, i.notAvailable)
234
- })),
235
- mailItems: n.map((e) => ({
236
- id: e.id,
237
- statusLabel: e.status,
238
- recipientsLabel: R(e, i),
239
- sentAtLabel: O(e.created_at, i.notAvailable)
240
- })),
241
- actions: P(e)
30
+ taxableSubtotal: e - i,
31
+ nonTaxableSubtotal: t - (n - i)
242
32
  };
243
33
  }
244
- function L(e, t) {
245
- return e === "status_changed" ? t.activityStatusChanged : e === "receivable_created" ? t.activityReceivableCreated : e === "receivable_updated" ? t.activityReceivableUpdated : e === "payment_received" ? t.activityPaymentReceived : e === "mail_sent" ? t.activityMailSent : t.activityUnknown;
246
- }
247
- function R(e, t) {
248
- let n = [
249
- ...e.recipients?.to ?? [],
250
- ...e.recipients?.cc ?? [],
251
- ...e.recipients?.bcc ?? []
252
- ].map((e) => e.email).filter(Boolean);
253
- return n.length > 0 ? n.join(", ") : t.recipientsNone;
254
- }
255
- function z({ values: e, billingAddressId: t, messages: n }) {
256
- let r = {};
257
- e.customerId ? t || (r.customerId = n.customerAddressRequired) : r.customerId = n.customerRequired, e.currency || (r.currency = n.currencyRequired);
258
- let i = u(e.lineItems, {
259
- currency: e.currency,
260
- messages: n
261
- }), a = c(i, b(e, n));
262
- i && (r.lineItems = i), a && (r.lineItemsSummary = a);
263
- let o = y(e, n);
264
- return o && (r.discount = o), r;
265
- }
266
- function B(e) {
267
- return Object.keys(e).length > 0;
268
- }
269
- function V({ 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;
270
67
  return {
271
- bank_account_id: e || void 0,
272
- bank_account_type: e && t || void 0
68
+ ...a,
69
+ discountAmount: o,
70
+ discountedSubtotal: m,
71
+ taxableSubtotal: s,
72
+ nonTaxableSubtotal: c,
73
+ totalTaxes: l,
74
+ total: m + l
273
75
  };
274
76
  }
275
- function H({ values: e, billingAddressId: t, unitNamesById: n }) {
276
- let i = e.lineItems.filter((e) => !r(e)).map((t) => a({
277
- lineItem: t,
77
+ function h(e) {
78
+ return m({
79
+ lineItems: e.lineItems.filter((e) => !t(e)),
278
80
  currency: e.currency,
279
- taxRate: e.taxRate,
280
- unitNamesById: n
281
- })), o = {
282
- counterpart_billing_address_id: t,
283
- counterpart_id: e.customerId,
284
- currency: e.currency,
285
- line_items: i,
286
- memo: e.openingNote,
287
- footer: e.closingNote,
288
- discount: _(e) ?? void 0,
289
- ...V(e)
290
- };
291
- return e.type === "quote" ? {
292
- ...o,
293
- expiry_date: e.dueDate || void 0,
294
- type: "quote"
295
- } : {
296
- ...o,
297
- ...p(e),
298
- payment_reminder_id: e.paymentReminderId || void 0,
299
- overdue_reminder_id: e.overdueReminderId || void 0,
300
- attachments: d(e.attachments),
301
- type: "invoice"
302
- };
303
- }
304
- function U(e, t) {
305
- 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({
306
- lineItem: n,
307
- currency: e.currency,
308
- units: t
309
- }));
310
- return {
311
- ...C(),
312
- type: r,
313
- customerId: e.counterpart_id,
314
- currency: e.currency,
315
- issueDate: q(e.issue_date),
316
- dueDate: e.type === "quote" ? q(e.expiry_date) : "",
317
- openingNote: e.memo ?? "",
318
- closingNote: e.footer ?? "",
319
- ...e.type === "invoice" ? h(e.payment_terms) : {},
320
- taxRate: i,
321
- savedTaxRate: i,
322
- ...v(e.discount, e.currency),
323
- lineItems: o.length > 0 ? o : [n(e.currency)],
324
- bankAccountId: e.bank_account_id ?? "",
325
- bankAccountType: W(e.bank_account_type),
326
- paymentReminderId: a?.payment_reminder_id ?? "",
327
- overdueReminderId: a?.overdue_reminder_id ?? "",
328
- attachments: f(e)
329
- };
81
+ taxRate: Number(e.taxRate) || void 0,
82
+ keepSavedRate: n(e.taxRate, e.savedTaxRate),
83
+ discount: s(e)
84
+ });
330
85
  }
331
- function W(e) {
332
- 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;
333
89
  }
334
- function G({ values: e, billingAddressId: t, lineItemChanges: n }) {
335
- let r = {
336
- counterpart_billing_address_id: t,
337
- counterpart_id: e.customerId,
338
- currency: e.currency,
339
- issue_date: e.issueDate || void 0,
340
- memo: e.openingNote,
341
- footer: e.closingNote,
342
- discount: _(e),
343
- ...V(e)
344
- };
345
- return e.type === "quote" ? { quote: {
346
- ...r,
347
- ...n ? { line_items: n } : {},
348
- expiry_date: e.dueDate || void 0,
349
- ...m(e)
350
- } } : { invoice: {
351
- ...r,
352
- ...n ? { line_items: n } : {},
353
- ...m(e),
354
- payment_reminder_id: e.paymentReminderId || null,
355
- overdue_reminder_id: e.overdueReminderId || null,
356
- attachments: d(e.attachments) ?? null
357
- } };
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);
358
95
  }
359
- function K({ values: e, originalLineItems: t, originalCurrency: n, unitNamesById: a, units: c }) {
360
- let u = l(t), d = i(e.taxRate, u), f = (e, t, n) => o({
361
- lineItem: e,
362
- currency: t,
363
- taxRate: n,
364
- keepSavedRate: d,
365
- unitNamesById: a
366
- }), p = new Map(t.map((e) => [e.id, JSON.stringify(f(s({
367
- lineItem: e,
96
+ function v(t, n, r) {
97
+ return new Intl.NumberFormat(void 0, {
98
+ style: "currency",
368
99
  currency: n,
369
- units: c
370
- }), 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) => {
371
- let n = p.get(t.id);
372
- if (n === void 0) return [];
373
- let r = f(t, e.currency, e.taxRate);
374
- return n === JSON.stringify(r) ? [] : [{
375
- id: t.id,
376
- data: r
377
- }];
378
- }), v = t.filter((e) => !h.has(e.id)).map((e) => e.id);
379
- if (g.length || _.length || v.length) return {
380
- ...g.length ? { add: g } : {},
381
- ..._.length ? { replace: _ } : {},
382
- ...v.length ? { remove: v } : {}
383
- };
384
- }
385
- function q(e) {
386
- return e?.slice(0, 10) ?? "";
387
- }
388
- function J(e, t) {
389
- let n = {};
390
- return e.to.trim() || (n.to = t.sendToRequired), e.subject.trim() || (n.subject = t.sendSubjectRequired), e.body.trim() || (n.body = t.sendBodyRequired), n;
391
- }
392
- function Y(e) {
393
- return Object.keys(e).length > 0;
394
- }
395
- function X(e) {
396
- return e.split(",").map((e) => e.trim()).filter(Boolean);
397
- }
398
- function Z(e, t, n) {
399
- let r = {};
400
- if (e.mode === "partial") {
401
- let i = A(e.amountPaid, n);
402
- (!i || i <= 0) && (r.amountPaid = t.paymentAmountInvalid);
403
- }
404
- return r;
405
- }
406
- function Q(e) {
407
- return Object.keys(e).length > 0;
408
- }
409
- function $(e, t) {
410
- return {
411
- ...x,
412
- to: e?.counterpart_contact?.email ?? "",
413
- subject: e?.document_id ? `${t.sendSubjectDefault} ${e.document_id}` : t.sendSubjectDefault,
414
- body: t.sendBodyDefault
415
- };
100
+ currencyDisplay: "narrowSymbol",
101
+ currencySign: r
102
+ }).format(t / 10 ** e(n));
416
103
  }
417
- function ee() {
104
+ function y(e, t) {
418
105
  return {
419
- ...S,
420
- 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)
421
112
  };
422
113
  }
423
- function te() {
424
- return [
425
- "draft",
426
- "issued",
427
- "failed",
428
- "accepted",
429
- "expired",
430
- "declined",
431
- "recurring",
432
- "partially_paid",
433
- "paid",
434
- "overdue",
435
- "uncollectible",
436
- "canceled"
437
- ].map((e) => ({
438
- value: e,
439
- label: e.split("_").map((e) => `${e.slice(0, 1).toUpperCase()}${e.slice(1)}`).join(" ")
440
- }));
441
- }
442
114
  //#endregion
443
- export { S as EMPTY_RECEIVABLE_PAYMENT_VALUES, x as EMPTY_RECEIVABLE_SEND_VALUES, P as buildReceivableActions, I as buildReceivableDetailsView, F as buildReceivableRows, E as coerceEnabledTabs, C as createEmptyReceivableFormValues, n as createLineItem, ee as defaultPaymentValues, $ as defaultSendValues, O as formatDate, k as formatMoney, A as fromMajorUnits, j as getDocumentTitle, M as getDocumentTypeLabel, N as getStatusTone, Q as hasPaymentErrors, B as hasReceivableFormErrors, Y as hasSendErrors, H as receivableFormValuesToCreatePayload, K as receivableFormValuesToLineItemChanges, G as receivableFormValuesToUpdatePayload, U as receivableToFormValues, D as resolveInitialTab, X as splitEmailList, te as statusFilterOptions, T as tabForType, w as typeForTab, Z as validatePaymentValues, z 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 };