@tesouro/embedded-components-react 0.7.66 → 0.7.68

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.
@@ -5,43 +5,44 @@
5
5
  import { toast as e } from "../../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
6
  import { getStateOptions as t } from "../../../../../shared/util/dist/lib/usStates.js";
7
7
  import { extractApiErrorMessage as n } from "../../../../../shared/util/dist/lib/apiErrors.js";
8
+ import { parseApiValidationErrors as r } from "../../../../../shared/util/dist/lib/apiValidationErrors.js";
8
9
  import "../../../../../shared/ui/dist/index.js";
9
- import { COUNTERPART_MESSAGE_LABELS_EN as r } from "../../../../../shared/counterpart-management/feature/dist/lib/labels.js";
10
- import { getCounterpartEmail as i } from "../../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
10
+ import { COUNTERPART_MESSAGE_LABELS_EN as i } from "../../../../../shared/counterpart-management/feature/dist/lib/labels.js";
11
+ import { getCounterpartEmail as ee } from "../../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
11
12
  import { useCounterpartQuery as a, useCreateCounterpartMutation as o } from "../../../../../shared/counterpart-management/data-access/dist/index3.js";
12
13
  import { useCounterpartAddressesQuery as s } from "../../../../../shared/counterpart-management/data-access/dist/index5.js";
13
- import { useCounterpartForm as c } from "../../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
14
+ import { useCounterpartForm as te } from "../../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
14
15
  import "../../../../../shared/counterpart-management/feature/dist/index.js";
15
16
  import "../../../../ui/dist/index20.js";
16
17
  import "../../../../ui/dist/index.js";
17
- import { INLINE_CUSTOMER_TYPE as ee, buildInlineCustomerPayload as te, seedCustomerFormValues as ne } from "./customer.js";
18
- import { useCreateReceivableMutation as l, useIssueReceivableMutation as u, useUpdateReceivableMutation as re } from "../../../../data-access/dist/index11.js";
19
- import { useCreateRecurrenceMutation as ie, useRecurrenceQuery as ae, useUpdateRecurrenceMutation as oe } from "../../../../data-access/dist/index16.js";
18
+ import { INLINE_CUSTOMER_TYPE as ne, buildInlineCustomerPayload as re, seedCustomerFormValues as ie } from "./customer.js";
19
+ import { useCreateReceivableMutation as c, useIssueReceivableMutation as l, useUpdateReceivableMutation as ae } from "../../../../data-access/dist/index11.js";
20
+ import { useCreateRecurrenceMutation as oe, useRecurrenceQuery as se, useUpdateRecurrenceMutation as ce } from "../../../../data-access/dist/index16.js";
20
21
  import "../../../../data-access/dist/index.js";
21
- import { buildLineItemControls as se, commitLineItemField as ce, commitTaxRateInput as le, convertPriceInput as ue, createLineItem as de, getCurrencySymbol as fe, lineItemFromProduct as pe, reconcileLineItemIds as me, reconcileMeasureUnits as he, sanitizeLineItemPatch as ge, sanitizeTaxRateInput as _e, stepLineItemQuantity as ve, stripBlankLineItems as ye, summarizeLineItemErrors as be, toSheetLineItem as xe, validateLineItems as Se } from "./lineItems.js";
22
- import { buildReceivableAttachmentsView as Ce } from "./attachments.js";
23
- import { useMeasureUnitsQuery as we } from "../../../../../shared/product-catalog/data-access/dist/index9.js";
24
- import { useMeasureUnits as Te } from "../../../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
22
+ import { buildLineItemControls as le, commitLineItemField as ue, commitTaxRateInput as de, convertPriceInput as fe, createLineItem as pe, getCurrencySymbol as me, lineItemFromProduct as he, reconcileLineItemIds as ge, reconcileMeasureUnits as _e, sanitizeLineItemPatch as ve, sanitizeTaxRateInput as ye, stepLineItemQuantity as be, stripBlankLineItems as xe, summarizeLineItemErrors as Se, toSheetLineItem as Ce, validateLineItems as we } from "./lineItems.js";
23
+ import { buildReceivableAttachmentsView as Te } from "./attachments.js";
24
+ import { useMeasureUnitsQuery as Ee } from "../../../../../shared/product-catalog/data-access/dist/index9.js";
25
+ import { useMeasureUnits as De } from "../../../../../shared/product-catalog/feature/dist/lib/useMeasureUnits.js";
25
26
  import "../../../../../shared/product-catalog/feature/dist/index.js";
