@tesouro/embedded-components-react 0.5.205 → 0.5.206

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 (48) hide show
  1. package/dist/index.d.ts +11 -4
  2. package/dist/index.js +1 -1
  3. package/dist/lib/ReceivablesWidget.d.ts +11 -4
  4. package/dist/lib/ReceivablesWidget.js +1 -1
  5. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +88 -193
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +184 -31
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +32 -145
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +150 -58
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +35 -89
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +53 -42
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +82 -299
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +47 -70
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +321 -100
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +68 -246
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +115 -0
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +270 -0
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +93 -407
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +422 -86
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +16 -12
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +92 -16
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +3 -1
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +24 -4
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +0 -10
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +2 -0
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +3 -264
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +16 -70
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +1 -424
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +4 -106
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +12 -93
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +5 -179
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +1 -344
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +264 -0
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +72 -0
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +401 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +106 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +93 -0
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +344 -0
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +182 -32
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +29 -202
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +183 -137
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +157 -20
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +16 -1
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +25 -3
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +4 -3
  47. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  48. package/package.json +1 -1
@@ -2,317 +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 Ce, useUpdateReceivableMutation as we } 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 Te } from "./index12.js";
18
- import { useReceivableBankAccount as Ee } from "./index14.js";
19
- import { calculateInvoiceTotals as De } from "./index15.js";
20
- import { getCurrencyOptions as Oe } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
21
- import { useMeasureUnitsQuery as ke } from "../../../shared/product-catalog/data-access/dist/index9.js";
22
- import { useMeasureUnits as Ae } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
23
- import "../../../shared/product-catalog/feature/dist/index.js";
24
- import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } 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 "./index15.js";
13
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
25
14
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js
26
- function p({ messages: p, counterpartMessageLabels: m, embeddedBankName: je, onCreated: h }) {
27
- let g = Ce(), _ = we(), v = d([]), y = d(""), b = n(), [x, S] = f(!1), [C, w] = f("create"), [T, E] = f(), [D, O] = f(() => s()), [Me, k] = f({}), [A, Ne] = f("none"), j = Ae(), M = ke(), N = M.data?.data, { unitNamesById: P } = j, [Pe, F] = f(), [I, L] = f(!1), R = d(!1), z = u(() => e(), []), Fe = u(() => ({
28
- ...r,
29
- ...m
30
- }), [m]), B = i(D.customerId), Ie = B.data?.data?.[0], V = B.data?.data?.[0]?.id, Le = c((e) => {
31
- O((t) => ({
32
- ...t,
33
- attachments: e(t.attachments)
34
- }));
35
- }, []), H = Te({
36
- attachments: D.attachments,
37
- setAttachments: Le,
38
- receivableId: T
39
- }), { reset: U, discardUploads: W, commitRemovals: G } = H, Re = D.type === "invoice" ? he({
40
- attachments: D.attachments,
41
- pendingUploads: H.pendingUploads,
42
- isCountLimitReached: H.isCountLimitReached,
43
- isRecurring: !1,
44
- messages: p
45
- }) : void 0, ze = c((e) => {
46
- O((t) => ({
47
- ...t,
48
- customerId: e ?? ""
49
- }));
50
- }, []), K = a({
51
- view: A,
52
- setView: Ne,
53
- selectedId: D.customerId || void 0,
54
- setSelectedId: ze,
55
- messages: Fe,
56
- counterpartType: "customer",
57
- counterpart: void 0,
58
- primaryAddress: Ie
59
- }), Be = c((e) => O((t) => ({
60
- ...t,
61
- ...e
62
- })), []), q = Ee({
63
- open: x,
64
- bankAccountId: D.bankAccountId,
65
- embeddedBankName: je,
66
- messages: p,
67
- onSelect: Be
68
- }), J = q.reset, Y = c(() => {
69
- v.current = [], F(void 0), w("create"), E(void 0), O(s()), k({}), L(!1), U();
70
- }, [U]), Ve = c((e = "invoice") => {
71
- J(), v.current = [], F(void 0), w("create"), E(void 0), O({
72
- ...s(),
73
- type: e
74
- }), k({}), U(), L(!1), S(!0);
75
- }, [U, J]), He = c((e) => {
76
- e.type !== "credit_note" && (J(), v.current = e.line_items, y.current = e.currency, F(void 0), w("edit"), E(e.id), O(xe(e, N)), k({}), L(!1), U(), S(!0));
77
- }, [
78
- U,
79
- J,
80
- N
81
- ]);
82
- l(() => {
83
- N?.length && O((e) => {
84
- let t = se(e.lineItems, N);
85
- return t === e.lineItems ? e : {
86
- ...e,
87
- lineItems: t
88
- };
89
- });
90
- }, [N]);
91
- let X = H.isUploading, Ue = c(() => {
92
- X || (W(), S(!1), k({}));
93
- }, [W, X]), We = c((e) => {
94
- let t = e.taxRate === void 0 ? e : {
95
- ...e,
96
- taxRate: le(e.taxRate)
97
- }, { currency: n, type: r } = t;
98
- if (r !== void 0 && r !== "invoice" && W(), n === void 0) {
99
- O((e) => ({
100
- ...e,
101
- ...t
102
- }));
103
- return;
104
- }
105
- R.current = !0, O((e) => e.currency === n ? {
106
- ...e,
107
- ...t
108
- } : {
109
- ...e,
110
- ...t,
111
- lineItems: e.lineItems.map((t) => ({
112
- ...t,
113
- price: re(t.price, e.currency, n)
114
- }))
115
- });
116
- }, [W]), Ge = c(() => {
117
- O((e) => {
118
- let t = ne(e.taxRate);
119
- return t === e.taxRate ? e : {
120
- ...e,
121
- taxRate: t
122
- };
123
- });
124
- }, []), Z = c((e, t) => {
125
- let n = me(e, {
126
- currency: t,
127
- messages: p
128
- });
129
- k((e) => ({
130
- ...e,
131
- lineItems: n,
132
- lineItemsSummary: fe(n)
133
- }));
134
- }, [p]), Q = c((e, { validate: t }) => {
135
- t && (R.current = !0), O((t) => ({
136
- ...t,
137
- lineItems: e(t.lineItems)
138
- }));
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({});
139
22
  }, []);
140
- l(() => {
141
- R.current && (R.current = !1, Z(D.lineItems, D.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
+ });
142
30
  }, [
143
- Z,
144
- D.currency,
145
- D.lineItems
31
+ T,
32
+ b,
33
+ g,
34
+ C
146
35
  ]);
147
- let Ke = c((e, t) => {
148
- let { unit: n, ...r } = t, i = ce(r);
149
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
150
- ...t,
151
- ...i
152
- } : t), { validate: I });
153
- }, [Q, I]), qe = c((e, t) => {
154
- Q((n) => n.map((n) => n.id === e ? {
155
- ...n,
156
- ...oe({
157
- product: t,
158
- currency: D.currency,
159
- unitNamesById: P
160
- })
161
- } : n), { validate: !0 });
162
- }, [
163
- Q,
164
- P,
165
- D.currency
166
- ]), $ = c((e, t) => {
167
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
168
- ...n,
169
- ...t.patch
170
- } : n), { validate: !0 });
171
- }, [Q]), Je = c((e, t) => {
172
- let n = D.lineItems.find((t) => t.id === e);
173
- n && $(e, te({
174
- lineItem: n,
175
- field: t,
176
- rowCount: D.lineItems.length,
177
- currency: D.currency
178
- }));
179
- }, [
180
- $,
181
- D.currency,
182
- D.lineItems
183
- ]), Ye = c((e, t) => {
184
- let n = D.lineItems.find((t) => t.id === e);
185
- n && $(e, ue({
186
- lineItem: n,
187
- step: t,
188
- rowCount: D.lineItems.length
189
- }));
190
- }, [$, D.lineItems]), Xe = c(() => {
191
- let e = o(D.currency);
192
- F(e.id), O((t) => ({
193
- ...t,
194
- lineItems: [...t.lineItems, e]
195
- }));
196
- }, [D.currency]), Ze = c((e) => {
197
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
198
- }, [Q]), Qe = c(async () => {
199
- if (X) return;
200
- if (M.isLoading) {
201
- k({ form: p.lineItemsLoading });
202
- return;
203
- }
204
- let e = de(D.lineItems), n = e.length === D.lineItems.length ? D : {
205
- ...D,
206
- lineItems: e
207
- };
208
- n !== D && O(n);
209
- let r = Se({
210
- values: n,
211
- billingAddressId: V,
212
- messages: p
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
213
41
  });
214
- if (_e(r)) {
215
- k(r), L(!0);
216
- return;
217
- }
218
- k({});
219
- try {
220
- if (C === "edit" && T) {
221
- let e = { receivable_id: T };
222
- await _.mutateAsync({
223
- path: e,
224
- body: be({
225
- values: n,
226
- billingAddressId: V ?? "",
227
- lineItemChanges: ye({
228
- values: n,
229
- originalLineItems: v.current,
230
- originalCurrency: y.current,
231
- unitNamesById: P,
232
- units: N
233
- })
234
- })
235
- }), G(), S(!1), Y();
236
- return;
237
- }
238
- let e = await g.mutateAsync({ body: ve({
239
- values: n,
240
- billingAddressId: V ?? "",
241
- unitNamesById: P
242
- }) });
243
- S(!1), Y(), e?.id && h?.(e.id, e.type);
244
- } catch (e) {
245
- k({ form: t(e) ?? p.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);
246
57
  }
247
58
  }, [
248
- V,
249
- G,
250
- g,
251
- T,
252
- X,
253
- p,
254
- C,
255
- h,
256
- Y,
257
- N,
258
- P,
259
- M.isLoading,
260
- _,
261
- D
262
- ]), $e = u(() => ({
263
- ...D,
264
- lineItems: D.lineItems.map(pe)
265
- }), [D]), et = u(() => ee(D.lineItems), [D.lineItems]), tt = u(() => De({
266
- lineItems: D.lineItems.filter((e) => !ae(e)),
267
- currency: D.currency,
268
- taxRate: Number(D.taxRate) || void 0
59
+ E,
60
+ k,
61
+ y,
62
+ b
63
+ ]), B = p(() => c({
64
+ accounts: C,
65
+ embeddedBankName: v,
66
+ messages: y
269
67
  }), [
270
- D.currency,
271
- D.lineItems,
272
- D.taxRate
68
+ v,
69
+ y,
70
+ C
273
71
  ]);
274
72
  return {
275
- open: x,
276
- setOpen: S,
277
- mode: C,
278
- values: D,
279
- sheetValues: $e,
280
- errors: Me,
281
- setValues: O,
282
- updateValues: We,
283
- commitTaxRate: Ge,
284
- updateLineItem: Ke,
285
- selectProduct: qe,
286
- commitLineItem: Je,
287
- stepLineItem: Ye,
288
- addLineItem: Xe,
289
- removeLineItem: Ze,
290
- attachmentsView: Re,
291
- attachmentsUploading: H.isUploading,
292
- saveDisabled: M.isLoading || H.isUploading,
293
- selectAttachmentFiles: H.selectFiles,
294
- setAttachmentIncludeInEmail: H.setIncludeInEmail,
295
- removeAttachment: H.remove,
296
- autoFocusLineItemId: Pe,
297
- lineItemUnitOptions: j.unitOptions,
298
- lineItemsLoading: M.isLoading,
299
- lineItemControls: et,
300
- totals: tt,
301
- currencySymbol: ie(D.currency),
302
- isSubmitting: g.isPending || _.isPending,
303
- currencyOptions: Oe(D.currency),
304
- paymentTermsOptions: ge(b.data?.data),
305
- openCreate: Ve,
306
- openEdit: He,
307
- close: Ue,
308
- submit: Qe,
309
- units: j,
310
- counterpartView: A,
311
- counterpartForm: K,
312
- stateOptions: z,
313
- openCounterpartCreate: K.openCreate,
314
- bankAccount: q
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
315
98
  };
316
99
  }
317
100
  //#endregion
318
- export { p 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/index17.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 };