@tesouro/embedded-components-react 0.5.201 → 0.5.203

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 (61) hide show
  1. package/README.md +20 -6
  2. package/dist/index.css +3 -0
  3. package/dist/index.d.ts +82 -7
  4. package/dist/index.js +8 -7
  5. package/dist/lib/MarketingWidget.d.ts +66 -7
  6. package/dist/lib/MarketingWidget.js +5 -4
  7. package/dist/lib/ReceivablesWidget.d.ts +16 -0
  8. package/dist/lib/ReceivablesWidget.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +6 -6
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +24 -18
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index4.js +65 -2
  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 +188 -45
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +30 -265
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +144 -64
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +47 -109
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +293 -216
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +75 -0
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +114 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +237 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index4.js +14 -1
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +28 -243
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +212 -375
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +64 -62
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +409 -187
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +73 -40
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +0 -9
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +4 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +10 -263
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -72
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +241 -398
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +66 -100
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +406 -76
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +92 -330
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +93 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +344 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +6 -1
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +157 -20
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +24 -1
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +1 -3
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +3 -18
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +2 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +18 -4
  45. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index.js +5 -4
  46. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index3.js +1 -0
  47. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index4.js +33 -81
  48. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index5.js +34 -0
  49. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index6.js +20 -0
  50. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index7.js +161 -0
  51. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index.js +3 -3
  52. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index3.js +5 -1
  53. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index8.js +34 -81
  54. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index9.js +92 -0
  55. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -37
  56. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +54 -54
  57. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +115 -94
  58. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationApplicationStatus.js +25 -0
  59. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationOnboardingSuppression.js +9 -9
  60. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  61. package/package.json +1 -1
