@tesouro/embedded-components-react 0.3.58 → 0.3.60

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/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js +1 -1
  2. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js +2 -2
  3. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index23.js +2 -2
  4. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index40.js +6 -2
  5. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index41.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index48.js +4 -3
  7. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index49.js +105 -93
  8. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index50.js +2 -2
  9. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index51.js +220 -82
  10. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index53.js +8 -6
  11. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index55.js +1 -1
  12. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js +4 -4
  13. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index66.js +1 -1
  14. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index70.js +1 -1
  15. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index74.js +1 -1
  16. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index76.js +1 -1
  17. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index79.js +2 -2
  18. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index9.js +1 -1
  19. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index.js +37 -37
  20. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index32.js +112 -90
  21. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index41.js +1 -0
  22. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index44.js +10 -152
  23. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index45.js +160 -2
  24. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index46.js +2 -4
  25. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index47.js +2 -39
  26. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index48.js +41 -2
  27. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index49.js +2 -7
  28. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index50.js +5 -90
  29. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index51.js +92 -2
  30. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index52.js +2 -4
  31. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index53.js +2 -14
  32. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index54.js +16 -2
  33. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index55.js +1 -83
  34. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index56.js +79 -261
  35. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index57.js +262 -9
  36. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index58.js +13 -1
  37. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index59.js +1 -8
  38. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index60.js +6 -37
  39. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index61.js +39 -2
  40. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index62.js +2 -39
  41. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index63.js +36 -9
  42. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index64.js +10 -199
  43. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index65.js +201 -3
  44. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index66.js +3 -17
  45. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index67.js +15 -345
  46. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index68.js +345 -8
  47. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index69.js +6 -4
  48. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index70.js +6 -91
  49. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index71.js +93 -0
  50. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index73.js +2 -121
  51. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index74.js +118 -23
  52. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index75.js +24 -87
  53. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index76.js +89 -2
  54. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index77.js +2 -7
  55. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index78.js +5 -28
  56. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index79.js +30 -2
  57. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index80.js +2 -7
  58. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index81.js +5 -32
  59. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index82.js +34 -2
  60. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index83.js +2 -12
  61. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index84.js +10 -104
  62. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index85.js +105 -1
  63. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index86.js +2 -17
  64. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index87.js +15 -123
  65. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index88.js +125 -2
  66. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index89.js +2 -18
  67. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index90.js +14 -6
  68. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index91.js +7 -167
  69. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index92.js +170 -2
  70. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index93.js +2 -14
  71. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index94.js +11 -105
  72. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index95.js +108 -2
  73. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index96.js +2 -10
  74. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index97.js +8 -45
  75. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index98.js +47 -2
  76. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index99.js +2 -0
  77. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  78. package/package.json +1 -1
  79. package/dist/libs/tesouro-embedded-components-react/bill-pay-widget/ui/dist/index72.js +0 -2
@@ -1,4 +1,4 @@
1
- import { MARK_AS_PAID_DIALOG_LABELS_EN as e } from "../../ui/dist/index86.js";
1
+ import { MARK_AS_PAID_DIALOG_LABELS_EN as e } from "../../ui/dist/index87.js";
2
2
  import "../../ui/dist/index.js";
