@tesouro/embedded-components-react 0.11.129 → 0.11.131

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 (59) hide show
  1. package/dist/fixtures/index.d.ts +4 -4
  2. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index.js +5 -4
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index21.js +20 -17
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index22.js +14 -37
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index23.js +31 -14
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index24.js +26 -2
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/data-access/dist/index25.js +2 -0
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index.js +7 -7
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index10.js +35 -12
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index11.js +57 -65
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index12.js +6 -11
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index13.js +20 -8
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index14.js +97 -7
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index15.js +10 -10
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index16.js +10 -29
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index17.js +7 -27
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index18.js +8 -18
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index19.js +24 -139
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index20.js +24 -13
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index21.js +14 -17
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index22.js +130 -27
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index23.js +17 -100
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index24.js +21 -82
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index25.js +41 -3
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index26.js +98 -53
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index27.js +82 -113
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index28.js +3 -193
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js +57 -81
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index30.js +110 -66
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index31.js +190 -111
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index32.js +71 -456
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index33.js +69 -114
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index34.js +113 -8
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index35.js +458 -79
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js +116 -79
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js +10 -256
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js +78 -36
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js +73 -236
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index4.js +1 -1
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js +256 -21
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index41.js +43 -516
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index42.js +245 -4
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index43.js +20 -40
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index44.js +497 -211
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index45.js +3 -2
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index46.js +40 -3
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index47.js +235 -57
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index48.js +2 -0
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index49.js +5 -0
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index50.js +64 -0
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index51.js +1 -0
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index6.js +4 -47
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index7.js +13 -4
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index8.js +8 -13
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index9.js +18 -9
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/ui/dist/index3.js +44 -34
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/lib/BillPayWidget/BillsTab.js +1 -1
  58. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  59. package/package.json +1 -1
