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