3
3
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index12.js
4
4
  var t = {
@@ -1,5 +1,5 @@
1
- import { REVIEW_TRANSACTION_DIALOG_LABELS_EN as e } from "../../ui/dist/index83.js";
2
- import { SCHEDULE_PAYMENT_DIALOG_LABELS_EN as t } from "../../ui/dist/index89.js";
1
+ import { REVIEW_TRANSACTION_DIALOG_LABELS_EN as e } from "../../ui/dist/index84.js";
2
+ import { SCHEDULE_PAYMENT_DIALOG_LABELS_EN as t } from "../../ui/dist/index90.js";
3
3
  import "../../ui/dist/index.js";
4
4
  import { SOURCE_ACCOUNT_LABELS_EN as n } from "./index20.js";
5
5
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index21.js
@@ -5,8 +5,8 @@
5
5
  import { useWidgetConfig as e } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
6
6
  import "../../../shared/feature/dist/index.js";
7
7
  import { resolveVendor as t } from "./index5.js";
8
- import { ReviewTransactionDialog as n } from "../../ui/dist/index84.js";
9
- import { SchedulePaymentDialog as r } from "../../ui/dist/index91.js";
8
+ import { ReviewTransactionDialog as n } from "../../ui/dist/index85.js";
9
+ import { SchedulePaymentDialog as r } from "../../ui/dist/index92.js";
10
10
  import "../../ui/dist/index.js";
11
11
  import { canReadCounterpartBankAccounts as i } from "./index16.js";
12
12
  import { resolveAmountDueMinorUnits as a } from "./index17.js";
@@ -1,4 +1,4 @@
1
- import { UNSAVED_BILL_DIALOG_LABELS_EN as e } from "../../ui/dist/index96.js";
1
+ import { UNSAVED_BILL_DIALOG_LABELS_EN as e } from "../../ui/dist/index97.js";
2
2
  import "../../ui/dist/index.js";
3
3
  import { PAY_BILL_FLOW_LABELS_EN as t, mergePayBillFlowLabels as n } from "./index21.js";
4
4
  import { MARK_AS_PAID_FLOW_LABELS_EN as r, mergeMarkAsPaidFlowLabels as i } from "./index12.js";
@@ -12,15 +12,19 @@ var u = {
12
12
  unknownValidationField: "(unknown field)",
13
13
  requiredField: "This field is required.",
14
14
  saveFailed: "We could not save this bill. Try again.",
15
+ discountTaxBlockedByLineItems: "Discount and Tax can't be saved on a bill with line items. Remove them, then save again.",
15
16
  finalizeFailed: "We could not submit this bill. Try again.",
16
17
  draftSaved: "Bill saved as a draft.",
17
18
  submittedSaved: "Bill updated.",
18
19
  submittedDemoted: "Bill updated. It moved back to Drafts because some required details are missing.",
19
20
  billFinalized: "Bill submitted for approval.",
21
+ numbersOnly: "Enter numbers only.",
20
22
  unreadableMoney: "Enter a valid amount.",
21
23
  unusableQuantity: "Enter a quantity greater than 0.",
22
24
  lineItemsNeedAttention: "Check the highlighted line items before saving.",
23
- totalsNeedAttention: "Enter valid amounts for discount, tax, and total."
25
+ unreadableDiscount: "Enter a valid discount amount.",
26
+ unreadableTax: "Enter a valid tax amount.",
27
+ unreadableTotal: "Enter a valid total amount."
24
28
  }, d = {
25
29
  achMethod: "via ACH bank transfer",
26
30
  noMethod: "No payment method on file",
@@ -4,7 +4,7 @@
4
4
  "use client";
5
5
  import { useAttachPayableFileMutation as e } from "../../data-access/dist/index12.js";
6
6
  import "../../data-access/dist/index.js";
7
- import { SourceDocumentPanel as t } from "../../ui/dist/index94.js";
7
+ import { SourceDocumentPanel as t } from "../../ui/dist/index95.js";
8
8
  import "../../ui/dist/index.js";
9
9
  import { createSourceDocumentPreview as n } from "./index39.js";
10
10
  import { SOURCE_DOCUMENT_CONTAINER_LABELS_EN as r } from "./index40.js";
@@ -10,7 +10,7 @@ function o(t, i = e) {
10
10
  let a = {};
11
11
  for (let e of t) {
12
12
  let t = n(e.price), o = n(e.amount), s = {};
13
- e.price.trim() && t === null && (s.price = i.unreadableMoney), e.amount.trim() && o === null && (s.amount = i.unreadableMoney), (t !== null || o !== null) && r(e.quantity) === null && (s.quantity = i.unusableQuantity), Object.keys(s).length && (a[e.id] = s);
13
+ 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);
14
14
  }
15
15
  return Object.keys(a).length ? a : void 0;
16
16
  }
@@ -28,7 +28,8 @@ function s(i, a, o, s = e) {
28
28
  };
29
29
  }
