@tesouro/embedded-components-react 0.3.12 → 0.3.14
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 +42 -30
- package/dist/index.js +1 -1
- package/dist/lib/BillPayWidget.js +1 -1
- package/dist/lib/CardsWidget.d.ts +12 -0
- package/dist/lib/CreateCardWidget.d.ts +12 -0
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +6 -6
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js +2 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +23 -205
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index31.js +200 -185
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index32.js +199 -50
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js +105 -13
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js +12 -46
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js +46 -30
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index36.js +26 -158
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js +162 -31
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index38.js +32 -98
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index39.js +102 -13
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +13 -242
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +247 -4
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index42.js +4 -30
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index43.js +28 -82
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index44.js +76 -137
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +145 -3
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +3 -4
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +2 -43
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +45 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +1 -8
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +6 -9
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +9 -92
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +94 -3
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +3 -9
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +7 -20
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +14 -51
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +59 -3
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +3 -110
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +107 -8
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +8 -40
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +38 -15
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +18 -98
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +92 -173
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +180 -4
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +5 -8
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +6 -112
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +114 -1
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +0 -24
- package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index68.js +25 -0
- package/dist/libs/tesouro-embedded-components-react/cards-widget/feature/dist/index5.js +1 -2
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index.js +3 -2
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index5.js +19 -12
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/data-access/dist/index6.js +22 -0
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index4.js +4 -1
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index5.js +0 -1
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index6.js +22 -37
- package/dist/libs/tesouro-embedded-components-react/create-card-widget/feature/dist/index7.js +167 -110
- package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/index.js +9 -9
- package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/helpers.js +6 -3
- package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js +1 -0
- package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/useCounterpartForm.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +18 -18
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +111 -104
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +144 -128
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/zod.gen.js +1028 -1019
- package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/user/useAllOrganizationUsersQuery.js +20 -18
- package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
- package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index7.js +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,108 @@
|
|
|
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 "../../../shared/ui/dist/index.js";
|
|
7
|
+
import { useUpdatePayableMutation as t } from "../../data-access/dist/index10.js";
|
|
8
|
+
import "../../data-access/dist/index.js";
|
|
9
|
+
import { counterpartFormBankAccountToCreatePayload as n, counterpartFormBankAccountToUpdatePayload as r, getAchInstructions as i, resolveCounterpartBankAccountWrite as a, validateAchFormValues as o } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
|
|
10
|
+
import { useCounterpartBankAccountsQuery as s, useCreateCounterpartBankAccountMutation as c, useUpdateCounterpartBankAccountMutation as l } from "../../../shared/counterpart-management/data-access/dist/index5.js";
|
|
11
|
+
import "../../../shared/counterpart-management/feature/dist/index.js";
|
|
12
|
+
import { useCallback as u, useEffect as d, useRef as f, useState as p } from "react";
|
|
1
13
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index33.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
var m = {
|
|
15
|
+
accountHolderName: "",
|
|
16
|
+
routingNumber: "",
|
|
17
|
+
accountNumber: ""
|
|
18
|
+
};
|
|
19
|
+
function h({ payableId: h, counterpartId: g, saveErrorMessage: _, linkErrorMessage: v }) {
|
|
20
|
+
let [y, b] = p(!1), [x, S] = p(m), [C, w] = p(), T = s(g), E = T.data?.data, D = c(), O = l(), k = t(), A = f(void 0), j = f(!1);
|
|
21
|
+
d(() => {
|
|
22
|
+
A.current = void 0;
|
|
23
|
+
}, [g]);
|
|
24
|
+
let M = u(() => {
|
|
25
|
+
let e = T.isFetching ? void 0 : i(E);
|
|
26
|
+
S(e ? {
|
|
27
|
+
accountHolderName: e.account_holder_name ?? "",
|
|
28
|
+
routingNumber: e.routing_number ?? "",
|
|
29
|
+
accountNumber: e.account_number ?? ""
|
|
30
|
+
} : m), A.current = e?.id ?? A.current, j.current = !T.isFetching, w(void 0), b(!0);
|
|
31
|
+
}, [E, T.isFetching]);
|
|
32
|
+
d(() => {
|
|
33
|
+
if (!y || j.current || T.isFetching) return;
|
|
34
|
+
j.current = !0;
|
|
35
|
+
let e = i(E);
|
|
36
|
+
e && (S((t) => t.accountHolderName === "" && t.routingNumber === "" && t.accountNumber === "" ? {
|
|
37
|
+
accountHolderName: e.account_holder_name ?? "",
|
|
38
|
+
routingNumber: e.routing_number ?? "",
|
|
39
|
+
accountNumber: e.account_number ?? ""
|
|
40
|
+
} : t), A.current = e.id);
|
|
41
|
+
}, [
|
|
42
|
+
y,
|
|
43
|
+
T.isFetching,
|
|
44
|
+
E
|
|
45
|
+
]);
|
|
46
|
+
let N = u(() => {
|
|
47
|
+
b(!1);
|
|
48
|
+
}, []), P = u((e) => {
|
|
49
|
+
S((t) => ({
|
|
50
|
+
...t,
|
|
51
|
+
...e
|
|
52
|
+
}));
|
|
53
|
+
}, []), F = u(async () => {
|
|
54
|
+
if (!h || !g) return !1;
|
|
55
|
+
let t = o(x);
|
|
56
|
+
if (Object.keys(t).length > 0) return w(t), !1;
|
|
57
|
+
if (w(void 0), T.isFetching || T.isError) return e.error(_), !1;
|
|
58
|
+
let s = A.current;
|
|
59
|
+
try {
|
|
60
|
+
let e = a(E, s ?? i(E)?.id);
|
|
61
|
+
e.kind === "update" ? (await O.mutateAsync({
|
|
62
|
+
path: {
|
|
63
|
+
counterpart_id: g,
|
|
64
|
+
bank_account_id: e.bankAccountId
|
|
65
|
+
},
|
|
66
|
+
body: r(x, { includeAchDefaults: e.includeAchDefaults })
|
|
67
|
+
}), s = e.bankAccountId) : s = (await D.mutateAsync({
|
|
68
|
+
path: { counterpart_id: g },
|
|
69
|
+
body: n(x, { isDefaultForCurrency: e.isDefaultForCurrency })
|
|
70
|
+
}))?.id, A.current = s;
|
|
71
|
+
} catch {
|
|
72
|
+
return e.error(_), !1;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await k.mutateAsync({
|
|
76
|
+
path: { payable_id: h },
|
|
77
|
+
body: { counterpart_bank_account_id: s }
|
|
78
|
+
});
|
|
79
|
+
} catch {
|
|
80
|
+
return e.error(v), !1;
|
|
81
|
+
}
|
|
82
|
+
return b(!1), !0;
|
|
83
|
+
}, [
|
|
84
|
+
E,
|
|
85
|
+
T.isError,
|
|
86
|
+
T.isFetching,
|
|
87
|
+
g,
|
|
88
|
+
D,
|
|
89
|
+
v,
|
|
90
|
+
h,
|
|
91
|
+
_,
|
|
92
|
+
O,
|
|
93
|
+
k,
|
|
94
|
+
x
|
|
95
|
+
]);
|
|
96
|
+
return {
|
|
97
|
+
isOpen: y,
|
|
98
|
+
values: x,
|
|
99
|
+
errors: C,
|
|
100
|
+
isSaving: D.isPending || O.isPending || k.isPending,
|
|
101
|
+
open: M,
|
|
102
|
+
close: N,
|
|
103
|
+
onChange: P,
|
|
104
|
+
save: F
|
|
105
|
+
};
|
|
14
106
|
}
|
|
15
107
|
//#endregion
|
|
16
|
-
export {
|
|
108
|
+
export { h as usePaymentInstructionsForm };
|
|
@@ -1,50 +1,16 @@
|
|
|
1
|
-
import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
|
|
2
|
-
import "../../data-access/dist/index.js";
|
|
3
1
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index34.js
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
|
|
16
|
-
}
|
|
17
|
-
function a(e) {
|
|
18
|
-
return n(e) ?? 0;
|
|
19
|
-
}
|
|
20
|
-
function o(e) {
|
|
21
|
-
let t = Number.parseFloat(e);
|
|
22
|
-
return Number.isFinite(t) ? t : 0;
|
|
23
|
-
}
|
|
24
|
-
function s(e) {
|
|
25
|
-
return (e / 100).toFixed(2);
|
|
26
|
-
}
|
|
27
|
-
function c({ values: e, counterpartId: r, clearCounterpart: i, editedTotals: a, document: o }) {
|
|
28
|
-
let s = { currency: t };
|
|
29
|
-
return r ? s.counterpart_id = r : i && (s.counterpart_id = null), e.invoiceNumber && (s.document_id = e.invoiceNumber), e.invoiceDate && (s.issued_at = e.invoiceDate), e.dueDate && (s.due_date = e.dueDate), o && (s.base64_encoded_file = o.base64EncodedFile, s.file_name = o.fileName), a && (s.discount = n(a.discount) ?? 0, s.tax_amount = n(a.tax) ?? 0, a.total !== void 0 && (s.total_amount = n(a.total) ?? 0)), s;
|
|
30
|
-
}
|
|
31
|
-
function l(e) {
|
|
32
|
-
return e.filter(i).map((e) => {
|
|
33
|
-
let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a);
|
|
34
|
-
return {
|
|
35
|
-
name: e.description,
|
|
36
|
-
quantity: i,
|
|
37
|
-
unit_price: a,
|
|
38
|
-
...t !== null && t !== o ? { subtotal: t } : {},
|
|
39
|
-
...e.glCode ? { ledger_account_id: e.glCode } : {}
|
|
40
|
-
};
|
|
2
|
+
function e(e) {
|
|
3
|
+
return new Promise((t, n) => {
|
|
4
|
+
let r = new FileReader();
|
|
5
|
+
r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("Failed to read file")), r.onload = () => {
|
|
6
|
+
let e = r.result;
|
|
7
|
+
if (typeof e != "string") {
|
|
8
|
+
n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
t(e.slice(e.indexOf(",") + 1));
|
|
12
|
+
}, r.readAsDataURL(e);
|
|
41
13
|
});
|
|
42
14
|
}
|
|
43
|
-
function u(e, t) {
|
|
44
|
-
return s(Math.round(o(e) * a(t)));
|
|
45
|
-
}
|
|
46
|
-
function d(e, t, n) {
|
|
47
|
-
return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
|
|
48
|
-
}
|
|
49
15
|
//#endregion
|
|
50
|
-
export {
|
|
16
|
+
export { e as encodeFileToBase64 };
|
|
@@ -1,34 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
|
|
2
|
+
import "../../data-access/dist/index.js";
|
|
3
3
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index35.js
|
|
4
|
-
var
|
|
5
|
-
function
|
|
4
|
+
var t = "USD";
|
|
5
|
+
function n(n) {
|
|
6
|
+
return e(n, t);
|
|
7
|
+
}
|
|
8
|
+
function r(e) {
|
|
6
9
|
let t = e.trim();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
function
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
if (!t) return null;
|
|
11
|
+
let n = Number(t);
|
|
12
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
13
|
+
}
|
|
14
|
+
function i(e) {
|
|
15
|
+
return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
|
|
16
|
+
}
|
|
17
|
+
function a(e) {
|
|
18
|
+
return n(e) ?? 0;
|
|
19
|
+
}
|
|
20
|
+
function o(e) {
|
|
21
|
+
let t = Number.parseFloat(e);
|
|
22
|
+
return Number.isFinite(t) ? t : 0;
|
|
23
|
+
}
|
|
24
|
+
function s(e) {
|
|
25
|
+
return (e / 100).toFixed(2);
|
|
26
|
+
}
|
|
27
|
+
function c({ values: e, counterpartId: r, clearCounterpart: i, counterpartBankAccountId: a, editedTotals: o, document: s }) {
|
|
28
|
+
let c = { currency: t };
|
|
29
|
+
return r ? c.counterpart_id = r : i && (c.counterpart_id = null), r ? c.counterpart_bank_account_id = a ?? null : i && (c.counterpart_bank_account_id = null), e.invoiceNumber && (c.document_id = e.invoiceNumber), e.invoiceDate && (c.issued_at = e.invoiceDate), e.dueDate && (c.due_date = e.dueDate), s && (c.base64_encoded_file = s.base64EncodedFile, c.file_name = s.fileName), o && (c.discount = n(o.discount) ?? 0, c.tax_amount = n(o.tax) ?? 0, o.total !== void 0 && (c.total_amount = n(o.total) ?? 0)), c;
|
|
30
|
+
}
|
|
31
|
+
function l(e) {
|
|
32
|
+
return e.filter(i).map((e) => {
|
|
33
|
+
let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a);
|
|
34
|
+
return {
|
|
35
|
+
name: e.description,
|
|
36
|
+
quantity: i,
|
|
37
|
+
unit_price: a,
|
|
38
|
+
...t !== null && t !== o ? { subtotal: t } : {},
|
|
39
|
+
...e.glCode ? { ledger_account_id: e.glCode } : {}
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function u(e, t) {
|
|
44
|
+
return s(Math.round(o(e) * a(t)));
|
|
45
|
+
}
|
|
46
|
+
function d(e, t, n) {
|
|
47
|
+
return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
|
|
32
48
|
}
|
|
33
49
|
//#endregion
|
|
34
|
-
export {
|
|
50
|
+
export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
|
|
@@ -1,166 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"use client";
|
|
4
|
-
"use client";
|
|
5
|
-
import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
|
|
6
|
-
import "../../../shared/ui/dist/index.js";
|
|
7
|
-
import { useReplacePayableLineItemsMutation as t } from "../../data-access/dist/index7.js";
|
|
8
|
-
import { useCreatePayableMutation as n, useSubmitPayableForApprovalMutation as r, useUpdatePayableMutation as i, useValidatePayableMutation as a } from "../../data-access/dist/index10.js";
|
|
9
|
-
import "../../data-access/dist/index.js";
|
|
10
|
-
import { BILL_CREATE_MESSAGE_LABELS_EN as o } from "./index28.js";
|
|
11
|
-
import { encodeFileToBase64 as s } from "./index33.js";
|
|
12
|
-
import { mapBillFormToPayload as c, mapLineItemsToPayload as l } from "./index34.js";
|
|
13
|
-
import { validateBillCompleteness as u, validateBillTotals as d, validateLineItems as f } from "./index35.js";
|
|
14
|
-
import { useCallback as p, useRef as m, useState as h } from "react";
|
|
1
|
+
import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index28.js";
|
|
2
|
+
import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index35.js";
|
|
15
3
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index36.js
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
counterpart_id: "vendor"
|
|
21
|
-
};
|
|
22
|
-
function _(e) {
|
|
23
|
-
return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
|
|
4
|
+
var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/;
|
|
5
|
+
function a(e) {
|
|
6
|
+
let t = e.trim();
|
|
7
|
+
return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
|
|
24
8
|
}
|
|
25
|
-
function
|
|
26
|
-
let
|
|
27
|
-
for (let
|
|
28
|
-
let
|
|
29
|
-
|
|
9
|
+
function o(t, i = e) {
|
|
10
|
+
let a = {};
|
|
11
|
+
for (let e of t) {
|
|
12
|
+
let t = n(e.price), o = n(e.amount), s = {};
|
|
13
|
+
e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), (t !== null || o !== null) && r(e.quantity) === null && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
|
|
30
14
|
}
|
|
31
|
-
return
|
|
15
|
+
return Object.keys(a).length ? a : void 0;
|
|
32
16
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
function s(i, a, o, s = e) {
|
|
18
|
+
let c = {};
|
|
19
|
+
a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField), i.invoiceDate.trim() || (c.invoiceDate = s.requiredField), i.dueDate.trim() || (c.dueDate = s.requiredField);
|
|
20
|
+
let l = {};
|
|
21
|
+
return o.forEach((e, i) => {
|
|
22
|
+
if (i > 0 && !t(e)) return;
|
|
23
|
+
let a = {};
|
|
24
|
+
e.description.trim() || (a.description = s.requiredField), r(e.quantity) === null && (a.quantity = s.requiredField), n(e.price) === null && n(e.amount) === null && (a.price = s.requiredField, a.amount = s.requiredField), Object.keys(a).length && (l[e.id] = a);
|
|
25
|
+
}), {
|
|
26
|
+
formErrors: Object.keys(c).length ? c : void 0,
|
|
27
|
+
lineItemErrors: Object.keys(l).length ? l : void 0
|
|
39
28
|
};
|
|
40
|
-
return n;
|
|
41
29
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
...o,
|
|
45
|
-
...D
|
|
46
|
-
}, [k, A] = h(), j = g ?? k, [M, N] = h(), P = p(() => N(void 0), []), [F, I] = h(), L = m(!1), R = n(), z = i(), B = t(), V = a(), H = r(), U = p(() => {
|
|
47
|
-
let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O);
|
|
48
|
-
return _.setLineItemErrors(t), !t && !n || (t ? (_.setErrors(void 0), e.error(O.lineItemsNeedAttention)) : _.setErrors(n), !1);
|
|
49
|
-
}, [_, O]), W = p(async () => {
|
|
50
|
-
let e = !j && M ? {
|
|
51
|
-
base64EncodedFile: await s(M),
|
|
52
|
-
fileName: M.name
|
|
53
|
-
} : void 0, t = c({
|
|
54
|
-
values: _.values,
|
|
55
|
-
counterpartId: b,
|
|
56
|
-
clearCounterpart: x,
|
|
57
|
-
editedTotals: _.isTotalsDirty ? {
|
|
58
|
-
discount: _.discount,
|
|
59
|
-
tax: _.tax,
|
|
60
|
-
total: _.totalOverride
|
|
61
|
-
} : void 0,
|
|
62
|
-
document: e
|
|
63
|
-
}), n = j;
|
|
64
|
-
if (n ? await z.mutateAsync({
|
|
65
|
-
path: { payable_id: n },
|
|
66
|
-
body: t
|
|
67
|
-
}) : (n = (await R.mutateAsync({ body: t }))?.id, n && (A(n), w?.(n), e && N(void 0))), !n) throw Error("Payable was created without an id");
|
|
68
|
-
return await B.mutateAsync({
|
|
69
|
-
path: { payable_id: n },
|
|
70
|
-
body: { data: l(_.lineItems) }
|
|
71
|
-
}), n;
|
|
72
|
-
}, [
|
|
73
|
-
b,
|
|
74
|
-
x,
|
|
75
|
-
R,
|
|
76
|
-
_.discount,
|
|
77
|
-
_.isTotalsDirty,
|
|
78
|
-
_.lineItems,
|
|
79
|
-
_.tax,
|
|
80
|
-
_.totalOverride,
|
|
81
|
-
_.values,
|
|
82
|
-
w,
|
|
83
|
-
j,
|
|
84
|
-
B,
|
|
85
|
-
M,
|
|
86
|
-
z
|
|
87
|
-
]);
|
|
88
|
-
return {
|
|
89
|
-
saveDraft: p(async () => {
|
|
90
|
-
if (!L.current && U()) {
|
|
91
|
-
L.current = !0, I("draft");
|
|
92
|
-
try {
|
|
93
|
-
if (await S?.() === !1) return;
|
|
94
|
-
let t = await W();
|
|
95
|
-
_.setErrors(void 0), C?.(t), T?.(t), e.success(O.draftSaved);
|
|
96
|
-
} catch {
|
|
97
|
-
_.setErrors({ form: O.saveFailed });
|
|
98
|
-
} finally {
|
|
99
|
-
I(void 0), L.current = !1;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, [
|
|
103
|
-
_,
|
|
104
|
-
U,
|
|
105
|
-
O.draftSaved,
|
|
106
|
-
O.saveFailed,
|
|
107
|
-
T,
|
|
108
|
-
C,
|
|
109
|
-
S,
|
|
110
|
-
W
|
|
111
|
-
]),
|
|
112
|
-
finalize: p(async () => {
|
|
113
|
-
if (L.current) return;
|
|
114
|
-
let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O), { formErrors: r, lineItemErrors: i } = u(_.values, b, _.lineItems, O), a = y(i, t);
|
|
115
|
-
_.setLineItemErrors(a);
|
|
116
|
-
let o = {
|
|
117
|
-
...r,
|
|
118
|
-
...n
|
|
119
|
-
};
|
|
120
|
-
if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(O.lineItemsNeedAttention), !(a || Object.keys(o).length)) {
|
|
121
|
-
L.current = !0, I("finalize");
|
|
122
|
-
try {
|
|
123
|
-
let t;
|
|
124
|
-
try {
|
|
125
|
-
if (await S?.() === !1) return;
|
|
126
|
-
t = await W();
|
|
127
|
-
} catch {
|
|
128
|
-
_.setErrors({ form: O.saveFailed });
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
C?.(t);
|
|
132
|
-
try {
|
|
133
|
-
let n = await V.mutateAsync({ path: { payable_id: t } });
|
|
134
|
-
if (n.validation_errors.length) {
|
|
135
|
-
_.setErrors(v(n.validation_errors, O));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
await H.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), E?.(t), e.success(O.billFinalized);
|
|
139
|
-
} catch {
|
|
140
|
-
_.setErrors({ form: O.finalizeFailed });
|
|
141
|
-
}
|
|
142
|
-
} finally {
|
|
143
|
-
I(void 0), L.current = !1;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}, [
|
|
147
|
-
b,
|
|
148
|
-
_,
|
|
149
|
-
O,
|
|
150
|
-
E,
|
|
151
|
-
C,
|
|
152
|
-
S,
|
|
153
|
-
W,
|
|
154
|
-
H,
|
|
155
|
-
V
|
|
156
|
-
]),
|
|
157
|
-
payableId: j,
|
|
158
|
-
isSavingDraft: F === "draft",
|
|
159
|
-
isFinalizing: F === "finalize",
|
|
160
|
-
stagedFile: M,
|
|
161
|
-
stageFile: N,
|
|
162
|
-
clearStagedFile: P
|
|
163
|
-
};
|
|
30
|
+
function c(t, r, i, o = e) {
|
|
31
|
+
return !a(t) || !a(r) || i !== void 0 && n(i) === null ? { form: o.totalsNeedAttention } : void 0;
|
|
164
32
|
}
|
|
165
33
|
//#endregion
|
|
166
|
-
export {
|
|
34
|
+
export { s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
|
|
@@ -1,38 +1,169 @@
|
|
|
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 "../../../shared/ui/dist/index.js";
|
|
7
|
+
import { useReplacePayableLineItemsMutation as t } from "../../data-access/dist/index7.js";
|
|
8
|
+
import { useCreatePayableMutation as n, useSubmitPayableForApprovalMutation as r, useUpdatePayableMutation as i, useValidatePayableMutation as a } from "../../data-access/dist/index10.js";
|
|
9
|
+
import "../../data-access/dist/index.js";
|
|
10
|
+
import { BILL_CREATE_MESSAGE_LABELS_EN as o } from "./index28.js";
|
|
11
|
+
import { encodeFileToBase64 as s } from "./index34.js";
|
|
12
|
+
import { mapBillFormToPayload as c, mapLineItemsToPayload as l } from "./index35.js";
|
|
13
|
+
import { validateBillCompleteness as u, validateBillTotals as d, validateLineItems as f } from "./index36.js";
|
|
14
|
+
import { useCallback as p, useRef as m, useState as h } from "react";
|
|
1
15
|
//#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index37.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
16
|
+
var g = {
|
|
17
|
+
document_id: "invoiceNumber",
|
|
18
|
+
issued_at: "invoiceDate",
|
|
19
|
+
due_date: "dueDate",
|
|
20
|
+
counterpart_id: "vendor"
|
|
21
|
+
};
|
|
22
|
+
function _(e) {
|
|
23
|
+
return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
|
|
11
24
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
25
|
+
function v(e, t = o) {
|
|
26
|
+
let n = {}, r = [];
|
|
27
|
+
for (let i of e) {
|
|
28
|
+
let e = i.loc[0] ?? t.unknownValidationField, a = g[e], o = _(i) ? t.requiredField : i.msg;
|
|
29
|
+
a ? n[a] = o : r.push(t.unmappedValidationError(e, o));
|
|
30
|
+
}
|
|
31
|
+
return r.length && (n.form = r.join(" ")), n;
|
|
32
|
+
}
|
|
33
|
+
function y(e, t) {
|
|
34
|
+
if (!e && !t) return;
|
|
35
|
+
let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
|
|
36
|
+
for (let i of r) n[i] = {
|
|
37
|
+
...e?.[i],
|
|
38
|
+
...t?.[i]
|
|
39
|
+
};
|
|
40
|
+
return n;
|
|
14
41
|
}
|
|
15
|
-
function
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
function b({ payableId: g, form: _, counterpartId: b, clearCounterpart: x, prepareVendorForSave: S, onSaved: C, onPayableCreated: w, onDraftSaved: T, onFinalized: E, labels: D }) {
|
|
43
|
+
let O = {
|
|
44
|
+
...o,
|
|
45
|
+
...D
|
|
46
|
+
}, [k, A] = h(), j = g ?? k, [M, N] = h(), P = p(() => N(void 0), []), [F, I] = h(), L = m(!1), R = n(), z = i(), B = t(), V = a(), H = r(), U = p(() => {
|
|
47
|
+
let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O);
|
|
48
|
+
return _.setLineItemErrors(t), !t && !n || (t ? (_.setErrors(void 0), e.error(O.lineItemsNeedAttention)) : _.setErrors(n), !1);
|
|
49
|
+
}, [_, O]), W = p(async (e) => {
|
|
50
|
+
let t = !j && M ? {
|
|
51
|
+
base64EncodedFile: await s(M),
|
|
52
|
+
fileName: M.name
|
|
53
|
+
} : void 0, n = c({
|
|
54
|
+
values: _.values,
|
|
55
|
+
counterpartId: b,
|
|
56
|
+
clearCounterpart: x,
|
|
57
|
+
counterpartBankAccountId: e,
|
|
58
|
+
editedTotals: _.isTotalsDirty ? {
|
|
59
|
+
discount: _.discount,
|
|
60
|
+
tax: _.tax,
|
|
61
|
+
total: _.totalOverride
|
|
62
|
+
} : void 0,
|
|
63
|
+
document: t
|
|
64
|
+
}), r = j;
|
|
65
|
+
if (r ? await z.mutateAsync({
|
|
66
|
+
path: { payable_id: r },
|
|
67
|
+
body: n
|
|
68
|
+
}) : (r = (await R.mutateAsync({ body: n }))?.id, r && (A(r), w?.(r), t && N(void 0))), !r) throw Error("Payable was created without an id");
|
|
69
|
+
return await B.mutateAsync({
|
|
70
|
+
path: { payable_id: r },
|
|
71
|
+
body: { data: l(_.lineItems) }
|
|
72
|
+
}), r;
|
|
73
|
+
}, [
|
|
74
|
+
b,
|
|
75
|
+
x,
|
|
76
|
+
R,
|
|
77
|
+
_.discount,
|
|
78
|
+
_.isTotalsDirty,
|
|
79
|
+
_.lineItems,
|
|
80
|
+
_.tax,
|
|
81
|
+
_.totalOverride,
|
|
82
|
+
_.values,
|
|
83
|
+
w,
|
|
84
|
+
j,
|
|
85
|
+
B,
|
|
86
|
+
M,
|
|
87
|
+
z
|
|
88
|
+
]);
|
|
29
89
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
90
|
+
saveDraft: p(async () => {
|
|
91
|
+
if (!L.current && U()) {
|
|
92
|
+
L.current = !0, I("draft");
|
|
93
|
+
try {
|
|
94
|
+
let t = await S?.();
|
|
95
|
+
if (t && !t.ok) return;
|
|
96
|
+
let n = await W(t?.counterpartBankAccountId);
|
|
97
|
+
_.setErrors(void 0), C?.(n), T?.(n), e.success(O.draftSaved);
|
|
98
|
+
} catch {
|
|
99
|
+
_.setErrors({ form: O.saveFailed });
|
|
100
|
+
} finally {
|
|
101
|
+
I(void 0), L.current = !1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
_,
|
|
106
|
+
U,
|
|
107
|
+
O.draftSaved,
|
|
108
|
+
O.saveFailed,
|
|
109
|
+
T,
|
|
110
|
+
C,
|
|
111
|
+
S,
|
|
112
|
+
W
|
|
113
|
+
]),
|
|
114
|
+
finalize: p(async () => {
|
|
115
|
+
if (L.current) return;
|
|
116
|
+
let t = f(_.lineItems, O), n = d(_.discount, _.tax, _.totalOverride, O), { formErrors: r, lineItemErrors: i } = u(_.values, b, _.lineItems, O), a = y(i, t);
|
|
117
|
+
_.setLineItemErrors(a);
|
|
118
|
+
let o = {
|
|
119
|
+
...r,
|
|
120
|
+
...n
|
|
121
|
+
};
|
|
122
|
+
if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(O.lineItemsNeedAttention), !(a || Object.keys(o).length)) {
|
|
123
|
+
L.current = !0, I("finalize");
|
|
124
|
+
try {
|
|
125
|
+
let t;
|
|
126
|
+
try {
|
|
127
|
+
let e = await S?.();
|
|
128
|
+
if (e && !e.ok) return;
|
|
129
|
+
t = await W(e?.counterpartBankAccountId);
|
|
130
|
+
} catch {
|
|
131
|
+
_.setErrors({ form: O.saveFailed });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
C?.(t);
|
|
135
|
+
try {
|
|
136
|
+
let n = await V.mutateAsync({ path: { payable_id: t } });
|
|
137
|
+
if (n.validation_errors.length) {
|
|
138
|
+
_.setErrors(v(n.validation_errors, O));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
await H.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), E?.(t), e.success(O.billFinalized);
|
|
142
|
+
} catch {
|
|
143
|
+
_.setErrors({ form: O.finalizeFailed });
|
|
144
|
+
}
|
|
145
|
+
} finally {
|
|
146
|
+
I(void 0), L.current = !1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}, [
|
|
150
|
+
b,
|
|
151
|
+
_,
|
|
152
|
+
O,
|
|
153
|
+
E,
|
|
154
|
+
C,
|
|
155
|
+
S,
|
|
156
|
+
W,
|
|
157
|
+
H,
|
|
158
|
+
V
|
|
159
|
+
]),
|
|
160
|
+
payableId: j,
|
|
161
|
+
isSavingDraft: F === "draft",
|
|
162
|
+
isFinalizing: F === "finalize",
|
|
163
|
+
stagedFile: M,
|
|
164
|
+
stageFile: N,
|
|
165
|
+
clearStagedFile: P
|
|
35
166
|
};
|
|
36
167
|
}
|
|
37
168
|
//#endregion
|
|
38
|
-
export {
|
|
169
|
+
export { v as mapValidationErrorsToForm, b as useBillCreateController };
|