@tesouro/embedded-components-react 0.5.227 → 0.5.230

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 (90) hide show
  1. package/README.md +22 -21
  2. package/dist/index.d.ts +87 -34
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +87 -34
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +5 -5
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +29 -59
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index11.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index5.js +32 -33
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index6.js +34 -32
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index7.js +1 -1
  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 +120 -52
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +44 -100
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +93 -442
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +356 -201
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +225 -157
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +152 -21
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +18 -221
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +220 -31
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +125 -124
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +58 -150
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +232 -46
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +303 -122
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +43 -58
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +125 -98
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index24.js +140 -106
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index25.js +46 -232
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index26.js +119 -29
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index27.js +81 -613
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index28.js +116 -39
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index29.js +27 -33
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index30.js +634 -72
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index31.js +39 -119
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index32.js +36 -317
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index33.js +82 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index34.js +139 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index35.js +340 -0
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +15 -2
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +55 -468
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +443 -97
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +24 -22
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +32 -2
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +205 -84
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +161 -3
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +12 -20
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +25 -1
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +4 -3
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +95 -3
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +3 -18
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +24 -1
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +42 -4
  54. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +14 -7
  55. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +19 -12
  56. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +73 -1
  57. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +17 -261
  58. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +12 -44
  59. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +28 -68
  60. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +288 -479
  61. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +1 -106
  62. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +48 -0
  63. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index28.js +72 -2
  64. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index29.js +496 -4
  65. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +121 -27
  66. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index30.js +106 -1
  67. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index32.js +2 -28
  68. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index33.js +4 -236
  69. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index34.js +0 -2
  70. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index35.js +90 -239
  71. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index36.js +24 -89
  72. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index37.js +231 -54
  73. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index38.js +3 -353
  74. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index39.js +249 -0
  75. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +100 -207
  76. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index40.js +93 -0
  77. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index41.js +59 -0
  78. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index42.js +353 -0
  79. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +35 -29
  80. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +2 -216
  81. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +9 -159
  82. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +27 -14
  83. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +216 -23
  84. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +40 -40
  85. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +189 -211
  86. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +43 -59
  87. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  88. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/index.js +12 -12
  89. package/package.json +1 -1
  90. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index31.js +0 -100
@@ -2,81 +2,643 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { buildReceivableRows as e, statusFilterOptions as t, typeForTab as n } from "./index12.js";
6
- import { useReceivablesQuery as r } from "../../data-access/dist/index10.js";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { getStateOptions as t } from "../../../shared/util/dist/lib/usStates.js";
7
+ import "../../../shared/ui/dist/index.js";
8
+ import { COUNTERPART_MESSAGE_LABELS_EN as n } from "../../../shared/counterpart-management/feature/dist/lib/labels.js";
9
+ import { getCounterpartEmail as r } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
10
+ import { useCounterpartAddressesQuery as i } from "../../../shared/counterpart-management/data-access/dist/index7.js";
11
+ import { useCounterpartForm as a } from "../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
12
+ import "../../../shared/counterpart-management/feature/dist/index.js";
13
+ import "../../ui/dist/index15.js";
14
+ import "../../ui/dist/index.js";
15
+ import { buildLineItemControls as o, commitLineItemField as s, commitTaxRateInput as c, convertPriceInput as l, createLineItem as u, getCurrencySymbol as ee, lineItemFromProduct as te, reconcileLineItemIds as ne, reconcileMeasureUnits as re, sanitizeLineItemPatch as ie, sanitizeTaxRateInput as ae, stepLineItemQuantity as oe, stripBlankLineItems as se, summarizeLineItemErrors as ce, toSheetLineItem as le, validateLineItems as ue } from "./index6.js";
16
+ import { buildReceivableAttachmentsView as de } from "./index7.js";
17
+ import { getCurrencyOptions as fe } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
18
+ import { useMeasureUnitsQuery as pe } from "../../../shared/product-catalog/data-access/dist/index9.js";
19
+ import { useMeasureUnits as me } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
20
+ import "../../../shared/product-catalog/feature/dist/index.js";
21
+ import { getInlineItems as he } from "./index8.js";
22
+ import { buildCreateRecurrencePayload as ge, buildUpdateRecurrencePayload as _e, clearRecurrenceRecipients as ve, countIssuedIterations as ye, isRecurring as d, recurrenceToFormFields as be, validateRecurrence as xe, willRecurrenceIssue as Se } from "./index9.js";
23
+ import { convertDiscountInput as Ce, decorateDiscountInput as we, discountInputToMinorUnits as Te, sanitizeDiscountInput as Ee } from "./index11.js";
24
+ import { buildFormTotalsView as De, calculateFormTotals as Oe, validateDiscount as ke, validateInvoiceTotals as Ae } from "./index12.js";
25
+ import { createEmptyReceivableFormValues as je, hasReceivableFormErrors as Me, receivableFormValuesToCreatePayload as Ne, receivableFormValuesToLineItemChanges as Pe, receivableFormValuesToUpdatePayload as Fe, receivableToFormValues as Ie, submittedLineItemRows as Le, validateReceivableForm as Re } from "./index13.js";
26
+ import { getIssueReminderBlocker as ze, shouldShowRemindersInitially as Be } from "./index15.js";
27
+ import { useCreateReceivableMutation as Ve, useIssueReceivableMutation as He, useUpdateReceivableMutation as Ue } from "../../data-access/dist/index7.js";
28
+ import { useCreateRecurrenceMutation as We, useRecurrenceQuery as Ge, useUpdateRecurrenceMutation as Ke } from "../../data-access/dist/index11.js";
7
29
  import "../../data-access/dist/index.js";