@@ -1,52 +1,195 @@
1
- import { parseQuantity as e, priceInputToMinorUnits as t } from "./index5.js";
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { extractApiErrorMessage as e } from "../../../shared/util/dist/lib/apiErrors.js";
6
+ import { defaultPaymentValues as t, defaultSendValues as n, fromMajorUnits as r, hasPaymentErrors as i, hasSendErrors as a, splitEmailList as o, validatePaymentValues as s, validateSendValues as c } from "./index8.js";
7
+ import { useSendReceivableEmailMutation as l } from "../../data-access/dist/index5.js";
8
+ import { useAcceptReceivableMutation as ee, useCancelReceivableMutation as te, useCloneReceivableMutation as u, useDeclineReceivableMutation as d, useDeleteReceivableMutation as f, useIssueReceivableMutation as p } from "../../data-access/dist/index6.js";
9
+ import { useMarkReceivablePaidMutation as m, useMarkReceivablePartiallyPaidMutation as h, useMarkReceivableUncollectibleMutation as g } from "../../data-access/dist/index8.js";
10
+ import "../../data-access/dist/index.js";
11
+ import { useCallback as _, useState as v } from "react";
2
12
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js
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
- }
13
+ function y({ selectedReceivable: y, messages: x, onCreated: S, onDeleted: C }) {
14
+ let w = p(), T = te(), E = u(), D = ee(), O = d(), k = f(), A = l(), j = m(), M = h(), N = g(), [P, F] = v(), [I, L] = v(), [R, z] = v(), [B, V] = v(() => n(void 0, x)), [H, U] = v({}), [W, G] = v(), [K, q] = v(() => t()), [J, Y] = v({}), X = _((e, r, i) => {
15
+ let a = "documentLabel" in r ? r.documentLabel : r.title, o = {
16
+ id: r.id,
17
+ type: r.type,
18
+ title: a,
19
+ action: e
20
+ }, s = i === void 0 ? y : i ?? void 0;
21
+ if (e === "send") {
22
+ z(o), V(n(s, x)), U({});
23
+ return;
24
+ }
25
+ if (e === "recordPayment") {
26
+ G({
27
+ ...o,
28
+ currency: s?.currency
29
+ }), q(t()), Y({});
30
+ return;
31
+ }
32
+ L(void 0), F(o);
33
+ }, [x, y]), Z = _(() => {
34
+ F(void 0), L(void 0);
35
+ }, []), Q = _(() => {
36
+ z(void 0), U({});
37
+ }, []), $ = _(() => {
38
+ G(void 0), Y({});
39
+ }, []), ne = _(async () => {
40
+ if (!P) return;
41
+ let t = { receivable_id: P.id };
42
+ try {
43
+ if (P.action === "issue") await w.mutateAsync({ path: t });
44
+ else if (P.action === "cancel") await T.mutateAsync({ path: t });
45
+ else if (P.action === "clone") {
46
+ let e = await E.mutateAsync({ path: t });
47
+ e?.id && S?.(e.id, e.type);
48
+ } else P.action === "accept" ? await D.mutateAsync({ path: t }) : P.action === "decline" ? await O.mutateAsync({ path: t }) : P.action === "delete" ? (await k.mutateAsync({ path: t }), C?.(P.id)) : P.action === "markPaid" ? await j.mutateAsync({
49
+ path: t,
50
+ body: { paid_at: (/* @__PURE__ */ new Date()).toISOString() }
51
+ }) : P.action === "markUncollectible" && await N.mutateAsync({ path: t });
52
+ F(void 0), L(void 0);
53
+ } catch (t) {
54
+ L(e(t) ?? x.genericError);
55
+ }
56
+ }, [
57
+ D,
58
+ P,
59
+ T,
60
+ E,
61
+ O,
62
+ k,
63
+ w,
64
+ j,
65
+ x.genericError,
66
+ S,
67
+ C,
68
+ N
69
+ ]), re = _(async () => {
70
+ if (!R) return;
71
+ let t = c(B, x);
72
+ if (a(t)) {
73
+ U(t);
74
+ return;
75
+ }
76
+ try {
77
+ await A.mutateAsync({
78
+ path: { receivable_id: R.id },
79
+ body: {
80
+ body_text: B.body,
81
+ subject_text: B.subject,
82
+ recipients: {
83
+ to: o(B.to),
84
+ cc: o(B.cc),
85
+ bcc: o(B.bcc)
86
+ }
87
+ }
88
+ }), Q();
89
+ } catch (t) {
90
+ U({ form: e(t) ?? x.genericError });
91
+ }
92
+ }, [
93
+ Q,
94
+ x,
95
+ A,
96
+ R,
97
+ B
98
+ ]), ie = _(async () => {
99
+ if (!W) return;
100
+ let t = s(K, x, W.currency);
101
+ if (i(t)) {
102
+ Y(t);
103
+ return;
104
+ }
105
+ try {
106
+ let e = { receivable_id: W.id }, t = K.paidAt ? new Date(K.paidAt).toISOString() : void 0;
107
+ K.mode === "full" ? await j.mutateAsync({
108
+ path: e,
109
+ body: {
110
+ comment: K.comment || void 0,
111
+ paid_at: t
112
+ }
113
+ }) : await M.mutateAsync({
114
+ path: e,
115
+ body: {
116
+ amount_paid: r(K.amountPaid, W.currency) ?? 0,
117
+ comment: K.comment || void 0
118
+ }
119
+ }), $();
120
+ } catch (t) {
121
+ Y({ form: e(t) ?? x.genericError });
122
+ }
123
+ }, [
124
+ $,
125
+ j,
126
+ x,
127
+ M,
128
+ W,
129
+ K
130
+ ]);
10
131
  return {
11
- taxableItemsSubtotal: o,
12
- nonTaxableItemsSubtotal: s,
13
- subtotal: o + s,
14
- rate: a
132
+ actionTarget: P,
133
+ actionDialog: P ? b(P.action, x) : void 0,
134
+ actionError: I,
135
+ actionInProgress: w.isPending || T.isPending || E.isPending || D.isPending || O.isPending || k.isPending || j.isPending || N.isPending,
136
+ openAction: X,
137
+ closeAction: Z,
138
+ confirmAction: ne,
139
+ sendOpen: !!R,
140
+ sendValues: B,
141
+ sendErrors: H,
142
+ sendInProgress: A.isPending,
143
+ setSendValues: V,
144
+ closeSend: Q,
145
+ submitSend: re,
146
+ paymentOpen: !!W,
147
+ paymentValues: K,
148
+ paymentErrors: J,
149
+ paymentInProgress: j.isPending || M.isPending,
150
+ setPaymentValues: q,
151
+ closePayment: $,
152
+ submitPayment: ie
15
153
  };
16
154
  }
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
155
+ function b(e, t) {
156
+ return e === "issue" ? {
157
+ title: t.issueTitle,
158
+ description: t.issueDescription,
159
+ confirmLabel: t.issueConfirm
160
+ } : e === "accept" ? {
161
+ title: t.acceptTitle,
162
+ description: t.acceptDescription,
163
+ confirmLabel: t.acceptConfirm
164
+ } : e === "decline" ? {
165
+ title: t.declineTitle,
166
+ description: t.declineDescription,
167
+ confirmLabel: t.declineConfirm,
168
+ destructive: !0
169
+ } : e === "cancel" ? {
170
+ title: t.cancelTitle,
171
+ description: t.cancelDescription,
172
+ confirmLabel: t.cancelConfirm,
173
+ destructive: !0
174
+ } : e === "clone" ? {
175
+ title: t.cloneTitle,
176
+ description: t.cloneDescription,
177
+ confirmLabel: t.cloneConfirm
178
+ } : e === "delete" ? {
179
+ title: t.deleteTitle,
180
+ description: t.deleteDescription,
181
+ confirmLabel: t.deleteConfirm,
182
+ destructive: !0
183
+ } : e === "markPaid" ? {
184
+ title: t.markPaidTitle,
185
+ description: t.markPaidDescription,
186
+ confirmLabel: t.markPaidConfirm
187
+ } : {
188
+ title: t.markUncollectibleTitle,
189
+ description: t.markUncollectibleDescription,
190
+ confirmLabel: t.markUncollectibleConfirm,
191
+ destructive: !0
49
192
  };
50
193
  }
