@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,245 +1,82 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index28.js";
6
- import { calculateTotal as t, displayLineAmount as n, normalizeMoneyOnBlur as r, parseMoneyToMinorUnits as i, parseQuantity as a } from "./index35.js";
7
- import { validateBillTotals as o } from "./index36.js";
8
- import { emptyLineItem as s, mapPayableToBillForm as c } from "./index38.js";
9
- import { useCallback as l, useEffect as u, useMemo as d, useRef as f, useState as p } from "react";
1
+ import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index31.js";
2
+ import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index38.js";
10
3
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index39.js
11
- var m = /^[0-9.,-]+$/;
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
+ }
12
29
  function h(e) {
13
- let t = e.trim().replace(/^\$\s*/, "");
14
- return t ? m.test(t) ? t : null : "";
30
+ let t = e.trim();
31
+ return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
15
32
  }
16
- var g = [
17
- "quantity",
18
- "price",
19
- "amount"
20
- ];
21
- function _(e) {
22
- let t = e.trim(), n = /[.,]$/.test(t) ? t.slice(0, -1) : t;
23
- return t && !n ? null : n;
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;
24
40
  }
25
- function v(e, t, n) {
26
- if (t === void 0) return;
27
- let r = _(t);
28
- if (r !== null) return o(e === "discount" ? r : "", e === "tax" ? r : "", e === "total" ? r : void 0, n)?.[e];
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
54
+ };
55
+ }
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;
29
61
  }
