@tesouro/embedded-components-react 0.5.48 → 0.5.49

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.
@@ -24,26 +24,39 @@ function o(e) {
24
24
  function s(e) {
25
25
  return (e / 100).toFixed(2);
26
26
  }
27
- function c({ values: e, initialLineItems: r, counterpartId: i, clearCounterpart: a, counterpartBankAccountId: o, editedTotals: s, currentTotals: c, lineItems: d, document: f }) {
28
- let p = { currency: t };
29
- if (i ? p.counterpart_id = i : a && (p.counterpart_id = null), i ? p.counterpart_bank_account_id = o ?? null : a && (p.counterpart_bank_account_id = null), e.invoiceNumber && (p.document_id = e.invoiceNumber), e.invoiceDate && (p.issued_at = e.invoiceDate), e.dueDate && (p.due_date = e.dueDate), f && (p.base64_encoded_file = f.base64EncodedFile, p.file_name = f.fileName), s && (p.discount = n(s.discount) ?? 0, p.tax_amount = n(s.tax) ?? 0, s.total !== void 0 && (p.total_amount = (n(s.total) ?? 0) + (n(s.discount) ?? 0))), c && d) {
30
- let e = u(d).reduce((e, t) => e + t.subtotal, 0), t = n(c.tax) ?? 0, r = n(c.discount) ?? 0, i = c.total === void 0 ? e + t : (n(c.total) ?? 0) + r;
31
- p.subtotal = e, p.tax_amount = t, p.total_amount = i;
32
- } else if (r && !("total_amount" in p)) {
27
+ function c({ values: e, initialLineItems: r, counterpartId: i, clearCounterpart: a, counterpartBankAccountId: o, editedTotals: s, currentTotals: c, lineItems: d, document: f, includeBlankPoNumber: p = !0 }) {
28
+ let m = { currency: t };
29
+ i ? m.counterpart_id = i : a && (m.counterpart_id = null), i ? m.counterpart_bank_account_id = o ?? null : a && (m.counterpart_bank_account_id = null), e.invoiceNumber && (m.document_id = e.invoiceNumber), e.invoiceDate && (m.issued_at = e.invoiceDate), e.dueDate && (m.due_date = e.dueDate);
30
+ let h = e.poNumber.trim();
31
+ if ((h || p) && (m.purchase_order_number = h || null), f && (m.base64_encoded_file = f.base64EncodedFile, m.file_name = f.fileName), s && (m.discount = n(s.discount) ?? 0, m.tax_amount = n(s.tax) ?? 0, s.total !== void 0 && (m.total_amount = (n(s.total) ?? 0) + (n(s.discount) ?? 0))), c && d) {
32
+ let e = u(d), t = n(c.tax) ?? 0, r = n(c.discount) ?? 0, i = c.total === void 0 ? (e ?? 0) + t : (n(c.total) ?? 0) + r;
33
+ e !== void 0 && (m.subtotal = e), m.tax_amount = t, m.total_amount = i;
34
+ } else if (r && !("total_amount" in m)) {
33
35
  let e = l(r, s?.tax);
34
- e !== void 0 && (p.total_amount = e);
36
+ e !== void 0 && (m.total_amount = e);
35
37
  }
36
- return p;
38
+ return m;
37
39
  }
38
40
  function l(e, t) {
39
- let r = !1, a = e.reduce((e, t) => {
40
- if (!i(t)) return e;
41
- let a = n(t.amount);
42
- return a === null ? e : (r = !0, e + a);
43
- }, 0);
44
- if (r) return a + (t ? n(t) ?? 0 : 0);
41
+ let r = u(e);
42
+ if (r !== void 0) return r + (t ? n(t) ?? 0 : 0);
45
43
  }
46
44
  function u(e) {
45
+ let t = !1, r = e.reduce((e, r) => {
46
+ if (!i(r)) return e;
47
+ let a = n(r.amount);
48
+ return a === null ? e : (t = !0, e + a);
49
+ }, 0);
50
+ if (t) return r;
51
+ }
52
+ function d({ lineItems: e, editedTotals: t }) {
53
+ let r = u(e), i = n(t.tax) ?? 0, a = n(t.discount) ?? 0, o = {
54
+ discount: a,
55
+ tax_amount: i
56
+ };
57
+ return r !== void 0 && (o.subtotal = r), t.total === void 0 ? r !== void 0 && (o.total_amount = r + i) : o.total_amount = (n(t.total) ?? 0) + a, o;
58
+ }
59
+ function f(e) {
47
60
  return e.filter(i).map((e) => {
48
61
  let t = n(e.amount), i = r(e.quantity) ?? 1, a = n(e.price) ?? (t === null ? 0 : Math.round(t / i)), o = Math.round(i * a), s = t ?? o;
49
62
  return {
@@ -58,11 +71,11 @@ function u(e) {
58
71
  };
59
72
  });
60
73
  }
61
- function d(e, t) {
74
+ function p(e, t) {
62
75
  return s(Math.round(o(e) * a(t)));
63
76
  }
64
- function f(e, t, n) {
77
+ function m(e, t, n) {
65
78
  return s(e.reduce((e, t) => e + a(t.amount), 0) + a(t) - a(n));
66
79
  }
67
80
  //#endregion
68
- export { f as calculateTotal, d as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, u as mapLineItemsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
81
+ export { m as calculateTotal, p as displayLineAmount, i as isPersistableLineItem, c as mapBillFormToPayload, f as mapLineItemsToPayload, d as mapPayableAmountFieldsToPayload, n as parseMoneyToMinorUnits, r as parseQuantity };
@@ -10,8 +10,8 @@ import { useCreatePayableMutation as r, useDeletePayableFileMutation as i, useSu
10
10
  import "../../data-access/dist/index.js";
11
11
  import { BILL_CREATE_MESSAGE_LABELS_EN as c } from "./index49.js";
12
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";
13
+ import { mapBillFormToPayload as u, mapLineItemsToPayload as d, mapPayableAmountFieldsToPayload as ee } from "./index55.js";
14
+ import { validateBillCompleteness as f, validateBillTotalIsPayable as te, validateBillTotals as ne, validateBillValues as p, validateLineItems as m, validateStoredAmountDue as re } from "./index56.js";
15
15
  import { useCallback as h, useRef as g, useState as _ } from "react";
16
16
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/feature/dist/index57.js
17
17
  var v = {
@@ -24,7 +24,7 @@ var v = {
24
24
  function b(e) {
25
25
  return e.type === "type_error.none.not_allowed" || e.msg === "none is not an allowed value";
26
26
  }
27
- var re = "pending-vendor";
27
+ var ie = "pending-vendor";
28
28
  function x(e) {
29
29
  return !!t(e)?.includes("line_items_enabled");
30
30
  }
@@ -39,7 +39,7 @@ function S(e, t = c) {
39
39
  totalsErrors: Object.keys(r).length ? r : void 0
40
40
  };
41
41
  }
42
- function C(e, t) {
42
+ function ae(e, t) {
43
43
  if (!e && !t) return;
44
44
  let n = {}, r = /* @__PURE__ */ new Set([...Object.keys(e ?? {}), ...Object.keys(t ?? {})]);
45
45
  for (let i of r) n[i] = {
@@ -48,176 +48,182 @@ function C(e, t) {
48
48
  };
49
49
  return n;
50
50
  }
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 = {
51
+ function C({ payableId: t, form: v, counterpartId: y, isVendorPending: b, clearCounterpart: C, prepareVendorForSave: w, onSaved: T, onPayableCreated: E, readSavedStatus: D, onDraftSaved: O, onFinalized: k, labels: A }) {
52
+ let j = {
53
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);
54
+ ...A
55
+ }, [M, N] = _(), P = t ?? M, [F, I] = _(), oe = h(() => I(void 0), []), [L, R] = _(!1), se = h(() => R(!0), []), [z, B] = _(), V = g(!1), [H, U] = _(0), W = h(() => U((e) => e + 1), []), G = r(), K = i(), q = o(), J = n(), Y = s(), X = a(), Z = h(() => v.isTotalsDirty ? ne(v.discount, v.tax, v.totalOverride, j) : void 0, [v, j]), Q = h(() => {
56
+ let t = p(v.values, j), n = m(v.lineItems, j), r = Z();
57
+ return v.setErrors(t), v.setLineItemErrors(n), v.setTotalsErrors(r), !t && !n && !r || (n && e.error(j.lineItemsNeedAttention), W(), !1);
58
58
  }, [
59
59
  v,
60
- M,
60
+ j,
61
61
  W,
62
62
  Z
63
63
  ]), $ = h(async (e, t) => {
64
- let n = !F && I ? {
65
- base64EncodedFile: await l(I),
66
- fileName: I.name
67
- } : void 0, r = u({
64
+ let n = !P && F ? {
65
+ base64EncodedFile: await l(F),
66
+ fileName: F.name
67
+ } : void 0, r = v.isTotalsDirty ? {
68
+ discount: v.discount,
69
+ tax: v.tax,
70
+ total: v.totalOverride
71
+ } : void 0, i = u({
68
72
  values: v.values,
69
- initialLineItems: F ? void 0 : v.lineItems,
73
+ initialLineItems: P ? void 0 : v.lineItems,
70
74
  counterpartId: t ?? y,
71
- clearCounterpart: w,
75
+ clearCounterpart: C,
72
76
  counterpartBankAccountId: e,
73
- editedTotals: v.isTotalsDirty ? {
74
- discount: v.discount,
75
- tax: v.tax,
76
- total: v.totalOverride
77
- } : void 0,
78
77
  currentTotals: {
79
78
  discount: v.discount,
80
79
  tax: v.tax,
81
80
  total: v.totalOverride
82
81
  },
83
82
  lineItems: v.lineItems,
83
+ editedTotals: r,
84
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) {
85
+ }), a = P;
86
+ if (a ? await q.mutateAsync({
87
+ path: { payable_id: a },
88
+ body: i
89
+ }) : (a = (await G.mutateAsync({ body: i }))?.id, a && (N(a), E?.(a), n && I(void 0))), !a) throw Error("Payable was created without an id");
90
+ if (L) {
91
91
  try {
92
- await K.mutateAsync({ path: { payable_id: i } });
92
+ await K.mutateAsync({ path: { payable_id: a } });
93
93
  } catch {}
94
- B(!1);
94
+ R(!1);
95
95
  }
96
96
  return await J.mutateAsync({
97
- path: { payable_id: i },
98
- body: { data: ee(v.lineItems) }
99
- }), i;
97
+ path: { payable_id: a },
98
+ body: { data: d(v.lineItems) }
99
+ }), r && await q.mutateAsync({
100
+ path: { payable_id: a },
101
+ body: ee({
102
+ lineItems: v.lineItems,
103
+ editedTotals: r
104
+ })
105
+ }), a;
100
106
  }, [
101
107
  y,
102
- w,
108
+ C,
103
109
  G,
104
110
  K,
105
- z,
111
+ L,
106
112
  v.discount,
107
113
  v.isTotalsDirty,
108
114
  v.lineItems,
109
115
  v.tax,
110
116
  v.totalOverride,
111
117
  v.values,
112
- D,
113
- F,
118
+ E,
119
+ P,
114
120
  J,
115
- I,
121
+ F,
116
122
  q
117
- ]), se = h(async () => {
118
- F && (await K.mutateAsync({ path: { payable_id: F } }), B(!1));
119
- }, [K, F]);
123
+ ]), ce = h(async () => {
124
+ P && (await K.mutateAsync({ path: { payable_id: P } }), R(!1));
125
+ }, [K, P]);
120
126
  return {
121
127
  saveDraft: h(async () => {
122
- if (!U.current && Q()) {
123
- U.current = !0, H("draft");
128
+ if (!V.current && Q()) {
129
+ V.current = !0, B("draft");
124
130
  try {
125
- let t = await T?.();
131
+ let t = await w?.();
126
132
  if (t && !t.ok) return;
127
133
  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;
134
+ v.setErrors(void 0), T?.(n), O?.(n);
135
+ let r = await D?.();
136
+ return e.success(r === "draft" ? j.submittedDemoted : j.draftSaved), n;
131
137
  } catch (e) {
132
- v.setSaveFailureMessage(x(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
138
+ v.setSaveFailureMessage(x(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
133
139
  return;
134
140
  } finally {
135
- H(void 0), U.current = !1;
141
+ B(void 0), V.current = !1;
136
142
  }
137
143
  }
138
144
  }, [
139
145
  v,
140
146
  Q,
141
- M.discountTaxBlockedByLineItems,
142
- M.draftSaved,
143
- M.saveFailed,
144
- M.submittedDemoted,
145
- k,
146
- E,
147
+ j.discountTaxBlockedByLineItems,
148
+ j.draftSaved,
149
+ j.saveFailed,
150
+ j.submittedDemoted,
147
151
  O,
148
152
  T,
153
+ D,
154
+ w,
149
155
  $,
150
156
  W
151
157
  ]),
152
158
  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 ? {
159
+ if (V.current) return;
160
+ let t = m(v.lineItems, j), n = p(v.values, j), r = Z(), i = te(v.total, j), a = v.isTotalsDirty ? re(v.totalOverride, j) : void 0, o = r || i || a ? {
155
161
  ...a,
156
162
  ...i,
157
163
  ...r
158
- } : void 0, { formErrors: s, lineItemErrors: c } = te(v.values, y ?? (b ? re : void 0), v.lineItems, M), l = C(c, t);
164
+ } : void 0, { formErrors: s, lineItemErrors: c } = f(v.values, y ?? (b ? ie : void 0), v.lineItems, j), l = ae(c, t);
159
165
  v.setLineItemErrors(l), v.setTotalsErrors(o);
160
166
  let u = {
161
167
  ...s,
162
168
  ...n
163
169
  };
164
- if (v.setErrors(Object.keys(u).length ? u : void 0), t && e.error(M.lineItemsNeedAttention), l || o || Object.keys(u).length) {
170
+ if (v.setErrors(Object.keys(u).length ? u : void 0), t && e.error(j.lineItemsNeedAttention), l || o || Object.keys(u).length) {
165
171
  W();
166
172
  return;
167
173
  }
168
- U.current = !0, H("finalize");
174
+ V.current = !0, B("finalize");
169
175
  try {
170
176
  let t;
171
177
  try {
172
- let e = await T?.();
178
+ let e = await w?.();
173
179
  if (e && !e.ok) return;
174
180
  t = await $(e?.counterpartBankAccountId, e?.counterpartId);
175
181
  } catch (e) {
176
- v.setSaveFailureMessage(x(e) ? M.discountTaxBlockedByLineItems : M.saveFailed), W();
182
+ v.setSaveFailureMessage(x(e) ? j.discountTaxBlockedByLineItems : j.saveFailed), W();
177
183
  return;
178
184
  }
179
- E?.(t);
185
+ T?.(t);
180
186
  try {
181
187
  let n = await Y.mutateAsync({ path: { payable_id: t } });
182
188
  if (n.validation_errors.length) {
183
- let e = S(n.validation_errors, M);
189
+ let e = S(n.validation_errors, j);
184
190
  v.setErrors(e.formErrors), v.setTotalsErrors(e.totalsErrors), W();
185
191
  return;
186
192
  }
187
- await X.mutateAsync({ path: { payable_id: t } }), v.setErrors(void 0), A?.(t), e.success(M.billFinalized);
193
+ await X.mutateAsync({ path: { payable_id: t } }), v.setErrors(void 0), k?.(t), e.success(j.billFinalized);
188
194
  } catch {
189
- v.setSaveFailureMessage(M.finalizeFailed), W();
195
+ v.setSaveFailureMessage(j.finalizeFailed), W();
190
196
  }
191
197
  } finally {
192
- H(void 0), U.current = !1;
198
+ B(void 0), V.current = !1;
193
199
  }
194
200
  }, [
195
201
  y,
196
202
  b,
197
203
  v,
198
- M,
199
- A,
200
- E,
204
+ j,
205
+ k,
201
206
  T,
207
+ w,
202
208
  $,
203
209
  W,
204
210
  X,
205
211
  Z,
206
212
  Y
207
213
  ]),
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,
214
+ payableId: P,
215
+ isSavingDraft: z === "draft",
216
+ isFinalizing: z === "finalize",
217
+ stagedFile: F,
218
+ stageFile: I,
219
+ clearStagedFile: oe,
220
+ scrollToErrorToken: H,
221
+ isFileDeletionPending: L,
222
+ requestFileDeletion: se,
223
+ detachFileNow: ce,
218
224
  isDeletingFile: K.isPending,
219
225
  hasFileDeletionFailed: K.isError
220
226
  };
221
227
  }
222
228
  //#endregion
223
- export { S as mapValidationErrorsToForm, w as useBillCreateController };
229
+ export { S as mapValidationErrorsToForm, C as useBillCreateController };
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.5.48", n = "28707329ff4897ede068ba34d07f758cd7a15480", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.5.49", n = "35cfe2ead26ab15b6504fc73ea208acfe15f4b89", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-react",
3
- "version": "0.5.48",
3
+ "version": "0.5.49",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "packageDepSync": {