@tesouro/embedded-components-react 0.5.45 → 0.5.47

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