8
- import { useReceivableStatusCards as i } from "./index29.js";
9
- import { useCallback as a, useEffect as o, useMemo as s, useState as c } from "react";
30
+ import { useReceivableIssuePreflight as qe } from "./index16.js";
31
+ import { UNSUBMITTED_PAYLOAD_VARIANTS as Je, apiValidationErrorsToFormErrors as Ye, getApiErrorMessage as Xe, parseApiValidationErrors as Ze } from "./index23.js";
32
+ import { useReceivableAttachmentUploads as Qe } from "./index24.js";
33
+ import { useReceivablePaymentTerms as $e } from "./index25.js";
34
+ import { useReceivableRecurrence as et } from "./index26.js";
35
+ import { useReceivableBankAccount as tt } from "./index27.js";
36
+ import { useReceivableReminders as nt } from "./index28.js";
37
+ import { useReceivablePreview as rt } from "./index29.js";
38
+ import { useCallback as f, useEffect as p, useMemo as m, useRef as h, useState as g } from "react";
10
39
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index30.js
11
- var l = [];
12
- function u({ activeTab: u, messages: f, statusLabels: p }) {
13
- let [m, h] = c([]), [g, _] = c(10), [v, y] = c(), [b, x] = c(""), [S, C] = c(""), [w, T] = c("all");
14
- o(() => {
15
- y(void 0), T("all");
16
- }, [u]), o(() => {
17
- let e = setTimeout(() => {
18
- C(b), y(void 0);
19
- }, 300);
20
- return () => clearTimeout(e);
21
- }, [b]);
22
- let E = m[0]?.id, D = E ? d[E] : void 0, O = m[0] ? m[0].desc ? "desc" : "asc" : void 0, k = r({
23
- type: n(u),
24
- limit: g,
25
- pagination_token: v,
26
- search_text: S || void 0,
27
- status: w === "all" ? void 0 : w,
28
- ...D ? {
29
- sort: D,
30
- order: O
31
- } : {}
32
- }), A = i({
33
- enabled: u === "invoices",
34
- statusFilter: w,
35
- messages: f,
36
- statusLabels: p
37
- }), j = k.data?.data ?? l, M = s(() => new Map(j.map((e) => [e.id, e])), [j]), N = a((e) => M.get(e), [M]), P = s(() => e({
38
- receivables: j,
39
- messages: f
40
- }), [f, j]), F = !!S || w !== "all", I = a((e) => {
41
- let t = typeof e == "function" ? e(m) : e;
42
- h(t), y(void 0);
43
- }, [m]), L = a((e) => {
44
- _(e), y(void 0);
45
- }, []), R = a((e) => {
46
- T(e), y(void 0);
47
- }, []), z = a(() => y(k.data?.next_pagination_token ?? void 0), [k.data?.next_pagination_token]), B = a(() => y(k.data?.prev_pagination_token ?? void 0), [k.data?.prev_pagination_token]), V = a(() => {
48
- k.refetch();
49
- }, [k]);
40
+ function _({ messages: _, counterpartMessageLabels: it, embeddedBankName: at, onCreated: ot }) {
41
+ let st = Ve(), ct = Ue(), lt = We(), ut = Ke(), dt = He(), v = h("draft"), ft = h(!1), y = h(!1), b = h(!1), pt = h(null), x = h(void 0), S = h([]), mt = h(""), [C, w] = g(!1), [T, ht] = g("create"), [gt, _t] = g(), [vt, yt] = g(), [E, D] = g(() => je()), [bt, O] = g({}), [xt, St] = g("none"), Ct = me(), k = pe(), A = k.data?.data, { unitNamesById: j } = Ct, [wt, Tt] = g(), [M, Et] = g(!1), Dt = h(!1), N = h(!1), P = h(!1), F = h({
42
+ lines: !1,
43
+ discount: !1
44
+ }), [Ot, I] = g(!1), kt = m(() => t(), []), At = m(() => ({
45
+ ...n,
46
+ ...it
47
+ }), [it]), L = i(E.customerId), jt = L.data?.data?.[0], R = L.data?.data?.[0]?.id, Mt = !!E.customerId && (L.isLoading || L.isFetching), z = qe({
48
+ counterpartId: E.customerId,
49
+ billingAddressId: R,
50
+ billingCountry: jt?.country
51
+ }), Nt = z.isLoading || Mt, Pt = f((e) => {
52
+ D((t) => ({
53
+ ...t,
54
+ attachments: e(t.attachments)
55
+ }));
56
+ }, []), B = Qe({
57
+ attachments: E.attachments,
58
+ setAttachments: Pt,
59
+ receivableId: gt
60
+ }), { reset: V, discardUploads: Ft, commitRemovals: It } = B, Lt = E.type === "invoice" ? de({
61
+ attachments: E.attachments,
62
+ pendingUploads: B.pendingUploads,
63
+ isCountLimitReached: B.isCountLimitReached,
64
+ isRecurring: d(E),
65
+ messages: _
66
+ }) : void 0, Rt = f((e) => {
67
+ D((t) => {
68
+ let n = e ?? "";
69
+ return n === t.customerId ? t : ve({
70
+ ...t,
71
+ customerId: n
72
+ });
73
+ });
74
+ }, []), zt = a({
75
+ view: xt,
76
+ setView: St,
77
+ selectedId: E.customerId || void 0,
78
+ setSelectedId: Rt,
79
+ messages: At,
80
+ counterpartType: "customer",
81
+ counterpart: void 0,
82
+ primaryAddress: jt
83
+ }), Bt = f((e) => D((t) => {
84
+ let n = e({
85
+ paymentTermsId: t.paymentTermsId,
86
+ paymentTermsCustomDate: t.paymentTermsCustomDate
87
+ });
88
+ return {
89
+ ...t,
90
+ ...n,
91
+ ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
92
+ };
93
+ }), []), Vt = $e({
94
+ paymentTermsId: E.paymentTermsId,
95
+ paymentTermsCustomDate: E.paymentTermsCustomDate,
96
+ issueDate: E.issueDate,
97
+ isRecurring: E.type === "invoice" && d(E),
98
+ messages: _,
99
+ onChange: Bt
100
+ }), Ht = Vt.reset, Ut = f((e) => D((t) => ({
101
+ ...t,
102
+ ...e
103
+ })), []), H = tt({
104
+ open: C,
105
+ bankAccountId: E.bankAccountId,
106
+ embeddedBankName: at,
107
+ messages: _,
108
+ onSelect: Ut
109
+ }), Wt = H.reset, Gt = Ge(vt), U = vt ? Gt.data : void 0, W = ye(U), Kt = W > 0, G = !!vt && Gt.isLoading, K = h(void 0);
110
+ p(() => {
111
+ U && K.current !== U.id && (K.current = U.id, D((e) => ({
112
+ ...e,
113
+ ...be(U)
114
+ })));
115
+ }, [U]);
116
+ let qt = f((e) => D(e), []), Jt = f((e) => O((t) => {
117
+ if (!e.some((e) => e in t)) return t;
118
+ let n = { ...t };
119
+ return e.forEach((e) => delete n[e]), n;
120
+ }), []), Yt = h([]), Xt = f((e) => {
121
+ if (!M) {
122
+ Jt(e);
123
+ return;
124
+ }
125
+ Yt.current.push(...e);
126
+ }, [Jt, M]);
127
+ p(() => {
128
+ let e = Yt.current;
129
+ if (!e.length) return;
130
+ Yt.current = [];
131
+ let t = xe({
132
+ fields: E,
133
+ issuedCount: W,
134
+ messages: _
135
+ });
136
+ O((n) => {
137
+ let r = { ...n };
138
+ return e.forEach((e) => {
139
+ t[e] ? r[e] = t[e] : delete r[e];
140
+ }), r;
141
+ });
142
+ }, [
143
+ W,
144
+ _,
145
+ E
146
+ ]);
147
+ let Zt = et({
148
+ values: E,
149
+ errors: bt,
150
+ lockSchedule: Kt,
151
+ messages: _,
152
+ onChange: qt,
153
+ onClearErrors: Jt,
154
+ onRevalidateErrors: Xt
155
+ }), q = Zt.reset, Qt = f((e) => D((t) => ({
156
+ ...t,
157
+ ...e
158
+ })), []), $t = st.isPending || ct.isPending || lt.isPending || ut.isPending || dt.isPending, en = nt({
159
+ open: C,
160
+ isInvoice: E.type === "invoice",
161
+ disabled: $t,
162
+ paymentTermsId: E.paymentTermsId,
163
+ paymentTermsCustomDate: E.paymentTermsCustomDate,
164
+ paymentReminderId: E.paymentReminderId,
165
+ overdueReminderId: E.overdueReminderId,
166
+ messages: _,
167
+ onSelect: Qt
168
+ }), tn = en.reset, nn = f(() => {
169
+ S.current = [], Tt(void 0), ht("create"), _t(void 0), yt(void 0), K.current = void 0, x.current = void 0, v.current = "draft", y.current = !1, b.current = !1, D(je()), O({}), Et(!1), I(!1), F.current = {
170
+ lines: !1,
171
+ discount: !1
172
+ }, V(), q();
173
+ }, [V, q]), rn = f((e = "invoice") => {
174
+ Ht(), Wt(), q();
175
+ let t = {
176
+ ...je(),
177
+ type: e
178
+ };
179
+ tn(Be(t)), S.current = [], x.current = void 0, v.current = "draft", y.current = !1, b.current = !1, K.current = void 0, Tt(void 0), ht("create"), _t(void 0), yt(void 0), D(t), O({}), V(), Et(!1), I(!1), F.current = {
180
+ lines: !1,
181
+ discount: !1
182
+ }, w(!0);
183
+ }, [
184
+ V,
185
+ Ht,
186
+ Wt,
187
+ q,
188
+ tn
189
+ ]), an = f((e, { highlightForIssue: t = !1 } = {}) => {
190
+ if (e.type === "credit_note") return;
191
+ Ht(), Wt(), q();
192
+ let n = Ie(e, A);
193
+ tn(Be(n)), S.current = e.line_items, mt.current = e.currency, x.current = void 0, v.current = t ? "issue" : "draft", y.current = !1, b.current = t, K.current = void 0, Tt(void 0), ht("edit"), _t(e.id), yt(e.type === "invoice" ? e.recurrence_id ?? void 0 : void 0), D(n), O({}), Et(!1), I(!1), F.current = {
194
+ lines: !1,
195
+ discount: !1
196
+ }, V(), w(!0);
197
+ }, [
198
+ V,
199
+ Ht,
200
+ Wt,
201
+ q,
202
+ tn,
203
+ A
204
+ ]);
205
+ p(() => {
206
+ A?.length && D((e) => {
207
+ let t = re(e.lineItems, A);
208
+ return t === e.lineItems ? e : {
209
+ ...e,
210
+ lineItems: t
211
+ };
212
+ });
213
+ }, [A]);
214
+ let on = B.isUploading, sn = f(() => {
215
+ on || (Ft(), w(!1), O({}));
216
+ }, [Ft, on]), cn = f((e) => {
217
+ let t = { ...e };
218
+ t.taxRate !== void 0 && (t.taxRate = ae(t.taxRate), P.current = !0), t.type !== void 0 && t.type !== "invoice" && Ft(), t.type !== void 0 && (v.current = "draft"), t.discount !== void 0 && M && (N.current = !0), t.discountType !== void 0 && (N.current = !0), t.currency !== void 0 && (Dt.current = !0), D((e) => {
219
+ let n = {
220
+ ...e,
221
+ ...t
222
+ };
223
+ return t.discount !== void 0 && (n.discount = Ee(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
224
+ ...t,
225
+ price: l(t.price, e.currency, n.currency)
226
+ }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = Ce({
227
+ value: n.discount,
228
+ type: n.discountType,
229
+ currency: n.currency
230
+ })), n;
231
+ });
232
+ }, [Ft, M]), ln = f(() => I(!0), []), un = f(() => {
233
+ I(!1), N.current = !0, D((e) => ({
234
+ ...e,
235
+ discount: Ce({
236
+ value: e.discount,
237
+ type: e.discountType,
238
+ currency: e.currency
239
+ })
240
+ }));
241
+ }, []), dn = f(() => {
242
+ P.current = !0, D((e) => {
243
+ let t = c(e.taxRate);
244
+ return t === e.taxRate ? e : {
245
+ ...e,
246
+ taxRate: t
247
+ };
248
+ });
249
+ }, []), J = f((e, { validate: t }) => {
250
+ t && (Dt.current = !0), D((t) => ({
251
+ ...t,
252
+ lineItems: e(t.lineItems)
253
+ }));
254
+ }, []);
255
+ p(() => {
256
+ let e = Dt.current, t = N.current;
257
+ if (!e && !t && !P.current) return;
258
+ Dt.current = !1, N.current = !1, P.current = !1, e && (F.current.lines = !0), t && (F.current.discount = !0);
259
+ let n = y.current || W > 0, r = e ? ue(E.lineItems, {
260
+ currency: E.currency,
261
+ messages: _,
262
+ requireComplete: n
263
+ }) : void 0;
264
+ O((t) => {
265
+ let i = { ...t };
266
+ return F.current.lines && (i.lineItems = e ? r : t.lineItems, i.lineItemsSummary = ce(i.lineItems, Ae(E, _), n && E.lineItems.length === 0 ? _.lineItemsRequired : void 0)), F.current.discount && (i.discount = ke(E, _)), i;
267
+ });
268
+ }, [
269
+ W,
270
+ _,
271
+ E
272
+ ]);
273
+ let fn = f((e, t) => {
274
+ let { unit: n, ...r } = t, i = ie(r);
275
+ i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), i.taxable !== void 0 && (P.current = !0), J((t) => t.map((t) => t.id === e ? {
276
+ ...t,
277
+ ...i
278
+ } : t), { validate: M });
279
+ }, [J, M]), pn = f((e, t) => {
280
+ J((n) => n.map((n) => n.id === e ? {
281
+ ...n,
282
+ ...te({
283
+ product: t,
284
+ currency: E.currency,
285
+ unitNamesById: j
286
+ })
287
+ } : n), { validate: !0 });
288
+ }, [
289
+ J,
290
+ j,
291
+ E.currency
292
+ ]), mn = f((e, t) => {
293
+ t && J((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
294
+ ...n,
295
+ ...t.patch
296
+ } : n), { validate: !0 });
297
+ }, [J]), hn = f((e, t) => {
298
+ let n = E.lineItems.find((t) => t.id === e);
299
+ n && mn(e, s({
300
+ lineItem: n,
301
+ field: t,
302
+ rowCount: E.lineItems.length,
303
+ currency: E.currency
304
+ }));
305
+ }, [
306
+ mn,
307
+ E.currency,
308
+ E.lineItems
309
+ ]), gn = f((e, t) => {
310
+ let n = E.lineItems.find((t) => t.id === e);
311
+ n && mn(e, oe({
312
+ lineItem: n,
313
+ step: t,
314
+ rowCount: E.lineItems.length
315
+ }));
316
+ }, [mn, E.lineItems]), _n = f(() => {
317
+ let e = u(E.currency);
318
+ Tt(e.id), D((t) => ({
319
+ ...t,
320
+ lineItems: [...t.lineItems, e]
321
+ }));
322
+ }, [E.currency]), vn = f((e) => {
323
+ J((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
324
+ }, [J]), Y = f((e, t) => e.type === "invoice" && (t === "issue" || Se(e) && W === 0), [W]), yn = f((e, t) => ({
325
+ ...Re({
326
+ values: e,
327
+ billingAddressId: R,
328
+ messages: _,
329
+ willIssue: t,
330
+ hasStartedRecurrence: W > 0
331
+ }),
332
+ ...e.type === "invoice" && d(e) ? xe({
333
+ fields: e,
334
+ issuedCount: W,
335
+ messages: _
336
+ }) : {}
337
+ }), [
338
+ R,
339
+ W,
340
+ _
341
+ ]), bn = f(() => {
342
+ requestAnimationFrame(() => {
343
+ let e = pt.current, t = e?.querySelector("[aria-invalid=\"true\"]");
344
+ if (!e || !t) return;
345
+ let n = t.getBoundingClientRect().top - e.getBoundingClientRect().top + e.scrollTop;
346
+ e.scrollTo({
347
+ top: Math.max(0, n - e.clientHeight / 2 + t.offsetHeight / 2),
348
+ behavior: "smooth"
349
+ });
350
+ });
351
+ }, []), X = f((e, t) => {
352
+ O(e), Et(!0), y.current = t, F.current = {
353
+ lines: !0,
354
+ discount: !0
355
+ }, bn();
356
+ }, [bn]), xn = !vt || E.frequency !== "once" || Gt.isError;
357
+ p(() => {
358
+ if (!C || !b.current || Mt || G || !xn) return;
359
+ b.current = !1;
360
+ let e = Y(E, "issue");
361
+ X(yn(E, e), e);
362
+ }, [
363
+ Mt,
364
+ C,
365
+ xn,
366
+ G,
367
+ X,
368
+ yn,
369
+ E,
370
+ Y
371
+ ]);
372
+ let Sn = h({
373
+ values: E,
374
+ billingAddressId: R
375
+ });
376
+ p(() => {
377
+ let e = Sn.current;
378
+ if (Sn.current = {
379
+ values: E,
380
+ billingAddressId: R
381
+ }, !M) return;
382
+ let t = [
383
+ "customerId",
384
+ "paymentTermsId",
385
+ "bankAccountId",
386
+ "openingNote",
387
+ "closingNote",
388
+ "taxRate"
389
+ ].filter((t) => e.values[t] !== E[t] || t === "customerId" && e.billingAddressId !== R || t === "paymentTermsId" && e.values.paymentTermsCustomDate !== E.paymentTermsCustomDate);
390
+ if (!t.length) return;
391
+ let n = Re({
392
+ values: E,
393
+ billingAddressId: R,
394
+ messages: _,
395
+ willIssue: y.current
396
+ });
397
+ O((e) => {
398
+ let r = { ...e };
399
+ return t.forEach((e) => {
400
+ n[e] ? r[e] = n[e] : delete r[e];
401
+ }), r;
402
+ });
403
+ }, [
404
+ R,
405
+ _,
406
+ M,
407
+ E
408
+ ]);
409
+ let Cn = f(async (t) => {
410
+ if (v.current = t, G) return;
411
+ if (on) {
412
+ e.error(_.attachmentsUploading);
413
+ return;
414
+ }
415
+ if (k.isLoading) {
416
+ e.error(_.lineItemsLoading);
417
+ return;
418
+ }
419
+ let n = se(E.lineItems), i = n.length === E.lineItems.length ? E : {
420
+ ...E,
421
+ lineItems: n
422
+ };
423
+ i !== E && D(i);
424
+ let a = i.type === "invoice" && d(i), o = Y(i, t);
425
+ if (o && (Nt || H.isLoading)) {
426
+ e.error(_.issueChecksLoading);
427
+ return;
428
+ }
429
+ if (o && !H.canAddAccount && !i.bankAccountId && !H.hasAccounts) {
430
+ e.error(_.issueBankAccountUnavailable);
431
+ return;
432
+ }
433
+ let s = yn(i, o);
434
+ if (Me(s)) {
435
+ X(s, o);
436
+ return;
437
+ }
438
+ if (O({}), o && z.isTaxIdMissing) {
439
+ e.error(_.issueTaxIdRequired);
440
+ return;
441
+ }
442
+ if (o && (i.paymentReminderId || i.overdueReminderId)) {
443
+ let t = ze(z.counterpart, _);
444
+ if (t) {
445
+ e.error(t);
446
+ return;
447
+ }
448
+ }
449
+ let c = T === "edit" ? gt : x.current, l, u, ee = {};
450
+ try {
451
+ if (c) {
452
+ let e = Pe({
453
+ values: i,
454
+ originalLineItems: S.current,
455
+ originalCurrency: mt.current,
456
+ unitNamesById: j,
457
+ units: A
458
+ });
459
+ ee = Le({
460
+ values: i,
461
+ originalLineItems: S.current,
462
+ changes: e
463
+ });
464
+ let t = await ct.mutateAsync({
465
+ path: { receivable_id: c },
466
+ body: Fe({
467
+ values: i,
468
+ billingAddressId: R ?? "",
469
+ lineItemChanges: e
470
+ })
471
+ });
472
+ It(), l = c, u = t?.type ?? i.type, a && t && (S.current = t.line_items, mt.current = t.currency, i = {
473
+ ...i,
474
+ lineItems: ne(i.lineItems, t.line_items)
475
+ }, D(i));
476
+ } else {
477
+ ee = Le({ values: i });
478
+ let e = await st.mutateAsync({ body: Ne({
479
+ values: i,
480
+ billingAddressId: R ?? "",
481
+ unitNamesById: j
482
+ }) });
483
+ if (!e?.id) {
484
+ w(!1), nn();
485
+ return;
486
+ }
487
+ l = e.id, u = e.type, a && (x.current = e.id, S.current = e.line_items, mt.current = e.currency, i = {
488
+ ...i,
489
+ lineItems: ne(i.lineItems, e.line_items)
490
+ }, D(i));
491
+ }
492
+ } catch (t) {
493
+ let n = Je[i.type], r = Xe(t, {
494
+ irrelevantVariants: n,
495
+ messages: _
496
+ });
497
+ e.error((c ? _.updateFailed : _.createFailed).replace("{errorMessage}", r));
498
+ let { errors: a, listError: s } = Ye(Ze(t, n), ee), l = ce(a.lineItems, void 0, s);
499
+ X({
500
+ ...a,
501
+ ...l ? { lineItemsSummary: l } : {}
502
+ }, o);
503
+ return;
504
+ }
505
+ let te = a ? "recurrence" : "draft";
506
+ if (a) try {
507
+ U ? await ut.mutateAsync({
508
+ path: { recurrence_id: U.id },
509
+ body: _e(i, { lockSchedule: Kt })
510
+ }) : await lt.mutateAsync({ body: ge(i, l) });
511
+ } catch (t) {
512
+ e.error(Xe(t, { messages: _ }));
513
+ return;
514
+ }
515
+ else if (o) try {
516
+ await dt.mutateAsync({ path: { receivable_id: l } }), te = "issue";
517
+ } catch {
518
+ e.error(_.issueFailedAfterSave);
519
+ }
520
+ let re = T === "create";
521
+ w(!1), nn(), re && ot?.(l, u, {
522
+ mode: te,
523
+ counterpartId: i.customerId,
524
+ inlineItems: he(i.lineItems, i.currency),
525
+ hasCustomerEmail: !!(z.counterpart && r(z.counterpart).trim())
526
+ });
527
+ }, [
528
+ H.canAddAccount,
529
+ H.hasAccounts,
530
+ H.isLoading,
531
+ R,
532
+ It,
533
+ st,
534
+ lt,
535
+ gt,
536
+ U,
537
+ on,
538
+ Nt,
539
+ dt,
540
+ Kt,
541
+ _,
542
+ T,
543
+ ot,
544
+ z.counterpart,
545
+ z.isTaxIdMissing,
546
+ G,
547
+ nn,
548
+ X,
549
+ A,
550
+ j,
551
+ k.isLoading,
552
+ ct,
553
+ ut,
554
+ yn,
555
+ E,
556
+ Y
557
+ ]), Z = f(async (e = v.current) => {
558
+ if (!ft.current) {
559
+ ft.current = !0;
560
+ try {
561
+ await Cn(e);
562
+ } finally {
563
+ ft.current = !1;
564
+ }
565
+ }
566
+ }, [Cn]), wn = m(() => ({
567
+ ...E,
568
+ discount: Ot ? E.discount : we(Te(E.discount, E.discountType, E.currency), E.discountType, E.currency),
569
+ lineItems: E.lineItems.map(le)
570
+ }), [Ot, E]), Tn = m(() => o(E.lineItems), [E.lineItems]), En = m(() => Oe(E), [E]), Q = E.type === "invoice", Dn = Q && d(E), On = $t || k.isLoading || B.isUploading || G, kn = T === "edit" ? _.updateDraftButton : _.saveDraftButton, An = Dn ? U ? _.recurrenceUpdateButton : _.recurrenceActivateButton : Q ? _.issueButton : kn, $ = Q && !Dn ? "issue" : "draft", jn = f(() => Z("draft"), [Z]), Mn = f(() => Z($), [$, Z]), Nn = f(() => Z(), [Z]), Pn = f(() => {
571
+ v.current = "draft";
572
+ }, []), Fn = f(() => {
573
+ v.current = $;
574
+ }, [$]), In = m(() => De(En, E.currency), [En, E.currency]), Ln = rt({
575
+ values: E,
576
+ totals: En,
577
+ billingAddress: jt,
578
+ unitNamesById: j,
579
+ messages: _,
580
+ enabled: C
581
+ });
50
582
  return {
51
- rows: P,
52
- isLoading: k.isLoading,
53
- isError: k.isError,
54
- sorting: m,
55
- onSortingChange: I,
56
- pageSize: g,
57
- onPageSizeChange: L,
58
- hasNextPage: !!k.data?.next_pagination_token,
59
- hasPrevPage: !!k.data?.prev_pagination_token,
60
- onNextPage: z,
61
- onPrevPage: B,
62
- searchValue: b,
63
- onSearchChange: x,
64
- statusFilter: w,
65
- statusOptions: t(w),
66
- onStatusFilterChange: R,
67
- statusCards: A,
68
- isFiltering: F,
69
- onRetry: V,
70
- getReceivableById: N
583
+ open: C,
584
+ setOpen: w,
585
+ mode: T,
586
+ values: E,
587
+ sheetValues: wn,
588
+ errors: bt,
589
+ setValues: D,
590
+ updateValues: cn,
591
+ commitTaxRate: dn,
592
+ focusDiscount: ln,
593
+ commitDiscount: un,
594
+ updateLineItem: fn,
595
+ selectProduct: pn,
596
+ commitLineItem: hn,
597
+ stepLineItem: gn,
598
+ addLineItem: _n,
599
+ removeLineItem: vn,
600
+ attachmentsView: Lt,
601
+ attachmentsUploading: B.isUploading,
602
+ draftButtonLabel: Q && !Dn ? kn : void 0,
603
+ draftDisabled: On,
604
+ primaryButtonLabel: An,
605
+ primaryDisabled: On || H.isLoading && Y(E, $) || Q && (Nt || !Dn && z.isCounterpartLoading),
606
+ scrollContainerRef: pt,
607
+ selectAttachmentFiles: B.selectFiles,
608
+ setAttachmentIncludeInEmail: B.setIncludeInEmail,
609
+ removeAttachment: B.remove,
610
+ autoFocusLineItemId: wt,
611
+ lineItemUnitOptions: Ct.unitOptions,
612
+ lineItemsLoading: k.isLoading,
613
+ lineItemControls: Tn,
614
+ totals: En,
615
+ preview: Ln,
616
+ totalsView: In,
617
+ currencySymbol: ee(E.currency),
618
+ isSubmitting: $t,
619
+ currencyOptions: fe(E.currency),
620
+ paymentTerms: Vt,
621
+ showBillingSection: E.type === "invoice" || T === "edit",
622
+ recurrence: Zt,
623
+ showRecurrenceSection: E.type === "invoice",
624
+ recurrenceLoading: G,
625
+ showDueDateField: E.type === "quote",
626
+ openCreate: rn,
627
+ openEdit: an,
628
+ close: sn,
629
+ submit: Nn,
630
+ submitDraft: jn,
631
+ submitPrimary: Mn,
632
+ selectDraftMode: Pn,
633
+ selectPrimaryMode: Fn,
634
+ units: Ct,
635
+ counterpartView: xt,
636
+ counterpartForm: zt,
637
+ stateOptions: kt,
638
+ openCounterpartCreate: zt.openCreate,
639
+ bankAccount: H,
640
+ reminders: en
71
641
  };
72
642
  }
73
- var d = {
74
- documentLabel: "document_id",
75
- customerLabel: "counterpart_name",
76
- status: "status",
77
- issueDateLabel: "issue_date",
78
- dueDateLabel: "due_date",
79
- totalLabel: "total_amount"
80
- };
81
643
  //#endregion
82
- export { u as useReceivablesTable };
644
+ export { _ as useReceivableForm };