@tesouro/embedded-components-react 0.5.74 → 0.5.76

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 (97) hide show
  1. package/dist/experimental/InvoiceSettings.d.ts +660 -0
  2. package/dist/experimental/InvoiceSettings.js +3 -0
  3. package/dist/experimental/index.d.ts +31 -2
  4. package/dist/experimental/index.js +4 -2
  5. package/dist/index.css +0 -8
  6. package/dist/index.js +1 -1
  7. package/dist/lib/BillPayWidget.js +1 -1
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index.js +8 -8
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index45.js +140 -7
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index46.js +46 -140
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index47.js +114 -47
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +163 -112
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +75 -164
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +21 -75
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +71 -23
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index52.js +376 -65
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +12 -381
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index54.js +84 -12
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +54 -79
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js +223 -54
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +37 -223
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index58.js +245 -37
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index59.js +21 -252
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index60.js +571 -21
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index61.js +4 -572
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index62.js +44 -4
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index63.js +247 -38
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index64.js +3 -234
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index65.js +4 -3
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +44 -2
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index67.js +1 -46
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index68.js +8 -1
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index69.js +11 -6
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index70.js +127 -11
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index71.js +3 -129
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index72.js +127 -3
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index73.js +8 -124
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index74.js +7 -8
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index75.js +47 -8
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index76.js +18 -44
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index77.js +28 -20
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index78.js +82 -27
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index79.js +47 -83
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index80.js +250 -47
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index81.js +123 -241
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index82.js +211 -126
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index83.js +3 -219
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index84.js +7 -4
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index85.js +98 -5
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index86.js +1 -100
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index87.js +26 -0
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index.js +10 -10
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index30.js +2 -72
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index31.js +12 -269
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index33.js +2 -19
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index34.js +16 -50
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index36.js +97 -15
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index37.js +76 -47
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index38.js +277 -2
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index39.js +2 -35
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index40.js +16 -369
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index41.js +56 -2
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index42.js +2 -23
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index43.js +15 -93
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index44.js +50 -2
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index45.js +1 -31
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index46.js +32 -49
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index47.js +374 -2
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index48.js +1 -55
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index49.js +20 -10
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index50.js +87 -188
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index51.js +1 -1
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index52.js +30 -2
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index53.js +48 -37
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index55.js +47 -10
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index56.js +10 -85
  77. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index57.js +197 -2
  78. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index58.js +2 -4
  79. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index59.js +2 -14
  80. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index60.js +41 -2
  81. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index61.js +2 -4
  82. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index62.js +14 -17
  83. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index63.js +88 -2
  84. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index64.js +1 -94
  85. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index65.js +167 -161
  86. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index82.js +5 -5
  87. package/dist/libs/tesouro-embedded-components-react/settings-widget/feature/dist/index.js +3 -1
  88. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/feature/dist/index.js +4 -0
  89. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/feature/dist/index2.js +5 -0
  90. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/feature/dist/index3.js +29 -0
  91. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/feature/dist/index4.js +2 -0
  92. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  93. package/dist/libs/tesouro-embedded-components-react/shared/util/dist/lib/auditHistory/buildPayableAuditHistory.js +5 -1
  94. package/dist/libs/tesouro-embedded-components-react/widget-suite/feature/dist/index8.js +1 -1
  95. package/dist/packages/shared-ui-shadcn/dist/index.js +1391 -1369
  96. package/package.json +1 -1
  97. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index88.js +0 -27
