@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
@@ -1,195 +1,111 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { extractApiErrorMessage as e } from "../../../shared/util/dist/lib/apiErrors.js";
6
- import { defaultPaymentValues as t, defaultSendValues as n, fromMajorUnits as r, hasPaymentErrors as i, hasSendErrors as a, splitEmailList as o, validatePaymentValues as s, validateSendValues as c } from "./index8.js";
7
- import { useSendReceivableEmailMutation as l } from "../../data-access/dist/index5.js";
8
- import { useAcceptReceivableMutation as ee, useCancelReceivableMutation as te, useCloneReceivableMutation as u, useDeclineReceivableMutation as d, useDeleteReceivableMutation as f, useIssueReceivableMutation as p } from "../../data-access/dist/index6.js";
9
- import { useMarkReceivablePaidMutation as m, useMarkReceivablePartiallyPaidMutation as h, useMarkReceivableUncollectibleMutation as g } from "../../data-access/dist/index8.js";
10
- import "../../data-access/dist/index.js";
11
- import { useCallback as _, useState as v } from "react";
12
1
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js
13
- function y({ selectedReceivable: y, messages: x, onCreated: S, onDeleted: C }) {
14
- let w = p(), T = te(), E = u(), D = ee(), O = d(), k = f(), A = l(), j = m(), M = h(), N = g(), [P, F] = v(), [I, L] = v(), [R, z] = v(), [B, V] = v(() => n(void 0, x)), [H, U] = v({}), [W, G] = v(), [K, q] = v(() => t()), [J, Y] = v({}), X = _((e, r, i) => {
15
- let a = "documentLabel" in r ? r.documentLabel : r.title, o = {
16
- id: r.id,
17
- type: r.type,
18
- title: a,
19
- action: e
20
- }, s = i === void 0 ? y : i ?? void 0;
21
- if (e === "send") {
22
- z(o), V(n(s, x)), U({});
23
- return;
24
- }
25
- if (e === "recordPayment") {
26
- G({
27
- ...o,
28
- currency: s?.currency
29
- }), q(t()), Y({});
30
- return;
31
- }
32
- L(void 0), F(o);
33
- }, [x, y]), Z = _(() => {
34
- F(void 0), L(void 0);
35
- }, []), Q = _(() => {
36
- z(void 0), U({});
37
- }, []), $ = _(() => {
38
- G(void 0), Y({});
39
- }, []), ne = _(async () => {
40
- if (!P) return;
41
- let t = { receivable_id: P.id };
42
- try {
43
- if (P.action === "issue") await w.mutateAsync({ path: t });
44
- else if (P.action === "cancel") await T.mutateAsync({ path: t });
45
- else if (P.action === "clone") {
46
- let e = await E.mutateAsync({ path: t });
47
- e?.id && S?.(e.id, e.type);
48
- } else P.action === "accept" ? await D.mutateAsync({ path: t }) : P.action === "decline" ? await O.mutateAsync({ path: t }) : P.action === "delete" ? (await k.mutateAsync({ path: t }), C?.(P.id)) : P.action === "markPaid" ? await j.mutateAsync({
49
- path: t,
50
- body: { paid_at: (/* @__PURE__ */ new Date()).toISOString() }
51
- }) : P.action === "markUncollectible" && await N.mutateAsync({ path: t });
52
- F(void 0), L(void 0);
53
- } catch (t) {
54
- L(e(t) ?? x.genericError);
55
- }
56
- }, [
57
- D,
58
- P,
59
- T,
60
- E,
61
- O,
62
- k,
63
- w,
64
- j,
65
- x.genericError,
66
- S,
67
- C,
68
- N
69
- ]), re = _(async () => {
70
- if (!R) return;
71
- let t = c(B, x);
72
- if (a(t)) {
73
- U(t);
74
- return;
75
- }
76
- try {
77
- await A.mutateAsync({
78
- path: { receivable_id: R.id },
79
- body: {
80
- body_text: B.body,
81
- subject_text: B.subject,
82
- recipients: {
83
- to: o(B.to),
84
- cc: o(B.cc),
85
- bcc: o(B.bcc)
86
- }
87
- }
88
- }), Q();
89
- } catch (t) {
90
- U({ form: e(t) ?? x.genericError });
91
- }
92
- }, [
93
- Q,
94
- x,
95
- A,
96
- R,
97
- B
98
- ]), ie = _(async () => {
99
- if (!W) return;
100
- let t = s(K, x, W.currency);
101
- if (i(t)) {
102
- Y(t);
103
- return;
104
- }
105
- try {
106
- let e = { receivable_id: W.id }, t = K.paidAt ? new Date(K.paidAt).toISOString() : void 0;
107
- K.mode === "full" ? await j.mutateAsync({
108
- path: e,
109
- body: {
110
- comment: K.comment || void 0,
111
- paid_at: t
112
- }
113
- }) : await M.mutateAsync({
114
- path: e,
115
- body: {
116
- amount_paid: r(K.amountPaid, W.currency) ?? 0,
117
- comment: K.comment || void 0
118
- }
119
- }), $();
120
- } catch (t) {
121
- Y({ form: e(t) ?? x.genericError });
122
- }
123
- }, [
124
- $,
125
- j,
126
- x,
127
- M,
128
- W,
129
- K
130
- ]);
131
- return {
132
- actionTarget: P,
133
- actionDialog: P ? b(P.action, x) : void 0,
134
- actionError: I,
135
- actionInProgress: w.isPending || T.isPending || E.isPending || D.isPending || O.isPending || k.isPending || j.isPending || N.isPending,
136
- openAction: X,
137
- closeAction: Z,
138
- confirmAction: ne,
139
- sendOpen: !!R,
140
- sendValues: B,
141
- sendErrors: H,
142
- sendInProgress: A.isPending,
143
- setSendValues: V,
144
- closeSend: Q,
145
- submitSend: re,
146
- paymentOpen: !!W,
147
- paymentValues: K,
148
- paymentErrors: J,
149
- paymentInProgress: j.isPending || M.isPending,
150
- setPaymentValues: q,
151
- closePayment: $,
152
- submitPayment: ie
153
- };
154
- }
155
- function b(e, t) {
156
- return e === "issue" ? {
157
- title: t.issueTitle,
158
- description: t.issueDescription,
159
- confirmLabel: t.issueConfirm
160
- } : e === "accept" ? {
161
- title: t.acceptTitle,
162
- description: t.acceptDescription,
163
- confirmLabel: t.acceptConfirm
164
- } : e === "decline" ? {
165
- title: t.declineTitle,
166
- description: t.declineDescription,
167
- confirmLabel: t.declineConfirm,
168
- destructive: !0
169
- } : e === "cancel" ? {
170
- title: t.cancelTitle,
171
- description: t.cancelDescription,
172
- confirmLabel: t.cancelConfirm,
173
- destructive: !0
174
- } : e === "clone" ? {
175
- title: t.cloneTitle,
176
- description: t.cloneDescription,
177
- confirmLabel: t.cloneConfirm
178
- } : e === "delete" ? {
179
- title: t.deleteTitle,
180
- description: t.deleteDescription,
181
- confirmLabel: t.deleteConfirm,
182
- destructive: !0
183
- } : e === "markPaid" ? {
184
- title: t.markPaidTitle,
185
- description: t.markPaidDescription,
186
- confirmLabel: t.markPaidConfirm
187
- } : {
188
- title: t.markUncollectibleTitle,
189
- description: t.markUncollectibleDescription,
190
- confirmLabel: t.markUncollectibleConfirm,
191
- destructive: !0
192
- };
193
- }
2
+ var e = {
3
+ customerRequired: "Customer is required",
4
+ customerAddressRequired: "The selected customer needs a billing address before a receivable can be created.",
5
+ currencyRequired: "Currency is required",
6
+ lineItemNameTooLong: "Product name must be 100 characters or less",
7
+ lineItemPriceTooHigh: "Price must be {maxAmount} or less",
8
+ sendToRequired: "Enter at least one recipient",
9
+ sendSubjectRequired: "Subject is required",
10
+ sendBodyRequired: "Message is required",
11
+ paymentAmountInvalid: "Amount paid must be greater than 0",
12
+ genericError: "Something went wrong. Please try again.",
13
+ lineItemsLoading: "Please wait for invoice details to finish loading.",
14
+ paymentTermsCustomDatePlaceholder: "Mon DD, YYYY",
15
+ bankAccountFallbackName: "Bank Account",
16
+ bankAccountPoweredBy: "Powered by {embeddedBankName}",
17
+ bankAccountLinked: "Linked account",
18
+ bankAccountHolderNameRequired: "Account holder name is required",
19
+ bankAccountHolderNameTooLong: "Account holder name must be 255 characters or less",
20
+ bankAccountNumberRequired: "Account number is required",
21
+ bankAccountNumberDigitsOnly: "Account number must contain only digits",
22
+ bankAccountNumberTooShort: "Account number must be at least 4 digits",
23
+ bankAccountNumberTooLong: "Account number must be at most 17 digits",
24
+ bankAccountRoutingNumberRequired: "Routing number is required",
25
+ bankAccountRoutingNumberInvalid: "Routing number must be 9 digits",
26
+ bankAccountNicknameTooLong: "Display name must be 200 characters or less",
27
+ bankAccountCreated: "Bank Account \"{name}\" has been created.",
28
+ bankAccountCreateFailed: "Failed to create Bank Account.",
29
+ untitledDocument: "Untitled document",
30
+ unknownCustomer: "Unknown customer",
31
+ notAvailable: "Not available",
32
+ invoiceType: "Invoice",
33
+ quoteType: "Quote",
34
+ creditNoteType: "Credit note",
35
+ summaryDocumentType: "Document type",
36
+ summaryDocumentNumber: "Document number",
37
+ summaryCustomer: "Customer",
38
+ summaryIssued: "Issued",
39
+ summaryDue: "Due",
40
+ summaryCreated: "Created",
41
+ summaryUpdated: "Updated",
42
+ summaryTotal: "Total",
43
+ summaryAmountDue: "Amount due",
44
+ activityStatusChanged: "Status changed",
45
+ activityReceivableCreated: "Receivable created",
46
+ activityReceivableUpdated: "Receivable updated",
47
+ activityPaymentReceived: "Payment received",
48
+ activityMailSent: "Email sent",
49
+ activityUnknown: "Activity",
50
+ recipientsNone: "No recipients",
51
+ sendSubjectDefault: "Your receivable document",
52
+ sendBodyDefault: "Please find the receivable document attached.",
53
+ issueTitle: "Issue receivable?",
54
+ issueDescription: "Issuing locks the document and makes it ready to send to the customer.",
55
+ issueConfirm: "Issue",
56
+ acceptTitle: "Accept quote?",
57
+ acceptDescription: "This marks the quote as accepted.",
58
+ acceptConfirm: "Accept",
59
+ declineTitle: "Decline quote?",
60
+ declineDescription: "This marks the quote as declined.",
61
+ declineConfirm: "Decline",
62
+ cancelTitle: "Cancel receivable?",
63
+ cancelDescription: "This cancels the document. You cannot undo this action.",
64
+ cancelConfirm: "Cancel document",
65
+ cloneTitle: "Clone receivable?",
66
+ cloneDescription: "This creates a new draft based on the selected document.",
67
+ cloneConfirm: "Clone",
68
+ deleteTitle: "Delete draft?",
69
+ deleteDescription: "This permanently deletes the draft document. You cannot undo this action.",
70
+ deleteConfirm: "Delete",
71
+ markPaidTitle: "Mark invoice as paid?",
72
+ markPaidDescription: "This records the invoice as fully paid.",
73
+ markPaidConfirm: "Mark paid",
74
+ markUncollectibleTitle: "Mark invoice uncollectible?",
75
+ markUncollectibleDescription: "This records the invoice as uncollectible. You cannot undo this action.",
76
+ markUncollectibleConfirm: "Mark uncollectible",
77
+ attachmentsEmailCaption: "Selected files will be attached to the invoice email sent to the customer.",
78
+ attachmentsRecurringEmailCaption: "Selected files will be attached to every invoice email in the recurring series.",
79
+ attachmentIncludeInEmail: "Include in email:",
80
+ attachmentRemove: "Remove",
81
+ attachmentUploading: "Uploading…",
82
+ attachmentUploadFailed: "Upload failed. Please try again.",
83
+ attachmentTooLarge: "File too large (max 3 MB)",
84
+ attachmentUnsupportedType: "File type not supported. Use PDF, DOC, JPG or PNG",
85
+ attachmentsCountLimit: "You can attach up to 10 files.",
86
+ attachmentIncludedInEmail: "Included in email",
87
+ attachmentNotIncludedInEmail: "Not included in email",
88
+ reminderUnitDay: "day",
89
+ reminderUnitDays: "days",
90
+ reminderNameDay: "{days} day",
91
+ reminderNameDays: "{days} days",
92
+ reminderNameAnd: "and",
93
+ reminderBeforeDueCaption: "Add schedule",
94
+ reminderOverdueCaption: "Add schedule (Specify up to 3 terms)",
95
+ reminderOverdueEmptyCaption: "Send up to three reminders",
96
+ reminderOverdueTermLabel: "Reminder {index}, days after due date",
97
+ reminderDaysRange: "Enter a number of days between {min} and {max}.",
98
+ reminderPastDueWarning: "This reminder would be sent after the due date has already passed.",
99
+ reminderAdded: "Reminder has been added",
100
+ reminderBeforeDueSubject: "Payment is due soon",
101
+ reminderBeforeDueBody: "Payment is due on {dueDate}.",
102
+ reminderBeforeDueBodyNoDate: "Payment is due soon.",
103
+ reminderOverdueSubject: "Payment is overdue",
104
+ reminderOverdueBody: "Payment was due on {dueDate}.",
105
+ reminderOverdueBodyNoDate: "Payment is overdue.",
106
+ issueRemindersDisabled: "Payment reminders are disabled for this customer. Please enable them in the customer details or turn them off.",
107
+ issueRemindersNoEmail: "No email address is added for the selected customer. Please add it to the customer details or turn off the reminders.",
108
+ issueRemindersDisabledNoEmail: "Reminders are disabled for this customer, and no email address has been added for it. Please update the details or turn off reminders."
109
+ };
194
110
  //#endregion