30
30
  function c(t, r, i, o = e) {
31
- return !a(t) || !a(r) || i !== void 0 && n(i) === null ? { form: o.totalsNeedAttention } : void 0;
31
+ let s = {};
32
+ return a(t) || (s.discount = o.unreadableDiscount), a(r) || (s.tax = o.unreadableTax), i !== void 0 && n(i) === null && (s.total = o.unreadableTotal), Object.keys(s).length ? s : void 0;
32
33
  }
33
34
  //#endregion
34
- export { s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
35
+ export { a as isReadableMoneyOrZero, s as validateBillCompleteness, c as validateBillTotals, o as validateLineItems };
@@ -4,11 +4,12 @@
4
4
  "use client";
5
5
  import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
6
  import "../../../shared/ui/dist/index.js";
7
- import { useReplacePayableLineItemsMutation as t } from "../../data-access/dist/index9.js";
8
- import { useCreatePayableMutation as n, useDeletePayableFileMutation as r, useSubmitPayableForApprovalMutation as i, useUpdatePayableMutation as a, useValidatePayableMutation as o } from "../../data-access/dist/index12.js";
7
+ import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
8
+ import { useReplacePayableLineItemsMutation as n } from "../../data-access/dist/index9.js";
9
+ import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSubmitPayableForApprovalMutation as a, useUpdatePayableMutation as o, useValidatePayableMutation as s } from "../../data-access/dist/index12.js";
9
10
  import "../../data-access/dist/index.js";
10
- import { BILL_CREATE_MESSAGE_LABELS_EN as s } from "./index40.js";
11
- import { encodeFileToBase64 as c } from "./index46.js";
11
+ import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index40.js";
12
+ import { encodeFileToBase64 as ee } from "./index46.js";
12
13
  import { mapBillFormToPayload as l, mapLineItemsToPayload as u } from "./index47.js";
13
14
  import { validateBillCompleteness as d, validateBillTotals as f, validateLineItems as p } from "./index48.js";
14
15
  import { useCallback as m, useRef as h, useState as g } from "react";
@@ -18,19 +19,25 @@ var _ = {
18
19
  issued_at: "invoiceDate",
19
20
  due_date: "dueDate",
20
21
  counterpart_id: "vendor"
21
- };
22
- function v(e) {
22
+ }, v = { tax_amount: "tax" };
23
+ function y(e) {
23
24
  return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
24
25
  }
25
- function y(e, t = s) {
26
- let n = {}, r = [];
27
- for (let i of e) {
28
- let e = i.loc[0] ?? t.unknownValidationField, a = _[e], o = v(i) ? t.requiredField : i.msg;
29
- a ? n[a] = o : r.push(t.unmappedValidationError(e, o));
26
+ function b(e) {
27
+ return !!t(e)?.includes("line_items_enabled");
28
+ }
29
+ function x(e, t = c) {
30
+ let n = {}, r = {}, i = [];
31
+ for (let a of e) {
32
+ let e = a.loc[0] ?? t.unknownValidationField, o = _[e], s = v[e], c = y(a) ? t.requiredField : a.msg;
33
+ o ? n[o] = c : s ? r[s] = c : i.push(t.unmappedValidationError(e, c));
30
34
  }
31
- return r.length && (n.form = r.join(" ")), n;
35
+ return i.length && (n.form = i.join(" ")), {
36
+ formErrors: n,
37
+ totalsErrors: Object.keys(r).length ? r : void 0
38
+ };
32
39
  }
33
- function b(e, t) {
40
+ function S(e, t) {
34
41
  if (!e && !t) return;
35
42
  let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
36
43
  for (let i of r) n[i] = {
@@ -39,88 +46,90 @@ function b(e, t) {
39
46
  };
40
47
  return n;
41
48
  }
42
- function x({ payableId: _, form: v, counterpartId: x, clearCounterpart: S, prepareVendorForSave: C, onSaved: w, onPayableCreated: T, readSavedStatus: E, onDraftSaved: D, onFinalized: O, labels: k }) {
49
+ function C({ payableId: t, form: _, counterpartId: v, clearCounterpart: y, prepareVendorForSave: C, onSaved: w, onPayableCreated: T, readSavedStatus: E, onDraftSaved: D, onFinalized: O, labels: k }) {
43
50
  let A = {
44
- ...s,
51
+ ...c,
45
52
  ...k
46
- }, [j, M] = g(), N = _ ?? j, [P, F] = g(), I = m(() => F(void 0), []), [L, R] = g(!1), z = m(() => R(!0), []), [B, V] = g(), H = h(!1), U = n(), W = r(), G = a(), K = t(), q = o(), J = i(), Y = m(() => v.isTotalsDirty ? f(v.discount, v.tax, v.totalOverride, A) : void 0, [v, A]), X = m(() => {
47
- let t = p(v.lineItems, A), n = Y();
48
- return v.setLineItemErrors(t), !t && !n || (t ? (v.setErrors(void 0), e.error(A.lineItemsNeedAttention)) : v.setErrors(n), !1);
53
+ }, [j, M] = g(), N = t ?? j, [P, F] = g(), I = m(() => F(void 0), []), [L, R] = g(!1), z = m(() => R(!0), []), [B, V] = g(), H = h(!1), [U, te] = g(0), W = m(() => te((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = m(() => _.isTotalsDirty ? f(_.discount, _.tax, _.totalOverride, A) : void 0, [_, A]), Q = m(() => {
54
+ let t = p(_.lineItems, A), n = Z();
55
+ return _.setLineItemErrors(t), _.setTotalsErrors(n), !t && !n || (_.setErrors(void 0), t && e.error(A.lineItemsNeedAttention), W(), !1);
49
56
  }, [
50
- v,
57
+ _,
51
58
  A,
52
- Y
53
- ]), Z = m(async (e) => {
59
+ W,
60
+ Z
61
+ ]), $ = m(async (e) => {
54
62
  let t = !N && P ? {
55
- base64EncodedFile: await c(P),
63
+ base64EncodedFile: await ee(P),
56
64
  fileName: P.name
57
65
  } : void 0, n = l({
58
- values: v.values,
59
- counterpartId: x,
60
- clearCounterpart: S,
66
+ values: _.values,
67
+ counterpartId: v,
68
+ clearCounterpart: y,
61
69
  counterpartBankAccountId: e,
62
- editedTotals: v.isTotalsDirty ? {
63
- discount: v.discount,
64
- tax: v.tax,
65
- total: v.totalOverride
70
+ editedTotals: _.isTotalsDirty ? {
71
+ discount: _.discount,
72
+ tax: _.tax,
73
+ total: _.totalOverride
66
74
  } : void 0,
67
75
  document: t
68
76
  }), r = N;
69
- if (r ? await G.mutateAsync({
77
+ if (r ? await q.mutateAsync({
70
78
  path: { payable_id: r },
71
79
  body: n
72
- }) : (r = (await U.mutateAsync({ body: n }))?.id, r && (M(r), T?.(r), t && F(void 0))), !r) throw Error("Payable was created without an id");
80
+ }) : (r = (await G.mutateAsync({ body: n }))?.id, r && (M(r), T?.(r), t && F(void 0))), !r) throw Error("Payable was created without an id");
73
81
  if (L) {
74
82
  try {
75
- await W.mutateAsync({ path: { payable_id: r } });
83
+ await K.mutateAsync({ path: { payable_id: r } });
76
84
  } catch {}
77
85
  R(!1);
78
86
  }
79
- return await K.mutateAsync({
87
+ return await J.mutateAsync({
80
88
  path: { payable_id: r },
81
- body: { data: u(v.lineItems) }
89
+ body: { data: u(_.lineItems) }
82
90
  }), r;
83
91
  }, [
84
- x,
85
- S,
86
- U,
87
- W,
92
+ v,
93
+ y,
94
+ G,
95
+ K,
88
96
  L,
89
- v.discount,
90
- v.isTotalsDirty,
91
- v.lineItems,
92
- v.tax,
93
- v.totalOverride,
94
- v.values,
97
+ _.discount,
98
+ _.isTotalsDirty,
99
+ _.lineItems,
100
+ _.tax,
101
+ _.totalOverride,
102
+ _.values,
95
103
  T,
96
104
  N,
97
- K,
105
+ J,
98
106
  P,
99
- G
100
- ]), Q = m(async () => {
101
- N && (await W.mutateAsync({ path: { payable_id: N } }), R(!1));
102
- }, [W, N]);
107
+ q
108
+ ]), ne = m(async () => {
109
+ N && (await K.mutateAsync({ path: { payable_id: N } }), R(!1));
110
+ }, [K, N]);
103
111
  return {
104
112
  saveDraft: m(async () => {
105
- if (!H.current && X()) {
113
+ if (!H.current && Q()) {
106
114
  H.current = !0, V("draft");
107
115
  try {
108
116
  let t = await C?.();
109
117
  if (t && !t.ok) return;
110
- let n = await Z(t?.counterpartBankAccountId);
111
- v.setErrors(void 0), w?.(n), D?.(n);
118
+ let n = await $(t?.counterpartBankAccountId);
119
+ _.setErrors(void 0), w?.(n), D?.(n);
112
120
  let r = await E?.();
113
121
  return e.success(r === "draft" ? A.submittedDemoted : A.draftSaved), n;
114
- } catch {
115
- v.setErrors({ form: A.saveFailed });
122
+ } catch (e) {
123
+ _.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
116
124
  return;
117
125
  } finally {
118
126
  V(void 0), H.current = !1;
119
127
  }
120
128
  }
121
129
  }, [
122
- v,
123
- X,
130
+ _,
131
+ Q,
132
+ A.discountTaxBlockedByLineItems,
124
133
  A.draftSaved,
125
134
  A.saveFailed,
126
135
  A.submittedDemoted,
@@ -128,54 +137,56 @@ function x({ payableId: _, form: v, counterpartId: x, clearCounterpart: S, prepa
128
137
  w,
129
138
  E,
130
139
  C,
131
- Z
140
+ $,
141
+ W
132
142
  ]),
133
143
  finalize: m(async () => {
134
144
  if (H.current) return;
135
- let t = p(v.lineItems, A), n = Y(), { formErrors: r, lineItemErrors: i } = d(v.values, x, v.lineItems, A), a = b(i, t);
136
- v.setLineItemErrors(a);
137
- let o = {
138
- ...r,
139
- ...n
140
- };
141
- if (v.setErrors(Object.keys(o).length ? o : void 0), t && e.error(A.lineItemsNeedAttention), !(a || Object.keys(o).length)) {
142
- H.current = !0, V("finalize");
145
+ let t = p(_.lineItems, A), n = Z(), { formErrors: r, lineItemErrors: i } = d(_.values, v, _.lineItems, A), a = S(i, t);
146
+ _.setLineItemErrors(a), _.setTotalsErrors(n);
147
+ let o = r ?? {};
148
+ if (_.setErrors(Object.keys(o).length ? o : void 0), t && e.error(A.lineItemsNeedAttention), a || n || Object.keys(o).length) {
149
+ W();
150
+ return;
151
+ }
152
+ H.current = !0, V("finalize");
153
+ try {
154
+ let t;
155
+ try {
156
+ let e = await C?.();
157
+ if (e && !e.ok) return;
158
+ t = await $(e?.counterpartBankAccountId);
159
+ } catch (e) {
160
+ _.setSaveFailureMessage(b(e) ? A.discountTaxBlockedByLineItems : A.saveFailed), W();
161
+ return;
162
+ }
163
+ w?.(t);
143
164
  try {
144
- let t;
145
- try {
146
- let e = await C?.();
147
- if (e && !e.ok) return;
148
- t = await Z(e?.counterpartBankAccountId);
149
- } catch {
150
- v.setErrors({ form: A.saveFailed });
165
+ let n = await Y.mutateAsync({ path: { payable_id: t } });
166
+ if (n.validation_errors.length) {
167
+ let e = x(n.validation_errors, A);
168
+ _.setErrors(e.formErrors), _.setTotalsErrors(e.totalsErrors), W();
151
169
  return;
152
170
  }
153
- w?.(t);
154
- try {
155
- let n = await q.mutateAsync({ path: { payable_id: t } });
156
- if (n.validation_errors.length) {
157
- v.setErrors(y(n.validation_errors, A));
158
- return;
159
- }
160
- await J.mutateAsync({ path: { payable_id: t } }), v.setErrors(void 0), O?.(t), e.success(A.billFinalized);
161
- } catch {
162
- v.setErrors({ form: A.finalizeFailed });
163
- }
164
- } finally {
165
- V(void 0), H.current = !1;
171
+ await X.mutateAsync({ path: { payable_id: t } }), _.setErrors(void 0), O?.(t), e.success(A.billFinalized);
172
+ } catch {
173
+ _.setSaveFailureMessage(A.finalizeFailed), W();
166
174
  }
175
+ } finally {
176
+ V(void 0), H.current = !1;
167
177
  }
168
178
  }, [
169
- x,
170
179
  v,
180
+ _,
171
181
  A,
172
182
  O,
173
183
  w,
174
184
  C,
185
+ $,
186
+ W,
187
+ X,
175
188
  Z,
176
- J,
177
- Y,
178
- q
189
+ Y
179
190
  ]),
180
191
  payableId: N,
181
192
  isSavingDraft: B === "draft",
@@ -183,12 +194,13 @@ function x({ payableId: _, form: v, counterpartId: x, clearCounterpart: S, prepa
183
194
  stagedFile: P,
184
195
  stageFile: F,
185
196
  clearStagedFile: I,
197
+ scrollToErrorToken: U,
186
198
  isFileDeletionPending: L,
187
199
  requestFileDeletion: z,
188
- detachFileNow: Q,
189
- isDeletingFile: W.isPending,
190
- hasFileDeletionFailed: W.isError
200
+ detachFileNow: ne,
201
+ isDeletingFile: K.isPending,
202
+ hasFileDeletionFailed: K.isError
191
203
  };
192
204
  }
193
205
  //#endregion
194
- export { y as mapValidationErrorsToForm, x as useBillCreateController };
206
+ export { x as mapValidationErrorsToForm, C as useBillCreateController };
@@ -25,13 +25,13 @@ function n({ payable: n, lineItems: r }) {
25
25
  quantity: e.quantity == null ? "" : String(e.quantity),
26
26
  price: t(e.unit_price),
27
27
  amount: t(e.subtotal)
28
- }));
28
+ })), o = n.amount_due ?? (n.total_amount == null ? void 0 : n.total_amount - (n.discount ?? 0));
29
29
  return {
30
30
  values: i,
31
31
  lineItems: a.length ? a : [e()],
32
32
  discount: t(n.discount),
33
33
  tax: t(n.tax_amount),
34
- total: n.total_amount ? t(n.total_amount) : ""
34
+ total: o ? t(o) : ""
35
35
  };
36
36
  }
37
37
  //#endregion