@tesouro/embedded-components-react 0.5.204 → 0.5.205

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 (44) hide show
  1. package/README.md +15 -14
  2. package/dist/index.d.ts +38 -0
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +38 -0
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +7 -7
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +26 -23
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index3.js +79 -2
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +53 -42
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +81 -283
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +47 -70
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +303 -99
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +68 -230
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +115 -0
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +253 -0
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +34 -19
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +14 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +18 -1
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +0 -3
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +0 -7
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +10 -0
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +1 -264
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +259 -67
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +61 -412
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +407 -89
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +73 -60
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +80 -331
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +20 -0
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +344 -0
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +183 -137
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +157 -20
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +24 -1
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +1 -3
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +1 -1
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +3 -18
  39. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  40. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +213 -202
  41. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +136 -116
  42. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  43. package/dist/packages/shared-ui-shadcn/dist/index.js +1763 -1749
  44. package/package.json +1 -1
@@ -2,302 +2,100 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { getStateOptions as e } from "../../../shared/util/dist/lib/usStates.js";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
6
  import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
- import { usePaymentTermsQuery as n } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
8
- import { COUNTERPART_MESSAGE_LABELS_EN as r } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
9
- import { useCounterpartAddressesQuery as i } from "../../../shared/counterpart-management/data-access/dist/index7.js";
10
- import { useCounterpartForm as a } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
- import "../../../shared/counterpart-management/feature/dist/index.js";
12
- import { buildLineItemControls as ee, commitLineItemField as te, commitTaxRateInput as ne, convertPriceInput as re, createLineItem as o, getCurrencySymbol as ie, isBlankLineItem as ae, lineItemFromProduct as oe, reconcileMeasureUnits as se, sanitizeLineItemPatch as ce, sanitizeTaxRateInput as le, stepLineItemQuantity as ue, stripBlankLineItems as de, summarizeLineItemErrors as fe, toSheetLineItem as pe, validateLineItems as me } from "./index6.js";
13
- import { buildReceivableAttachmentsView as he } from "./index7.js";
14
- import { createEmptyReceivableFormValues as s, getPaymentTermOptions as ge, hasReceivableFormErrors as _e, receivableFormValuesToCreatePayload as ve, receivableFormValuesToLineItemChanges as ye, receivableFormValuesToUpdatePayload as be, receivableToFormValues as xe, validateReceivableForm as Se } from "./index8.js";
15
- import { useCreateReceivableMutation as c, useUpdateReceivableMutation as Ce } from "../../data-access/dist/index6.js";
7
+ import "../../../shared/ui/dist/index.js";
8
+ import { useWidgetConfig as n } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
9
+ import "../../../shared/feature/dist/index.js";
10
+ import { useCreateEntityBankAccountMutation as r, usePaymentAccountsQuery as i } from "../../data-access/dist/index3.js";
16
11
  import "../../data-access/dist/index.js";