195
- export { y as useReceivableActions };
111
+ export { e as RECEIVABLE_MESSAGE_LABELS_EN };
@@ -1,42 +1,159 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { buildReceivableDetailsView as e } from "./index8.js";
6
- import { useReceivableHistoryQuery as t, useReceivableMailsQuery as n, useReceivablePdfLinkQuery as r, useReceivableQuery as i } from "../../data-access/dist/index9.js";
7
- import "../../data-access/dist/index.js";
8
- import { useMemo as a } from "react";
1
+ import { hasAnyScope as e } from "../../../shared/data-access/dist/lib/hasAnyScope.js";
2
+ import { Scope as t } from "../../../shared/data-access/dist/lib/scopes.js";
3
+ import "../../../shared/data-access/dist/index.js";
4
+ import { getCounterpartEmail as n } from "../../../shared/counterpart-management/feature/dist/lib/helpers.js";
5
+ import "../../../shared/counterpart-management/feature/dist/index.js";
6
+ import { RECEIVABLE_PAYMENT_TERMS_RECEIPT_DUE as r } from "../../ui/dist/index9.js";
7
+ import "../../ui/dist/index.js";
9
8
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js
10
- function o({ selectedReceivableId: o, enabled: s = !0, messages: c }) {
11
- let l = i(o, { enabled: s }), u = t(o, {
12
- enabled: s,
13
- limit: 25,
14
- sort: "timestamp",
15
- order: "desc"
16
- }), d = n(o, {
17
- enabled: s,
18
- limit: 10,
19
- sort: "created_at",
20
- order: "desc"
21
- }), f = r(o, { enabled: s && !!l.data }), p = a(() => e({
22
- receivable: l.data,
23
- history: u.data?.data ?? [],
24
- mails: d.data?.data ?? [],
25
- pdfUrl: f.data?.file_url || f.data?.original_file_url || void 0,
26
- messages: c
27
- }), [
28
- l.data,
29
- u.data?.data,
30
- d.data?.data,
31
- c,
32
- f.data
33
- ]);
9
+ var i = 1e4, a = 864e5;
10
+ function o(n) {
11
+ return e(new Set(n ?? []), [t.InvoiceWriteOrg]);
12
+ }
13
+ function s(e) {
14
+ return e.replace(/\D/g, "");
15
+ }
16
+ var c = (e) => e.length > 0 ? Math.min(...e) : Infinity;
17
+ function l(e) {
18
+ return c([
19
+ e.term_1_reminder,
20
+ e.term_2_reminder,
21
+ e.term_final_reminder
22
+ ].flatMap((e) => e ? [e.days_before] : []));
23
+ }
24
+ function u(e) {
25
+ return c((e.terms ?? []).map((e) => e.days_after));
26
+ }
27
+ function d(e) {
28
+ return [...e ?? []].sort((e, t) => l(e) - l(t)).map(({ id: e, name: t }) => ({
29
+ value: e,
30
+ label: t
31
+ }));
32
+ }
33
+ function f(e) {
34
+ return [...e ?? []].sort((e, t) => u(e) - u(t)).map(({ id: e, name: t }) => ({
35
+ value: e,
36
+ label: t
37
+ }));
38
+ }
39
+ function p(e) {
40
+ let [t, n, r] = e.split("-").map(Number);
41
+ if (t && n && r) return new Date(t, n - 1, r);
42
+ }
43
+ function m(e, t) {
44
+ return Math.round((Date.UTC(t.getFullYear(), t.getMonth(), t.getDate()) - Date.UTC(e.getFullYear(), e.getMonth(), e.getDate())) / a);
45
+ }
46
+ function h({ paymentTermsId: e, paymentTermsCustomDate: t }) {
47
+ return e === "custom" ? p(t) : void 0;
48
+ }
49
+ function g({ paymentTermsId: e, paymentTermsCustomDate: t, paymentTerms: n, today: r }) {
50
+ if (e === "custom") return p(t);
51
+ let i = e === "receipt_due" ? 0 : n?.find((t) => t.id === e)?.term_final.number_of_days;
52
+ if (i !== void 0) return new Date(r.getFullYear(), r.getMonth(), r.getDate() + i);
53
+ }
54
+ function _(e) {
55
+ return new Intl.DateTimeFormat("en-US", {
56
+ month: "short",
57
+ day: "numeric",
58
+ year: "numeric"
59
+ }).format(e);
60
+ }
61
+ function v(e, t) {
62
+ return (e === 1 ? t.reminderNameDay : t.reminderNameDays).replace("{days}", String(e));
63
+ }
64
+ function y(e, t) {
65
+ return Number(e) === 1 ? t.reminderUnitDay : t.reminderUnitDays;
66
+ }
67
+ function b(e) {
68
+ let t = Number(e);
69
+ return e !== "" && t >= 1 && t <= 1e4;
70
+ }
71
+ function x(e) {
72
+ return e.every((e) => Number(e) >= 1);
73
+ }
74
+ function S({ daysBefore: e, dueDate: t, messages: n }) {
75
+ return {
76
+ name: v(e, n),
77
+ term_final_reminder: {
78
+ days_before: e,
79
+ subject: n.reminderBeforeDueSubject,
80
+ body: t ? n.reminderBeforeDueBody.replace("{dueDate}", _(t)) : n.reminderBeforeDueBodyNoDate
81
+ }
82
+ };
83
+ }
84
+ function C({ terms: e, dueDate: t, messages: n }) {
85
+ let r = e.map(Number).sort((e, t) => e - t), i = r.map((e) => v(e, n)), a = i.length === 1 ? i[0] : `${i.slice(0, -1).join(", ")} ${n.reminderNameAnd} ${i[i.length - 1]}`, o = t ? n.reminderOverdueBody.replace("{dueDate}", _(t)) : n.reminderOverdueBodyNoDate;
86
+ return {
87
+ name: a,
88
+ terms: r.map((e) => ({
89
+ days_after: e,
90
+ subject: n.reminderOverdueSubject,
91
+ body: o
92
+ }))
93
+ };
94
+ }
95
+ function w(e) {
96
+ return !!(e.paymentTermsId || e.paymentReminderId || e.overdueReminderId);
97
+ }
98
+ function T({ showReminders: e, paymentTermsId: t, paymentTermsCustomDate: n, paymentReminderId: a, overdueReminderId: o, paymentReminders: s, overdueReminders: c, canCreate: l, disabled: u, beforeDueInput: p, overdueTerms: g, isCreatingPaymentReminder: _, isCreatingOverdueReminder: v, today: S, messages: C }) {
99
+ let w = {
100
+ checked: e,
101
+ toggleDisabled: !t
102
+ };
103
+ if (!e) return w;
104
+ let T = p !== "", E = b(p), D = h({
105
+ paymentTermsId: t,
106
+ paymentTermsCustomDate: n
107
+ }), O = D ? m(S, D) : void 0, k = s?.find((e) => e.id === a), A = k ? [
108
+ k.term_1_reminder,
109
+ k.term_2_reminder,
110
+ k.term_final_reminder
111
+ ].flatMap((e) => e ? [e.days_before] : []) : [], j = O !== void 0 && (T && Number(p) > O || A.some((e) => e > O)), M = t === r, N = d(s), P = f(c);
34
112
  return {
35
- receivable: l.data,
36
- detailsView: p,
37
- isLoading: l.isLoading || u.isLoading || d.isLoading || f.isLoading,
38
- isError: l.isError
113
+ ...w,
114
+ cards: {
115
+ beforeDue: M ? void 0 : {
116
+ options: N,
117
+ selectedId: a,
118
+ create: l ? {
119
+ value: p,
120
+ unitLabel: y(p, C),
121
+ caption: N.length > 0 ? C.reminderBeforeDueCaption : void 0,
122
+ error: T && !E ? C.reminderDaysRange.replace("{min}", "1").replace("{max}", String(i)) : void 0,
123
+ inputDisabled: u || _,
124
+ saveDisabled: !E || _,
125
+ isSaving: _
126
+ } : void 0,
127
+ warning: j ? C.reminderPastDueWarning : void 0
128
+ },
129
+ overdue: {
130
+ options: P,
131
+ selectedId: o,
132
+ create: l ? {
133
+ caption: P.length > 0 ? C.reminderOverdueCaption : C.reminderOverdueEmptyCaption,
134
+ terms: g.map((e, t) => ({
135
+ value: e,
136
+ unitLabel: y(e, C),
137
+ ariaLabel: C.reminderOverdueTermLabel.replace("{index}", String(t + 1)),
138
+ showPlaceholder: g.length === 1
139
+ })),
140
+ showAddTerm: g.length < 3,
141
+ addTermDisabled: u || v || !g[g.length - 1],
142
+ inputsDisabled: u || v,
143
+ clearDisabled: u || v,
144
+ saveDisabled: u || v || !x(g),
145
+ isSaving: v
146
+ } : void 0
147
+ }
148
+ }
39
149
  };
40
150
  }
151
+ function E(e) {
152
+ return e.type === "invoice" && !!(e.payment_reminder_id || e.overdue_reminder_id);
153
+ }
154
+ function D(e, t) {
155
+ let r = !!(e && n(e)), i = !!e?.reminders_enabled;
156
+ if (!(i && r)) return r ? t.issueRemindersDisabled : i ? t.issueRemindersNoEmail : t.issueRemindersDisabledNoEmail;
157
+ }
41
158
  //#endregion
42
- export { o as useReceivableDetails };
159
+ export { i as MAX_REMINDER_DAYS, x as areOverdueTermsValid, f as buildOverdueReminderOptions, C as buildOverdueReminderPayload, d as buildPaymentReminderOptions, S as buildPaymentReminderPayload, T as buildRemindersView, o as canCreateReminders, h as getCustomDueDate, g as getImpliedDueDate, D as getIssueReminderBlocker, E as hasSelectedReminder, b as isBeforeDueDaysValid, s as sanitizeReminderDays, w as shouldShowRemindersInitially };