@tesouro/embedded-components-react 0.2.266 → 0.2.267

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 (39) hide show
  1. package/dist/index.css +45 -9
  2. package/dist/index.js +1 -1
  3. package/dist/lib/BillPayWidget.js +1 -1
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +6 -6
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index10.js +99 -7
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index11.js +7 -97
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js +99 -4
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index13.js +4 -4
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index14.js +2 -41
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index15.js +43 -1
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index16.js +1 -50
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index17.js +48 -6
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index18.js +9 -5
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index19.js +8 -91
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index2.js +6 -2
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index20.js +7 -3
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js +100 -6
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index22.js +3 -9
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index23.js +6 -83
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index24.js +9 -3
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index25.js +83 -6
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index26.js +2 -111
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index27.js +8 -1
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js +103 -16
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index29.js +1 -0
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js +25 -0
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index6.js +37 -27
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index7.js +15 -116
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index8.js +126 -31
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js +32 -69
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index12.js +0 -3
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index13.js +34 -69
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index15.js +4 -0
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index16.js +261 -181
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index28.js +32 -33
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index7.js +2 -2
  37. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  38. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index5.js +1 -1
  39. package/package.json +1 -1
@@ -2,24 +2,111 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { Implementation as e } from "../../../shared/feature/dist/lib/WidgetProvider/types.js";
6
- import { useWidgetConfig as t } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
5
+ import { hasAnyScope as e } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
6
+ import { Scope as t } from "../../../shared/data-access/dist/lib/scopes.js";
7
+ import "../../../shared/data-access/dist/index.js";
8
+ import { EmbeddedToaster as n } from "../../../shared/ui/dist/lib/EmbeddedToaster.js";
9
+ import "../../../shared/ui/dist/index.js";
10
+ import { useAnalyticsTrack as r } from "../../../shared/feature/dist/lib/analytics/hooks.js";
11
+ import { WidgetProvider as i } from "../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
12
+ import { useWidgetConfig as a } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
7
13
  import "../../../shared/feature/dist/index.js";