17
- import { useReceivableAttachmentUploads as we } from "./index12.js";
18
- import { calculateInvoiceTotals as Te } from "./index13.js";
19
- import { getCurrencyOptions as Ee } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
20
- import { useMeasureUnitsQuery as De } from "../../../shared/product-catalog/data-access/dist/index9.js";
21
- import { useMeasureUnits as l } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
22
- import "../../../shared/product-catalog/feature/dist/index.js";
23
- import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
12
+ import { EMPTY_BANK_ACCOUNT_FORM_VALUES as a, bankAccountFormToPayload as o, buildBankAccountSectionView as s, buildPaymentAccountOptions as c, getBankAccountPermissions as l, validateBankAccountForm as u } from "./index13.js";
13
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
24
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js
25
- function h({ messages: h, counterpartMessageLabels: g, onCreated: _ }) {
26
- let v = c(), y = Ce(), b = p([]), x = p(""), S = n(), [C, w] = m(!1), [T, E] = m("create"), [D, O] = m(), [k, A] = m(() => s()), [Oe, j] = m({}), [M, ke] = m("none"), N = l(), P = De(), F = P.data?.data, { unitNamesById: I } = N, [Ae, L] = m(), [R, z] = m(!1), B = p(!1), V = f(() => e(), []), je = f(() => ({
27
- ...r,
28
- ...g
29
- }), [g]), H = i(k.customerId), Me = H.data?.data?.[0], U = H.data?.data?.[0]?.id, Ne = u((e) => {
30
- A((t) => ({
31
- ...t,
32
- attachments: e(t.attachments)
33
- }));
34
- }, []), W = we({
35
- attachments: k.attachments,
36
- setAttachments: Ne,
37
- receivableId: D
38
- }), { reset: G, discardUploads: K, commitRemovals: q } = W, Pe = k.type === "invoice" ? he({
39
- attachments: k.attachments,
40
- pendingUploads: W.pendingUploads,
41
- isCountLimitReached: W.isCountLimitReached,
42
- isRecurring: !1,
43
- messages: h
44
- }) : void 0, Fe = u((e) => {
45
- A((t) => ({
46
- ...t,
47
- customerId: e ?? ""
48
- }));
49
- }, []), J = a({
50
- view: M,
51
- setView: ke,
52
- selectedId: k.customerId || void 0,
53
- setSelectedId: Fe,
54
- messages: je,
55
- counterpartType: "customer",
56
- counterpart: void 0,
57
- primaryAddress: Me
58
- }), Y = u(() => {
59
- b.current = [], L(void 0), E("create"), O(void 0), A(s()), j({}), z(!1), G();
60
- }, [G]), Ie = u((e = "invoice") => {
61
- b.current = [], L(void 0), E("create"), O(void 0), A({
62
- ...s(),
63
- type: e
64
- }), j({}), G(), z(!1), w(!0);
65
- }, [G]), Le = u((e) => {
66
- e.type !== "credit_note" && (b.current = e.line_items, x.current = e.currency, L(void 0), E("edit"), O(e.id), A(xe(e, F)), j({}), z(!1), G(), w(!0));
67
- }, [G, F]);
68
- d(() => {
69
- F?.length && A((e) => {
70
- let t = se(e.lineItems, F);
71
- return t === e.lineItems ? e : {
72
- ...e,
73
- lineItems: t
74
- };
75
- });
76
- }, [F]);
77
- let X = W.isUploading, Re = u(() => {
78
- X || (K(), w(!1), j({}));
79
- }, [K, X]), ze = u((e) => {
80
- let t = e.taxRate === void 0 ? e : {
81
- ...e,
82
- taxRate: le(e.taxRate)
83
- }, { currency: n, type: r } = t;
84
- if (r !== void 0 && r !== "invoice" && K(), n === void 0) {
85
- A((e) => ({
86
- ...e,
87
- ...t
88
- }));
89
- return;
90
- }
91
- B.current = !0, A((e) => e.currency === n ? {
92
- ...e,
93
- ...t
94
- } : {
95
- ...e,
96
- ...t,
97
- lineItems: e.lineItems.map((t) => ({
98
- ...t,
99
- price: re(t.price, e.currency, n)
100
- }))
101
- });
102
- }, [K]), Be = u(() => {
103
- A((e) => {
104
- let t = ne(e.taxRate);
105
- return t === e.taxRate ? e : {
106
- ...e,
107
- taxRate: t
108
- };
109
- });
110
- }, []), Z = u((e, t) => {
111
- let n = me(e, {
112
- currency: t,
113
- messages: h
114
- });
115
- j((e) => ({
116
- ...e,
117
- lineItems: n,
118
- lineItemsSummary: fe(n)
119
- }));
120
- }, [h]), Q = u((e, { validate: t }) => {
121
- t && (B.current = !0), A((t) => ({
122
- ...t,
123
- lineItems: e(t.lineItems)
124
- }));
15
+ function g({ open: g, bankAccountId: _, embeddedBankName: v, messages: y, onSelect: b }) {
16
+ let { initResponse: x } = n(), S = p(() => l(x?.scopes), [x?.scopes]), { paymentAccounts: C, isLoading: w, isIncomplete: T } = i({
17
+ enabled: g,
18
+ canReadEmbedded: S.canReadEmbedded,
19
+ canReadExternal: S.canReadExternal
20
+ }), E = r(), [D, O] = h(!1), [k, A] = h(a), [j, M] = h({}), N = m(!1), P = d(() => {
21
+ N.current = !1, O(!1), A(a), M({});
125
22
  }, []);
126
- d(() => {
127
- B.current && (B.current = !1, Z(k.lineItems, k.currency));
23
+ f(() => {
24
+ if (!g || T || N.current || C.length !== 1) return;
25
+ let [e] = C;
26
+ N.current = !0, b({
27
+ bankAccountId: e.id,
28
+ bankAccountType: e.type
29
+ });
128
30
  }, [
129
- Z,
130
- k.currency,
131
- k.lineItems
31
+ T,
32
+ b,
33
+ g,
34
+ C
132
35
  ]);
133
- let Ve = u((e, t) => {
134
- let { unit: n, ...r } = t, i = ce(r);
135
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
136
- ...t,
137
- ...i
138
- } : t), { validate: R });
139
- }, [Q, R]), He = u((e, t) => {
140
- Q((n) => n.map((n) => n.id === e ? {
141
- ...n,
142
- ...oe({
143
- product: t,
144
- currency: k.currency,
145
- unitNamesById: I
146
- })
147
- } : n), { validate: !0 });
148
- }, [
149
- Q,
150
- I,
151
- k.currency
152
- ]), $ = u((e, t) => {
153
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
154
- ...n,
155
- ...t.patch
156
- } : n), { validate: !0 });
157
- }, [Q]), Ue = u((e, t) => {
158
- let n = k.lineItems.find((t) => t.id === e);
159
- n && $(e, te({
160
- lineItem: n,
161
- field: t,
162
- rowCount: k.lineItems.length,
163
- currency: k.currency
164
- }));
165
- }, [
166
- $,
167
- k.currency,
168
- k.lineItems
169
- ]), We = u((e, t) => {
170
- let n = k.lineItems.find((t) => t.id === e);
171
- n && $(e, ue({
172
- lineItem: n,
173
- step: t,
174
- rowCount: k.lineItems.length
175
- }));
176
- }, [$, k.lineItems]), Ge = u(() => {
177
- let e = o(k.currency);
178
- L(e.id), A((t) => ({
179
- ...t,
180
- lineItems: [...t.lineItems, e]
181
- }));
182
- }, [k.currency]), Ke = u((e) => {
183
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
184
- }, [Q]), qe = u(async () => {
185
- if (X) return;
186
- if (P.isLoading) {
187
- j({ form: h.lineItemsLoading });
188
- return;
189
- }
190
- let e = de(k.lineItems), n = e.length === k.lineItems.length ? k : {
191
- ...k,
192
- lineItems: e
193
- };
194
- n !== k && A(n);
195
- let r = Se({
196
- values: n,
197
- billingAddressId: U,
198
- messages: h
36
+ let F = d((e) => {
37
+ let t = C.find((t) => t.id === e);
38
+ t && b({
39
+ bankAccountId: t.id,
40
+ bankAccountType: t.type
199
41
  });
200
- if (_e(r)) {
201
- j(r), z(!0);
202
- return;
203
- }
204
- j({});
205
- try {
206
- if (T === "edit" && D) {
207
- let e = { receivable_id: D };
208
- await y.mutateAsync({
209
- path: e,
210
- body: be({
211
- values: n,
212
- billingAddressId: U ?? "",
213
- lineItemChanges: ye({
214
- values: n,
215
- originalLineItems: b.current,
216
- originalCurrency: x.current,
217
- unitNamesById: I,
218
- units: F
219
- })
220
- })
221
- }), q(), w(!1), Y();
222
- return;
223
- }
224
- let e = await v.mutateAsync({ body: ve({
225
- values: n,
226
- billingAddressId: U ?? "",
227
- unitNamesById: I
228
- }) });
229
- w(!1), Y(), e?.id && _?.(e.id, e.type);
230
- } catch (e) {
231
- j({ form: t(e) ?? h.genericError });
42
+ }, [b, C]), I = d(() => O(!0), []), L = d(() => {
43
+ O(!1), A(a), M({});
44
+ }, []), R = d((e) => A((t) => ({
45
+ ...t,
46
+ ...e
47
+ })), []), z = d(async () => {
48
+ let n = u(k, y);
49
+ if (M(n), !(Object.keys(n).length > 0)) try {
50
+ let t = await E.mutateAsync({ body: o(k) });
51
+ O(!1), A(a), b({
52
+ bankAccountId: t.id,
53
+ bankAccountType: "BANK_DETAILS"
54
+ }), e.success(y.bankAccountCreated.replace("{name}", t.display_name ?? ""));
55
+ } catch (n) {
56
+ e.error(t(n) ?? y.bankAccountCreateFailed);
232
57
  }
233
58
  }, [
234
- U,
235
- q,
236
- v,
237
- D,
238
- X,
239
- h,
240
- T,
241
- _,
242
- Y,
243
- F,
244
- I,
245
- P.isLoading,
59
+ E,
60
+ k,
246
61
  y,
247
- k
248
- ]), Je = f(() => ({
249
- ...k,
250
- lineItems: k.lineItems.map(pe)
251
- }), [k]), Ye = f(() => ee(k.lineItems), [k.lineItems]), Xe = f(() => Te({
252
- lineItems: k.lineItems.filter((e) => !ae(e)),
253
- currency: k.currency,
254
- taxRate: Number(k.taxRate) || void 0
62
+ b
63
+ ]), B = p(() => c({
64
+ accounts: C,
65
+ embeddedBankName: v,
66
+ messages: y
255
67
  }), [
256
- k.currency,
257
- k.lineItems,
258
- k.taxRate
68
+ v,
69
+ y,
70
+ C
259
71
  ]);
260
72
  return {
261
- open: C,
262
- setOpen: w,
263
- mode: T,
264
- values: k,
265
- sheetValues: Je,
266
- errors: Oe,
267
- setValues: A,
268
- updateValues: ze,
269
- commitTaxRate: Be,
270
- updateLineItem: Ve,
271
- selectProduct: He,
272
- commitLineItem: Ue,
273
- stepLineItem: We,
274
- addLineItem: Ge,
275
- removeLineItem: Ke,
276
- attachmentsView: Pe,
277
- attachmentsUploading: W.isUploading,
278
- saveDisabled: P.isLoading || W.isUploading,
279
- selectAttachmentFiles: W.selectFiles,
280
- setAttachmentIncludeInEmail: W.setIncludeInEmail,
281
- removeAttachment: W.remove,
282
- autoFocusLineItemId: Ae,
283
- lineItemUnitOptions: N.unitOptions,
284
- lineItemsLoading: P.isLoading,
285
- lineItemControls: Ye,
286
- totals: Xe,
287
- currencySymbol: ie(k.currency),
288
- isSubmitting: v.isPending || y.isPending,
289
- currencyOptions: Ee(k.currency),
290
- paymentTermsOptions: ge(S.data?.data),
291
- openCreate: Ie,
292
- openEdit: Le,
293
- close: Re,
294
- submit: qe,
295
- units: N,
296
- counterpartView: M,
297
- counterpartForm: J,
298
- stateOptions: V,
299
- openCounterpartCreate: J.openCreate
73
+ view: p(() => s({
74
+ options: B,
75
+ isLoading: w,
76
+ selectedId: _,
77
+ isAddingAccount: D,
78
+ canAddAccount: S.canAddAccount,
79
+ formValues: k,
80
+ formErrors: j,
81
+ isSaving: E.isPending
82
+ }), [
83
+ _,
84
+ E.isPending,
85
+ j,
86
+ k,
87
+ D,
88
+ w,
89
+ B,
90
+ S.canAddAccount
91
+ ]),
92
+ reset: P,
93
+ selectAccount: F,
94
+ openAddAccount: I,
95
+ cancelAddAccount: L,
96
+ updateAccountForm: R,
97
+ saveAccount: z
300
98
  };
301
99
  }
302
100
  //#endregion
303
- export { h as useReceivableForm };
101
+ export { g as useReceivableBankAccount };
@@ -1,75 +1,52 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index8.js";
6
- import { useReceivablesQuery as r } from "../../data-access/dist/index9.js";
7
- import "../../data-access/dist/index.js";
8
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
1
+ import { parseQuantity as e, priceInputToMinorUnits as t } from "./index6.js";
9
2
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js
10
- var c = [];
11
- function l({ activeTab: l, messages: d }) {
12
- let [f, p] = s([]), [m, h] = s(10), [g, _] = s(), [v, y] = s(""), [b, x] = s(""), [S, C] = s("all");
13
- a(() => {
14
- _(void 0), C("all");
15
- }, [l]), a(() => {
16
- let e = setTimeout(() => {
17
- x(v), _(void 0);
18
- }, 300);
19
- return () => clearTimeout(e);
20
- }, [v]);
21
- let w = f[0]?.id, T = w ? u[w] : void 0, E = f[0] ? f[0].desc ? "desc" : "asc" : void 0, D = r({
22
- type: n(l),
23
- limit: m,
24
- pagination_token: g,
25
- search_text: b || void 0,
26
- status: S === "all" ? void 0 : S,
27
- ...T ? {
28
- sort: T,
29
- order: E
30
- } : {}
31
- }), O = D.data?.data ?? c, k = o(() => new Map(O.map((e) => [e.id, e])), [O]), A = i((e) => k.get(e), [k]), j = o(() => e({
32
- receivables: O,
33
- messages: d
34
- }), [d, O]), M = !!b || S !== "all", N = i((e) => {
35
- let t = typeof e == "function" ? e(f) : e;
36
- p(t), _(void 0);
37
- }, [f]), P = i((e) => {
38
- h(e), _(void 0);
39
- }, []), F = i((e) => {
40
- C(e), _(void 0);
41
- }, []), I = i(() => _(D.data?.next_pagination_token ?? void 0), [D.data?.next_pagination_token]), L = i(() => _(D.data?.prev_pagination_token ?? void 0), [D.data?.prev_pagination_token]), R = i(() => {
42
- D.refetch();
43
- }, [D]);
3
+ var n = 1e4;
4
+ function r({ lineItems: n, currency: r, taxRate: i }) {
5
+ let a = i ? i / 100 : 0, o = 0, s = 0;
6
+ for (let i of n) {
7
+ let n = Math.round(t(i.price, r) * e(i.quantity));
8
+ i.taxable ? o += n : s += n;
9
+ }
44
10
  return {
45
- rows: j,
46
- isLoading: D.isLoading,
47
- isError: D.isError,
48
- sorting: f,
49
- onSortingChange: N,
50
- pageSize: m,
51
- onPageSizeChange: P,
52
- hasNextPage: !!D.data?.next_pagination_token,
53
- hasPrevPage: !!D.data?.prev_pagination_token,
54
- onNextPage: I,
55
- onPrevPage: L,
56
- searchValue: v,
57
- onSearchChange: y,
58
- statusFilter: S,
59
- statusOptions: t(),
60
- onStatusFilterChange: F,
61
- isFiltering: M,
62
- onRetry: R,
63
- getReceivableById: A
11
+ taxableItemsSubtotal: o,
12
+ nonTaxableItemsSubtotal: s,
13
+ subtotal: o + s,
14
+ rate: a
15
+ };
16
+ }
17
+ function i({ discount: e, subtotal: t }) {
18
+ if (!e) return 0;
19
+ let r = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / n));
20
+ return Math.min(Math.max(r, 0), t);
21
+ }
22
+ function a({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
23
+ let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
24
+ return {
25
+ taxableSubtotal: e - i,
26
+ nonTaxableSubtotal: t - (n - i)
27
+ };
28
+ }
29
+ function o({ lineItems: e, currency: t, taxRate: n, discount: o }) {
30
+ let s = r({
31
+ lineItems: e,
32
+ currency: t,
33
+ taxRate: n
34
+ }), c = i({
35
+ discount: o,
36
+ subtotal: s.subtotal
37
+ }), { taxableSubtotal: l, nonTaxableSubtotal: u } = a({
38
+ ...s,
39
+ discountAmount: c
40
+ }), d = s.rate ? Math.round(l * s.rate) : 0, f = s.subtotal - c;
41
+ return {
42
+ ...s,
43
+ discountAmount: c,
44
+ discountedSubtotal: f,
45
+ taxableSubtotal: l,
46
+ nonTaxableSubtotal: u,
47
+ totalTaxes: d,
48
+ total: f + d
64
49
  };
65
50
  }
66
- var u = {
67
- documentLabel: "document_id",
68
- customerLabel: "counterpart_name",
69
- status: "status",
70
- issueDateLabel: "issue_date",
71
- dueDateLabel: "due_date",
72
- totalLabel: "total_amount"
73
- };
74
51
  //#endregion
75
- export { l as useReceivablesTable };
52
+ export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };