@tesouro/embedded-components-react 0.5.206 → 0.5.210

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