@tesouro/embedded-components-react 0.5.206 → 0.5.207

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