@@ -1,82 +1,119 @@
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";
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/index16.js";
8
+ import "../../data-access/dist/index.js";
9
+ import { cloneElement as n, isValidElement as r, useCallback as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
3
10
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index36.js
4
- var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/, a = 255, o = 10, s = 5, c = 30, l = 864e5;
5
- function u() {
6
- let e = /* @__PURE__ */ new Date();
7
- return Date.UTC(e.getFullYear(), e.getMonth(), e.getDate());
8
- }
9
- function d() {
10
- let e = new Date(u());
11
- return e.setUTCFullYear(e.getUTCFullYear() - o), e;
12
- }
13
- function f(e) {
14
- let t = new Date(e);
15
- if (Number.isNaN(t.getTime())) return !1;
16
- let n = new Date(u() + c * l);
17
- return t < d() || t > n;
18
- }
19
- function p(e) {
20
- let t = new Date(e);
21
- if (Number.isNaN(t.getTime())) return !1;
22
- let n = new Date(u());
23
- return n.setUTCFullYear(n.getUTCFullYear() + s), t < d() || t > n;
24
- }
25
- function m(t, n = e) {
26
- let r = {};
27
- return t.poNumber.length > a && (r.poNumber = n.poNumberTooLong), Object.keys(r).length ? r : void 0;
28
- }
29
- function h(e) {
30
- let t = e.trim();
31
- return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
32
- }
33
- function g(t, i = e) {
34
- let a = {};
35
- for (let e of t) {
36
- let t = n(e.price), o = n(e.amount), s = {};
37
- e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), r(e.quantity) === null && (e.quantity.trim() || t !== null || o !== null) && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
38
- }
39
- return Object.keys(a).length ? a : void 0;
40
- }
41
- function _(i, a, o, s = e) {
42
- let c = {};
43
- a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField);
44
- let l = i.invoiceDate.trim(), u = i.dueDate.trim();
45
- l ? f(l) && (c.invoiceDate = s.implausibleInvoiceDate) : c.invoiceDate = s.requiredField, u ? p(u) ? c.dueDate = s.implausibleDueDate : l && u < l && (c.dueDate = s.dueBeforeInvoiceDate) : c.dueDate = s.requiredField;
46
- let d = {};
47
- return o.forEach((e, i) => {
48
- if (i > 0 && !t(e)) return;
49
- let a = {};
50
- 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 && (d[e.id] = a);
51
- }), {
52
- formErrors: Object.keys(c).length ? c : void 0,
53
- lineItemErrors: Object.keys(d).length ? d : void 0
11
+ function l({ vendor: l, payableId: u, linkedCounterpartId: d, linkedBankAccountId: f, canSavePayToEdits: p, readOnly: m, refreshPayable: h, labels: g }) {
12
+ let _ = t(), [v, y] = c(!1), b = s(void 0), x = i(async () => {
13
+ if (b.current) return b.current;
14
+ let t = (async () => {
15
+ if (p) {
16
+ y(!0);
17
+ try {
18
+ let t;
19
+ try {
20
+ t = await l.prepareVendorForSave({ closeOnSuccess: !1 });
21
+ } catch {
22
+ e.error(g.paymentInstructionsSaveError);
23
+ return;
24
+ }
25
+ if (!t.ok) return;
26
+ if (!u) {
27
+ l.finalizePayToSave();
28
+ return;
29
+ }
30
+ let n = t.counterpartId && t.counterpartId !== d ? t.counterpartId : void 0, r = t.counterpartBankAccountId && t.counterpartBankAccountId !== f ? t.counterpartBankAccountId : void 0;
31
+ if (n || r) {
32
+ let t = {
33
+ path: { payable_id: u },
34
+ body: {
35
+ ...n ? { counterpart_id: n } : {},
36
+ ...r ? { counterpart_bank_account_id: r } : {}
37
+ }
38
+ };
39
+ try {
40
+ await _.mutateAsync(t);
41
+ } catch {
42
+ try {
43
+ await _.mutateAsync(t);
44
+ } catch {
45
+ e.error(g.paymentInstructionsLinkError);
46
+ return;
47
+ }
48
+ }
49
+ l.finalizePayToSave();
50
+ return;
51
+ }
52
+ l.finalizePayToSave(), await h();
53
+ } finally {
54
+ y(!1);
55
+ }
56
+ }
57
+ })();
58
+ b.current = t;
59
+ try {
60
+ await t;
61
+ } finally {
62
+ b.current = void 0;
63
+ }
64
+ }, [
65
+ p,
66
+ g.paymentInstructionsLinkError,
67
+ g.paymentInstructionsSaveError,
68
+ _,
69
+ f,
70
+ d,
71
+ u,
72
+ h,
73
+ l
74
+ ]), S = o(() => {
75
+ if (!p) return l;
76
+ if (l.mode === "creating" && r(l.newVendorForm)) return {
77
+ ...l,
78
+ newVendorForm: n(l.newVendorForm, {
79
+ onSave: x,
80
+ isSaving: v
81
+ })
82
+ };
83
+ if (l.mode === "resolved" && l.paymentInstructions) {
84
+ let e = {
85
+ onSave: x,
86
+ isSaving: v
87
+ };
88
+ return {
89
+ ...l,
90
+ paymentInstructions: {
91
+ ...l.paymentInstructions,
92
+ ...e
93
+ },
94
+ paymentInstructionsEditor: l.paymentInstructionsEditor && {
95
+ ...l.paymentInstructionsEditor,
96
+ ...e
97
+ }
98
+ };
99
+ }
100
+ return l;
101
+ }, [
102
+ p,
103
+ v,
104
+ x,
105
+ l
106
+ ]);
107
+ return a(() => {
108
+ m && l.isEditingPayTo && !p && l.discardPayToEdits();
109
+ }, [
110
+ p,
111
+ m,
112
+ l.discardPayToEdits,
113
+ l.isEditingPayTo
114
+ ]), {
115
+ vendorWithInlineSave: S,
116
+ isSavingPayToEdits: v
54
117
  };
55
118
  }
56
- function v(e) {
57
- let t = e.trim();
58
- if (!t) return !0;
59
- let n = t.startsWith("-") ? t.slice(1) : t;
60
- return i.test(n) ? Number(t.replaceAll(",", "")) <= 0 : !1;
61
- }
62
- function y(e, t) {
63
- if (n(e) === null) return v(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
64
- }
65
- function b(t, n = e) {
66
- let r = y(t, n);
67
- return r ? { total: r } : void 0;
68
- }
69
- function x(t, r = e) {
70
- if (t === void 0) return;
71
- let i = n(t);
72
- if (i !== null) return i > 0 ? void 0 : { total: r.totalNotGreaterThanZero };
73
- }
74
- function S(t, n, r, i = e) {
75
- let a = {};
76
- if (h(t) || (a.discount = i.unreadableDiscount), h(n) || (a.tax = i.unreadableTax), r !== void 0) {
77
- let e = y(r, i);
78
- e && (a.total = e);
79
- }
80
- return Object.keys(a).length ? a : void 0;
81
- }
82
- export { h as isReadableMoneyOrZero, _ as validateBillCompleteness, b as validateBillTotalIsPayable, S as validateBillTotals, m as validateBillValues, g as validateLineItems, x as validateStoredAmountDue };
119
+ export { l as usePayToSave };
@@ -1,257 +1,11 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { extractApiErrorMessage as t } from "../../../../shared/util/dist/lib/apiErrors.js";
7
- import "../../../../shared/util/dist/index.js";
8
- import { isApiConflictError as n } from "../../../../shared/data-access/dist/lib/isApiConflictError.js";
9
- import { isApiUnprocessableError as r } from "../../../../shared/data-access/dist/lib/isApiUnprocessableError.js";
10
- import "../../../../shared/data-access/dist/index.js";
11
- import "../../../../shared/ui/dist/index.js";
12
- import { BILL_CREATE_MESSAGE_LABELS_EN as i } from "./index28.js";
13
- import { encodeFileToBase64 as a } from "./index34.js";
14
- import { mapBillFormToPayload as o, mapLineItemsToPayload as s, mapPayableAmountFieldsToPayload as c } from "./index35.js";
15
- import { validateBillCompleteness as l, validateBillTotalIsPayable as u, validateBillTotals as d, validateBillValues as f, validateLineItems as p, validateStoredAmountDue as ee } from "./index36.js";
16
- import { useReplacePayableLineItemsMutation as m } from "../../data-access/dist/index5.js";
17
- import { useCreatePayableMutation as h } from "../../data-access/dist/index9.js";
18
- import { useDeletePayableFileMutation as g } from "../../data-access/dist/index10.js";
19
- import { useSubmitPayableForApprovalMutation as te } from "../../data-access/dist/index15.js";
20
- import { useUpdatePayableMutation as ne } from "../../data-access/dist/index16.js";
21
- import { useValidatePayableMutation as re } from "../../data-access/dist/index17.js";
22
- import "../../data-access/dist/index.js";
23
- import { useCallback as _, useRef as v, useState as y } from "react";
24
1
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index37.js
25
- var b = {
26
- document_id: "invoiceNumber",
27
- issued_at: "invoiceDate",
28
- due_date: "dueDate",
29
- counterpart_id: "vendor",
30
- purchase_order_number: "poNumber"
31
- }, x = { tax_amount: "tax" };
32
- function S(e) {
33
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
34
- }
35
- var ie = "pending-vendor";
36
- function C(e) {
37
- return !!t(e)?.includes("line_items_enabled");
38
- }
39
- function w(e) {
40
- return !!t(e)?.includes("A vendor could not be linked or created for this payable");
41
- }
42
- function T(e) {
43
- if (!n(e) && !r(e) || typeof e != "object" || !e || !("error" in e)) return;
44
- let t = e.error;
45
- if (typeof t == "object" && t && "message" in t) return typeof t.message == "string" && t.message.trim() ? t.message : void 0;
46
- }
47
- function E(e, t) {
48
- if (C(e)) return t.discountTaxBlockedByLineItems;
49
- let n = T(e);
50
- return n ? t.saveRejected(n) : t.saveFailed;
51
- }
52
- function D(e, t = i) {
53
- let n = {}, r = {}, a = [];
54
- for (let i of e) {
55
- let e = i.loc[0] ?? t.unknownValidationField, o = b[e], s = x[e], c = S(i) ? t.requiredField : i.msg;
56
- o ? n[o] = c : s ? r[s] = c : a.push(t.unmappedValidationError(e, c));
57
- }
58
- return a.length && (n.form = a.join(" ")), {
59
- formErrors: n,
60
- totalsErrors: Object.keys(r).length ? r : void 0
61
- };
62
- }
63
- function ae(e, t) {
64
- if (!e && !t) return;
65
- let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
66
- for (let i of r) n[i] = {
67
- ...e?.[i],
68
- ...t?.[i]
69
- };
70
- return n;
71
- }
72
- function O({ payableId: t, form: n, counterpartId: r, isVendorPending: b, onVendorIncomplete: x, clearCounterpart: S, prepareVendorForSave: C, onSaved: T, onPayableCreated: O, readSavedStatus: k, onDraftSaved: A, onFinalized: j, labels: M }) {
73
- let N = {
74
- ...i,
75
- ...M
76
- }, [P, F] = y(), I = t ?? P, [L, R] = y(), oe = _(() => R(void 0), []), [z, B] = y(!1), se = _(() => B(!0), []), [V, H] = y(), U = v(!1), [ce, le] = y(0), W = _(() => le((e) => e + 1), []), G = h(), K = g(), q = ne(), J = m(), Y = re(), X = te(), Z = _(() => n.isTotalsDirty ? d(n.discount, n.tax, n.totalOverride, N) : void 0, [n, N]), Q = _(() => {
77
- let t = f(n.values, N), r = p(n.lineItems, N), i = Z();
78
- return n.setErrors(t), n.setLineItemErrors(r), n.setTotalsErrors(i), !t && !r && !i || (r && e.error(N.lineItemsNeedAttention), W(), !1);
79
- }, [
80
- n,
81
- N,
82
- W,
83
- Z
84
- ]), $ = _(async (e, t, i) => {
85
- let l = !I && L ? {
86
- base64EncodedFile: await a(L),
87
- fileName: L.name
88
- } : void 0, u = n.isTotalsDirty ? {
89
- discount: n.discount,
90
- tax: n.tax,
91
- total: n.totalOverride
92
- } : void 0, d = o({
93
- values: n.values,
94
- initialLineItems: I ? void 0 : n.lineItems,
95
- counterpartId: t ?? r,
96
- clearCounterpart: S,
97
- counterpartBankAccountId: e,
98
- currentTotals: {
99
- discount: n.discount,
100
- tax: n.tax,
101
- total: n.totalOverride
102
- },
103
- lineItems: n.lineItems,
104
- editedTotals: u,
105
- document: l
106
- }), f = i ? {
107
- ...d,
108
- counterpart_raw_data: i
109
- } : d, p = I;
110
- if (p ? await q.mutateAsync({
111
- path: { payable_id: p },
112
- body: f
113
- }) : (p = (await G.mutateAsync({ body: f }))?.id, p && (F(p), O?.(p), l && R(void 0))), !p) throw Error("Payable was created without an id");
114
- if (z) {
115
- try {
116
- await K.mutateAsync({ path: { payable_id: p } });
117
- } catch {}
118
- B(!1);
119
- }
120
- return await J.mutateAsync({
121
- path: { payable_id: p },
122
- body: { data: s(n.lineItems) }
123
- }), u && await q.mutateAsync({
124
- path: { payable_id: p },
125
- body: c({
126
- lineItems: n.lineItems,
127
- editedTotals: u
128
- })
129
- }), p;
130
- }, [
131
- r,
132
- S,
133
- G,
134
- K,
135
- z,
136
- n.discount,
137
- n.isTotalsDirty,
138
- n.lineItems,
139
- n.tax,
140
- n.totalOverride,
141
- n.values,
142
- O,
143
- I,
144
- J,
145
- L,
146
- q
147
- ]), ue = _(async () => {
148
- I && (await K.mutateAsync({ path: { payable_id: I } }), B(!1));
149
- }, [K, I]);
150
- return {
151
- saveDraft: _(async () => {
152
- if (!U.current && Q()) {
153
- U.current = !0, H("draft");
154
- try {
155
- let t = await C?.({ allowIncompleteVendor: !0 });
156
- if (t && !t.ok) return;
157
- let r = await $(t?.counterpartBankAccountId, t?.counterpartId, t?.counterpartRawData);
158
- n.setErrors(void 0), T?.(r), A?.(r);
159
- let i = await k?.();
160
- return e.success(i === "draft" ? N.submittedDemoted : N.draftSaved), r;
161
- } catch (e) {
162
- n.setSaveFailureMessage(E(e, {
163
- discountTaxBlockedByLineItems: N.discountTaxBlockedByLineItems,
164
- saveFailed: N.saveFailed,
165
- saveRejected: N.saveRejected
166
- })), W();
167
- return;
168
- } finally {
169
- H(void 0), U.current = !1;
170
- }
171
- }
172
- }, [
173
- n,
174
- Q,
175
- N.discountTaxBlockedByLineItems,
176
- N.draftSaved,
177
- N.saveFailed,
178
- N.saveRejected,
179
- N.submittedDemoted,
180
- A,
181
- T,
182
- k,
183
- C,
184
- $,
185
- W
186
- ]),
187
- finalize: _(async () => {
188
- if (U.current) return;
189
- let t = p(n.lineItems, N), i = f(n.values, N), a = Z(), o = u(n.total, N), s = n.isTotalsDirty ? ee(n.totalOverride, N) : void 0, c = a || o || s ? {
190
- ...s,
191
- ...o,
192
- ...a
193
- } : void 0, { formErrors: d, lineItemErrors: m } = l(n.values, r ?? (b ? ie : void 0), n.lineItems, N), h = ae(m, t);
194
- n.setLineItemErrors(h), n.setTotalsErrors(c);
195
- let g = {
196
- ...d,
197
- ...i
198
- };
199
- if (n.setErrors(Object.keys(g).length ? g : void 0), t && e.error(N.lineItemsNeedAttention), h || c || Object.keys(g).length) g.vendor && x?.(), W();
200
- else {
201
- U.current = !0, H("finalize");
202
- try {
203
- let t;
204
- try {
205
- let e = await C?.();
206
- if (e && !e.ok) return;
207
- t = await $(e?.counterpartBankAccountId, e?.counterpartId);
208
- } catch (e) {
209
- n.setSaveFailureMessage(E(e, N)), W();
210
- return;
211
- }
212
- T?.(t);
213
- try {
214
- let r = await Y.mutateAsync({ path: { payable_id: t } });
215
- if (r.validation_errors.length) {
216
- let e = D(r.validation_errors, N);
217
- n.setErrors(e.formErrors), n.setTotalsErrors(e.totalsErrors), W();
218
- return;
219
- }
220
- await X.mutateAsync({ path: { payable_id: t } }), n.setErrors(void 0), j?.(t), e.success(N.billFinalized);
221
- } catch (e) {
222
- w(e) ? n.setErrors({ vendor: N.vendorResolutionFailed }) : n.setSaveFailureMessage(N.finalizeFailed), W();
223
- }
224
- } finally {
225
- H(void 0), U.current = !1;
226
- }
227
- }
228
- }, [
229
- r,
230
- b,
231
- n,
232
- N,
233
- j,
234
- T,
235
- x,
236
- C,
237
- $,
238
- W,
239
- X,
240
- Z,
241
- Y
242
- ]),
243
- payableId: I,
244
- isSavingDraft: V === "draft",
245
- isFinalizing: V === "finalize",
246
- stagedFile: L,
247
- stageFile: R,
248
- clearStagedFile: oe,
249
- scrollToErrorToken: ce,
250
- isFileDeletionPending: z,
251
- requestFileDeletion: se,
252
- detachFileNow: ue,
253
- isDeletingFile: K.isPending,
254
- hasFileDeletionFailed: K.isError
255
- };
256
- }
257
- export { D as mapValidationErrorsToForm, O as useBillCreateController };
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
+ typeof e == "string" ? t(e.slice(e.indexOf(",") + 1)) : n(/* @__PURE__ */ Error("Failed to read file as a data URL"));
8
+ }, r.readAsDataURL(e);
9
+ });
10
+ }
11
+ export { e as encodeFileToBase64 };
@@ -1,46 +1,88 @@
1
- import { resolveLineItemAmountMinorUnits as e } from "../../../util/dist/lib/resolveLineItemAmount.js";
2
- import { resolveLineItemQuantity as t } from "../../../util/dist/lib/resolveLineItemQuantity.js";
1
+ import { parseDecimalAmountToMinorUnits as e } from "../../../../shared/util/dist/lib/parseDecimalAmountToMinorUnits.js";
2
+ import "../../../../shared/util/dist/index.js";
3
3
  import "../../../util/dist/index.js";
