@tesouro/embedded-components-react 0.5.198 → 0.5.201
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.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/lib/ReceivablesWidget.d.ts +4 -0
- package/dist/lib/ReceivablesWidget.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/accept-disclosures-widget/data-access/dist/index.js +4 -3
- package/dist/libs/tesouro-embedded-components-react/accept-disclosures-widget/feature/dist/index5.js +78 -77
- package/dist/libs/tesouro-embedded-components-react/bank-account-onboarding-widget/feature/dist/index25.js +258 -257
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +47 -250
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +267 -65
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +66 -105
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +103 -214
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +226 -0
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +67 -37
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +83 -79
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +207 -172
- package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +4 -0
- package/dist/libs/tesouro-embedded-components-react/shared/bank-disclosures/feature/dist/lib/BankDisclosuresWidget/collectDisclosureDocuments.js +3 -4
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +6 -5
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/disclosures/personDisclosure.js +6 -0
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/disclosures/useAcceptWidgetDisclosures.js +20 -19
- package/dist/libs/tesouro-embedded-components-react/shared/data-access-mocks/dist/lib/fixtures.js +27 -11
- package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
- package/package.json +1 -1
package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js
CHANGED
|
@@ -1,255 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
"use client";
|
|
3
|
-
"use client";
|
|
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 a, commitLineItemField as te, convertPriceInput as ne, createLineItem as re, getCurrencySymbol as o, lineItemFromProduct as s, reconcileMeasureUnits as c, sanitizeLineItemPatch as l, stepLineItemQuantity as u, stripBlankLineItems as ie, summarizeLineItemErrors as ae, toSheetLineItem as d, validateLineItems as oe } from "./index5.js";
|
|
13
|
-
import { createEmptyReceivableFormValues as f, getPaymentTermOptions as se, hasReceivableFormErrors as ce, receivableFormValuesToCreatePayload as le, receivableFormValuesToLineItemChanges as ue, receivableFormValuesToUpdatePayload as de, receivableToFormValues as fe, validateReceivableForm as p } from "./index6.js";
|
|
14
|
-
import { useCreateReceivableMutation as m, useUpdateReceivableMutation as pe } from "../../data-access/dist/index6.js";
|
|
15
|
-
import "../../data-access/dist/index.js";
|
|
16
|
-
import { getCurrencyOptions as me } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
|
|
17
|
-
import { useMeasureUnitsQuery as he } from "../../../shared/product-catalog/data-access/dist/index9.js";
|
|
18
|
-
import { useMeasureUnits as ge } from "../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
|
|
19
|
-
import "../../../shared/product-catalog/feature/dist/index.js";
|
|
20
|
-
import { useCallback as h, useEffect as g, useMemo as _, useRef as v, useState as y } from "react";
|
|
1
|
+
import { parseQuantity as e, priceInputToMinorUnits as t } from "./index5.js";
|
|
21
2
|
//#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
customerId: e ?? ""
|
|
30
|
-
}));
|
|
31
|
-
}, []), Y = ee({
|
|
32
|
-
view: R,
|
|
33
|
-
setView: _e,
|
|
34
|
-
selectedId: P.customerId || void 0,
|
|
35
|
-
setSelectedId: Se,
|
|
36
|
-
messages: be,
|
|
37
|
-
counterpartType: "customer",
|
|
38
|
-
counterpart: void 0,
|
|
39
|
-
primaryAddress: xe
|
|
40
|
-
}), X = h(() => {
|
|
41
|
-
T.current = [], U(void 0), j("create"), N(void 0), F(f()), L({}), G(!1);
|
|
42
|
-
}, []), Ce = h((e = "invoice") => {
|
|
43
|
-
T.current = [], U(void 0), j("create"), N(void 0), F({
|
|
44
|
-
...f(),
|
|
45
|
-
type: e
|
|
46
|
-
}), L({}), G(!1), k(!0);
|
|
47
|
-
}, []), we = h((e) => {
|
|
48
|
-
e.type !== "credit_note" && (T.current = e.line_items, E.current = e.currency, U(void 0), j("edit"), N(e.id), F(fe(e, V)), L({}), G(!1), k(!0));
|
|
49
|
-
}, [V]);
|
|
50
|
-
g(() => {
|
|
51
|
-
V?.length && F((e) => {
|
|
52
|
-
let t = c(e.lineItems, V);
|
|
53
|
-
return t === e.lineItems ? e : {
|
|
54
|
-
...e,
|
|
55
|
-
lineItems: t
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}, [V]);
|
|
59
|
-
let Te = h(() => {
|
|
60
|
-
k(!1), L({});
|
|
61
|
-
}, []), Ee = h((e) => {
|
|
62
|
-
let { currency: t } = e;
|
|
63
|
-
if (t === void 0) {
|
|
64
|
-
F((t) => ({
|
|
65
|
-
...t,
|
|
66
|
-
...e
|
|
67
|
-
}));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
K.current = !0, F((n) => n.currency === t ? {
|
|
71
|
-
...n,
|
|
72
|
-
...e
|
|
73
|
-
} : {
|
|
74
|
-
...n,
|
|
75
|
-
...e,
|
|
76
|
-
lineItems: n.lineItems.map((e) => ({
|
|
77
|
-
...e,
|
|
78
|
-
price: ne(e.price, n.currency, t)
|
|
79
|
-
}))
|
|
80
|
-
});
|
|
81
|
-
}, []), Z = h((e, t) => {
|
|
82
|
-
let n = oe(e, {
|
|
83
|
-
currency: t,
|
|
84
|
-
messages: b
|
|
85
|
-
});
|
|
86
|
-
L((e) => ({
|
|
87
|
-
...e,
|
|
88
|
-
lineItems: n,
|
|
89
|
-
lineItemsSummary: ae(n)
|
|
90
|
-
}));
|
|
91
|
-
}, [b]), Q = h((e, { validate: t }) => {
|
|
92
|
-
t && (K.current = !0), F((t) => ({
|
|
93
|
-
...t,
|
|
94
|
-
lineItems: e(t.lineItems)
|
|
95
|
-
}));
|
|
96
|
-
}, []);
|
|
97
|
-
g(() => {
|
|
98
|
-
K.current && (K.current = !1, Z(P.lineItems, P.currency));
|
|
99
|
-
}, [
|
|
100
|
-
Z,
|
|
101
|
-
P.currency,
|
|
102
|
-
P.lineItems
|
|
103
|
-
]);
|
|
104
|
-
let De = h((e, t) => {
|
|
105
|
-
let { unit: n, ...r } = t, i = l(r);
|
|
106
|
-
i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), Q((t) => t.map((t) => t.id === e ? {
|
|
107
|
-
...t,
|
|
108
|
-
...i
|
|
109
|
-
} : t), { validate: W });
|
|
110
|
-
}, [Q, W]), Oe = h((e, t) => {
|
|
111
|
-
Q((n) => n.map((n) => n.id === e ? {
|
|
112
|
-
...n,
|
|
113
|
-
...s({
|
|
114
|
-
product: t,
|
|
115
|
-
currency: P.currency,
|
|
116
|
-
unitNamesById: H
|
|
117
|
-
})
|
|
118
|
-
} : n), { validate: !0 });
|
|
119
|
-
}, [
|
|
120
|
-
Q,
|
|
121
|
-
H,
|
|
122
|
-
P.currency
|
|
123
|
-
]), $ = h((e, t) => {
|
|
124
|
-
t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
|
|
125
|
-
...n,
|
|
126
|
-
...t.patch
|
|
127
|
-
} : n), { validate: !0 });
|
|
128
|
-
}, [Q]), ke = h((e, t) => {
|
|
129
|
-
let n = P.lineItems.find((t) => t.id === e);
|
|
130
|
-
n && $(e, te({
|
|
131
|
-
lineItem: n,
|
|
132
|
-
field: t,
|
|
133
|
-
rowCount: P.lineItems.length,
|
|
134
|
-
currency: P.currency
|
|
135
|
-
}));
|
|
136
|
-
}, [
|
|
137
|
-
$,
|
|
138
|
-
P.currency,
|
|
139
|
-
P.lineItems
|
|
140
|
-
]), Ae = h((e, t) => {
|
|
141
|
-
let n = P.lineItems.find((t) => t.id === e);
|
|
142
|
-
n && $(e, u({
|
|
143
|
-
lineItem: n,
|
|
144
|
-
step: t,
|
|
145
|
-
rowCount: P.lineItems.length
|
|
146
|
-
}));
|
|
147
|
-
}, [$, P.lineItems]), je = h(() => {
|
|
148
|
-
let e = re(P.currency);
|
|
149
|
-
U(e.id), F((t) => ({
|
|
150
|
-
...t,
|
|
151
|
-
lineItems: [...t.lineItems, e]
|
|
152
|
-
}));
|
|
153
|
-
}, [P.currency]), Me = h((e) => {
|
|
154
|
-
Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
|
|
155
|
-
}, [Q]), Ne = h(async () => {
|
|
156
|
-
if (B.isLoading) {
|
|
157
|
-
L({ form: b.lineItemsLoading });
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
let e = ie(P.lineItems), n = e.length === P.lineItems.length ? P : {
|
|
161
|
-
...P,
|
|
162
|
-
lineItems: e
|
|
163
|
-
};
|
|
164
|
-
n !== P && F(n);
|
|
165
|
-
let r = p({
|
|
166
|
-
values: n,
|
|
167
|
-
billingAddressId: J,
|
|
168
|
-
messages: b
|
|
169
|
-
});
|
|
170
|
-
if (ce(r)) {
|
|
171
|
-
L(r), G(!0);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
L({});
|
|
175
|
-
try {
|
|
176
|
-
if (A === "edit" && M) {
|
|
177
|
-
let e = { receivable_id: M };
|
|
178
|
-
await w.mutateAsync({
|
|
179
|
-
path: e,
|
|
180
|
-
body: de({
|
|
181
|
-
values: n,
|
|
182
|
-
billingAddressId: J ?? "",
|
|
183
|
-
lineItemChanges: ue({
|
|
184
|
-
values: n,
|
|
185
|
-
originalLineItems: T.current,
|
|
186
|
-
originalCurrency: E.current,
|
|
187
|
-
unitNamesById: H,
|
|
188
|
-
units: V
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
}), k(!1), X();
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
let e = await C.mutateAsync({ body: le({
|
|
195
|
-
values: n,
|
|
196
|
-
billingAddressId: J ?? "",
|
|
197
|
-
unitNamesById: H
|
|
198
|
-
}) });
|
|
199
|
-
k(!1), X(), e?.id && S?.(e.id, e.type);
|
|
200
|
-
} catch (e) {
|
|
201
|
-
L({ form: t(e) ?? b.genericError });
|
|
202
|
-
}
|
|
203
|
-
}, [
|
|
204
|
-
J,
|
|
205
|
-
C,
|
|
206
|
-
M,
|
|
207
|
-
b,
|
|
208
|
-
A,
|
|
209
|
-
S,
|
|
210
|
-
X,
|
|
211
|
-
V,
|
|
212
|
-
H,
|
|
213
|
-
B.isLoading,
|
|
214
|
-
w,
|
|
215
|
-
P
|
|
216
|
-
]), Pe = _(() => ({
|
|
217
|
-
...P,
|
|
218
|
-
lineItems: P.lineItems.map(d)
|
|
219
|
-
}), [P]), Fe = _(() => a(P.lineItems), [P.lineItems]);
|
|
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
|
+
}
|
|
220
10
|
return {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
|
252
49
|
};
|
|
253
50
|
}
|
|
254
51
|
//#endregion
|
|
255
|
-
export {
|
|
52
|
+
export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };
|
package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
CHANGED
|
@@ -2,74 +2,276 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
"use client";
|
|
4
4
|
"use client";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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";
|
|
7
15
|
import "../../data-access/dist/index.js";
|
|
8
|
-
import {
|
|
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";
|
|
9
22
|
//#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
235
|
+
}), [
|
|
236
|
+
F.currency,
|
|
237
|
+
F.lineItems,
|
|
238
|
+
F.taxRate
|
|
239
|
+
]);
|
|
44
240
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
64
274
|
};
|
|
65
275
|
}
|
|
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
276
|
//#endregion
|
|
75
|
-
export {
|
|
277
|
+
export { x as useReceivableForm };
|