@@ -1,63 +1,232 @@
1
- import { BILL_CREATE_MESSAGE_LABELS_EN as e } from "./index49.js";
2
- import { isPersistableLineItem as t, parseMoneyToMinorUnits as n, parseQuantity as r } from "./index55.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 { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
8
+ import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index10.js";
9
+ import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSubmitPayableForApprovalMutation as a, useUpdatePayableMutation as o, useValidatePayableMutation as s } from "../../data-access/dist/index13.js";
10
+ import "../../data-access/dist/index.js";
11
+ import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index48.js";
12
+ import { encodeFileToBase64 as l } from "./index53.js";
13
+ import { mapBillFormToPayload as u, mapLineItemsToPayload as ee, mapPayableAmountFieldsToPayload as te } from "./index54.js";
14
+ import { validateBillCompleteness as ne, validateBillTotalIsPayable as d, validateBillTotals as re, validateBillValues as f, validateLineItems as p, validateStoredAmountDue as m } from "./index55.js";
15
+ import { useCallback as h, useRef as ie, useState as g } from "react";
3
16
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index56.js
4
- var i = /^(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)$/, a = 255;
5
- function o(t, n = e) {
6
- let r = {};
7
- return t.poNumber.length > a && (r.poNumber = n.poNumberTooLong), Object.keys(r).length ? r : void 0;
17
+ var _ = {
18
+ document_id: "invoiceNumber",
19
+ issued_at: "invoiceDate",
20
+ due_date: "dueDate",
21
+ counterpart_id: "vendor",
22
+ purchase_order_number: "poNumber"
23
+ }, v = { tax_amount: "tax" };
24
+ function y(e) {
25
+ return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
8
26
  }
9
- function s(e) {
10
- let t = e.trim();
11
- return !t || n(t) !== null ? !0 : i.test(t) ? Number(t.replaceAll(",", "")) === 0 : !1;
27
+ var ae = "pending-vendor";
28
+ function b(e) {
29
+ return !!t(e)?.includes("line_items_enabled");
12
30
  }
13
- function c(t, i = e) {
14
- let a = {};
15
- for (let e of t) {
16
- let t = n(e.price), o = n(e.amount), s = {};
17
- 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);
18
- }
19
- return Object.keys(a).length ? a : void 0;
31
+ function x(e) {
32
+ return !!t(e)?.includes("A vendor could not be linked or created for this payable");
20
33
  }
21
- function l(i, a, o, s = e) {
22
- let c = {};
23
- a || (c.vendor = s.requiredField), i.invoiceNumber.trim() || (c.invoiceNumber = s.requiredField);
24
- let l = i.invoiceDate.trim(), u = i.dueDate.trim();
25
- l || (c.invoiceDate = s.requiredField), u ? l && u < l && (c.dueDate = s.dueBeforeInvoiceDate) : c.dueDate = s.requiredField;
26
- let d = {};
27
- return o.forEach((e, i) => {
28
- if (i > 0 && !t(e)) return;
29
- let a = {};
30
- 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);
31
- }), {
32
- formErrors: Object.keys(c).length ? c : void 0,
33
- lineItemErrors: Object.keys(d).length ? d : void 0
34
+ function S(e, t = c) {
35
+ let n = {}, r = {}, i = [];
36
+ for (let a of e) {
37
+ let e = a.loc[0] ?? t.unknownValidationField, o = _[e], s = v[e], c = y(a) ? t.requiredField : a.msg;
38
+ o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
39
+ }
40
+ return i.length && (n.form = i.join(" ")), {
41
+ formErrors: n,
42
+ totalsErrors: Object.keys(r).length ? r : void 0
34
43
  };
35
44
  }
36
- function u(e) {
37
- let t = e.trim();
38
- if (!t) return !0;
39
- let n = t.startsWith("-") ? t.slice(1) : t;
40
- return i.test(n) ? Number(t.replaceAll(",", "")) <= 0 : !1;
41
- }
42
- function d(e, t) {
43
- if (n(e) === null) return u(e) ? t.totalNotGreaterThanZero : t.unreadableTotal;
44
- }
45
- function f(t, n = e) {
46
- let r = d(t, n);
47
- return r ? { total: r } : void 0;
48
- }
49
- function p(t, r = e) {
50
- if (t === void 0) return;
51
- let i = n(t);
52
- if (i !== null) return i > 0 ? void 0 : { total: r.totalNotGreaterThanZero };
45
+ function C(e, t) {
46
+ if (!e && !t) return;
47
+ let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
48
+ for (let i of r) n[i] = {
49
+ ...e?.[i],
50
+ ...t?.[i]
51
+ };
52
+ return n;
53
53
  }
54
- function m(t, n, r, i = e) {
55
- let a = {};
56
- if (s(t) || (a.discount = i.unreadableDiscount), s(n) || (a.tax = i.unreadableTax), r !== void 0) {
57
- let e = d(r, i);
58
- e && (a.total = e);
59
- }
60
- return Object.keys(a).length ? a : void 0;
54
+ function w({ payableId: t, form: _, counterpartId: v, isVendorPending: y, clearCounterpart: w, prepareVendorForSave: T, onSaved: E, onPayableCreated: D, readSavedStatus: O, onDraftSaved: k, onFinalized: A, labels: j }) {
55
+ let M = {
56
+ ...c,
57
+ ...j
58
+ }, [N, P] = g(), F = t ?? N, [I, L] = g(), R = h(() => L(void 0), []), [z, B] = g(!1), oe = h(() => B(!0), []), [V, H] = g(), U = ie(!1), [se, ce] = g(0), W = h(() => ce((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = h(() => _.isTotalsDirty ? re(_.discount, _.tax, _.totalOverride, M) : void 0, [_, M]), Q = h(() => {
59
+ let t = f(_.values, M), n = p(_.lineItems, M), r = Z();
60
+ return _.setErrors(t), _.setLineItemErrors(n), _.setTotalsErrors(r), !t && !n && !r || (n && e.error(M.lineItemsNeedAttention), W(), !1);
61
+ }, [
62
+ _,
63
+ M,
64
+ W,
65
+ Z
66
+ ]), $ = h(async (e, t) => {
67
+ let n = !F && I ? {
68
+ base64EncodedFile: await l(I),
69
+ fileName: I.name
70
+ } : void 0, r = _.isTotalsDirty ? {
71
+ discount: _.discount,
72
+ tax: _.tax,
73
+ total: _.totalOverride
74
+ } : void 0, i = u({
75
+ values: _.values,
76
+ initialLineItems: F ? void 0 : _.lineItems,
77
+ counterpartId: t ?? v,
78
+ clearCounterpart: w,
79
+ counterpartBankAccountId: e,
80
+ currentTotals: {
81
+ discount: _.discount,
82
+ tax: _.tax,
83
+ total: _.totalOverride
84
+ },
85
+ lineItems: _.lineItems,
86
+ editedTotals: r,
87
+ document: n
88
+ }), a = F;
89
+ if (a ? await q.mutateAsync({
90
+ path: { payable_id: a },
91
+ body: i
92
+ }) : (a = (await G.mutateAsync({ body: i }))?.id, a && (P(a), D?.(a), n && L(void 0))), !a) throw Error("Payable was created without an id");
93
+ if (z) {
94
+ try {
95
+ await K.mutateAsync({ path: { payable_id: a } });
96
+ } catch {}
97
+ B(!1);
98
+ }
99
+ return await J.mutateAsync({
100
+ path: { payable_id: a },
101
+ body: { data: ee(_.lineItems) }
102
+ }), r && await q.mutateAsync({
103
+ path: { payable_id: a },
104
+ body: te({
105
+ lineItems: _.lineItems,
106
+ editedTotals: r
107
+ })
108
+ }), a;
109
+ }, [
110
+ v,
111
+ w,
112
+ G,
113
+ K,
114
+ z,
115
+ _.discount,
116
+ _.isTotalsDirty,
117
+ _.lineItems,
118
+ _.tax,
119
+ _.totalOverride,
120
+ _.values,
121
+ D,
122
+ F,
123
+ J,
124
+ I,
125
+ q
126
+ ]), le = h(async () => {
127
+ F && (await K.mutateAsync({ path: { payable_id: F } }), B(!1));
128
+ }, [K, F]);
129
+ return {
130
+ saveDraft: h(async () => {
131
+ if (!U.current && Q()) {
132
+ U.current = !0, H("draft");
133
+ try {
134
+ let t = await T?.();
135
+ if (t && !t.ok) return;
136
+ let n = await $(t?.counterpartBankAccountId, t?.counterpartId);
137
+ _.setErrors(void 0), E?.(n), k?.(n);
138
+ let r = await O?.();
139
+ return e.success(r === "draft" ? M.submittedDemoted : M.draftSaved), n;
140
+ } catch (e) {
141
+ _.setSaveFailureMessage(b(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
142
+ return;
143
+ } finally {
144
+ H(void 0), U.current = !1;
145
+ }
146
+ }
147
+ }, [
148
+ _,
149
+ Q,
150
+ M.discountTaxBlockedByLineItems,
151
+ M.draftSaved,
152
+ M.saveFailed,
153
+ M.submittedDemoted,
154
+ k,
155
+ E,
156
+ O,
157
+ T,
158
+ $,
159
+ W
160
+ ]),
161
+ finalize: h(async () => {
162
+ if (U.current) return;
163
+ let t = p(_.lineItems, M), n = f(_.values, M), r = Z(), i = d(_.total, M), a = _.isTotalsDirty ? m(_.totalOverride, M) : void 0, o = r || i || a ? {
164
+ ...a,
165
+ ...i,
166
+ ...r
167
+ } : void 0, { formErrors: s, lineItemErrors: c } = ne(_.values, v ?? (y ? ae : void 0), _.lineItems, M), l = C(c, t);
168
+ _.setLineItemErrors(l), _.setTotalsErrors(o);
169
+ let u = {
170
+ ...s,
171
+ ...n
172
+ };
173
+ if (_.setErrors(Object.keys(u).length ? u : void 0), t && e.error(M.lineItemsNeedAttention), l || o || Object.keys(u).length) {
174
+ W();
175
+ return;
176
+ }
177
+ U.current = !0, H("finalize");
178
+ try {
179
+ let t;
180
+ try {
181
+ let e = await T?.();
182
+ if (e && !e.ok) return;
183
+ t = await $(e?.counterpartBankAccountId, e?.counterpartId);
184
+ } catch (e) {
185
+ _.setSaveFailureMessage(b(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
186
+ return;
187
+ }
188
+ E?.(t);
189
+ try {
190
+ let n = await Y.mutateAsync({ path: { payable_id: t } });
191
+ if (n.validation_errors.length) {
192
+ let e = S(n.validation_errors, M);
193
+ _.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
194
+ return;
195
+ }
196
+ await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), A?.(t), e.success(M.billFinalized);
197
+ } catch (e) {
198
+ x(e) ? _.setErrors({ vendor: M.vendorResolutionFailed }) : _.setSaveFailureMessage(M.finalizeFailed), W();
199
+ }
200
+ } finally {
201
+ H(void 0), U.current = !1;
202
+ }
203
+ }, [
204
+ v,
205
+ y,
206
+ _,
207
+ M,
208
+ A,
209
+ E,
210
+ T,
211
+ $,
212
+ W,
213
+ X,
214
+ Z,
215
+ Y
216
+ ]),
217
+ payableId: F,
218
+ isSavingDraft: V === "draft",
219
+ isFinalizing: V === "finalize",
220
+ stagedFile: I,
221
+ stageFile: L,
222
+ clearStagedFile: R,
223
+ scrollToErrorToken: se,
224
+ isFileDeletionPending: z,
225
+ requestFileDeletion: oe,
226
+ detachFileNow: le,
227
+ isDeletingFile: K.isPending,
228
+ hasFileDeletionFailed: K.isError
229
+ };
61
230
  }
62
231
  //#endregion
63
- export { s as isReadableMoneyOrZero, l as validateBillCompleteness, f as validateBillTotalIsPayable, m as validateBillTotals, o as validateBillValues, c as validateLineItems, p as validateStoredAmountDue };
232
+ export { S as mapValidationErrorsToForm, w as useBillCreateController };
@@ -1,232 +1,46 @@
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 { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
8
- import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index10.js";
9
- import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSubmitPayableForApprovalMutation as a, useUpdatePayableMutation as o, useValidatePayableMutation as s } from "../../data-access/dist/index13.js";
10
- import "../../data-access/dist/index.js";
11
- import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index49.js";
12
- import { encodeFileToBase64 as l } from "./index54.js";
13
- import { mapBillFormToPayload as u, mapLineItemsToPayload as ee, mapPayableAmountFieldsToPayload as te } from "./index55.js";
14
- import { validateBillCompleteness as ne, validateBillTotalIsPayable as d, validateBillTotals as re, validateBillValues as f, validateLineItems as p, validateStoredAmountDue as m } from "./index56.js";
15
- import { useCallback as h, useRef as ie, useState as g } from "react";
1
+ import { resolveLineItemAmountMinorUnits as e } from "./index40.js";
2
+ import { resolveLineItemQuantity as t } from "./index41.js";
16
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js
17
- var _ = {
18
- document_id: "invoiceNumber",
19
- issued_at: "invoiceDate",
20
- due_date: "dueDate",
21
- counterpart_id: "vendor",
22
- purchase_order_number: "poNumber"
23
- }, v = { tax_amount: "tax" };
24
- function y(e) {
25
- return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
4
+ function n() {
5
+ return {
6
+ id: crypto.randomUUID(),
7
+ description: "",
8
+ glCode: "",
9
+ quantity: "1",
10
+ price: "",
11
+ amount: ""
12
+ };
26
13
  }
27
- var ae = "pending-vendor";
28
- function b(e) {
29
- return !!t(e)?.includes("line_items_enabled");
14
+ function r(e) {
15
+ return typeof e == "number" ? (e / 100).toFixed(2) : "";
30
16
  }
31
- function x(e) {
32
- return !!t(e)?.includes("A vendor could not be linked or created for this payable");
17
+ function i(e) {
18
+ return typeof e == "string" ? e : "";
33
19
  }
34
- function S(e, t = c) {
35
- let n = {}, r = {}, i = [];
36
- for (let a of e) {
37
- let e = a.loc[0] ?? t.unknownValidationField, o = _[e], s = v[e], c = y(a) ? t.requiredField : a.msg;
38
- o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
39
- }
40
- return i.length && (n.form = i.join(" ")), {
41
- formErrors: n,
42
- totalsErrors: Object.keys(r).length ? r : void 0
43
- };
44
- }
45
- function C(e, t) {
46
- if (!e && !t) return;
47
- let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
48
- for (let i of r) n[i] = {
49
- ...e?.[i],
50
- ...t?.[i]
51
- };
52
- return n;
20
+ function a(e) {
21
+ return e.total_amount ?? e.amount_due ?? void 0;
53
22
  }
54
- function w({ payableId: t, form: _, counterpartId: v, isVendorPending: y, clearCounterpart: w, prepareVendorForSave: T, onSaved: E, onPayableCreated: D, readSavedStatus: O, onDraftSaved: k, onFinalized: A, labels: j }) {
55
- let M = {
56
- ...c,
57
- ...j
58
- }, [N, P] = g(), F = t ?? N, [I, L] = g(), R = h(() => L(void 0), []), [z, B] = g(!1), oe = h(() => B(!0), []), [V, H] = g(), U = ie(!1), [se, ce] = g(0), W = h(() => ce((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = h(() => _.isTotalsDirty ? re(_.discount, _.tax, _.totalOverride, M) : void 0, [_, M]), Q = h(() => {
59
- let t = f(_.values, M), n = p(_.lineItems, M), r = Z();
60
- return _.setErrors(t), _.setLineItemErrors(n), _.setTotalsErrors(r), !t && !n && !r || (n && e.error(M.lineItemsNeedAttention), W(), !1);
61
- }, [
62
- _,
63
- M,
64
- W,
65
- Z
66
- ]), $ = h(async (e, t) => {
67
- let n = !F && I ? {
68
- base64EncodedFile: await l(I),
69
- fileName: I.name
70
- } : void 0, r = _.isTotalsDirty ? {
71
- discount: _.discount,
72
- tax: _.tax,
73
- total: _.totalOverride
74
- } : void 0, i = u({
75
- values: _.values,
76
- initialLineItems: F ? void 0 : _.lineItems,
77
- counterpartId: t ?? v,
78
- clearCounterpart: w,
79
- counterpartBankAccountId: e,
80
- currentTotals: {
81
- discount: _.discount,
82
- tax: _.tax,
83
- total: _.totalOverride
84
- },
85
- lineItems: _.lineItems,
86
- editedTotals: r,
87
- document: n
88
- }), a = F;
89
- if (a ? await q.mutateAsync({
90
- path: { payable_id: a },
91
- body: i
92
- }) : (a = (await G.mutateAsync({ body: i }))?.id, a && (P(a), D?.(a), n && L(void 0))), !a) throw Error("Payable was created without an id");
93
- if (z) {
94
- try {
95
- await K.mutateAsync({ path: { payable_id: a } });
96
- } catch {}
97
- B(!1);
98
- }
99
- return await J.mutateAsync({
100
- path: { payable_id: a },
101
- body: { data: ee(_.lineItems) }
102
- }), r && await q.mutateAsync({
103
- path: { payable_id: a },
104
- body: te({
105
- lineItems: _.lineItems,
106
- editedTotals: r
107
- })
108
- }), a;
109
- }, [
110
- v,
111
- w,
112
- G,
113
- K,
114
- z,
115
- _.discount,
116
- _.isTotalsDirty,
117
- _.lineItems,
118
- _.tax,
119
- _.totalOverride,
120
- _.values,
121
- D,
122
- F,
123
- J,
124
- I,
125
- q
126
- ]), le = h(async () => {
127
- F && (await K.mutateAsync({ path: { payable_id: F } }), B(!1));
128
- }, [K, F]);
23
+ function o({ payable: o, lineItems: s }) {
24
+ let c = {
25
+ invoiceNumber: o.document_id ?? "",
26
+ invoiceDate: o.issued_at ?? "",
27
+ dueDate: o.due_date ?? "",
28
+ poNumber: i(o.purchase_order_number)
29
+ }, l = s.map((n) => ({
30
+ id: n.id,
31
+ description: n.name ?? "",
32
+ glCode: n.ledger_account_id ?? "",
33
+ quantity: String(t(n)),
34
+ price: r(n.unit_price),
35
+ amount: r(e(n))
36
+ })), u = a(o);
129
37
  return {
130
- saveDraft: h(async () => {
131
- if (!U.current && Q()) {
132
- U.current = !0, H("draft");
133
- try {
134
- let t = await T?.();
135
- if (t && !t.ok) return;
136
- let n = await $(t?.counterpartBankAccountId, t?.counterpartId);
137
- _.setErrors(void 0), E?.(n), k?.(n);
138
- let r = await O?.();
139
- return e.success(r === "draft" ? M.submittedDemoted : M.draftSaved), n;
140
- } catch (e) {
141
- _.setSaveFailureMessage(b(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
142
- return;
143
- } finally {
144
- H(void 0), U.current = !1;
145
- }
146
- }
147
- }, [
148
- _,
149
- Q,
150
- M.discountTaxBlockedByLineItems,
151
- M.draftSaved,
152
- M.saveFailed,
153
- M.submittedDemoted,
154
- k,
155
- E,
156
- O,
157
- T,
158
- $,
159
- W
160
- ]),
161
- finalize: h(async () => {
162
- if (U.current) return;
163
- let t = p(_.lineItems, M), n = f(_.values, M), r = Z(), i = d(_.total, M), a = _.isTotalsDirty ? m(_.totalOverride, M) : void 0, o = r || i || a ? {
164
- ...a,
165
- ...i,
166
- ...r
167
- } : void 0, { formErrors: s, lineItemErrors: c } = ne(_.values, v ?? (y ? ae : void 0), _.lineItems, M), l = C(c, t);
168
- _.setLineItemErrors(l), _.setTotalsErrors(o);
169
- let u = {
170
- ...s,
171
- ...n
172
- };
173
- if (_.setErrors(Object.keys(u).length ? u : void 0), t && e.error(M.lineItemsNeedAttention), l || o || Object.keys(u).length) {
174
- W();
175
- return;
176
- }
177
- U.current = !0, H("finalize");
178
- try {
179
- let t;
180
- try {
181
- let e = await T?.();
182
- if (e && !e.ok) return;
183
- t = await $(e?.counterpartBankAccountId, e?.counterpartId);
184
- } catch (e) {
185
- _.setSaveFailureMessage(b(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
186
- return;
187
- }
188
- E?.(t);
189
- try {
190
- let n = await Y.mutateAsync({ path: { payable_id: t } });
191
- if (n.validation_errors.length) {
192
- let e = S(n.validation_errors, M);
193
- _.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
194
- return;
195
- }
196
- await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), A?.(t), e.success(M.billFinalized);
197
- } catch (e) {
198
- x(e) ? _.setErrors({ vendor: M.vendorResolutionFailed }) : _.setSaveFailureMessage(M.finalizeFailed), W();
199
- }
200
- } finally {
201
- H(void 0), U.current = !1;
202
- }
203
- }, [
204
- v,
205
- y,
206
- _,
207
- M,
208
- A,
209
- E,
210
- T,
211
- $,
212
- W,
213
- X,
214
- Z,
215
- Y
216
- ]),
217
- payableId: F,
218
- isSavingDraft: V === "draft",
219
- isFinalizing: V === "finalize",
220
- stagedFile: I,
221
- stageFile: L,
222
- clearStagedFile: R,
223
- scrollToErrorToken: se,
224
- isFileDeletionPending: z,
225
- requestFileDeletion: oe,
226
- detachFileNow: le,
227
- isDeletingFile: K.isPending,
228
- hasFileDeletionFailed: K.isError
38
+ values: c,
39
+ lineItems: l.length ? l : [n()],
40
+ discount: r(o.discount),
41
+ tax: r(o.tax_amount),
42
+ total: u ? r(u) : ""
229
43
  };
230
44
  }
231
45
  //#endregion
232
- export { S as mapValidationErrorsToForm, w as useBillCreateController };
46
+ export { n as emptyLineItem, o as mapPayableToBillForm };