4
4
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index38.js
5
- function n() {
6
- return {
7
- id: crypto.randomUUID(),
8
- description: "",
9
- glCode: "",
10
- quantity: "1",
11
- price: "",
12
- amount: ""
13
- };
5
+ var t = "USD";
6
+ function n(n) {
7
+ return e(n, t);
14
8
  }
15
9
  function r(e) {
16
- return typeof e == "number" ? (e / 100).toFixed(2) : "";
10
+ let t = e.trim();
11
+ if (!t) return null;
12
+ let n = Number(t);
13
+ return Number.isFinite(n) && n > 0 ? n : null;
17
14
  }
18
15
  function i(e) {
19
- return typeof e == "string" ? e : "";
16
+ return !!(e.description.trim() || e.glCode.trim() || n(e.price) !== null || n(e.amount) !== null);
20
17
  }
21
18
  function a(e) {
22
- return e.total_amount ?? e.amount_due ?? void 0;
23
- }
24
- function o({ payable: o, lineItems: s }) {
25
- let c = {
26
- invoiceNumber: o.document_id ?? "",
27
- invoiceDate: o.issued_at ?? "",
28
- dueDate: o.due_date ?? "",
29
- poNumber: i(o.purchase_order_number)
30
- }, l = s.map((n) => ({
31
- id: n.id,
32
- description: n.name ?? "",
33
- glCode: n.ledger_account_id ?? "",
34
- quantity: String(t(n)),
35
- price: r(n.unit_price),
36
- amount: r(e(n))
37
- })), u = a(o);
38
- return {
39
- values: c,
40
- lineItems: l.length ? l : [n()],
41
- discount: r(o.discount),
42
- tax: r(o.tax_amount),
43
- total: u ? r(u) : ""
19
+ return n(e) ?? 0;
20
+ }
21
+ function o(e) {
22
+ let t = Number.parseFloat(e);
23
+ return Number.isFinite(t) ? t : 0;
24
+ }
25
+ function s(e) {
26
+ let t = n(e);
27
+ return t === null ? e : c(t);
28
+ }
29
+ function c(e) {
30
+ return (e / 100).toFixed(2);
31
+ }
32
+ function l({ values: e, initialLineItems: r, counterpartId: i, clearCounterpart: a, counterpartBankAccountId: o, editedTotals: s, currentTotals: c, lineItems: l, document: f, includeBlankPoNumber: p = !0 }) {
33
+ let m = { currency: t };
34
+ i ? m.counterpart_id = i : a && (m.counterpart_id = null), i ? m.counterpart_bank_account_id = o ?? null : a && (m.counterpart_bank_account_id = null), e.invoiceNumber && (m.document_id = e.invoiceNumber), e.invoiceDate && (m.issued_at = e.invoiceDate), e.dueDate && (m.due_date = e.dueDate);
35
+ let h = e.poNumber.trim();
36
+ if ((h || p) && (m.purchase_order_number = h || null), f && (m.base64_encoded_file = f.base64EncodedFile, m.file_name = f.fileName), s && (m.discount = n(s.discount) ?? 0, m.tax_amount = n(s.tax) ?? 0, s.total !== void 0 && (m.total_amount = n(s.total) ?? 0)), c && l) {
37
+ let e = d(l), t = n(c.tax) ?? 0, r = n(c.discount) ?? 0, i = c.total === void 0 ? (e ?? 0) - r + t : n(c.total) ?? 0;
38
+ e !== void 0 && (m.subtotal = e), m.discount = r, m.tax_amount = t, m.total_amount = i;
39
+ } else if (r && !("total_amount" in m)) {
40
+ let e = u(r, {
41
+ tax: s?.tax,
42
+ discount: s?.discount
43
+ });
44
+ e !== void 0 && (m.total_amount = e);
45
+ }
46
+ return m;
47
+ }
48
+ function u(e, { tax: t, discount: r }) {
49
+ let i = d(e);
50
+ if (i !== void 0) return i + (t ? n(t) ?? 0 : 0) - (r ? n(r) ?? 0 : 0);
51
+ }
52
+ function d(e) {
53
+ let t = !1, r = e.reduce((e, r) => {
54
+ if (!i(r)) return e;
55
+ let a = n(r.amount);
56
+ return a === null ? e : (t = !0, e + a);
57
+ }, 0);
58
+ if (t) return r;
59
+ }
60
+ function f({ lineItems: e, editedTotals: t }) {
61
+ let r = d(e), i = n(t.tax) ?? 0, a = n(t.discount) ?? 0, o = {
62
+ discount: a,
63
+ tax_amount: i
44
64
  };
65
+ return r !== void 0 && (o.subtotal = r), t.total === void 0 ? r !== void 0 && (o.total_amount = r - a + i) : o.total_amount = n(t.total) ?? 0, o;
66
+ }
67
+ function p(e) {
68
+ return e.filter(i).map((e) => {
69
+ 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), s = t ?? o;
70
+ return {
71
+ name: e.description,
72
+ quantity: i,
73
+ unit_price: a,
74
+ tax: 0,
75
+ subtotal: s,
76
+ tax_amount: 0,
77
+ total: s,
78
+ ...e.glCode ? { ledger_account_id: e.glCode } : {}
79
+ };
80
+ });
81
+ }
82
+ function m(e, t) {
83
+ return c(Math.round(o(e) * a(t)));
84
+ }
85
+ function h(e, t, n) {
86
+ return c(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
45
87
  }
46
- export { n as emptyLineItem, o as mapPayableToBillForm };
88
+ export { h as calculateTotal, m as displayLineAmount, i as isPersistableLineItem, l as mapBillFormToPayload, p as mapLineItemsToPayload, f as mapPayableAmountFieldsToPayload, s as normalizeMoneyOnBlur, n as parseMoneyToMinorUnits, r as parseQuantity };