@tesouro/embedded-components-react 0.5.205 → 0.5.207

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +51 -4
  3. package/dist/index.js +1 -1
  4. package/dist/lib/ReceivablesWidget.d.ts +51 -4
  5. package/dist/lib/ReceivablesWidget.js +1 -1
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +2 -2
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index10.js +84 -2
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +31 -25
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +109 -193
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +154 -37
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +193 -135
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +37 -58
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +140 -86
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +42 -47
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +58 -313
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +91 -65
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js +108 -102
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js +48 -249
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index20.js +365 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index21.js +75 -0
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index22.js +115 -0
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index23.js +285 -0
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +1 -1
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +93 -407
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +430 -86
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +17 -12
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +92 -16
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +3 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +24 -4
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +0 -10
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +2 -0
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +3 -264
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +16 -70
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +1 -424
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +4 -106
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +12 -93
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +5 -179
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index20.js +1 -344
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index21.js +264 -0
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index22.js +72 -0
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index23.js +402 -0
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index24.js +106 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index25.js +249 -0
  45. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index26.js +93 -0
  46. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index27.js +344 -0
  47. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index3.js +195 -32
  48. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +29 -202
  49. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +183 -137
  50. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +157 -20
  51. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +16 -1
  52. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +25 -3
  53. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +4 -3
  54. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/index.js +11 -11
  55. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -38
  56. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +220 -198
  57. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +124 -84
  58. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  59. package/package.json +1 -1
@@ -2,114 +2,120 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { useAnalyticsTrack as e } from "../../../shared/feature/dist/lib/analytics/hooks.js";
5
+ import { toast as e } from "../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { extractApiErrorMessage as t } from "../../../shared/util/dist/lib/apiErrors.js";
7
+ import { usePaymentTermsQuery as n } from "../../../shared/data-access/dist/lib/reference-data/usePaymentTermsQuery.js";
8
+ import "../../../shared/ui/dist/index.js";
9
+ import { useWidgetConfig as r } from "../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
6
10
  import "../../../shared/feature/dist/index.js";