30
62
  function y(e, t) {
31
- let n = {}, r = {
32
- price: null,
33
- amount: null
34
- };
35
- for (let a of ["price", "amount"]) {
36
- let o = _(e[a]);
37
- o !== null && (r[a] = i(o), o && r[a] === null && (n[a] = t.unreadableMoney));
38
- }
39
- let o = _(e.quantity);
40
- if (o !== null) {
41
- let e = r.price !== null || r.amount !== null;
42
- a(o) === null && (o || e) && (n.quantity = t.unusableQuantity);
43
- }
44
- return n;
63
+ if (n(e) === null) return v(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
45
64
  }
46
- function b(e, t, r) {
47
- return i(t) === null ? r : n(e, t);
65
+ function b(t, n = e) {
66
+ let r = y(t, n);
67
+ return r ? { total: r } : void 0;
48
68
  }
49
- function x({ payable: n, lineItems: i, labels: a = e } = {}) {
50
- let o = d(() => c({
51
- payable: n ?? {},
52
- lineItems: i ?? []
53
- }), [n, i]), [m, _] = p(o.values), [x, S] = p(o.lineItems), [C, w] = p(o.discount), [T, E] = p(o.tax), [D, O] = p(o.total || void 0), [ee, k] = p(), A = f(void 0), te = l((e) => {
54
- k((t) => {
55
- let n = typeof e == "function" ? e(t) : e;
56
- return n?.form !== A.current && (A.current = void 0), n;
57
- });
58
- }, []), ne = l((e) => {
59
- A.current = e, k((t) => ({
60
- ...t,
61
- form: e
62
- }));
63
- }, []), j = l(() => {
64
- k((e) => {
65
- if (!e?.form || e.form !== A.current) return e;
66
- A.current = void 0;
67
- let t = { ...e };
68
- return delete t.form, Object.keys(t).length ? t : void 0;
69
- });
70
- }, []), [re, M] = p(), [N, P] = p(), [F, I] = p(!1), [L, R] = p(!1), [z, B] = p(!1);
71
- u(() => {
72
- F || _(o.values);
73
- }, [o]), u(() => {
74
- L || S(o.lineItems);
75
- }, [o]), u(() => {
76
- z || (w(o.discount), E(o.tax), O(o.total || void 0));
77
- }, [o]);
78
- let ie = l((e) => {
79
- _((t) => ({
80
- ...t,
81
- ...e
82
- })), I(!0), k((t) => {
83
- if (!t) return t;
84
- let n = { ...t };
85
- for (let t of Object.keys(e)) delete n[t];
86
- return Object.keys(n).length ? n : void 0;
87
- }), j();
88
- }, [j]), V = l((e, t) => {
89
- M((n) => {
90
- if (!n?.[e] && !t) return n;
91
- let r = {
92
- ...n,
93
- [e]: t
94
- };
95
- return t || delete r[e], Object.keys(r).length ? r : void 0;
96
- });
97
- }, []), H = l((e, t) => {
98
- V(e, v(e, t, a));
99
- }, [a, V]), U = l(() => {
100
- O(void 0), H("total", void 0), j();
101
- }, [H, j]), W = l((e, t = []) => {
102
- let n = y(e, a);
103
- P((r) => {
104
- let i = r?.[e.id], a = { ...i };
105
- for (let e of [
106
- "price",
107
- "amount",
108
- "quantity"
109
- ]) n[e] ? a[e] = n[e] : delete a[e];
110
- t.includes("description") && delete a.description;
111
- let o = Object.keys(a).length > 0;
112
- if (!i && !o) return r;
113
- let s = { ...r };
114
- return o ? s[e.id] = a : delete s[e.id], Object.keys(s).length ? s : void 0;
115
- });
116
- }, [a]), G = l((e, t, n) => {
117
- P((r) => ({
118
- ...r,
119
- [e]: {
120
- ...r?.[e],
121
- [t]: n
122
- }
123
- }));
124
- }, []), K = l((e, t, n = []) => {
125
- let r = x.find((t) => t.id === e);
126
- if (!r) return;
127
- let i = t(r);
128
- S(x.map((t) => t.id === e ? i : t)), W(i, n), R(!0), U();
129
- }, [
130
- U,
131
- x,
132
- W
133
- ]), q = l((e, t) => {
134
- let n = { ...t };
135
- for (let r of g) {
136
- let i = t[r];
137
- if (i === void 0) continue;
138
- let o = h(i);
139
- if (o === null) {
140
- G(e, r, a.numbersOnly);
141
- return;
142
- }
143
- n[r] = o;
144
- }
145
- K(e, (e) => {
146
- let t = {
147
- ...e,
148
- ...n
149
- };
150
- return "amount" in n ? t : {
151
- ...t,
152
- amount: b(t.quantity, t.price, t.amount)
153
- };
154
- }, Object.keys(n));
155
- }, [
156
- K,
157
- a,
158
- G
159
- ]), J = l((e, t) => {
160
- S((n) => n.map((n) => n.id === e ? {
161
- ...n,
162
- [t]: r(n[t])
163
- } : n));
164
- }, []), Y = l((e, t) => {
165
- K(e, (e) => {
166
- let n = Number.parseFloat(e.quantity), r = String(Math.max(1, (Number.isFinite(n) ? n : 0) + t));
167
- return {
168
- ...e,
169
- quantity: r,
170
- amount: b(r, e.price, e.amount)
171
- };
172
- });
173
- }, [K]), X = l((e) => {
174
- P((t) => {
175
- if (!t?.[e]) return t;
176
- let n = { ...t };
177
- return delete n[e], Object.keys(n).length ? n : void 0;
178
- });
179
- }, []), Z = l((e) => {
180
- X(e), S((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e)), R(!0), U();
181
- }, [X, U]), ae = l(() => {
182
- S((e) => [...e, s()]), R(!0), U();
183
- }, [U]), Q = l((e, t, n) => {
184
- let r = h(t);
185
- r === null ? V(e, a.numbersOnly) : (n(r), B(!0), U(), H(e, r));
186
- }, [
187
- U,
188
- a,
189
- H,
190
- V
191
- ]), oe = l((e) => Q("discount", e, w), [Q]), se = l((e) => Q("tax", e, E), [Q]), $ = l(() => w((e) => r(e)), []), ce = l(() => E((e) => r(e)), []), le = l((e) => {
192
- let t = h(e);
193
- t === null ? V("total", a.numbersOnly) : (O(t), B(!0), H("total", t), j());
194
- }, [
195
- j,
196
- a,
197
- H,
198
- V
199
- ]), ue = l(() => {
200
- O((e) => e === void 0 ? e : r(e));
201
- }, []), de = d(() => x.map((e) => ({
202
- ...e,
203
- onChange: (t) => q(e.id, t),
204
- onBlur: (t) => J(e.id, t),
205
- onQuantityStep: (t) => Y(e.id, t),
206
- onRemove: () => Z(e.id)
207
- })), [
208
- J,
209
- x,
210
- q,
211
- Z,
212
- Y
213
- ]), fe = d(() => t(x, T, C), [
214
- x,
215
- T,
216
- C
217
- ]);
218
- return {
219
- values: m,
220
- errors: ee,
221
- setErrors: te,
222
- setSaveFailureMessage: ne,
223
- lineItemErrors: N,
224
- setLineItemErrors: P,
225
- totalsErrors: re,
226
- setTotalsErrors: M,
227
- onChange: ie,
228
- lineItems: x,
229
- lineItemRows: de,
230
- discount: C,
231
- onDiscountChange: oe,
232
- onDiscountBlur: $,
233
- tax: T,
234
- onTaxChange: se,
235
- onTaxBlur: ce,
236
- total: D ?? fe,
237
- totalOverride: D,
238
- onTotalChange: le,
239
- onTotalBlur: ue,
240
- onAddLineItem: ae,
241
- isTotalsDirty: z,
242
- isDirty: F || L || z
243
- };
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;
244
81
  }
245
- export { x as useBillForm };
82
+ export { h as isReadableMoneyOrZero, _ as validateBillCompleteness, b as validateBillTotalIsPayable, S as validateBillTotals, m as validateBillValues, g as validateLineItems, x as validateStoredAmountDue };
@@ -18,7 +18,7 @@ import "../../../util/dist/index.js";
18
18
  import { derivePayableStatus as d } from "../../../../shared/document-status/util/dist/lib/derivePayableStatus.js";
19
19
  import { useApplyDuplicateVerdictsMutation as f } from "../../../data-access/dist/lib/useApplyDuplicateVerdictsMutation.js";
20
20
  import "../../../data-access/dist/index.js";
21
- import { usePayablesByIdsQueries as p } from "../../data-access/dist/index23.js";
21
+ import { usePayablesByIdsQueries as p } from "../../data-access/dist/index24.js";
22
22
  import "../../data-access/dist/index.js";
23
23
  import { DUPLICATE_BILLS_LABELS_EN as m } from "./index3.js";
24
24
  import { useCallback as h, useMemo as g, useState as _ } from "react";
@@ -1,22 +1,257 @@
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 "./index31.js";
13
+ import { encodeFileToBase64 as a } from "./index37.js";
14
+ import { mapBillFormToPayload as o, mapLineItemsToPayload as s, mapPayableAmountFieldsToPayload as c } from "./index38.js";
15
+ import { validateBillCompleteness as l, validateBillTotalIsPayable as u, validateBillTotals as d, validateBillValues as f, validateLineItems as p, validateStoredAmountDue as ee } from "./index39.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";
1
24
  // ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index40.js
2
- var e = {
3
- dialog: "bill-pay-bill-dialog-dialog",
4
- vendorSection: "bill-pay-bill-dialog-vendor",
5
- lineItems: "bill-pay-bill-dialog-line-items",
6
- documentPanel: "bill-pay-bill-dialog-document",
7
- duplicateNotice: "bill-pay-bill-dialog-duplicate-notice",
8
- duplicateRemoveDialog: "bill-pay-bill-dialog-duplicate-remove-dialog",
9
- duplicateRemoveConfirm: "bill-pay-bill-dialog-duplicate-remove-confirm",
10
- decisionDialog: "bill-pay-bill-decision-dialog",
11
- decisionConfirm: "bill-pay-bill-decision-confirm",
12
- decisionReason: "bill-pay-bill-decision-reason",
13
- deleteDraftDialog: "bill-pay-bill-delete-draft-dialog",
14
- deleteDraftConfirm: "bill-pay-bill-delete-draft-confirm",
15
- unsavedDialog: "bill-pay-bill-unsaved-dialog",
16
- unsavedSaveDraft: "bill-pay-bill-unsaved-save-draft",
17
- unsavedDiscard: "bill-pay-bill-unsaved-discard",
18
- unsavedClose: "bill-pay-bill-unsaved-close",
19
- discardDialog: "bill-pay-bill-discard-dialog",
20
- discardConfirm: "bill-pay-bill-discard-confirm"
21
- };
22
- export { e as billDialogTestIds };
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 };