26
- import { getInlineItems as Ee } from "./actionsModal.js";
27
- import { buildCreateRecurrencePayload as De, buildUpdateRecurrencePayload as Oe, clearRecurrenceRecipients as d, countIssuedIterations as ke, isRecurring as f, recurrenceToFormFields as Ae, validateRecurrence as je, willRecurrenceIssue as Me } from "./recurrence.js";
28
- import { convertDiscountInput as Ne, decorateDiscountInput as Pe, discountInputToMinorUnits as Fe, sanitizeDiscountInput as Ie } from "./discount.js";
29
- import { buildFormTotalsView as Le, calculateFormTotals as Re, validateDiscount as ze, validateInvoiceTotals as Be } from "./totals.js";
30
- import { createEmptyReceivableFormValues as Ve, hasReceivableFormErrors as He, receivableFormValuesToCreatePayload as Ue, receivableFormValuesToLineItemChanges as We, receivableFormValuesToUpdatePayload as Ge, receivableToFormValues as Ke, resolveCounterpartAddresses as qe, submittedLineItemRows as Je, validateReceivableForm as Ye } from "./helpers.js";
31
- import { getIssueReminderBlocker as Xe, shouldShowRemindersInitially as Ze } from "./reminders.js";
32
- import { useReceivableIssuePreflight as Qe } from "./useReceivableIssuePreflight.js";
33
- import { UNSUBMITTED_PAYLOAD_VARIANTS as $e, apiValidationErrorsToFormErrors as et, getApiErrorMessage as tt, parseApiValidationErrors as nt } from "./apiValidationErrors.js";
34
- import { useReceivableAttachmentUploads as rt } from "./useReceivableAttachmentUploads.js";
35
- import { useReceivablePaymentTerms as it } from "./useReceivablePaymentTerms.js";
36
- import { useReceivableRecurrence as at } from "./useReceivableRecurrence.js";
37
- import { useReceivableBankAccount as ot } from "./useReceivableBankAccount.js";
38
- import { useReceivableReminders as st } from "./useReceivableReminders.js";
39
- import { useReceivablePreview as ct } from "./useReceivablePreview.js";
40
- import { hasUnsavedChanges as lt } from "./unsavedChanges.js";
41
- import { useCallback as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
27
+ import { getInlineItems as Oe } from "./actionsModal.js";
28
+ import { buildCreateRecurrencePayload as ke, buildUpdateRecurrencePayload as Ae, clearRecurrenceRecipients as u, countIssuedIterations as je, isRecurring as d, recurrenceToFormFields as Me, validateRecurrence as Ne, willRecurrenceIssue as Pe } from "./recurrence.js";
29
+ import { convertDiscountInput as Fe, decorateDiscountInput as Ie, discountInputToMinorUnits as Le, sanitizeDiscountInput as Re } from "./discount.js";
30
+ import { buildFormTotalsView as ze, calculateFormTotals as Be, validateDiscount as Ve, validateInvoiceTotals as He } from "./totals.js";
31
+ import { createEmptyReceivableFormValues as Ue, hasReceivableFormErrors as We, receivableFormValuesToCreatePayload as Ge, receivableFormValuesToLineItemChanges as Ke, receivableFormValuesToUpdatePayload as qe, receivableToFormValues as Je, resolveCounterpartAddresses as Ye, submittedLineItemRows as Xe, validateReceivableForm as Ze } from "./helpers.js";
32
+ import { getIssueReminderBlocker as Qe, shouldShowRemindersInitially as $e } from "./reminders.js";
33
+ import { useReceivableIssuePreflight as et } from "./useReceivableIssuePreflight.js";
34
+ import { UNSUBMITTED_PAYLOAD_VARIANTS as tt, apiValidationErrorsToFormErrors as nt, getApiErrorMessage as rt } from "./apiValidationErrors.js";
35
+ import { useReceivableAttachmentUploads as it } from "./useReceivableAttachmentUploads.js";
36
+ import { useReceivablePaymentTerms as at } from "./useReceivablePaymentTerms.js";
37
+ import { useReceivableRecurrence as ot } from "./useReceivableRecurrence.js";
38
+ import { useReceivableBankAccount as st } from "./useReceivableBankAccount.js";
39
+ import { useReceivableReminders as ct } from "./useReceivableReminders.js";
40
+ import { useReceivablePreview as lt } from "./useReceivablePreview.js";
41
+ import { hasUnsavedChanges as ut } from "./unsavedChanges.js";
42
+ import { useCallback as f, useEffect as p, useMemo as m, useRef as h, useState as g } from "react";
42
43
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivableForm.js
43
- function ut(e, t) {
44
- return t === e.customerId ? e : d({
44
+ function dt(e, t) {
45
+ return t === e.customerId ? e : u({
45
46
  ...e,
46
47
  customerId: t,
47
48
  billingAddressId: "",
@@ -52,7 +53,7 @@ function ut(e, t) {
52
53
  } : {}
53
54
  });
54
55
  }
55
- function dt(e, t) {
56
+ function ft(e, t) {
56
57
  return {
57
58
  ...e,
58
59
  customerId: t,
@@ -60,60 +61,60 @@ function dt(e, t) {
60
61
  customerEmail: ""
61
62
  };
62
63
  }
63
- function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, canCreateCustomer: v = !0, onCreated: mt, onUpdated: ht }) {
64
- let gt = l(), _t = re(), vt = ie(), yt = oe(), bt = u(), xt = o(), y = g("draft"), St = g(!1), [Ct, wt] = _(), b = g(!1), x = g(!1), Tt = g(null), S = g(void 0), C = g([]), Et = g(""), [w, T] = _(!1), [E, Dt] = _("create"), [Ot, kt] = _(), [At, jt] = _(), [D, O] = _(() => Ve()), k = g(D), [Mt, A] = _(!1), [Nt, j] = _({}), [Pt, Ft] = _("none"), It = Te(), M = we(), N = M.data?.data, { unitNamesById: P } = It, [Lt, Rt] = _(), [F, zt] = _(!1), Bt = g(!1), I = g(!1), L = g(!1), R = g({
64
+ function pt({ messages: u, counterpartMessageLabels: pt, embeddedBankName: mt, canCreateCustomer: _ = !0, onCreated: ht, onUpdated: gt }) {
65
+ let _t = c(), vt = ae(), yt = oe(), bt = ce(), xt = l(), St = o(), v = h("draft"), Ct = h(!1), [wt, Tt] = g(), y = h(!1), b = h(!1), Et = h(null), x = h(void 0), S = h([]), Dt = h(""), [C, w] = g(!1), [T, Ot] = g("create"), [kt, At] = g(), [jt, Mt] = g(), [E, D] = g(() => Ue()), O = h(E), [Nt, k] = g(!1), [Pt, A] = g({}), [Ft, It] = g("none"), Lt = De(), j = Ee(), M = j.data?.data, { unitNamesById: N } = Lt, [Rt, zt] = g(), [P, Bt] = g(!1), Vt = h(!1), F = h(!1), I = h(!1), L = h({
65
66
  lines: !1,
66
67
  discount: !1
67
- }), [Vt, z] = _(!1), [Ht, Ut] = _(!1), Wt = h(() => t(), []), Gt = h(() => ({
68
- ...r,
69
- ...ft
70
- }), [ft]), Kt = s(D.customerId), qt = a(D.customerId || void 0), Jt = Kt.data?.data?.[0], { billingAddressId: Yt, billingAddress: Xt, shippingAddressId: Zt } = qe({
71
- values: D,
72
- counterpart: qt.data,
73
- addresses: Kt.data?.data
74
- }), B = !!D.customerId && (Kt.isLoading || qt.isLoading), V = Qe({
75
- counterpartId: D.customerId,
76
- billingAddressId: Yt,
77
- billingCountry: Xt?.country,
78
- inlineCustomerType: v && !D.customerId && D.customerName.trim() ? ee : void 0,
79
- isAddressesLoading: B
80
- }), Qt = V.isLoading || B, $t = p((e) => {
81
- O((t) => ({
68
+ }), [Ht, R] = g(!1), [Ut, Wt] = g(!1), Gt = m(() => t(), []), Kt = m(() => ({
69
+ ...i,
70
+ ...pt
71
+ }), [pt]), qt = s(E.customerId), Jt = a(E.customerId || void 0), Yt = qt.data?.data?.[0], { billingAddressId: Xt, billingAddress: Zt, shippingAddressId: Qt } = Ye({
72
+ values: E,
73
+ counterpart: Jt.data,
74
+ addresses: qt.data?.data
75
+ }), z = !!E.customerId && (qt.isLoading || Jt.isLoading), B = et({
76
+ counterpartId: E.customerId,
77
+ billingAddressId: Xt,
78
+ billingCountry: Zt?.country,
79
+ inlineCustomerType: _ && !E.customerId && E.customerName.trim() ? ne : void 0,
80
+ isAddressesLoading: z
81
+ }), $t = B.isLoading || z, en = f((e) => {
82
+ D((t) => ({
82
83
  ...t,
83
84
  attachments: e(t.attachments)
84
85
  }));
85
- }, []), H = rt({
86
- attachments: D.attachments,
87
- setAttachments: $t,
88
- receivableId: Ot
89
- }), { reset: U, discardUploads: en, commitRemovals: tn } = H, nn = D.type === "invoice" ? Ce({
90
- attachments: D.attachments,
91
- pendingUploads: H.pendingUploads,
92
- isCountLimitReached: H.isCountLimitReached,
93
- isRecurring: f(D),
94
- messages: d
95
- }) : void 0, rn = p((e) => {
96
- e && O((t) => ut(t, e));
97
- }, []), an = c({
98
- view: Pt,
99
- setView: Ft,
100
- selectedId: D.customerId || void 0,
101
- setSelectedId: rn,
102
- messages: Gt,
86
+ }, []), V = it({
87
+ attachments: E.attachments,
88
+ setAttachments: en,
89
+ receivableId: kt
90
+ }), { reset: H, discardUploads: tn, commitRemovals: nn } = V, rn = E.type === "invoice" ? Te({
91
+ attachments: E.attachments,
92
+ pendingUploads: V.pendingUploads,
93
+ isCountLimitReached: V.isCountLimitReached,
94
+ isRecurring: d(E),
95
+ messages: u
96
+ }) : void 0, an = f((e) => {
97
+ e && D((t) => dt(t, e));
98
+ }, []), on = te({
99
+ view: Ft,
100
+ setView: It,
101
+ selectedId: E.customerId || void 0,
102
+ setSelectedId: an,
103
+ messages: Kt,
103
104
  counterpartType: "customer",
104
105
  counterpart: void 0,
105
- primaryAddress: Jt
106
- }), { openCreate: on, setValues: sn } = an, cn = p(() => {
107
- on(), sn((e) => ne(e, {
108
- name: D.customerName,
109
- email: D.customerEmail
106
+ primaryAddress: Yt
107
+ }), { openCreate: sn, setValues: cn } = on, ln = f(() => {
108
+ sn(), cn((e) => ie(e, {
109
+ name: E.customerName,
110
+ email: E.customerEmail
110
111
  }));
111
112
  }, [
112
- on,
113
113
  sn,
114
- D.customerName,
115
- D.customerEmail
116
- ]), ln = p((e) => O((t) => {
114
+ cn,
115
+ E.customerName,
116
+ E.customerEmail
117
+ ]), un = f((e) => D((t) => {
117
118
  let n = e({
118
119
  paymentTermsId: t.paymentTermsId,
119
120
  paymentTermsCustomDate: t.paymentTermsCustomDate
@@ -123,314 +124,314 @@ function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, c
123
124
  ...n,
124
125
  ...n.paymentTermsId === "receipt_due" ? { paymentReminderId: "" } : {}
125
126
  };
126
- }), []), un = it({
127
- paymentTermsId: D.paymentTermsId,
128
- paymentTermsCustomDate: D.paymentTermsCustomDate,
129
- issueDate: D.issueDate,
130
- isRecurring: D.type === "invoice" && f(D),
131
- messages: d,
132
- onChange: ln
133
- }), dn = un.reset, fn = p((e, { automatic: t = !1 } = {}) => {
134
- t && (k.current = {
135
- ...k.current,
127
+ }), []), dn = at({
128
+ paymentTermsId: E.paymentTermsId,
129
+ paymentTermsCustomDate: E.paymentTermsCustomDate,
130
+ issueDate: E.issueDate,
131
+ isRecurring: E.type === "invoice" && d(E),
132
+ messages: u,
133
+ onChange: un
134
+ }), fn = dn.reset, pn = f((e, { automatic: t = !1 } = {}) => {
135
+ t && (O.current = {
136
+ ...O.current,
136
137
  ...e
137
- }), O((t) => ({
138
+ }), D((t) => ({
138
139
  ...t,
139
140
  ...e
140
141
  }));
141
- }, []), W = ot({
142
- open: w,
143
- bankAccountId: D.bankAccountId,
144
- bankAccountType: D.bankAccountType,
145
- embeddedBankName: pt,
146
- messages: d,
147
- onSelect: fn
148
- }), pn = W.reset, mn = ae(At), G = At ? mn.data : void 0, K = ke(G), hn = K > 0, q = !!At && mn.isLoading, J = g(void 0);
149
- m(() => {
150
- if (!G || J.current === G.id) return;
151
- J.current = G.id;
152
- let e = Ae(G);
153
- k.current = {
154
- ...k.current,
142
+ }, []), U = st({
143
+ open: C,
144
+ bankAccountId: E.bankAccountId,
145
+ bankAccountType: E.bankAccountType,
146
+ embeddedBankName: mt,
147
+ messages: u,
148
+ onSelect: pn
149
+ }), mn = U.reset, hn = se(jt), W = jt ? hn.data : void 0, G = je(W), gn = G > 0, K = !!jt && hn.isLoading, q = h(void 0);
150
+ p(() => {
151
+ if (!W || q.current === W.id) return;
152
+ q.current = W.id;
153
+ let e = Me(W);
154
+ O.current = {
155
+ ...O.current,
155
156
  ...e
156
- }, O((t) => ({
157
+ }, D((t) => ({
157
158
  ...t,
158
159
  ...e
159
160
  }));
160
- }, [G]);
161
- let gn = p((e) => O(e), []), _n = p((e) => j((t) => {
161
+ }, [W]);
162
+ let _n = f((e) => D(e), []), vn = f((e) => A((t) => {
162
163
  if (!e.some((e) => e in t)) return t;
163
164
  let n = { ...t };
164
165
  return e.forEach((e) => delete n[e]), n;
165
- }), []), vn = g([]), yn = p((e) => {
166
- if (!F) {
167
- _n(e);
166
+ }), []), yn = h([]), bn = f((e) => {
167
+ if (!P) {
168
+ vn(e);
168
169
  return;
169
170
  }
170
- vn.current.push(...e);
171
- }, [_n, F]);
172
- m(() => {
173
- let e = vn.current;
171
+ yn.current.push(...e);
172
+ }, [vn, P]);
173
+ p(() => {
174
+ let e = yn.current;
174
175
  if (!e.length) return;
175
- vn.current = [];
176
- let t = je({
177
- fields: D,
178
- issuedCount: K,
179
- messages: d
176
+ yn.current = [];
177
+ let t = Ne({
178
+ fields: E,
179
+ issuedCount: G,
180
+ messages: u
180
181
  });
181
- j((n) => {
182
+ A((n) => {
182
183
  let r = { ...n };
183
184
  return e.forEach((e) => {
184
185
  t[e] ? r[e] = t[e] : delete r[e];
185
186
  }), r;
186
187
  });
187
188
  }, [
188
- K,
189
- d,
190
- D
189
+ G,
190
+ u,
191
+ E
191
192
  ]);
192
- let bn = at({
193
- values: D,
194
- errors: Nt,
195
- lockSchedule: hn,
196
- messages: d,
197
- onChange: gn,
198
- onClearErrors: _n,
199
- onRevalidateErrors: yn
200
- }), Y = bn.reset, xn = p((e) => O((t) => ({
193
+ let xn = ot({
194
+ values: E,
195
+ errors: Pt,
196
+ lockSchedule: gn,
197
+ messages: u,
198
+ onChange: _n,
199
+ onClearErrors: vn,
200
+ onRevalidateErrors: bn
201
+ }), J = xn.reset, Sn = f((e) => D((t) => ({
201
202
  ...t,
202
203
  ...e
203
- })), []), X = xt.isPending || gt.isPending || _t.isPending || vt.isPending || yt.isPending || bt.isPending, Sn = st({
204
- open: w,
205
- isInvoice: D.type === "invoice",
206
- disabled: X,
207
- paymentTermsId: D.paymentTermsId,
208
- paymentTermsCustomDate: D.paymentTermsCustomDate,
209
- paymentReminderId: D.paymentReminderId,
210
- overdueReminderId: D.overdueReminderId,
211
- messages: d,
212
- onSelect: xn
213
- }), Cn = Sn.reset, wn = p(() => {
214
- C.current = [], Rt(void 0), Dt("create"), kt(void 0), jt(void 0), J.current = void 0, S.current = void 0, y.current = "draft", b.current = !1, x.current = !1, O(Ve()), A(!1), j({}), zt(!1), z(!1), R.current = {
204
+ })), []), Y = St.isPending || _t.isPending || vt.isPending || yt.isPending || bt.isPending || xt.isPending, Cn = ct({
205
+ open: C,
206
+ isInvoice: E.type === "invoice",
207
+ disabled: Y,
208
+ paymentTermsId: E.paymentTermsId,
209
+ paymentTermsCustomDate: E.paymentTermsCustomDate,
210
+ paymentReminderId: E.paymentReminderId,
211
+ overdueReminderId: E.overdueReminderId,
212
+ messages: u,
213
+ onSelect: Sn
214
+ }), wn = Cn.reset, Tn = f(() => {
215
+ S.current = [], zt(void 0), Ot("create"), At(void 0), Mt(void 0), q.current = void 0, x.current = void 0, v.current = "draft", y.current = !1, b.current = !1, D(Ue()), k(!1), A({}), Bt(!1), R(!1), L.current = {
215
216
  lines: !1,
216
217
  discount: !1
217
- }, U(), Y();
218
- }, [U, Y]), Tn = p((e = "invoice", { customerId: t = "" } = {}) => {
219
- dn(), pn(), Y();
218
+ }, H(), J();
219
+ }, [H, J]), En = f((e = "invoice", { customerId: t = "" } = {}) => {
220
+ fn(), mn(), J();
220
221
  let n = {
221
- ...Ve(),
222
+ ...Ue(),
222
223
  type: e,
223
224
  customerId: t
224
225
  };
225
- Cn(Ze(n)), C.current = [], S.current = void 0, y.current = "draft", b.current = !1, x.current = !1, J.current = void 0, Rt(void 0), Dt("create"), kt(void 0), jt(void 0), k.current = n, O(n), A(!1), j({}), U(), zt(!1), z(!1), R.current = {
226
+ wn($e(n)), S.current = [], x.current = void 0, v.current = "draft", y.current = !1, b.current = !1, q.current = void 0, zt(void 0), Ot("create"), At(void 0), Mt(void 0), O.current = n, D(n), k(!1), A({}), H(), Bt(!1), R(!1), L.current = {
226
227
  lines: !1,
227
228
  discount: !1
228
- }, T(!0);
229
+ }, w(!0);
229
230
  }, [
230
- U,
231
- dn,
232
- pn,
233
- Y,
234
- Cn
235
- ]), En = p((e, { highlightForIssue: t = !1 } = {}) => {
231
+ H,
232
+ fn,
233
+ mn,
234
+ J,
235
+ wn
236
+ ]), Dn = f((e, { highlightForIssue: t = !1 } = {}) => {
236
237
  if (e.type === "credit_note") return;
237
- dn(), pn(), Y();
238
- let n = Ke(e, N);
239
- Cn(Ze(n)), C.current = e.line_items, Et.current = e.currency, S.current = void 0, y.current = "draft", b.current = !1, x.current = t, J.current = void 0, Rt(void 0), Dt("edit"), kt(e.id), jt(e.type === "invoice" ? e.recurrence_id ?? void 0 : void 0), k.current = n, O(n), A(!1), j({}), zt(!1), z(!1), R.current = {
238
+ fn(), mn(), J();
239
+ let n = Je(e, M);
240
+ wn($e(n)), S.current = e.line_items, Dt.current = e.currency, x.current = void 0, v.current = "draft", y.current = !1, b.current = t, q.current = void 0, zt(void 0), Ot("edit"), At(e.id), Mt(e.type === "invoice" ? e.recurrence_id ?? void 0 : void 0), O.current = n, D(n), k(!1), A({}), Bt(!1), R(!1), L.current = {
240
241
  lines: !1,
241
242
  discount: !1
242
- }, U(), T(!0);
243
+ }, H(), w(!0);
243
244
  }, [
244
- U,
245
- dn,
246
- pn,
247
- Y,
248
- Cn,
249
- N
245
+ H,
246
+ fn,
247
+ mn,
248
+ J,
249
+ wn,
250
+ M
250
251
  ]);
251
- m(() => {
252
- N?.length && (k.current = {
253
- ...k.current,
254
- lineItems: he(k.current.lineItems, N)
255
- }, O((e) => {
256
- let t = he(e.lineItems, N);
252
+ p(() => {
253
+ M?.length && (O.current = {
254
+ ...O.current,
255
+ lineItems: _e(O.current.lineItems, M)
256
+ }, D((e) => {
257
+ let t = _e(e.lineItems, M);
257
258
  return t === e.lineItems ? e : {
258
259
  ...e,
259
260
  lineItems: t
260
261
  };
261
262
  }));
262
- }, [N]);
263
- let Z = H.isUploading, Dn = p(() => {
264
- Z || (en(), A(!1), T(!1), j({}));
265
- }, [en, Z]), On = p(() => {
266
- if (Mt) {
267
- A(!1);
263
+ }, [M]);
264
+ let X = V.isUploading, Z = f(() => {
265
+ X || (tn(), k(!1), w(!1), A({}));
266
+ }, [tn, X]), On = f(() => {
267
+ if (Nt) {
268
+ k(!1);
268
269
  return;
269
270
  }
270
- if (Z) {
271
- e.error(d.attachmentsUploading);
271
+ if (X) {
272
+ e.error(u.attachmentsUploading);
272
273
  return;
273
274
  }
274
- if (lt(k.current, D)) {
275
- A(!0);
275
+ if (ut(O.current, E)) {
276
+ k(!0);
276
277
  return;
277
278
  }
278
- Dn();
279
+ Z();
279
280
  }, [
280
- Dn,
281
281
  Z,
282
- d.attachmentsUploading,
283
- Mt,
284
- D
285
- ]), kn = p((e) => {
282
+ X,
283
+ u.attachmentsUploading,
284
+ Nt,
285
+ E
286
+ ]), kn = f((e) => {
286
287
  let t = { ...e };
287
- t.taxRate !== void 0 && (t.taxRate = _e(t.taxRate), L.current = !0), t.type !== void 0 && t.type !== "invoice" && en(), t.discount !== void 0 && Ut(!1), t.discount !== void 0 && F && (I.current = !0), t.discountType !== void 0 && (I.current = !0), t.currency !== void 0 && (Bt.current = !0), O((e) => {
288
+ t.taxRate !== void 0 && (t.taxRate = ye(t.taxRate), I.current = !0), t.type !== void 0 && t.type !== "invoice" && tn(), t.discount !== void 0 && Wt(!1), t.discount !== void 0 && P && (F.current = !0), t.discountType !== void 0 && (F.current = !0), t.currency !== void 0 && (Vt.current = !0), D((e) => {
288
289
  let n = {
289
- ...t.customerId === void 0 ? e : ut(e, t.customerId),
290
+ ...t.customerId === void 0 ? e : dt(e, t.customerId),
290
291
  ...t
291
292
  };
292
- return t.discount !== void 0 && (n.discount = Ie(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
293
+ return t.discount !== void 0 && (n.discount = Re(t.discount, n.discountType, n.currency)), n.currency !== e.currency && (n.lineItems = e.lineItems.map((t) => ({
293
294
  ...t,
294
- price: ue(t.price, e.currency, n.currency)
295
- }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = Ne({
295
+ price: fe(t.price, e.currency, n.currency)
296
+ }))), (n.currency !== e.currency || n.discountType !== e.discountType) && (n.discount = Fe({
296
297
  value: n.discount,
297
298
  type: n.discountType,
298
299
  currency: n.currency
299
300
  })), n;
300
301
  });
301
- }, [en, F]), An = p(() => {
302
- z(!0), Ut(Fe(D.discount, D.discountType, D.currency) === 0);
302
+ }, [tn, P]), An = f(() => {
303
+ R(!0), Wt(Le(E.discount, E.discountType, E.currency) === 0);
303
304
  }, [
304
- D.discount,
305
- D.discountType,
306
- D.currency
307
- ]), jn = p(() => {
308
- z(!1), I.current = !0, O((e) => ({
305
+ E.discount,
306
+ E.discountType,
307
+ E.currency
308
+ ]), jn = f(() => {
309
+ R(!1), F.current = !0, D((e) => ({
309
310
  ...e,
310
- discount: Ne({
311
+ discount: Fe({
311
312
  value: e.discount,
312
313
  type: e.discountType,
313
314
  currency: e.currency
314
315
  })
315
316
  }));
316
- }, []), Mn = p(() => {
317
- let e = Ye({
318
- values: D,
319
- messages: d,
320
- canCreateCustomer: v
317
+ }, []), Mn = f(() => {
318
+ let e = Ze({
319
+ values: E,
320
+ messages: u,
321
+ canCreateCustomer: _
321
322
  }).customerEmail;
322
- j((t) => {
323
+ A((t) => {
323
324
  if (t.customerEmail === e) return t;
324
325
  let n = { ...t };
325
326
  return e ? n.customerEmail = e : delete n.customerEmail, n;
326
327
  });
327
328
  }, [
328
- v,
329
- d,
330
- D
331
- ]), Nn = p(() => {
332
- L.current = !0, O((e) => {
333
- let t = le(e.taxRate);
329
+ _,
330
+ u,
331
+ E
332
+ ]), Nn = f(() => {
333
+ I.current = !0, D((e) => {
334
+ let t = de(e.taxRate);
334
335
  return t === e.taxRate ? e : {
335
336
  ...e,
336
337
  taxRate: t
337
338
  };
338
339
  });
339
- }, []), Q = p((e, { validate: t }) => {
340
- t && (Bt.current = !0), O((t) => ({
340
+ }, []), Q = f((e, { validate: t }) => {
341
+ t && (Vt.current = !0), D((t) => ({
341
342
  ...t,
342
343
  lineItems: e(t.lineItems)
343
344
  }));
344
345
  }, []);
345
- m(() => {
346
- let e = Bt.current, t = I.current;
347
- if (!e && !t && !L.current) return;
348
- Bt.current = !1, I.current = !1, L.current = !1, e && (R.current.lines = !0), t && (R.current.discount = !0);
349
- let n = b.current || K > 0, r = e ? Se(D.lineItems, {
350
- currency: D.currency,
351
- messages: d,
346
+ p(() => {
347
+ let e = Vt.current, t = F.current;
348
+ if (!e && !t && !I.current) return;
349
+ Vt.current = !1, F.current = !1, I.current = !1, e && (L.current.lines = !0), t && (L.current.discount = !0);
350
+ let n = y.current || G > 0, r = e ? we(E.lineItems, {
351
+ currency: E.currency,
352
+ messages: u,
352
353
  requireComplete: n
353
354
  }) : void 0;
354
- j((t) => {
355
+ A((t) => {
355
356
  let i = { ...t };
356
- return R.current.lines && (i.lineItems = e ? r : t.lineItems, i.lineItemsSummary = be(i.lineItems, Be(D, d), n && D.lineItems.length === 0 ? d.lineItemsRequired : void 0)), R.current.discount && (i.discount = ze(D, d)), i;
357
+ return L.current.lines && (i.lineItems = e ? r : t.lineItems, i.lineItemsSummary = Se(i.lineItems, He(E, u), n && E.lineItems.length === 0 ? u.lineItemsRequired : void 0)), L.current.discount && (i.discount = Ve(E, u)), i;
357
358
  });
358
359
  }, [
359
- K,
360
- d,
361
- D
360
+ G,
361
+ u,
362
+ E
362
363
  ]);
363
- let Pn = p((e, t) => {
364
- let { unit: n, ...r } = t, i = ge(r);
365
- i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), i.taxable !== void 0 && (L.current = !0), Q((t) => t.map((t) => t.id === e ? {
364
+ let Pn = f((e, t) => {
365
+ let { unit: n, ...r } = t, i = ve(r);
366
+ i.name !== void 0 && (i.productId = ""), n !== void 0 && (i.measureUnitId = n, i.measureUnitName = ""), i.taxable !== void 0 && (I.current = !0), Q((t) => t.map((t) => t.id === e ? {
366
367
  ...t,
367
368
  ...i
368
- } : t), { validate: F });
369
- }, [Q, F]), Fn = p((e, t) => {
369
+ } : t), { validate: P });
370
+ }, [Q, P]), Fn = f((e, t) => {
370
371
  Q((n) => n.map((n) => n.id === e ? {
371
372
  ...n,
372
- ...pe({
373
+ ...he({
373
374
  product: t,
374
- currency: D.currency,
375
- unitNamesById: P
375
+ currency: E.currency,
376
+ unitNamesById: N
376
377
  })
377
378
  } : n), { validate: !0 });
378
379
  }, [
379
380
  Q,
380
- P,
381
- D.currency
382
- ]), In = p((e, t) => {
381
+ N,
382
+ E.currency
383
+ ]), In = f((e, t) => {
383
384
  t && Q((n) => t.kind === "remove" ? n.filter((t) => t.id !== e) : n.map((n) => n.id === e ? {
384
385
  ...n,
385
386
  ...t.patch
386
387
  } : n), { validate: !0 });
387
- }, [Q]), Ln = p((e, t) => {
388
- let n = D.lineItems.find((t) => t.id === e);
389
- n && In(e, ce({
388
+ }, [Q]), Ln = f((e, t) => {
389
+ let n = E.lineItems.find((t) => t.id === e);
390
+ n && In(e, ue({
390
391
  lineItem: n,
391
392
  field: t,
392
- rowCount: D.lineItems.length,
393
- currency: D.currency
393
+ rowCount: E.lineItems.length,
394
+ currency: E.currency
394
395
  }));
395
396
  }, [
396
397
  In,
397
- D.currency,
398
- D.lineItems
399
- ]), Rn = p((e, t) => {
400
- let n = D.lineItems.find((t) => t.id === e);
401
- n && In(e, ve({
398
+ E.currency,
399
+ E.lineItems
400
+ ]), Rn = f((e, t) => {
401
+ let n = E.lineItems.find((t) => t.id === e);
402
+ n && In(e, be({
402
403
  lineItem: n,
403
404
  step: t,
404
- rowCount: D.lineItems.length
405
+ rowCount: E.lineItems.length
405
406
  }));
406
- }, [In, D.lineItems]), zn = p(() => {
407
- let e = de(D.currency);
408
- Rt(e.id), O((t) => ({
407
+ }, [In, E.lineItems]), zn = f(() => {
408
+ let e = pe(E.currency);
409
+ zt(e.id), D((t) => ({
409
410
  ...t,
410
411
  lineItems: [...t.lineItems, e]
411
412
  }));
412
- }, [D.currency]), Bn = p((e) => {
413
+ }, [E.currency]), Bn = f((e) => {
413
414
  Q((t) => t.length <= 1 ? t : t.filter((t) => t.id !== e), { validate: !0 });
414
- }, [Q]), Vn = p((e, t) => e.type === "invoice" && (t === "issue" || Me(e) && K === 0), [K]), Hn = p((e, t) => ({
415
- ...Ye({
415
+ }, [Q]), Vn = f((e, t) => e.type === "invoice" && (t === "issue" || Pe(e) && G === 0), [G]), Hn = f((e, t) => ({
416
+ ...Ze({
416
417
  values: e,
417
- messages: d,
418
+ messages: u,
418
419
  willIssue: t,
419
- hasStartedRecurrence: K > 0,
420
- canCreateCustomer: v
420
+ hasStartedRecurrence: G > 0,
421
+ canCreateCustomer: _
421
422
  }),
422
- ...e.type === "invoice" && f(e) ? je({
423
+ ...e.type === "invoice" && d(e) ? Ne({
423
424
  fields: e,
424
- issuedCount: K,
425
- messages: d
425
+ issuedCount: G,
426
+ messages: u
426
427
  }) : {}
427
428
  }), [
428
- v,
429
- K,
430
- d
431
- ]), Un = p(() => {
429
+ _,
430
+ G,
431
+ u
432
+ ]), Un = f(() => {
432
433
  requestAnimationFrame(() => {
433
- let e = Tt.current, t = e?.querySelector("[aria-invalid=\"true\"], [data-invalid=\"true\"]");
434
+ let e = Et.current, t = e?.querySelector("[aria-invalid=\"true\"], [data-invalid=\"true\"]");
434
435
  if (!e || !t) return;
435
436
  let n = t.getBoundingClientRect().top - e.getBoundingClientRect().top + e.scrollTop;
436
437
  e.scrollTo({
@@ -438,31 +439,31 @@ function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, c
438
439
  behavior: "smooth"
439
440
  });
440
441
  });
441
- }, []), Wn = p((e, t) => {
442
- j(e), zt(!0), b.current = t, R.current = {
442
+ }, []), Wn = f((e, t) => {
443
+ A(e), Bt(!0), y.current = t, L.current = {
443
444
  lines: !0,
444
445
  discount: !0
445
446
  }, Un();
446
- }, [Un]), Gn = !At || D.frequency !== "once" || mn.isError;
447
- m(() => {
448
- if (!w || !x.current || B || q || !Gn) return;
449
- x.current = !1;
450
- let e = Vn(D, "issue");
451
- Wn(Hn(D, e), e);
447
+ }, [Un]), Gn = !jt || E.frequency !== "once" || hn.isError;
448
+ p(() => {
449
+ if (!C || !b.current || z || K || !Gn) return;
450
+ b.current = !1;
451
+ let e = Vn(E, "issue");
452
+ Wn(Hn(E, e), e);
452
453
  }, [
453
- B,
454
- w,
454
+ z,
455
+ C,
455
456
  Gn,
456
- q,
457
+ K,
457
458
  Wn,
458
459
  Hn,
459
- D,
460
+ E,
460
461
  Vn
461
462
  ]);
462
- let Kn = g({ values: D });
463
- m(() => {
463
+ let Kn = h({ values: E });
464
+ p(() => {
464
465
  let e = Kn.current;
465
- if (Kn.current = { values: D }, !F) return;
466
+ if (Kn.current = { values: E }, !P) return;
466
467
  let t = [
467
468
  "customerId",
468
469
  "customerEmail",
@@ -472,257 +473,257 @@ function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, c
472
473
  "openingNote",
473
474
  "closingNote",
474
475
  "taxRate"
475
- ].filter((t) => e.values[t] !== D[t] || t === "customerId" && e.values.customerName !== D.customerName || t === "paymentTermsId" && e.values.paymentTermsCustomDate !== D.paymentTermsCustomDate);
476
+ ].filter((t) => e.values[t] !== E[t] || t === "customerId" && e.values.customerName !== E.customerName || t === "paymentTermsId" && e.values.paymentTermsCustomDate !== E.paymentTermsCustomDate);
476
477
  if (!t.length) return;
477
- let n = Ye({
478
- values: D,
479
- messages: d,
480
- willIssue: b.current,
481
- canCreateCustomer: v
478
+ let n = Ze({
479
+ values: E,
480
+ messages: u,
481
+ willIssue: y.current,
482
+ canCreateCustomer: _
482
483
  });
483
- j((e) => {
484
+ A((e) => {
484
485
  let r = { ...e };
485
486
  return t.forEach((e) => {
486
487
  n[e] ? r[e] = n[e] : delete r[e];
487
488
  }), r;
488
489
  });
489
490
  }, [
490
- v,
491
- d,
492
- F,
493
- D
491
+ _,
492
+ u,
493
+ P,
494
+ E
494
495
  ]);
495
- let qn = p(async (t) => {
496
- if (y.current = t, q) return;
497
- if (Z) {
498
- e.error(d.attachmentsUploading);
496
+ let qn = f(async (t) => {
497
+ if (v.current = t, K) return;
498
+ if (X) {
499
+ e.error(u.attachmentsUploading);
499
500
  return;
500
501
  }
501
- if (M.isLoading || B) {
502
- e.error(d.lineItemsLoading);
502
+ if (j.isLoading || z) {
503
+ e.error(u.lineItemsLoading);
503
504
  return;
504
505
  }
505
- let r = ye(D.lineItems), a = r.length === D.lineItems.length ? D : {
506
- ...D,
507
- lineItems: r
506
+ let i = xe(E.lineItems), a = i.length === E.lineItems.length ? E : {
507
+ ...E,
508
+ lineItems: i
508
509
  };
509
- a !== D && O(a);
510
- let o = a.type === "invoice" && f(a), s = Vn(a, t);
511
- if (s && (Qt || W.isLoading)) {
512
- e.error(d.issueChecksLoading);
510
+ a !== E && D(a);
511
+ let o = a.type === "invoice" && d(a), s = Vn(a, t);
512
+ if (s && ($t || U.isLoading)) {
513
+ e.error(u.issueChecksLoading);
513
514
  return;
514
515
  }
515
- if (s && !W.canAddAccount && !a.bankAccountId && !W.hasAccounts) {
516
- e.error(d.issueBankAccountUnavailable);
516
+ if (s && !U.canAddAccount && !a.bankAccountId && !U.hasAccounts) {
517
+ e.error(u.issueBankAccountUnavailable);
517
518
  return;
518
519
  }
519
- let c = Hn(a, s);
520
- if (He(c)) {
521
- Wn(c, s);
520
+ let te = Hn(a, s);
521
+ if (We(te)) {
522
+ Wn(te, s);
522
523
  return;
523
524
  }
524
- if (j({}), s && V.isTaxIdMissing) {
525
- e.error(d.issueTaxIdRequired);
525
+ if (A({}), s && B.isTaxIdMissing) {
526
+ e.error(u.issueTaxIdRequired);
526
527
  return;
527
528
  }
528
- let ee = v && !a.customerId && !!a.customerName.trim(), ne = a.customerEmail.trim();
529
+ let ne = _ && !a.customerId && !!a.customerName.trim(), ie = a.customerEmail.trim();
529
530
  if (s && (a.paymentReminderId || a.overdueReminderId)) {
530
- let t = ee ? ne ? void 0 : d.issueRemindersNoEmail : Xe(V.counterpart, d);
531
+ let t = ne ? ie ? void 0 : u.issueRemindersNoEmail : Qe(B.counterpart, u);
531
532
  if (t) {
532
533
  e.error(t);
533
534
  return;
534
535
  }
535
536
  }
536
- if (ee) {
537
+ if (ne) {
537
538
  let t;
538
539
  try {
539
- t = (await xt.mutateAsync({ body: te({
540
+ t = (await St.mutateAsync({ body: re({
540
541
  name: a.customerName,
541
542
  email: a.customerEmail
542
543
  }) }))?.id;
543
544
  } catch (t) {
544
- e.error(tt(t, { messages: d }));
545
+ e.error(rt(t, { messages: u }));
545
546
  return;
546
547
  }
547
548
  if (!t) return;
548
- a = dt(a, t);
549
+ a = ft(a, t);
549
550
  let n = t;
550
- O((e) => dt(e, n));
551
+ D((e) => ft(e, n));
551
552
  }
552
- let l = E === "edit" ? Ot : S.current, u, re, ie = "", ae = {};
553
+ let c = T === "edit" ? kt : x.current, l, ae, oe = "", se = {};
553
554
  try {
554
- if (l) {
555
- let e = We({
555
+ if (c) {
556
+ let e = Ke({
556
557
  values: a,
557
- originalLineItems: C.current,
558
- originalCurrency: Et.current,
559
- unitNamesById: P,
560
- units: N
558
+ originalLineItems: S.current,
559
+ originalCurrency: Dt.current,
560
+ unitNamesById: N,
561
+ units: M
561
562
  });
562
- ae = Je({
563
+ se = Xe({
563
564
  values: a,
564
- originalLineItems: C.current,
565
+ originalLineItems: S.current,
565
566
  changes: e
566
567
  });
567
- let t = await _t.mutateAsync({
568
- path: { receivable_id: l },
569
- body: Ge({
568
+ let t = await vt.mutateAsync({
569
+ path: { receivable_id: c },
570
+ body: qe({
570
571
  values: a,
571
- billingAddressId: Yt,
572
- shippingAddressId: Zt,
572
+ billingAddressId: Xt,
573
+ shippingAddressId: Qt,
573
574
  lineItemChanges: e
574
575
  })
575
576
  });
576
- tn(), u = l, re = t?.type ?? a.type, o && t && (C.current = t.line_items, Et.current = t.currency, a = {
577
+ nn(), l = c, ae = t?.type ?? a.type, o && t && (S.current = t.line_items, Dt.current = t.currency, a = {
577
578
  ...a,
578
- lineItems: me(a.lineItems, t.line_items)
579
- }, O(a));
579
+ lineItems: ge(a.lineItems, t.line_items)
580
+ }, D(a));
580
581
  } else {
581
- ae = Je({ values: a });
582
- let e = await gt.mutateAsync({ body: Ue({
582
+ se = Xe({ values: a });
583
+ let e = await _t.mutateAsync({ body: Ge({
583
584
  values: a,
584
- billingAddressId: Yt,
585
- shippingAddressId: Zt,
586
- unitNamesById: P
585
+ billingAddressId: Xt,
586
+ shippingAddressId: Qt,
587
+ unitNamesById: N
587
588
  }) });
588
589
  if (!e?.id) {
589
- T(!1), wn();
590
+ w(!1), Tn();
590
591
  return;
591
592
  }
592
- u = e.id, re = e.type, ie = e.counterpart_name ?? "", o && (S.current = e.id, C.current = e.line_items, Et.current = e.currency, a = {
593
+ l = e.id, ae = e.type, oe = e.counterpart_name ?? "", o && (x.current = e.id, S.current = e.line_items, Dt.current = e.currency, a = {
593
594
  ...a,
594
- lineItems: me(a.lineItems, e.line_items)
595
- }, O(a));
595
+ lineItems: ge(a.lineItems, e.line_items)
596
+ }, D(a));
596
597
  }
597
598
  } catch (t) {
598
- let n = $e[a.type], r = tt(t, {
599
+ let n = tt[a.type], i = rt(t, {
599
600
  irrelevantVariants: n,
600
- messages: d
601
+ messages: u
601
602
  });
602
- e.error((l ? d.updateFailed : d.createFailed).replace("{errorMessage}", r));
603
- let { errors: i, listError: o } = et(nt(t, n), ae), c = be(i.lineItems, void 0, o);
603
+ e.error((c ? u.updateFailed : u.createFailed).replace("{errorMessage}", i));
604
+ let { errors: ee, listError: o } = nt(r(t, n), se), te = Se(ee.lineItems, void 0, o);
604
605
  Wn({
605
- ...i,
606
- ...c ? { lineItemsSummary: c } : {}
606
+ ...ee,
607
+ ...te ? { lineItemsSummary: te } : {}
607
608
  }, s);
608
609
  return;
609
610
  }
610
- let oe = o ? "recurrence" : "draft";
611
+ let ce = o ? "recurrence" : "draft";
611
612
  if (o) try {
612
- G ? (await yt.mutateAsync({
613
- path: { recurrence_id: G.id },
614
- body: Oe(a, { lockSchedule: hn })
615
- }), e.success(d.recurrenceUpdated)) : (await vt.mutateAsync({ body: De(a, u) }), e.success(d.recurrenceActivated));
613
+ W ? (await bt.mutateAsync({
614
+ path: { recurrence_id: W.id },
615
+ body: Ae(a, { lockSchedule: gn })
616
+ }), e.success(u.recurrenceUpdated)) : (await yt.mutateAsync({ body: ke(a, l) }), e.success(u.recurrenceActivated));
616
617
  } catch (t) {
617
- e.error(tt(t, { messages: d }));
618
+ e.error(rt(t, { messages: u }));
618
619
  return;
619
620
  }
620
621
  else if (s) try {
621
- await bt.mutateAsync({ path: { receivable_id: u } }), oe = "issue", e.success(d.issueSucceeded);
622
+ await xt.mutateAsync({ path: { receivable_id: l } }), ce = "issue", e.success(u.issueSucceeded);
622
623
  } catch (t) {
623
- e.error(n(t) ?? d.unrecognizedError), e.error(d.issueFailedAfterSave);
624
+ e.error(n(t) ?? u.unrecognizedError), e.error(u.issueFailedAfterSave);
624
625
  }
625
- else E === "create" ? e.success(d.createSucceeded.replace("{customer}", ie)) : e.success(d.updateSucceeded);
626
- let se = E === "create" ? mt : ht;
627
- T(!1), wn(), se?.(u, re, {
628
- mode: oe,
626
+ else T === "create" ? e.success(u.createSucceeded.replace("{customer}", oe)) : e.success(u.updateSucceeded);
627
+ let le = T === "create" ? ht : gt;
628
+ w(!1), Tn(), le?.(l, ae, {
629
+ mode: ce,
629
630
  counterpartId: a.customerId,
630
- inlineItems: Ee(a.lineItems, a.currency),
631
- hasCustomerEmail: ee ? !!ne : !!(V.counterpart && i(V.counterpart).trim())
631
+ inlineItems: Oe(a.lineItems, a.currency),
632
+ hasCustomerEmail: ne ? !!ie : !!(B.counterpart && ee(B.counterpart).trim())
632
633
  });
633
634
  }, [
634
- W.canAddAccount,
635
- W.hasAccounts,
636
- W.isLoading,
637
- Yt,
638
- v,
639
- tn,
635
+ U.canAddAccount,
636
+ U.hasAccounts,
637
+ U.isLoading,
638
+ Xt,
639
+ _,
640
+ nn,
641
+ St,
642
+ _t,
643
+ yt,
644
+ kt,
645
+ W,
646
+ z,
647
+ X,
648
+ $t,
640
649
  xt,
650
+ gn,
651
+ u,
652
+ T,
653
+ ht,
641
654
  gt,
642
- vt,
643
- Ot,
644
- G,
645
- B,
646
- Z,
655
+ B.counterpart,
656
+ B.isTaxIdMissing,
657
+ K,
658
+ Tn,
647
659
  Qt,
648
- bt,
649
- hn,
650
- d,
651
- E,
652
- mt,
653
- ht,
654
- V.counterpart,
655
- V.isTaxIdMissing,
656
- q,
657
- wn,
658
- Zt,
659
660
  Wn,
661
+ M,
660
662
  N,
661
- P,
662
- M.isLoading,
663
- _t,
664
- yt,
663
+ j.isLoading,
664
+ vt,
665
+ bt,
665
666
  Hn,
666
- D,
667
+ E,
667
668
  Vn
668
- ]), $ = p(async (e = y.current) => {
669
- if (!St.current) {
670
- St.current = !0, wt(e);
669
+ ]), $ = f(async (e = v.current) => {
670
+ if (!Ct.current) {
671
+ Ct.current = !0, Tt(e);
671
672
  try {
672
673
  await qn(e);
673
674
  } finally {
674
- St.current = !1, wt(void 0);
675
+ Ct.current = !1, Tt(void 0);
675
676
  }
676
677
  }
677
- }, [qn]), Jn = h(() => ({
678
- ...D,
679
- discount: Vt ? Ht ? "" : D.discount : Pe(Fe(D.discount, D.discountType, D.currency), D.discountType, D.currency),
680
- lineItems: D.lineItems.map(xe)
678
+ }, [qn]), Jn = m(() => ({
679
+ ...E,
680
+ discount: Ht ? Ut ? "" : E.discount : Ie(Le(E.discount, E.discountType, E.currency), E.discountType, E.currency),
681
+ lineItems: E.lineItems.map(Ce)
681
682
  }), [
683
+ Ut,
682
684
  Ht,
683
- Vt,
684
- D
685
- ]), Yn = h(() => se(D.lineItems), [D.lineItems]), Xn = h(() => Re(D), [D]), Zn = D.type === "invoice", Qn = Zn && f(D), $n = X || M.isLoading || W.isLoading, er = $n || B || H.isUploading || q, tr = E === "edit" ? d.updateDraftButton : d.saveDraftButton, nr = Qn ? G ? d.recurrenceUpdateButton : d.recurrenceActivateButton : Zn ? d.issueButton : tr, rr = Zn && !Qn ? "issue" : "draft", ir = p(() => $("draft"), [$]), ar = p(() => $(rr), [rr, $]), or = p(() => $(), [$]), sr = p(() => {
686
- y.current = "draft";
687
- }, []), cr = p(() => {
688
- y.current = rr;
689
- }, [rr]), lr = er || Qn, ur = p(async () => {
685
+ E
686
+ ]), Yn = m(() => le(E.lineItems), [E.lineItems]), Xn = m(() => Be(E), [E]), Zn = E.type === "invoice", Qn = Zn && d(E), $n = Y || j.isLoading || U.isLoading, er = $n || z || V.isUploading || K, tr = T === "edit" ? u.updateDraftButton : u.saveDraftButton, nr = Qn ? W ? u.recurrenceUpdateButton : u.recurrenceActivateButton : Zn ? u.issueButton : tr, rr = Zn && !Qn ? "issue" : "draft", ir = f(() => $("draft"), [$]), ar = f(() => $(rr), [rr, $]), or = f(() => $(), [$]), sr = f(() => {
687
+ v.current = "draft";
688
+ }, []), cr = f(() => {
689
+ v.current = rr;
690
+ }, [rr]), lr = er || Qn, ur = f(async () => {
690
691
  if (!lr) try {
691
692
  await $("draft");
692
693
  } finally {
693
- A(!1);
694
+ k(!1);
694
695
  }
695
- }, [lr, $]), dr = p(() => A(!1), []), fr = h(() => ({
696
- open: Mt,
696
+ }, [lr, $]), dr = f(() => k(!1), []), fr = m(() => ({
697
+ open: Nt,
697
698
  onSaveDraft: () => void ur(),
698
- onDiscard: Dn,
699
+ onDiscard: Z,
699
700
  onCancel: dr,
700
- isSaving: X,
701
+ isSaving: Y,
701
702
  isSaveDraftDisabled: lr
702
703
  }), [
703
704
  dr,
704
- Dn,
705
- X,
705
+ Z,
706
+ Y,
706
707
  lr,
707
708
  ur,
708
- Mt
709
- ]), pr = h(() => Le(Xn, D.currency), [Xn, D.currency]), mr = ct({
710
- values: D,
709
+ Nt
710
+ ]), pr = m(() => ze(Xn, E.currency), [Xn, E.currency]), mr = lt({
711
+ values: E,
711
712
  totals: Xn,
712
- billingAddress: Xt,
713
- bankAccount: W.selectedAccount,
714
- unitNamesById: P,
715
- messages: d,
716
- enabled: w
713
+ billingAddress: Zt,
714
+ bankAccount: U.selectedAccount,
715
+ unitNamesById: N,
716
+ messages: u,
717
+ enabled: C
717
718
  });
718
719
  return {
719
- open: w,
720
- setOpen: T,
721
- mode: E,
722
- values: D,
720
+ open: C,
721
+ setOpen: w,
722
+ mode: T,
723
+ values: E,
723
724
  sheetValues: Jn,
724
- errors: Nt,
725
- setValues: O,
725
+ errors: Pt,
726
+ setValues: D,
726
727
  updateValues: kn,
727
728
  commitTaxRate: Nn,
728
729
  commitCustomerEmail: Mn,
@@ -734,41 +735,41 @@ function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, c
734
735
  stepLineItem: Rn,
735
736
  addLineItem: zn,
736
737
  removeLineItem: Bn,
737
- attachmentsView: nn,
738
- attachmentsUploading: H.isUploading,
738
+ attachmentsView: rn,
739
+ attachmentsUploading: V.isUploading,
739
740
  draftButtonLabel: Zn && !Qn ? tr : void 0,
740
741
  draftDisabled: er,
741
- draftLoading: X && Ct === "draft",
742
+ draftLoading: Y && wt === "draft",
742
743
  primaryButtonLabel: nr,
743
- primaryLoading: X && Ct === rr,
744
- primaryDisabled: er || Zn && (Qt || !Qn && V.isCounterpartLoading),
745
- scrollContainerRef: Tt,
746
- selectAttachmentFiles: H.selectFiles,
747
- setAttachmentIncludeInEmail: H.setIncludeInEmail,
748
- removeAttachment: H.remove,
749
- autoFocusLineItemId: Lt,
750
- lineItemUnitOptions: It.unitOptions,
751
- lineItemsLoading: M.isLoading,
744
+ primaryLoading: Y && wt === rr,
745
+ primaryDisabled: er || Zn && ($t || !Qn && B.isCounterpartLoading),
746
+ scrollContainerRef: Et,
747
+ selectAttachmentFiles: V.selectFiles,
748
+ setAttachmentIncludeInEmail: V.setIncludeInEmail,
749
+ removeAttachment: V.remove,
750
+ autoFocusLineItemId: Rt,
751
+ lineItemUnitOptions: Lt.unitOptions,
752
+ lineItemsLoading: j.isLoading,
752
753
  lineItemControls: Yn,
753
754
  totals: Xn,
754
755
  preview: mr,
755
756
  totalsView: pr,
756
- currencySymbol: fe(D.currency),
757
- isSubmitting: X,
757
+ currencySymbol: me(E.currency),
758
+ isSubmitting: Y,
758
759
  fieldsDisabled: $n,
759
- paymentTerms: un,
760
- showBillingSection: D.type === "invoice" || E === "edit",
761
- purchaseOrder: E === "create" ? {
762
- value: D.purchaseOrder,
763
- error: Nt.purchaseOrder
760
+ paymentTerms: dn,
761
+ showBillingSection: E.type === "invoice" || T === "edit",
762
+ purchaseOrder: T === "create" ? {
763
+ value: E.purchaseOrder,
764
+ error: Pt.purchaseOrder
764
765
  } : void 0,
765
- recurrence: bn,
766
- showRecurrenceSection: D.type === "invoice",
767
- recurrenceLoading: q,
768
- showDueDateField: D.type === "quote",
769
- openCreate: Tn,
770
- openEdit: En,
771
- close: Dn,
766
+ recurrence: xn,
767
+ showRecurrenceSection: E.type === "invoice",
768
+ recurrenceLoading: K,
769
+ showDueDateField: E.type === "quote",
770
+ openCreate: En,
771
+ openEdit: Dn,
772
+ close: Z,
772
773
  requestClose: On,
773
774
  unsavedPrompt: fr,
774
775
  submit: or,
@@ -776,15 +777,15 @@ function ft({ messages: d, counterpartMessageLabels: ft, embeddedBankName: pt, c
776
777
  submitPrimary: ar,
777
778
  selectDraftMode: sr,
778
779
  selectPrimaryMode: cr,
779
- units: It,
780
- counterpartView: Pt,
781
- counterpartForm: an,
782
- stateOptions: Wt,
783
- openCounterpartCreate: cn,
784
- customer: qt.data?.id === D.customerId ? qt.data : void 0,
785
- bankAccount: W,
786
- reminders: Sn
780
+ units: Lt,
781
+ counterpartView: Ft,
782
+ counterpartForm: on,
783
+ stateOptions: Gt,
784
+ openCounterpartCreate: ln,
785
+ customer: Jt.data?.id === E.customerId ? Jt.data : void 0,
786
+ bankAccount: U,
787
+ reminders: Cn
787
788
  };
788
789
  }
789
790
  //#endregion
790
- export { ft as useReceivableForm };
791
+ export { pt as useReceivableForm };