51
194
  //#endregion
52
- export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };
195
+ export { y as useReceivableActions };
@@ -2,276 +2,41 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { getStateOptions as e } from "../../../shared/util/dist/lib/usStates.js";
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 ee } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
11
- import "../../../shared/counterpart-management/feature/dist/index.js";
12
- import { buildLineItemControls as te, commitLineItemField as ne, commitTaxRateInput as re, convertPriceInput as a, createLineItem as o, getCurrencySymbol as s, isBlankLineItem as ie, lineItemFromProduct as ae, reconcileMeasureUnits as oe, sanitizeLineItemPatch as se, sanitizeTaxRateInput as ce, stepLineItemQuantity as c, stripBlankLineItems as le, summarizeLineItemErrors as ue, toSheetLineItem as de, validateLineItems as fe } from "./index5.js";
13
- import { createEmptyReceivableFormValues as l, getPaymentTermOptions as pe, hasReceivableFormErrors as me, receivableFormValuesToCreatePayload as he, receivableFormValuesToLineItemChanges as ge, receivableFormValuesToUpdatePayload as _e, receivableToFormValues as ve, validateReceivableForm as ye } from "./index6.js";
14
- import { useCreateReceivableMutation as u, useUpdateReceivableMutation as d } from "../../data-access/dist/index6.js";
5
+ import { buildReceivableDetailsView as e } from "./index8.js";
6
+ import { useReceivableHistoryQuery as t, useReceivableMailsQuery as n, useReceivablePdfLinkQuery as r, useReceivableQuery as i } from "../../data-access/dist/index9.js";
15
7
  import "../../data-access/dist/index.js";
16
- import { calculateInvoiceTotals as f } from "./index10.js";
17
- import { getCurrencyOptions as p } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
18
- import { useMeasureUnitsQuery as m } from "../../../shared/product-catalog/data-access/dist/index9.js";
19
- import { useMeasureUnits as h } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
20
- import "../../../shared/product-catalog/feature/dist/index.js";
21
- import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
8
+ import { useMemo as a } from "react";
22
9
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
23
- function x({ messages: x, counterpartMessageLabels: S, onCreated: C }) {
24
- let w = u(), T = d(), E = y([]), D = y(""), O = n(), [k, A] = b(!1), [j, M] = b("create"), [N, P] = b(), [F, I] = b(() => l()), [be, L] = b({}), [R, xe] = b("none"), z = h(), B = m(), V = B.data?.data, { unitNamesById: H } = z, [Se, U] = b(), [W, G] = b(!1), K = y(!1), Ce = v(() => e(), []), we = v(() => ({
25
- ...r,
26
- ...S
27
- }), [S]), q = i(F.customerId), Te = q.data?.data?.[0], J = q.data?.data?.[0]?.id, Ee = g((e) => {
28
- I((t) => ({
29
- ...t,
30
- customerId: e ?? ""
31
- }));
32
- }, []), Y = ee({
33
- view: R,
34
- setView: xe,
35
- selectedId: F.customerId || void 0,
36
- setSelectedId: Ee,
37
- messages: we,
38
- counterpartType: "customer",
39
- counterpart: void 0,
40
- primaryAddress: Te
41
- }), X = g(() => {
42
- E.current = [], U(void 0), M("create"), P(void 0), I(l()), L({}), G(!1);
43
- }, []), De = g((e = "invoice") => {
44
- E.current = [], U(void 0), M("create"), P(void 0), I({
45
- ...l(),
46
- type: e
47
- }), L({}), G(!1), A(!0);
48
- }, []), Oe = g((e) => {
49
- e.type !== "credit_note" && (E.current = e.line_items, D.current = e.currency, U(void 0), M("edit"), P(e.id), I(ve(e, V)), L({}), G(!1), A(!0));
50
- }, [V]);
51
- _(() => {
52
- V?.length && I((e) => {
53
- let t = oe(e.lineItems, V);
54
- return t === e.lineItems ? e : {
55
- ...e,
56
- lineItems: t
57
- };
58
- });
59
- }, [V]);
60
- let ke = g(() => {
61
- A(!1), L({});
62
- }, []), Ae = g((e) => {
63
- let t = e.taxRate === void 0 ? e : {
64
- ...e,
65
- taxRate: ce(e.taxRate)
66
- }, { currency: n } = t;
67
- if (n === void 0) {
68
- I((e) => ({
69
- ...e,
70
- ...t
71
- }));
72
- return;
73
- }
74
- K.current = !0, I((e) => e.currency === n ? {
75
- ...e,
76
- ...t
77
- } : {
78
- ...e,
79
- ...t,
80
- lineItems: e.lineItems.map((t) => ({
81
- ...t,
82
- price: a(t.price, e.currency, n)
83
- }))
84
- });
85
- }, []), je = g(() => {
86
- I((e) => {
87
- let t = re(e.taxRate);
88
- return t === e.taxRate ? e : {
89
- ...e,
90
- taxRate: t
91
- };
92
- });
93
- }, []), Z = g((e, t) => {
94
- let n = fe(e, {
95
- currency: t,
96
- messages: x
97
- });
98
- L((e) => ({
99
- ...e,
100
- lineItems: n,
101
- lineItemsSummary: ue(n)
102
- }));
103
- }, [x]), Q = g((e, { validate: t }) => {
104
- t && (K.current = !0), I((t) => ({
105
- ...t,
106
- lineItems: e(t.lineItems)
107
- }));
108
- }, []);
109
- _(() => {
110
- K.current && (K.current = !1, Z(F.lineItems, F.currency));
111
- }, [
112
- Z,
113
- F.currency,
114
- F.lineItems
115
- ]);
116
- let Me = g((e, t) => {
117
- let { unit: n, ...r } = t, i = se(r);
118
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
119
- ...t,
120
- ...i
121
- } : t), { validate: W });
122
- }, [Q, W]), Ne = g((e, t) => {
123
- Q((n) => n.map((n) => n.id === e ? {
124
- ...n,
125
- ...ae({
126
- product: t,
127
- currency: F.currency,
128
- unitNamesById: H
129
- })
130
- } : n), { validate: !0 });
131
- }, [
132
- Q,
133
- H,
134
- F.currency
135
- ]), $ = g((e, t) => {
136
- t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
137
- ...n,
138
- ...t.patch
139
- } : n), { validate: !0 });
140
- }, [Q]), Pe = g((e, t) => {
141
- let n = F.lineItems.find((t) => t.id === e);
142
- n && $(e, ne({
143
- lineItem: n,
144
- field: t,
145
- rowCount: F.lineItems.length,
146
- currency: F.currency
147
- }));
148
- }, [
149
- $,
150
- F.currency,
151
- F.lineItems
152
- ]), Fe = g((e, t) => {
153
- let n = F.lineItems.find((t) => t.id === e);
154
- n && $(e, c({
155
- lineItem: n,
156
- step: t,
157
- rowCount: F.lineItems.length
158
- }));
159
- }, [$, F.lineItems]), Ie = g(() => {
160
- let e = o(F.currency);
161
- U(e.id), I((t) => ({
162
- ...t,
163
- lineItems: [...t.lineItems, e]
164
- }));
165
- }, [F.currency]), Le = g((e) => {
166
- Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
167
- }, [Q]), Re = g(async () => {
168
- if (B.isLoading) {
169
- L({ form: x.lineItemsLoading });
170
- return;
171
- }
172
- let e = le(F.lineItems), n = e.length === F.lineItems.length ? F : {
173
- ...F,
174
- lineItems: e
175
- };
176
- n !== F && I(n);
177
- let r = ye({
178
- values: n,
179
- billingAddressId: J,
180
- messages: x
181
- });
182
- if (me(r)) {
183
- L(r), G(!0);
184
- return;
185
- }
186
- L({});
187
- try {
188
- if (j === "edit" && N) {
189
- let e = { receivable_id: N };
190
- await T.mutateAsync({
191
- path: e,
192
- body: _e({
193
- values: n,
194
- billingAddressId: J ?? "",
195
- lineItemChanges: ge({
196
- values: n,
197
- originalLineItems: E.current,
198
- originalCurrency: D.current,
199
- unitNamesById: H,
200
- units: V
201
- })
202
- })
203
- }), A(!1), X();
204
- return;
205
- }
206
- let e = await w.mutateAsync({ body: he({
207
- values: n,
208
- billingAddressId: J ?? "",
209
- unitNamesById: H
210
- }) });
211
- A(!1), X(), e?.id && C?.(e.id, e.type);
212
- } catch (e) {
213
- L({ form: t(e) ?? x.genericError });
214
- }
215
- }, [
216
- J,
217
- w,
218
- N,
219
- x,
220
- j,
221
- C,
222
- X,
223
- V,
224
- H,
225
- B.isLoading,
226
- T,
227
- F
228
- ]), ze = v(() => ({
229
- ...F,
230
- lineItems: F.lineItems.map(de)
231
- }), [F]), Be = v(() => te(F.lineItems), [F.lineItems]), Ve = v(() => f({
232
- lineItems: F.lineItems.filter((e) => !ie(e)),
233
- currency: F.currency,
234
- taxRate: Number(F.taxRate) || void 0
10
+ function o({ selectedReceivableId: o, enabled: s = !0, messages: c }) {
11
+ let l = i(o, { enabled: s }), u = t(o, {
12
+ enabled: s,
13
+ limit: 25,
14
+ sort: "timestamp",
15
+ order: "desc"
16
+ }), d = n(o, {
17
+ enabled: s,
18
+ limit: 10,
19
+ sort: "created_at",
20
+ order: "desc"
21
+ }), f = r(o, { enabled: s && !!l.data }), p = a(() => e({
22
+ receivable: l.data,
23
+ history: u.data?.data ?? [],
24
+ mails: d.data?.data ?? [],
25
+ pdfUrl: f.data?.file_url || f.data?.original_file_url || void 0,
26
+ messages: c
235
27
  }), [
236
- F.currency,
237
- F.lineItems,
238
- F.taxRate
28
+ l.data,
29
+ u.data?.data,
30
+ d.data?.data,
31
+ c,
32
+ f.data
239
33
  ]);
240
34
  return {
241
- open: k,
242
- setOpen: A,
243
- mode: j,
244
- values: F,
245
- sheetValues: ze,
246
- errors: be,
247
- setValues: I,
248
- updateValues: Ae,
249
- commitTaxRate: je,
250
- updateLineItem: Me,
251
- selectProduct: Ne,
252
- commitLineItem: Pe,
253
- stepLineItem: Fe,
254
- addLineItem: Ie,
255
- removeLineItem: Le,
256
- autoFocusLineItemId: Se,
257
- lineItemUnitOptions: z.unitOptions,
258
- lineItemsLoading: B.isLoading,
259
- lineItemControls: Be,
260
- totals: Ve,
261
- currencySymbol: s(F.currency),
262
- isSubmitting: w.isPending || T.isPending,
263
- currencyOptions: p(F.currency),
264
- paymentTermsOptions: pe(O.data?.data),
265
- openCreate: De,
266
- openEdit: Oe,
267
- close: ke,
268
- submit: Re,
269
- units: z,
270
- counterpartView: R,
271
- counterpartForm: Y,
272
- stateOptions: Ce,
273
- openCounterpartCreate: Y.openCreate
35
+ receivable: l.data,
36
+ detailsView: p,
37
+ isLoading: l.isLoading || u.isLoading || d.isLoading || f.isLoading,
38
+ isError: l.isError
274
39
  };
275
40
  }
276
41
  //#endregion
277
- export { x as useReceivableForm };
42
+ export { o as useReceivableDetails };