8
- import { BillPayWidgetMonite as n } from "./index14.js";
9
- import "./index15.js";
10
- import { BillPayWidgetNative as r } from "./index26.js";
11
- import "./index27.js";
12
- import { jsx as i } from "react/jsx-runtime";
14
+ import { BillPayWidgetUi as o } from "../../ui/dist/index31.js";
15
+ import { BillUploadStatusTray as s } from "../../ui/dist/index41.js";
16
+ import "../../ui/dist/index.js";
17
+ import { billsTabTestIds as c } from "./index20.js";
18
+ import { BillsTab as l } from "./index21.js";
19
+ import "./index22.js";
20
+ import { useBillUploadQueue as u } from "./index25.js";
21
+ import "./index26.js";
22
+ import { BillPayWidgetAnalyticsEvent as d, WIDGET_NAME as f } from "./index14.js";
23
+ import { DEFAULT_TABS_LABELS as p } from "./index27.js";
24
+ import { ApprovalPoliciesSettings as m } from "../../../shared/approval-policy/feature/dist/lib/ApprovalPoliciesSettings.js";
25
+ import "../../../shared/approval-policy/feature/dist/index.js";
26
+ import { CounterpartsWidget as h } from "../../../counterparts-widget/feature/dist/index8.js";
27
+ import "../../../counterparts-widget/feature/dist/index.js";
28
+ import { useCallback as g, useEffect as _, useState as v } from "react";
29
+ import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
13
30
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index28.js
14
- function a({ implementation: a, ...o }) {
15
- let s = t().implementation, c = a ?? s ?? e.Monite;
16
- return c === e.Native ? /* @__PURE__ */ i(r, {
17
- implementation: c,
18
- ...o
19
- }) : /* @__PURE__ */ i(n, {
20
- implementation: c,
21
- ...o
31
+ var S = {
32
+ Bills: "bills",
33
+ Vendors: "vendors",
34
+ Settings: "settings"
35
+ }, C = [
36
+ S.Bills,
37
+ S.Vendors,
38
+ S.Settings
39
+ ];
40
+ function w({ labels: i, tabsLabels: f, approvalPolicyLabels: w, approvalPolicyComponentLabels: T, vendorLabels: E }) {
41
+ let D = r();
42
+ _(() => {
43
+ D(d.Mounted);
44
+ }, [D]);
45
+ let O = {
46
+ ...p,
47
+ ...f
48
+ }, { initResponse: k } = a(), A = e(k?.scopes, [t.ApprovalPolicyWriteOrg]), j = !k || A, [M, N] = v(S.Bills), [P, F] = v(), I = g((e) => {
49
+ N(S.Bills), F(e);
50
+ }, []), L = u({ onOpenBill: I }), R = [{
51
+ id: S.Bills,
52
+ label: O.bills,
53
+ content: /* @__PURE__ */ b(l, {
54
+ onEnqueueFiles: L.enqueue,
55
+ openPayableId: P,
56
+ onOpenPayableHandled: () => F(void 0)
57
+ })
58
+ }, {
59
+ id: S.Vendors,
60
+ label: O.vendors,
61
+ content: /* @__PURE__ */ b(h, {
62
+ ...E,
63
+ counterpartType: "vendor",
64
+ showTitle: !1,
65
+ onViewAllDocuments: () => N(S.Bills)
66
+ })
67
+ }];
68
+ j && R.push({
69
+ id: S.Settings,
70
+ label: O.settings,
71
+ content: /* @__PURE__ */ b(m, {
72
+ labels: w,
73
+ componentLabels: T
74
+ })
75
+ });
76
+ let z = R.some((e) => e.id === M) ? M : C.find((e) => R.some((t) => t.id === e)) ?? R[0]?.id ?? "";
77
+ return /* @__PURE__ */ x(y, { children: [
78
+ /* @__PURE__ */ b(n, {}),
79
+ /* @__PURE__ */ b(o, {
80
+ labels: i,
81
+ tabs: R,
82
+ selectedTabId: z,
83
+ onTabChange: N
84
+ }),
85
+ L.isVisible ? /* @__PURE__ */ b(s, {
86
+ sections: L.sections,
87
+ summaryLabel: L.summaryLabel,
88
+ collapsed: L.collapsed,
89
+ onToggleCollapsed: L.onToggleCollapsed,
90
+ onClose: L.onClose,
91
+ testId: c.uploadTray
92
+ }) : null
93
+ ] });
94
+ }
95
+ function T({ baseUrl: e, widgetToken: t, organizationId: n, configClient: r, linkComponent: a, implementation: o, uiFramework: s, errorFallback: c, onError: l, analytics: u, ...d }) {
96
+ return /* @__PURE__ */ b(i, {
97
+ widgetName: f,
98
+ baseUrl: e,
99
+ widgetToken: t,
100
+ organizationId: n,
101
+ configClient: r,
102
+ linkComponent: a,
103
+ implementation: o,
104
+ uiFramework: s,
105
+ errorFallback: c,
106
+ onError: l,
107
+ analytics: u,
108
+ children: /* @__PURE__ */ b(w, { ...d })
22
109
  });
23
110
  }
24
111
  //#endregion
25
- export { a as BillPayWidget, a as default };
112
+ export { T as BillPayWidgetNative, T as default };
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { Implementation as e } from "../../../shared/feature/dist/lib/WidgetProvider/types.js";
6
+ import { useWidgetConfig as t } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
7
+ import "../../../shared/feature/dist/index.js";
8
+ import { BillPayWidgetMonite as n } from "./index15.js";
9
+ import "./index16.js";
10
+ import { BillPayWidgetNative as r } from "./index28.js";
11
+ import "./index29.js";
12
+ import { jsx as i } from "react/jsx-runtime";
13
+ //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index30.js
14
+ function a({ implementation: a, ...o }) {
15
+ let s = t().implementation, c = a ?? s ?? e.Monite;
16
+ return c === e.Native ? /* @__PURE__ */ i(r, {
17
+ implementation: c,
18
+ ...o
19
+ }) : /* @__PURE__ */ i(n, {
20
+ implementation: c,
21
+ ...o
22
+ });
23
+ }
24
+ //#endregion
25
+ export { a as BillPayWidget, a as default };
@@ -1,40 +1,50 @@
1
- import { formatMoneyExact as e } from "../../../shared/util/dist/lib/formatMoneyExact.js";
2
- import { parseDecimalAmountToMinorUnits as t } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
1
+ import { parseDecimalAmountToMinorUnits as e } from "../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
3
2
  import "../../data-access/dist/index.js";
4
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index6.js
5
- var n = "USD";
4
+ var t = "USD";
5
+ function n(n) {
6
+ return e(n, t);
7
+ }
6
8
  function r(e) {
7
- return t(e, n) ?? 0;
9
+ let t = e.trim();
10
+ if (!t) return null;
11
+ let n = Number(t);
12
+ return Number.isFinite(n) && n > 0 ? n : null;
8
13
  }
9
14
  function i(e) {
15
+ return !!(e.description.trim() || n(e.price) !== null || n(e.amount) !== null);
16
+ }
17
+ function a(e) {
18
+ return n(e) ?? 0;
19
+ }
20
+ function o(e) {
10
21
  let t = Number.parseFloat(e);
11
22
  return Number.isFinite(t) ? t : 0;
12
23
  }
13
- function a({ values: e, paymentTerm: t, counterpartId: r }) {
14
- let i = { currency: n };
15
- return r && (i.counterpart_id = r), e.invoiceNumber && (i.document_id = e.invoiceNumber), e.invoiceDate && (i.issued_at = e.invoiceDate), e.dueDate && (i.due_date = e.dueDate), t?.term_final && t.name && (i.payment_terms = {
16
- name: t.name,
17
- ...t.description ? { description: t.description } : {},
18
- ...t.term_1 ? { term_1: t.term_1 } : {},
19
- ...t.term_2 ? { term_2: t.term_2 } : {},
20
- term_final: t.term_final
21
- }), i;
24
+ function s(e) {
25
+ return (e / 100).toFixed(2);
22
26
  }
23
- function o(e) {
24
- return e.filter((e) => e.description || e.price).map((e) => ({
25
- name: e.description,
26
- quantity: i(e.quantity),
27
- unit_price: r(e.price),
28
- ...e.glCode ? { ledger_account_id: e.glCode } : {}
29
- }));
27
+ function c({ values: e, counterpartId: r, editedTotals: i }) {
28
+ let a = { currency: t };
29
+ return r && (a.counterpart_id = r), e.invoiceNumber && (a.document_id = e.invoiceNumber), e.invoiceDate && (a.issued_at = e.invoiceDate), e.dueDate && (a.due_date = e.dueDate), i && (a.discount = n(i.discount) ?? 0, a.tax_amount = n(i.tax) ?? 0, i.total !== void 0 && (a.total_amount = n(i.total) ?? 0)), a;
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
+ });
30
42
  }
31
- function s(t, a) {
32
- let o = Math.round(i(t) * r(a));
33
- return e(o / 100, { currencyCode: n });
43
+ function u(e, t) {
44
+ return s(Math.round(o(e) * a(t)));
34
45
  }
35
- function c(t) {
36
- let a = t.reduce((e, t) => e + Math.round(i(t.quantity) * r(t.price)), 0);
37
- return e(a / 100, { currencyCode: n });
46
+ function d(e, t, n) {
47
+ return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
38
48
  }
39
49
  //#endregion
40
- export { s as displayLineAmount, c as displayTotal, a as mapBillFormToPayload, o as mapLineItemsToPayload };
50
+ export { d as calculateTotal, u as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, l as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
@@ -1,122 +1,21 @@
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 { BILL_CREATE_MESSAGE_LABELS_EN as t } from "./index2.js";
8
- import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index6.js";
9
- import { useCreatePayableMutation as r, useSubmitPayableForApprovalMutation as i, useUpdatePayableMutation as a, useValidatePayableMutation as o } from "../../data-access/dist/index7.js";
10
- import "../../data-access/dist/index.js";
11
- import { mapBillFormToPayload as s, mapLineItemsToPayload as c } from "./index6.js";
12
- import { useCallback as l, useRef as u, useState as d } from "react";
1
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index2.js";
2
+ import { parseMoneyToMinorUnits as t, parseQuantity as n } from "./index6.js";
13
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index7.js
14
- var f = {
15
- document_id: "invoiceNumber",
16
- issued_at: "invoiceDate",
17
- due_date: "dueDate",
18
- payment_terms: "paymentTerms"
19
- };
20
- function p(e) {
21
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
4
+ var r = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/;
5
+ function i(e) {
6
+ let n = e.trim();
7
+ return !n || t(n) !== null ? !0 : r.test(n) ? Number(n.replaceAll(",", "")) === 0 : !1;
22
8
  }
23
- function m(e, n = t) {
24
- let r = {}, i = [];
25
- for (let t of e) {
26
- let e = t.loc[0] ?? n.unknownValidationField, a = f[e], o = p(t) ? n.requiredField : t.msg;
27
- a ? r[a] = o : i.push(n.unmappedValidationError(e, o));
9
+ function a(r, i = e) {
10
+ let a = {};
11
+ for (let e of r) {
12
+ let r = t(e.price), o = t(e.amount), s = {};
13
+ e.price.trim() && r === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), (r !== null || o !== null) && n(e.quantity) === null && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
28
14
  }
29
- return i.length && (r.form = i.join(" ")), r;
15
+ return Object.keys(a).length ? a : void 0;
30
16
  }
31
- function h({ payableId: f, form: p, paymentTerm: h, counterpartId: g, onSaved: _, onPayableCreated: v, onDraftSaved: y, onFinalized: b, labels: x }) {
32
- let S = {
33
- ...t,
34
- ...x
35
- }, [C, w] = d(), T = f ?? C, [E, D] = d(), O = u(!1), k = r(), A = a(), j = n(), M = o(), N = i(), P = l(async () => {
36
- let e = s({
37
- values: p.values,
38
- paymentTerm: h,
39
- counterpartId: g
40
- }), t = T;
41
- if (t ? await A.mutateAsync({
42
- path: { payable_id: t },
43
- body: e
44
- }) : (t = (await k.mutateAsync({ body: e }))?.id, t && (w(t), v?.(t))), !t) throw Error("Payable was created without an id");
45
- return await j.mutateAsync({
46
- path: { payable_id: t },
47
- body: { data: c(p.lineItems) }
48
- }), t;
49
- }, [
50
- g,
51
- k,
52
- p.lineItems,
53
- p.values,
54
- v,
55
- h,
56
- T,
57
- j,
58
- A
59
- ]);
60
- return {
61
- saveDraft: l(async () => {
62
- if (!O.current) {
63
- O.current = !0, D("draft");
64
- try {
65
- let t = await P();
66
- p.setErrors(void 0), _?.(t), y?.(t), e.success(S.draftSaved);
67
- } catch {
68
- p.setErrors({ form: S.saveFailed });
69
- } finally {
70
- D(void 0), O.current = !1;
71
- }
72
- }
73
- }, [
74
- p,
75
- S.draftSaved,
76
- S.saveFailed,
77
- y,
78
- _,
79
- P
80
- ]),
81
- finalize: l(async () => {
82
- if (!O.current) {
83
- O.current = !0, D("finalize");
84
- try {
85
- let t;
86
- try {
87
- t = await P();
88
- } catch {
89
- p.setErrors({ form: S.saveFailed });
90
- return;
91
- }
92
- _?.(t);
93
- try {
94
- let n = await M.mutateAsync({ path: { payable_id: t } });
95
- if (n.validation_errors.length) {
96
- p.setErrors(m(n.validation_errors, S));
97
- return;
98
- }
99
- await N.mutateAsync({ path: { payable_id: t } }), p.setErrors(void 0), b?.(t), e.success(S.billFinalized);
100
- } catch {
101
- p.setErrors({ form: S.finalizeFailed });
102
- }
103
- } finally {
104
- D(void 0), O.current = !1;
105
- }
106
- }
107
- }, [
108
- p,
109
- S,
110
- b,
111
- _,
112
- P,
113
- N,
114
- M
115
- ]),
116
- payableId: T,
117
- isSavingDraft: E === "draft",
118
- isFinalizing: E === "finalize"
119
- };
17
+ function o(t, n, r, a = e) {
18
+ return !i(t) || !i(n) || r !== void 0 && (!r.trim() || !i(r)) ? { form: a.totalsNeedAttention } : void 0;
120
19
  }
121
20
  //#endregion
122
- export { m as mapValidationErrorsToForm, h as useBillCreateController };
21
+ export { o as validateBillTotals, a as validateLineItems };
@@ -1,39 +1,134 @@
1
- import { formatMoneyExact as e } from "../../../shared/util/dist/lib/formatMoneyExact.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 "../../../shared/ui/dist/index.js";
7
+ import { BILL_CREATE_MESSAGE_LABELS_EN as t } from "./index2.js";
8
+ import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index6.js";
9
+ import { useCreatePayableMutation as r, useSubmitPayableForApprovalMutation as i, useUpdatePayableMutation as a, useValidatePayableMutation as o } from "../../data-access/dist/index7.js";
2
10
  import "../../data-access/dist/index.js";
11
+ import { mapBillFormToPayload as s, mapLineItemsToPayload as c } from "./index6.js";
12
+ import { validateBillTotals as l, validateLineItems as u } from "./index7.js";
13
+ import { useCallback as d, useRef as f, useState as p } from "react";
3
14
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index8.js
4
- var t = "USD";
5
- function n() {
6
- return {
7
- id: crypto.randomUUID(),
8
- description: "",
9
- glCode: "",
10
- quantity: "1",
11
- price: "",
12
- amount: ""
13
- };
15
+ var m = {
16
+ document_id: "invoiceNumber",
17
+ issued_at: "invoiceDate",
18
+ due_date: "dueDate"
19
+ };
20
+ function h(e) {
21
+ return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
14
22
  }
15
- function r(e) {
16
- return typeof e == "number" ? (e / 100).toFixed(2) : "";
23
+ function g(e, n = t) {
24
+ let r = {}, i = [];
25
+ for (let t of e) {
26
+ let e = t.loc[0] ?? n.unknownValidationField, a = m[e], o = h(t) ? n.requiredField : t.msg;
27
+ a ? r[a] = o : i.push(n.unmappedValidationError(e, o));
28
+ }
29
+ return i.length && (r.form = i.join(" ")), r;
17
30
  }
18
- function i({ payable: i, lineItems: a }) {
19
- let o = {
20
- invoiceNumber: i.document_id ?? "",
21
- invoiceDate: i.issued_at ?? "",
22
- dueDate: i.due_date ?? "",
23
- paymentTerms: "",
24
- poNumber: ""
25
- }, s = a.map((n) => ({
26
- id: n.id,
27
- description: n.name ?? "",
28
- glCode: n.ledger_account_id ?? "",
29
- quantity: n.quantity == null ? "" : String(n.quantity),
30
- price: r(n.unit_price),
31
- amount: typeof n.total == "number" ? e(n.total / 100, { currencyCode: t }) : ""
32
- }));
31
+ function _({ payableId: m, form: h, counterpartId: _, onSaved: v, onPayableCreated: y, onDraftSaved: b, onFinalized: x, labels: S }) {
32
+ let C = {
33
+ ...t,
34
+ ...S
35
+ }, [w, T] = p(), E = m ?? w, [D, O] = p(), k = f(!1), A = r(), j = a(), M = n(), N = o(), P = i(), F = d(() => {
36
+ let e = u(h.lineItems, C), t = l(h.discount, h.tax, h.totalOverride, C);
37
+ return h.setLineItemErrors(e), !e && !t || (h.setErrors(e ? { form: C.lineItemsNeedAttention } : t), !1);
38
+ }, [h, C]), I = d(async () => {
39
+ let e = s({
40
+ values: h.values,
41
+ counterpartId: _,
42
+ editedTotals: h.isTotalsDirty ? {
43
+ discount: h.discount,
44
+ tax: h.tax,
45
+ total: h.totalOverride
46
+ } : void 0
47
+ }), t = E;
48
+ if (t ? await j.mutateAsync({
49
+ path: { payable_id: t },
50
+ body: e
51
+ }) : (t = (await A.mutateAsync({ body: e }))?.id, t && (T(t), y?.(t))), !t) throw Error("Payable was created without an id");
52
+ return await M.mutateAsync({
53
+ path: { payable_id: t },
54
+ body: { data: c(h.lineItems) }
55
+ }), t;
56
+ }, [
57
+ _,
58
+ A,
59
+ h.discount,
60
+ h.isTotalsDirty,
61
+ h.lineItems,
62
+ h.tax,
63
+ h.totalOverride,
64
+ h.values,
65
+ y,
66
+ E,
67
+ M,
68
+ j
69
+ ]);
33
70
  return {
34
- values: o,
35
- lineItems: s.length ? s : [n()]
71
+ saveDraft: d(async () => {
72
+ if (!k.current && F()) {
73
+ k.current = !0, O("draft");
74
+ try {
75
+ let t = await I();
76
+ h.setErrors(void 0), v?.(t), b?.(t), e.success(C.draftSaved);
77
+ } catch {
78
+ h.setErrors({ form: C.saveFailed });
79
+ } finally {
80
+ O(void 0), k.current = !1;
81
+ }
82
+ }
83
+ }, [
84
+ h,
85
+ F,
86
+ C.draftSaved,
87
+ C.saveFailed,
88
+ b,
89
+ v,
90
+ I
91
+ ]),
92
+ finalize: d(async () => {
93
+ if (!k.current && F()) {
94
+ k.current = !0, O("finalize");
95
+ try {
96
+ let t;
97
+ try {
98
+ t = await I();
99
+ } catch {
100
+ h.setErrors({ form: C.saveFailed });
101
+ return;
102
+ }
103
+ v?.(t);
104
+ try {
105
+ let n = await N.mutateAsync({ path: { payable_id: t } });
106
+ if (n.validation_errors.length) {
107
+ h.setErrors(g(n.validation_errors, C));
108
+ return;
109
+ }
110
+ await P.mutateAsync({ path: { payable_id: t } }), h.setErrors(void 0), x?.(t), e.success(C.billFinalized);
111
+ } catch {
112
+ h.setErrors({ form: C.finalizeFailed });
113
+ }
114
+ } finally {
115
+ O(void 0), k.current = !1;
116
+ }
117
+ }
118
+ }, [
119
+ h,
120
+ F,
121
+ C,
122
+ x,
123
+ v,
124
+ I,
125
+ P,
126
+ N
127
+ ]),
128
+ payableId: E,
129
+ isSavingDraft: D === "draft",
130
+ isFinalizing: D === "finalize"
36
131
  };
37
132
  }
38
133
  //#endregion
39
- export { n as emptyLineItem, i as mapPayableToBillForm };
134
+ export { g as mapValidationErrorsToForm, _ as useBillCreateController };
@@ -1,74 +1,37 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { displayLineAmount as e, displayTotal as t } from "./index6.js";
6
- import { emptyLineItem as n, mapPayableToBillForm as r } from "./index8.js";
7
- import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
8
1
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js
9
- function c({ payable: c, lineItems: l } = {}) {
10
- let u = o(() => r({
11
- payable: c ?? {},
12
- lineItems: l ?? []
13
- }), [c, l]), [d, f] = s(u.values), [p, m] = s(u.lineItems), [h, g] = s(), [_, v] = s(!1), [y, b] = s(!1);
14
- a(() => {
15
- _ || f(u.values);
16
- }, [u]), a(() => {
17
- y || m(u.lineItems);
18
- }, [u]);
19
- let x = i((e) => {
20
- f((t) => ({
21
- ...t,
22
- ...e
23
- })), v(!0);
24
- }, []), S = i((t, n) => {
25
- m((r) => r.map((r) => {
26
- if (r.id !== t) return r;
27
- let i = {
28
- ...r,
29
- ...n
30
- };
31
- return {
32
- ...i,
33
- amount: e(i.quantity, i.price)
34
- };
35
- })), b(!0);
36
- }, []), C = i((t, n) => {
37
- m((r) => r.map((r) => {
38
- if (r.id !== t) return r;
39
- let i = Number.parseFloat(r.quantity), a = String(Math.max(1, (Number.isFinite(i) ? i : 1) + n));
40
- return {
41
- ...r,
42
- quantity: a,
43
- amount: e(a, r.price)
44
- };
45
- })), b(!0);
46
- }, []), w = i((e) => {
47
- m((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e)), b(!0);
48
- }, []), T = i(() => {
49
- m((e) => [...e, n()]), b(!0);
50
- }, []);
2
+ function e() {
51
3
  return {
52
- values: d,
53
- errors: h,
54
- setErrors: g,
55
- onChange: x,
56
- lineItems: p,
57
- lineItemRows: o(() => p.map((e) => ({
58
- ...e,
59
- onChange: (t) => S(e.id, t),
60
- onQuantityStep: (t) => C(e.id, t),
61
- onRemove: () => w(e.id)
62
- })), [
63
- p,
64
- S,
65
- w,
66
- C
67
- ]),
68
- totalAmountLabel: o(() => t(p), [p]),
69
- onAddLineItem: T,
70
- isDirty: _ || y
4
+ id: crypto.randomUUID(),
5
+ description: "",
6
+ glCode: "",
7
+ quantity: "1",
8
+ price: "",
9
+ amount: ""
10
+ };
11
+ }
12
+ function t(e) {
13
+ return typeof e == "number" ? (e / 100).toFixed(2) : "";
14
+ }
15
+ function n({ payable: n, lineItems: r }) {
16
+ let i = {
17
+ invoiceNumber: n.document_id ?? "",
18
+ invoiceDate: n.issued_at ?? "",
19
+ dueDate: n.due_date ?? "",
20
+ poNumber: ""
21
+ }, a = r.map((e) => ({
22
+ id: e.id,
23
+ description: e.name ?? "",
24
+ glCode: e.ledger_account_id ?? "",
25
+ quantity: e.quantity == null ? "" : String(e.quantity),
26
+ price: t(e.unit_price),
27
+ amount: t(e.subtotal)
28
+ }));
29
+ return {
30
+ values: i,
31
+ lineItems: a.length ? a : [e()],
32
+ discount: t(n.discount),
33
+ tax: t(n.tax_amount)
71
34
  };
72
35
  }
73
36
  //#endregion
74
- export { c as useBillForm };
37
+ export { e as emptyLineItem, n as mapPayableToBillForm };
@@ -3,9 +3,6 @@ var e = {
3
3
  invoiceNumber: "Invoice number",
4
4
  invoiceDate: "Invoice date",
5
5
  dueDate: "Due date",
6
- paymentTerms: "Payment terms (optional)",
7
- paymentTermsPlaceholder: "Select payment terms",
8
- paymentTermsNone: "No payment terms",
9
6
  poNumber: "PO number (optional)"
10
7
  };
11
8
  //#endregion