7
- import { ReceivablesWidgetAnalyticsEvent as t } from "./index2.js";
8
- import { coerceEnabledTabs as n, resolveInitialTab as r, tabForType as i, typeForTab as a } from "./index8.js";
9
- import { RECEIVABLE_MESSAGE_LABELS_EN as o } from "./index9.js";
10
- import { useReceivableActions as s } from "./index10.js";
11
- import { useReceivableDetails as c } from "./index11.js";
12
- import { hasSelectedText as l } from "../../../shared/product-catalog/feature/dist/lib/helpers.js";
13
- import "../../../shared/product-catalog/feature/dist/index.js";
14
- import { useReceivableForm as u } from "./index16.js";
15
- import { useReceivablesTable as d } from "./index17.js";
16
- import { useCallback as f, useEffect as p, useMemo as m, useState as h } from "react";
11
+ import { areOverdueTermsValid as i, buildOverdueReminderPayload as a, buildPaymentReminderPayload as o, buildRemindersView as s, canCreateReminders as c, getImpliedDueDate as l, isBeforeDueDaysValid as u, sanitizeReminderDays as d } from "./index11.js";
12
+ import { useCreateOverdueReminderMutation as f, useCreatePaymentReminderMutation as p, useOverdueRemindersQuery as m, usePaymentRemindersQuery as h } from "../../data-access/dist/index10.js";
13
+ import "../../data-access/dist/index.js";
14
+ import { useCallback as g, useMemo as _, useState as v } from "react";
17
15
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index18.js
18
- function g({ counterpartMessageLabels: g, defaultTab: _, embeddedBankName: v, enabledTabs: y, messageLabels: b, onReceivableCreated: x, onReceivableOpened: S }) {
19
- let C = e();
20
- p(() => {
21
- C(t.Mounted);
22
- }, [C]);
23
- let w = m(() => ({
24
- ...o,
25
- ...b
26
- }), [b]), T = m(() => n(y), [y]), [E, D] = h(() => r({
27
- defaultTab: _,
28
- enabledTabs: T
29
- })), [O, k] = h(), [A, j] = h(!1);
30
- p(() => {
31
- T.includes(E) || D(r({
32
- defaultTab: _,
33
- enabledTabs: T
34
- }));
16
+ var y = [""];
17
+ function b({ open: b, isInvoice: x, disabled: S, paymentTermsId: C, paymentTermsCustomDate: w, paymentReminderId: T, overdueReminderId: E, messages: D, onSelect: O }) {
18
+ let { initResponse: k } = r(), A = n().data?.data, j = _(() => c(k?.scopes), [k?.scopes]), [M, N] = v(!1), [P, F] = v(""), [I, L] = v(y), R = b && x && M, z = h({ enabled: R }), B = m({ enabled: R }), V = p(), H = f(), U = g((e) => {
19
+ N(e), F(""), L(y);
20
+ }, []), W = g((e) => {
21
+ e || (O({
22
+ paymentReminderId: "",
23
+ overdueReminderId: ""
24
+ }), F(""), L(y)), N(e);
25
+ }, [O]), G = g((e) => O({ paymentReminderId: e }), [O]), K = g((e) => O({ overdueReminderId: e }), [O]), q = g((e) => F(d(e)), []), J = g((e, t) => {
26
+ let n = d(t);
27
+ L((t) => t.map((t, r) => r === e ? n : t));
28
+ }, []), Y = g(() => {
29
+ L((e) => e.length < 3 ? [...e, ""] : e);
30
+ }, []), X = g(() => L(y), []), Z = g(() => l({
31
+ paymentTermsId: C,
32
+ paymentTermsCustomDate: w,
33
+ paymentTerms: A,
34
+ today: /* @__PURE__ */ new Date()
35
+ }), [
36
+ A,
37
+ w,
38
+ C
39
+ ]), Q = g(async () => {
40
+ if (u(P)) try {
41
+ let t = await V.mutateAsync({ body: o({
42
+ daysBefore: Number(P),
43
+ dueDate: Z(),
44
+ messages: D
45
+ }) });
46
+ F(""), O({ paymentReminderId: t.id }), e.success(D.reminderAdded);
47
+ } catch (n) {
48
+ e.error(t(n) ?? D.genericError);
49
+ }
35
50
  }, [
36
- E,
37
- _,
38
- T
39
- ]);
40
- let M = f((e, t) => {
41
- D(i(t)), k(e), j(!0), x?.(e, t);
42
- }, [x]), N = d({
43
- activeTab: E,
44
- messages: w
45
- }), P = c({
46
- selectedReceivableId: O,
47
- enabled: A,
48
- messages: w
49
- }), F = u({
50
- messages: w,
51
- counterpartMessageLabels: g,
52
- embeddedBankName: v,
53
- onCreated: M
54
- }), I = f(() => {
55
- let e = a(E);
56
- F.openCreate(e === "quote" ? "quote" : "invoice");
57
- }, [E, F.openCreate]), L = s({
58
- selectedReceivable: P.receivable,
59
- messages: w,
60
- onCreated: M,
61
- onDeleted: (e) => {
62
- e === O && (k(void 0), j(!1));
51
+ P,
52
+ V,
53
+ Z,
54
+ D,
55
+ O
56
+ ]), $ = g(async () => {
57
+ if (i(I)) try {
58
+ let t = await H.mutateAsync({ body: a({
59
+ terms: I,
60
+ dueDate: Z(),
61
+ messages: D
62
+ }) });
63
+ L(y), O({ overdueReminderId: t.id }), e.success(D.reminderAdded);
64
+ } catch (n) {
65
+ e.error(t(n) ?? D.genericError);
63
66
  }
64
- }), R = f((e) => {
65
- l() || (k(e.id), j(!0), S?.(e.id, e.type));
66
- }, [S]);
67
+ }, [
68
+ H,
69
+ Z,
70
+ D,
71
+ O,
72
+ I
73
+ ]);
67
74
  return {
68
- activeTab: E,
69
- enabledTabs: T,
70
- setActiveTab: D,
71
- table: N,
72
- details: P,
73
- detailsOpen: A,
74
- closeDetails: f(() => {
75
- j(!1), k(void 0);
76
- }, []),
77
- form: F,
78
- openCreate: I,
79
- actions: L,
80
- handleRowClick: R,
81
- handleActionClick: f((e, t) => {
82
- let n = N.getReceivableById(t.id);
83
- if (e === "edit") {
84
- if (n) {
85
- F.openEdit(n);
86
- return;
87
- }
88
- k(t.id), j(!0);
89
- return;
90
- }
91
- k(t.id), L.openAction(e, t, n ?? null);
92
- }, [
93
- L,
94
- F.openEdit,
95
- N.getReceivableById
75
+ view: _(() => x ? s({
76
+ showReminders: M,
77
+ paymentTermsId: C,
78
+ paymentTermsCustomDate: w,
79
+ paymentReminderId: T,
80
+ overdueReminderId: E,
81
+ paymentReminders: z.data?.data,
82
+ overdueReminders: B.data?.data,
83
+ canCreate: j,
84
+ disabled: S,
85
+ beforeDueInput: P,
86
+ overdueTerms: I,
87
+ isCreatingPaymentReminder: V.isPending,
88
+ isCreatingOverdueReminder: H.isPending,
89
+ today: /* @__PURE__ */ new Date(),
90
+ messages: D
91
+ }) : void 0, [
92
+ P,
93
+ j,
94
+ H.isPending,
95
+ V.isPending,
96
+ S,
97
+ x,
98
+ D,
99
+ E,
100
+ B.data?.data,
101
+ I,
102
+ T,
103
+ z.data?.data,
104
+ w,
105
+ C,
106
+ M
96
107
  ]),
97
- handleDetailsActionClick: f((e, t) => {
98
- if (e === "edit") {
99
- P.receivable && (F.openEdit(P.receivable), j(!1));
100
- return;
101
- }
102
- L.openAction(e, {
103
- id: t.id,
104
- title: t.title,
105
- type: t.type
106
- }, P.receivable ?? null);
107
- }, [
108
- L,
109
- P.receivable,
110
- F.openEdit
111
- ])
108
+ reset: U,
109
+ toggle: W,
110
+ selectPaymentReminder: G,
111
+ selectOverdueReminder: K,
112
+ changeBeforeDueInput: q,
113
+ saveBeforeDue: Q,
114
+ changeOverdueTerm: J,
115
+ addOverdueTerm: Y,
116
+ clearOverdueTerms: X,
117
+ saveOverdue: $
112
118
  };
113
119
  }
114
120
  //#endregion
115
- export { g as useReceivablesWidget };
121
+ export { b as useReceivableReminders };
@@ -1,253 +1,52 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { EmbeddedToaster as e } from "../../../shared/ui/dist/lib/EmbeddedToaster.js";
6
- import "../../../shared/ui/dist/index.js";
7
- import { useAnalyticsTrack as t } from "../../../shared/feature/dist/lib/analytics/hooks.js";
8
- import { WidgetProvider as n } from "../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
9
- import "../../../shared/feature/dist/index.js";
10
- import { CounterpartFormSheet as r } from "../../../shared/counterpart-management/ui/dist/index9.js";
11
- import { CounterpartSelector as i } from "../../../shared/counterpart-management/feature/dist/lib/CounterpartSelector.js";
12
- import "../../../shared/counterpart-management/feature/dist/index.js";
13
- import { ReceivablesWidgetAnalyticsEvent as a, WIDGET_NAME as o } from "./index2.js";
14
- import { PAGE_SIZE_OPTIONS as s } from "./index4.js";
15
- import { ReceivableActionDialog as c } from "../../ui/dist/index3.js";
16
- import { ReceivableBankAccountSection as l } from "../../ui/dist/index4.js";
17
- import { ReceivableDetailsSheet as u } from "../../ui/dist/index15.js";
18
- import { ReceivableFormSheet as d } from "../../ui/dist/index17.js";
19
- import { ReceivablePaymentDialog as f } from "../../ui/dist/index18.js";
20
- import { ReceivableSendDialog as p } from "../../ui/dist/index19.js";
21
- import { ReceivablesScreen as m } from "../../ui/dist/index20.js";
22
- import "../../ui/dist/index.js";
23
- import { ReceivableAttachmentsSection as h } from "./index5.js";
24
- import { MeasureUnitsManagerContainer as g } from "../../../shared/product-catalog/feature/dist/lib/MeasureUnitsManagerContainer.js";
25
- import { ProductSelector as _ } from "../../../shared/product-catalog/feature/dist/lib/ProductSelector.js";
26
- import "../../../shared/product-catalog/feature/dist/index.js";
27
- import { useReceivablesWidget as v } from "./index18.js";
28
- import { useEffect as y, useId as b, useState as x } from "react";
29
- import { Fragment as S, jsx as C, jsxs as w } from "react/jsx-runtime";
1
+ import { parseQuantity as e, priceInputToMinorUnits as t } from "./index6.js";
30
2
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index19.js
31
- function T({ counterpartFormLabels: n, counterpartMessageLabels: o, defaultTab: T, detailsLabels: E, embeddedBankName: D, enabledTabs: O, formLabels: k, measureUnitDeleteLabels: A, measureUnitsLabels: j, messageLabels: M, onReceivableCreated: N, onReceivableOpened: P, onTemplateSettingsClick: F, pageSizeOptions: I = s, paymentLabels: L, productMessageLabels: R, screenLabels: z, sendLabels: B, actionLabels: V }) {
32
- let H = t();
33
- y(() => {
34
- H(a.Mounted);
35
- }, [H]);
36
- let U = v({
37
- counterpartMessageLabels: o,
38
- defaultTab: T,
39
- embeddedBankName: D,
40
- enabledTabs: O,
41
- messageLabels: M,
42
- onReceivableCreated: N,
43
- onReceivableOpened: P
44
- }), [W, G] = x(!1), K = b();
45
- return /* @__PURE__ */ w(S, { children: [
46
- /* @__PURE__ */ C(e, {}),
47
- /* @__PURE__ */ C(m, {
48
- rows: U.table.rows,
49
- activeTab: U.activeTab,
50
- enabledTabs: U.enabledTabs,
51
- onTabChange: U.setActiveTab,
52
- isLoading: U.table.isLoading,
53
- isError: U.table.isError,
54
- sorting: U.table.sorting,
55
- onSortingChange: U.table.onSortingChange,
56
- pageSize: U.table.pageSize,
57
- onPageSizeChange: U.table.onPageSizeChange,
58
- pageSizeOptions: I,
59
- hasNextPage: U.table.hasNextPage,
60
- hasPrevPage: U.table.hasPrevPage,
61
- onNextPage: U.table.onNextPage,
62
- onPrevPage: U.table.onPrevPage,
63
- searchValue: U.table.searchValue,
64
- onSearchChange: U.table.onSearchChange,
65
- statusFilter: U.table.statusFilter,
66
- statusOptions: U.table.statusOptions,
67
- onStatusFilterChange: U.table.onStatusFilterChange,
68
- isFiltering: U.table.isFiltering,
69
- onCreateClick: U.openCreate,
70
- onTemplateSettingsClick: F,
71
- onRowClick: U.handleRowClick,
72
- onActionClick: U.handleActionClick,
73
- onRetry: U.table.onRetry,
74
- labels: z
75
- }),
76
- /* @__PURE__ */ C(d, {
77
- open: U.form.open,
78
- onOpenChange: (e) => {
79
- e || U.form.close();
80
- },
81
- mode: U.form.mode,
82
- values: U.form.sheetValues,
83
- errors: U.form.errors,
84
- currencyOptions: U.form.currencyOptions,
85
- paymentTermsOptions: U.form.paymentTermsOptions,
86
- unitOptions: U.form.lineItemUnitOptions,
87
- currencySymbol: U.form.currencySymbol,
88
- lineItemControls: U.form.lineItemControls,
89
- autoFocusLineItemId: U.form.autoFocusLineItemId,
90
- lineItemsLoading: U.form.lineItemsLoading,
91
- inProgress: U.form.isSubmitting,
92
- customerSelector: /* @__PURE__ */ C(i, {
93
- mode: "customer",
94
- value: U.form.values.customerId || void 0,
95
- onValueChange: (e) => U.form.updateValues({ customerId: e }),
96
- onCreateClick: U.form.openCounterpartCreate
97
- }),
98
- renderProductSelector: (e, t) => /* @__PURE__ */ C(_, {
99
- ...t,
100
- inputValue: e.name,
101
- selectedProductId: U.form.values.lineItems.find((t) => t.id === e.id)?.productId || void 0,
102
- currency: U.form.values.currency,
103
- maxLength: 100,
104
- onInputValueChange: (t) => U.form.updateLineItem(e.id, { name: t }),
105
- onProductSelect: (t) => U.form.selectProduct(e.id, t)
106
- }),
107
- onChange: U.form.updateValues,
108
- onLineItemChange: U.form.updateLineItem,
109
- onLineItemCommit: U.form.commitLineItem,
110
- onLineItemQuantityStep: U.form.stepLineItem,
111
- onTaxRateCommit: U.form.commitTaxRate,
112
- onManageUnits: () => G(!0),
113
- onAddLineItem: U.form.addLineItem,
114
- onRemoveLineItem: U.form.removeLineItem,
115
- bankAccountSection: /* @__PURE__ */ C(l, {
116
- idPrefix: K,
117
- view: U.form.bankAccount.view,
118
- disabled: U.form.isSubmitting,
119
- onAccountSelect: U.form.bankAccount.selectAccount,
120
- onAddAccountClick: U.form.bankAccount.openAddAccount,
121
- onFormChange: U.form.bankAccount.updateAccountForm,
122
- onFormSave: U.form.bankAccount.saveAccount,
123
- onFormCancel: U.form.bankAccount.cancelAddAccount,
124
- labels: k
125
- }),
126
- attachmentsSection: U.form.attachmentsView && /* @__PURE__ */ C(h, {
127
- view: U.form.attachmentsView,
128
- disabled: U.form.isSubmitting,
129
- onFilesSelect: U.form.selectAttachmentFiles,
130
- onIncludeInEmailChange: U.form.setAttachmentIncludeInEmail,
131
- onRemove: U.form.removeAttachment,
132
- labels: k
133
- }),
134
- cancelDisabled: U.form.attachmentsUploading,
135
- saveDisabled: U.form.saveDisabled,
136
- onSubmit: U.form.submit,
137
- onCancel: U.form.close,
138
- labels: k
139
- }),
140
- /* @__PURE__ */ C(u, {
141
- open: U.detailsOpen,
142
- onOpenChange: (e) => {
143
- e || U.closeDetails();
144
- },
145
- details: U.details.detailsView,
146
- isLoading: U.details.isLoading,
147
- isError: U.details.isError,
148
- onActionClick: U.handleDetailsActionClick,
149
- onClose: U.closeDetails,
150
- labels: E
151
- }),
152
- /* @__PURE__ */ C(p, {
153
- open: U.actions.sendOpen,
154
- onOpenChange: (e) => {
155
- e || U.actions.closeSend();
156
- },
157
- values: U.actions.sendValues,
158
- errors: U.actions.sendErrors,
159
- inProgress: U.actions.sendInProgress,
160
- onChange: (e) => U.actions.setSendValues((t) => ({
161
- ...t,
162
- ...e
163
- })),
164
- onSubmit: U.actions.submitSend,
165
- onCancel: U.actions.closeSend,
166
- labels: B
167
- }),
168
- /* @__PURE__ */ C(f, {
169
- open: U.actions.paymentOpen,
170
- onOpenChange: (e) => {
171
- e || U.actions.closePayment();
172
- },
173
- values: U.actions.paymentValues,
174
- errors: U.actions.paymentErrors,
175
- inProgress: U.actions.paymentInProgress,
176
- onChange: (e) => U.actions.setPaymentValues((t) => ({
177
- ...t,
178
- ...e
179
- })),
180
- onSubmit: U.actions.submitPayment,
181
- onCancel: U.actions.closePayment,
182
- labels: L
183
- }),
184
- U.actions.actionDialog && /* @__PURE__ */ C(c, {
185
- open: !!U.actions.actionTarget,
186
- onOpenChange: (e) => {
187
- e || U.actions.closeAction();
188
- },
189
- title: U.actions.actionDialog.title,
190
- description: U.actions.actionDialog.description,
191
- confirmLabel: U.actions.actionDialog.confirmLabel,
192
- destructive: U.actions.actionDialog.destructive,
193
- error: U.actions.actionError,
194
- inProgress: U.actions.actionInProgress,
195
- onConfirm: U.actions.confirmAction,
196
- onCancel: U.actions.closeAction,
197
- labels: V
198
- }),
199
- /* @__PURE__ */ C(r, {
200
- open: U.form.counterpartView === "create",
201
- onOpenChange: (e) => {
202
- e || U.form.counterpartForm.close();
203
- },
204
- mode: "create",
205
- values: U.form.counterpartForm.values,
206
- errors: U.form.counterpartForm.errors,
207
- stateOptions: U.form.stateOptions,
208
- inProgress: U.form.counterpartForm.isSubmitting,
209
- onChange: (e) => U.form.counterpartForm.setValues((t) => ({
210
- ...t,
211
- ...e
212
- })),
213
- onAddressChange: (e) => U.form.counterpartForm.setValues((t) => ({
214
- ...t,
215
- address: {
216
- ...t.address,
217
- ...e
218
- }
219
- })),
220
- onSubmit: U.form.counterpartForm.submit,
221
- onCancel: U.form.counterpartForm.close,
222
- labels: n
223
- }),
224
- /* @__PURE__ */ C(g, {
225
- open: W,
226
- onClose: () => G(!1),
227
- managerLabels: j,
228
- deleteLabels: A,
229
- messageLabels: R
230
- })
231
- ] });
3
+ var n = 1e4;
4
+ function r({ lineItems: n, currency: r, taxRate: i }) {
5
+ let a = i ? i / 100 : 0, o = 0, s = 0;
6
+ for (let i of n) {
7
+ let n = Math.round(t(i.price, r) * e(i.quantity));
8
+ i.taxable ? o += n : s += n;
9
+ }
10
+ return {
11
+ taxableItemsSubtotal: o,
12
+ nonTaxableItemsSubtotal: s,
13
+ subtotal: o + s,
14
+ rate: a
15
+ };
232
16
  }
233
- function E({ baseUrl: e, widgetToken: t, organizationId: r, configClient: i, gatewayRouting: a, linkComponent: s, implementation: c, uiFramework: l, errorFallback: u, onError: d, analytics: f, disclosuresAcceptance: p, providerLabels: m, ...h }) {
234
- return /* @__PURE__ */ C(n, {
235
- widgetName: o,
236
- baseUrl: e,
237
- widgetToken: t,
238
- organizationId: r,
239
- configClient: i,
240
- gatewayRouting: a,
241
- linkComponent: s,
242
- implementation: c,
243
- uiFramework: l,
244
- errorFallback: u,
245
- onError: d,
246
- analytics: f,
247
- disclosuresAcceptance: p,
248
- providerLabels: m,
249
- children: /* @__PURE__ */ C(T, { ...h })
250
- });
17
+ function i({ discount: e, subtotal: t }) {
18
+ if (!e) return 0;
19
+ let r = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / n));
20
+ return Math.min(Math.max(r, 0), t);
21
+ }
22
+ function a({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
23
+ let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
24
+ return {
25
+ taxableSubtotal: e - i,
26
+ nonTaxableSubtotal: t - (n - i)
27
+ };
28
+ }
29
+ function o({ lineItems: e, currency: t, taxRate: n, discount: o }) {
30
+ let s = r({
31
+ lineItems: e,
32
+ currency: t,
33
+ taxRate: n
34
+ }), c = i({
35
+ discount: o,
36
+ subtotal: s.subtotal
37
+ }), { taxableSubtotal: l, nonTaxableSubtotal: u } = a({
38
+ ...s,
39
+ discountAmount: c
40
+ }), d = s.rate ? Math.round(l * s.rate) : 0, f = s.subtotal - c;
41
+ return {
42
+ ...s,
43
+ discountAmount: c,
44
+ discountedSubtotal: f,
45
+ taxableSubtotal: l,
46
+ nonTaxableSubtotal: u,
47
+ totalTaxes: d,
48
+ total: f + d
49
+ };
251
50
  }
252
51
  //#endregion
253
- export { E as ReceivablesWidget, E as default };
52
+ export { a as allocateDiscount, o as calculateInvoiceTotals, r as calculateItemsSubtotals, i as resolveDiscountAmount };