@tesouro/embedded-components-react 0.5.201 → 0.5.203

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 (61) hide show
  1. package/README.md +20 -6
  2. package/dist/index.css +3 -0
  3. package/dist/index.d.ts +82 -7
  4. package/dist/index.js +8 -7
  5. package/dist/lib/MarketingWidget.d.ts +66 -7
  6. package/dist/lib/MarketingWidget.js +5 -4
  7. package/dist/lib/ReceivablesWidget.d.ts +16 -0
  8. package/dist/lib/ReceivablesWidget.js +1 -1
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index.js +6 -6
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index2.js +24 -18
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/data-access/dist/index4.js +65 -2
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index.js +1 -1
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index10.js +188 -45
  14. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index11.js +30 -265
  15. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index12.js +144 -64
  16. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index13.js +47 -109
  17. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index14.js +293 -216
  18. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index15.js +75 -0
  19. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index16.js +114 -0
  20. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index17.js +237 -0
  21. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index4.js +14 -1
  22. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index5.js +28 -243
  23. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js +212 -375
  24. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index7.js +64 -62
  25. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index8.js +409 -187
  26. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index9.js +73 -40
  27. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index.js +10 -9
  28. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index10.js +0 -9
  29. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index11.js +4 -1
  30. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index12.js +10 -263
  31. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index13.js +1 -72
  32. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index14.js +241 -398
  33. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index15.js +66 -100
  34. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index16.js +406 -76
  35. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index17.js +92 -330
  36. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index18.js +93 -0
  37. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index19.js +344 -0
  38. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index2.js +6 -1
  39. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index4.js +157 -20
  40. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index5.js +24 -1
  41. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index6.js +1 -3
  42. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index7.js +3 -18
  43. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index8.js +2 -0
  44. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/ui/dist/index9.js +18 -4
  45. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index.js +5 -4
  46. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index3.js +1 -0
  47. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index4.js +33 -81
  48. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index5.js +34 -0
  49. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index6.js +20 -0
  50. package/dist/libs/tesouro-embedded-components-react/marketing-widget/feature/dist/index7.js +161 -0
  51. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index.js +3 -3
  52. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index3.js +5 -1
  53. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index8.js +34 -81
  54. package/dist/libs/tesouro-embedded-components-react/marketing-widget/ui/dist/index9.js +92 -0
  55. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/index.js +38 -37
  56. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/@tanstack/react-query.gen.js +54 -54
  57. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/rest/sdk.gen.js +115 -94
  58. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationApplicationStatus.js +25 -0
  59. package/dist/libs/tesouro-embedded-components-react/shared/data-access/dist/lib/useOrganizationOnboardingSuppression.js +9 -9
  60. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  61. package/package.json +1 -1
@@ -1,412 +1,249 @@
1
1
  import { minorExponentForCurrency as e } from "../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
- import { parseDateOrTimestamp as t } from "../../../shared/util/dist/lib/parseCalendarDate.js";
3
- import { createLineItem as n, isBlankLineItem as r, lineItemToCreatePayload as i, lineItemToUpdatePayload as a, responseLineItemToFormValues as o, summarizeLineItemErrors as s, taxRateFromLineItems as c, validateLineItems as l } from "./index5.js";
4
2
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js
5
- var u = {
6
- to: "",
7
- cc: "",
8
- bcc: "",
9
- subject: "",
10
- body: ""
11
- }, d = {
12
- mode: "full",
13
- amountPaid: "",
14
- paidAt: "",
15
- comment: ""
16
- };
17
- function f() {
3
+ var t = 9e15;
4
+ function n(e) {
5
+ let t = new Intl.NumberFormat(e), n = t.formatToParts(12345.67);
18
6
  return {
19
- type: "invoice",
20
- customerId: "",
21
- currency: "USD",
22
- issueDate: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
23
- dueDate: "",
24
- openingNote: "",
25
- closingNote: "",
26
- paymentTermsId: "",
27
- taxRate: "",
28
- lineItems: [n()]
7
+ decimal: n.find((e) => e.type === "decimal")?.value ?? ".",
8
+ group: n.find((e) => e.type === "group")?.value ?? "",
9
+ digits: Array.from({ length: 10 }, (e, n) => t.format(n))
29
10
  };
30
11
  }
12
+ function r(e) {
13
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14
+ }
15
+ function i(e) {
16
+ let t = e.replace(/[^0-9.]/g, ""), n = t.indexOf(".");
17
+ return n !== -1 && (t = t.slice(0, n + 1) + t.slice(n + 1).replace(/\./g, ""), t = t.slice(0, n + 3)), t;
18
+ }
19
+ function a(e) {
20
+ return e === "" || e === "." ? 0 : Number(e) || 0;
21
+ }
22
+ var o = (e) => Math.round(e * 100) / 100;
23
+ function s(t, n) {
24
+ let r = e(n);
25
+ return new Intl.NumberFormat(void 0, {
26
+ minimumFractionDigits: r,
27
+ maximumFractionDigits: r
28
+ }).format(t / 10 ** r);
29
+ }
30
+ function c(t, i, a = n()) {
31
+ if (t.trim() === "") return 0;
32
+ let o = Array.from(t, (e) => {
33
+ let t = a.digits.indexOf(e);
34
+ return t === -1 ? e : String(t);
35
+ }).join("");
36
+ a.group && (o = o.replace(new RegExp(r(a.group), "g"), "")), o = o.replace(a.decimal, ".");
37
+ let s = parseFloat(o);
38
+ return Number.isNaN(s) ? 0 : Math.round(s * 10 ** e(i));
39
+ }
40
+ function l(t, r, i, a = n()) {
41
+ let o = c(t, r, a) / 10 ** e(r);
42
+ return s(Math.round(o * 10 ** e(i)), i);
43
+ }
44
+ function u(e) {
45
+ let t = i(e);
46
+ return t.length > 1 && t.startsWith("0") && t[1] !== "." && (t = t.replace(/^0+/, "") || "0"), t === "" || t === "." ? t : Number(t) > 100 ? "100" : t;
47
+ }
48
+ function d(e) {
49
+ return e.endsWith(".") ? e.slice(0, -1) : e;
50
+ }
51
+ function f(e) {
52
+ return Math.round((Number(e) || 0) * 100);
53
+ }
31
54
  function p(e) {
32
- return e === "quotes" ? "quote" : e === "credit_notes" ? "credit_note" : "invoice";
55
+ return (e ?? "taxable") === "taxable";
33
56
  }
34
57
  function m(e) {
35
- return e === "quote" ? "quotes" : e === "credit_note" ? "credit_notes" : "invoices";
58
+ let t = e.find((e) => p(e.tax_status))?.product.tax_rate?.value;
59
+ return t === void 0 ? "" : String(t / 100);
36
60
  }
37
61
  function h(e) {
38
- return (e?.length ? e : [
39
- "invoices",
40
- "quotes",
41
- "credit_notes"
42
- ]).filter((e, t, n) => [
43
- "invoices",
44
- "quotes",
45
- "credit_notes"
46
- ].includes(e) && n.indexOf(e) === t);
47
- }
48
- function g({ defaultTab: e, enabledTabs: t }) {
49
- return e && t.includes(e) ? e : t[0] ?? "invoices";
50
- }
51
- function _(e, n) {
52
- let r = t(e);
53
- return r ? new Intl.DateTimeFormat(void 0, {
54
- day: "numeric",
55
- month: "short",
56
- year: "numeric"
57
- }).format(r) : n;
58
- }
59
- function v({ amount: t, currency: n, fallback: r }) {
60
- return t == null || !n ? r : new Intl.NumberFormat(void 0, {
61
- currency: n,
62
- style: "currency"
63
- }).format(t / 10 ** e(n));
64
- }
65
- function y(t, n) {
66
- let r = Number(t);
67
- if (!Number.isFinite(r)) return;
68
- let i = n ? e(n) : 2;
69
- return Math.round(r * 10 ** i);
70
- }
71
- function b(e, t) {
72
- return e.document_id || t.untitledDocument;
73
- }
74
- function x(e, t) {
75
- return e === "quote" ? t.quoteType : e === "credit_note" ? t.creditNoteType : t.invoiceType;
62
+ try {
63
+ return new Intl.NumberFormat(void 0, {
64
+ style: "currency",
65
+ currency: e
66
+ }).formatToParts(0).find((e) => e.type === "currency")?.value ?? e;
67
+ } catch {
68
+ return e;
69
+ }
76
70
  }
77
- function S(e) {
78
- return e === "paid" || e === "accepted" || e === "issued" || e === "recurring" ? "success" : e === "draft" || e === "issuing" ? "neutral" : e === "overdue" || e === "partially_paid" ? "warning" : e === "failed" || e === "declined" || e === "expired" || e === "uncollectible" || e === "canceled" || e === "deleted" ? "danger" : "info";
79
- }
80
- function C(e) {
81
- let t = e.status === "draft", n = e.status === "issued", r = e.type === "invoice", i = e.type === "quote", a = e.type === "credit_note", o = r && [
82
- "issued",
83
- "overdue",
84
- "partially_paid"
85
- ].includes(e.status);
71
+ function g() {
72
+ return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(16).slice(2)}`;
73
+ }
74
+ function _(e = "USD") {
86
75
  return {
87
- edit: t && !a,
88
- accept: i && n,
89
- cancel: ![
90
- "paid",
91
- "canceled",
92
- "deleted",
93
- "uncollectible"
94
- ].includes(e.status) && !t,
95
- clone: !a && e.status !== "deleted",
96
- decline: i && n,
97
- delete: t,
98
- issue: t,
99
- markPaid: o,
100
- markUncollectible: o,
101
- recordPayment: o,
102
- send: [
103
- "issued",
104
- "accepted",
105
- "overdue",
106
- "partially_paid"
107
- ].includes(e.status) && !a
76
+ id: g(),
77
+ productId: "",
78
+ name: "",
79
+ quantity: "1",
80
+ price: s(0, e),
81
+ measureUnitId: "",
82
+ measureUnitName: "",
83
+ productType: "product",
84
+ taxable: !0
108
85
  };
109
86
  }
110
- function w({ receivables: e, messages: t }) {
111
- return e.map((e) => {
112
- let n = e.type === "invoice" ? e.amount_due : void 0;
113
- return {
114
- id: e.id,
115
- type: e.type,
116
- documentLabel: b(e, t),
117
- customerLabel: e.counterpart_name || t.unknownCustomer,
118
- status: e.status,
119
- statusTone: S(e.status),
120
- issueDateLabel: _(e.issue_date, t.notAvailable),
121
- dueDateLabel: _(e.type === "quote" ? e.expiry_date : e.due_date, t.notAvailable),
122
- totalLabel: v({
123
- amount: e.total_amount,
124
- currency: e.currency,
125
- fallback: t.notAvailable
126
- }),
127
- amountDueLabel: v({
128
- amount: n,
129
- currency: e.currency,
130
- fallback: t.notAvailable
131
- }),
132
- actions: C(e)
133
- };
134
- });
135
- }
136
- function T({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
137
- if (!e) return;
138
- let a = e.type === "invoice" ? e.amount_due : void 0, o = e.type === "quote" ? e.expiry_date : e.due_date;
87
+ function v({ id: e, name: t, quantity: n, price: r, measureUnitId: i, taxable: a }) {
139
88
  return {
140
- id: e.id,
141
- type: e.type,
142
- title: b(e, i),
143
- customerLabel: e.counterpart_name || i.unknownCustomer,
144
- status: e.status,
145
- statusTone: S(e.status),
146
- totalLabel: v({
147
- amount: e.total_amount,
148
- currency: e.currency,
149
- fallback: i.notAvailable
150
- }),
151
- amountDueLabel: v({
152
- amount: a,
153
- currency: e.currency,
154
- fallback: i.notAvailable
155
- }),
156
- pdfUrl: r || e.file_url || e.original_file_url || void 0,
157
- summaryItems: [
158
- {
159
- label: i.summaryDocumentType,
160
- value: x(e.type, i)
161
- },
162
- {
163
- label: i.summaryDocumentNumber,
164
- value: b(e, i)
165
- },
166
- {
167
- label: i.summaryCustomer,
168
- value: e.counterpart_name || i.unknownCustomer
169
- },
170
- {
171
- label: i.summaryIssued,
172
- value: _(e.issue_date, i.notAvailable)
173
- },
174
- {
175
- label: i.summaryDue,
176
- value: _(o, i.notAvailable)
177
- },
178
- {
179
- label: i.summaryCreated,
180
- value: _(e.created_at, i.notAvailable)
181
- },
182
- {
183
- label: i.summaryUpdated,
184
- value: _(e.updated_at, i.notAvailable)
185
- },
186
- {
187
- label: i.summaryTotal,
188
- value: v({
189
- amount: e.total_amount,
190
- currency: e.currency,
191
- fallback: i.notAvailable
192
- })
193
- },
194
- {
195
- label: i.summaryAmountDue,
196
- value: v({
197
- amount: a,
198
- currency: e.currency,
199
- fallback: i.notAvailable
200
- })
201
- }
202
- ],
203
- lineItems: e.line_items.map((t, n) => ({
204
- id: t.product.id || String(n),
205
- name: t.product.name,
206
- quantityLabel: String(t.quantity),
207
- unitPriceLabel: v({
208
- amount: t.product.price?.value,
209
- currency: t.product.price?.currency || e.currency,
210
- fallback: i.notAvailable
211
- }),
212
- totalLabel: v({
213
- amount: t.total_after_tax ?? t.total_before_tax,
214
- currency: e.currency,
215
- fallback: i.notAvailable
216
- })
217
- })),
218
- activityItems: t.map((e) => ({
219
- id: e.id,
220
- title: E(e.event_type, i),
221
- description: e.event_type,
222
- timestampLabel: _(e.timestamp, i.notAvailable)
223
- })),
224
- mailItems: n.map((e) => ({
225
- id: e.id,
226
- statusLabel: e.status,
227
- recipientsLabel: D(e, i),
228
- sentAtLabel: _(e.created_at, i.notAvailable)
229
- })),
230
- actions: C(e)
89
+ id: e,
90
+ name: t,
91
+ quantity: n,
92
+ price: r,
93
+ unit: i,
94
+ taxable: a
231
95
  };
232
96
  }
233
- function E(e, t) {
234
- return e === "status_changed" ? t.activityStatusChanged : e === "receivable_created" ? t.activityReceivableCreated : e === "receivable_updated" ? t.activityReceivableUpdated : e === "payment_received" ? t.activityPaymentReceived : e === "mail_sent" ? t.activityMailSent : t.activityUnknown;
235
- }
236
- function D(e, t) {
237
- let n = [
238
- ...e.recipients?.to ?? [],
239
- ...e.recipients?.cc ?? [],
240
- ...e.recipients?.bcc ?? []
241
- ].map((e) => e.email).filter(Boolean);
242
- return n.length > 0 ? n.join(", ") : t.recipientsNone;
243
- }
244
- function O({ values: e, billingAddressId: t, messages: n }) {
245
- let r = {};
246
- e.customerId ? t || (r.customerId = n.customerAddressRequired) : r.customerId = n.customerRequired, e.currency || (r.currency = n.currencyRequired);
247
- let i = l(e.lineItems, {
248
- currency: e.currency,
249
- messages: n
250
- });
251
- return i && (r.lineItems = i, r.lineItemsSummary = s(i)), r;
252
- }
253
- function k(e) {
254
- return Object.keys(e).length > 0;
255
- }
256
- function A({ values: e, billingAddressId: t, unitNamesById: n }) {
257
- let a = e.lineItems.filter((e) => !r(e)).map((t) => i({
258
- lineItem: t,
259
- currency: e.currency,
260
- taxRate: e.taxRate,
261
- unitNamesById: n
262
- })), o = {
263
- counterpart_billing_address_id: t,
264
- counterpart_id: e.customerId,
265
- currency: e.currency,
266
- line_items: a,
267
- memo: e.openingNote,
268
- footer: e.closingNote
269
- };
270
- return e.type === "quote" ? {
271
- ...o,
272
- expiry_date: e.dueDate || void 0,
273
- type: "quote"
274
- } : {
275
- ...o,
276
- payment_terms_id: e.paymentTermsId || void 0,
277
- payment_terms: !e.paymentTermsId && e.dueDate ? { term_final: { end_date: e.dueDate } } : void 0,
278
- type: "invoice"
279
- };
97
+ function y(e) {
98
+ return !e.name.trim();
280
99
  }
281
- function j(e, t) {
282
- let r = e.type === "quote" ? "quote" : "invoice", i = e.type === "invoice" ? e.payment_terms?.id ?? "" : "", a = e.line_items.map((n) => o({
283
- lineItem: n,
284
- currency: e.currency,
285
- units: t
286
- }));
100
+ function b(e) {
101
+ let t = e.filter((e) => !y(e));
102
+ return t.length > 0 ? t : e.slice(0, 1);
103
+ }
104
+ function x({ product: e, currency: t, unitNamesById: n }) {
105
+ let r = e.measure_unit_id ?? "";
287
106
  return {
288
- ...f(),
289
- type: r,
290
- customerId: e.counterpart_id,
291
- currency: e.currency,
292
- issueDate: P(e.issue_date),
293
- dueDate: P(e.type === "quote" ? e.expiry_date : e.due_date),
294
- openingNote: e.memo ?? "",
295
- closingNote: e.footer ?? "",
296
- paymentTermsId: i,
297
- taxRate: c(e.line_items),
298
- lineItems: a.length > 0 ? a : [n(e.currency)]
107
+ productId: e.id,
108
+ name: e.name,
109
+ quantity: String(e.smallest_amount || 1),
110
+ price: s(e.price?.value ?? 0, t),
111
+ productType: "product",
112
+ ...r && n[r] ? {
113
+ measureUnitId: r,
114
+ measureUnitName: ""
115
+ } : {}
299
116
  };
300
117
  }
301
- function M({ values: e, billingAddressId: t, lineItemChanges: n }) {
302
- let r = {
303
- counterpart_billing_address_id: t,
304
- counterpart_id: e.customerId,
305
- currency: e.currency,
306
- issue_date: e.issueDate || void 0,
307
- memo: e.openingNote,
308
- footer: e.closingNote
118
+ function S(e) {
119
+ return e.quantity === void 0 ? e : {
120
+ ...e,
121
+ quantity: i(e.quantity)
309
122
  };
310
- return e.type === "quote" ? { quote: {
311
- ...r,
312
- ...n ? { line_items: n } : {},
313
- expiry_date: e.dueDate || void 0,
314
- payment_terms_id: e.paymentTermsId || void 0
315
- } } : { invoice: {
316
- ...r,
317
- ...n ? { line_items: n } : {},
318
- due_date: e.dueDate || void 0,
319
- payment_terms_id: e.paymentTermsId || void 0,
320
- payment_terms: !e.paymentTermsId && e.dueDate ? { term_final: { end_date: e.dueDate } } : void 0
321
- } };
322
- }
323
- function N({ values: e, originalLineItems: t, originalCurrency: n, unitNamesById: i, units: s }) {
324
- let l = (e, t, n) => a({
325
- lineItem: e,
326
- currency: t,
327
- taxRate: n,
328
- unitNamesById: i
329
- }), u = c(t), d = new Map(t.map((e) => [e.id, JSON.stringify(l(o({
330
- lineItem: e,
331
- currency: n,
332
- units: s
333
- }), n, u))])), f = e.lineItems.filter((e) => !r(e)), p = new Set(f.map((e) => e.id)), m = f.filter((e) => !d.has(e.id)).map((t) => l(t, e.currency, e.taxRate)), h = f.flatMap((t) => {
334
- let n = d.get(t.id);
335
- if (n === void 0) return [];
336
- let r = l(t, e.currency, e.taxRate);
337
- return n === JSON.stringify(r) ? [] : [{
338
- id: t.id,
339
- data: r
340
- }];
341
- }), g = t.filter((e) => !p.has(e.id)).map((e) => e.id);
342
- if (m.length || h.length || g.length) return {
343
- ...m.length ? { add: m } : {},
344
- ...h.length ? { replace: h } : {},
345
- ...g.length ? { remove: g } : {}
123
+ }
124
+ function C({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n() }) {
125
+ if (t === "price") return {
126
+ kind: "update",
127
+ patch: { price: s(c(e.price, l, u), l) }
128
+ };
129
+ let d = o(a(i(e.quantity)));
130
+ return d <= 0 ? r > 1 ? { kind: "remove" } : {
131
+ kind: "update",
132
+ patch: { quantity: "1" }
133
+ } : {
134
+ kind: "update",
135
+ patch: { quantity: String(d) }
346
136
  };
347
137
  }
348
- function P(e) {
349
- return e?.slice(0, 10) ?? "";
138
+ function w({ lineItem: e, step: t, rowCount: n }) {
139
+ if (y(e)) return;
140
+ let r = o(Math.max(0, a(e.quantity)) + t);
141
+ return r <= 0 && n > 1 ? { kind: "remove" } : {
142
+ kind: "update",
143
+ patch: { quantity: String(Math.max(n > 1 ? 0 : 1, r)) }
144
+ };
350
145
  }
351
- function F(e) {
352
- return (e ?? []).map((e) => ({
353
- value: e.id,
354
- label: e.name
146
+ function T(e) {
147
+ return Object.fromEntries(e.map((t) => {
148
+ let n = !y(t), r = a(t.quantity);
149
+ return [t.id, {
150
+ canDecreaseQuantity: n && (e.length > 1 || r > 1),
151
+ canIncreaseQuantity: n
152
+ }];
355
153
  }));
356
154
  }
357
- function I(e, t) {
358
- let n = {};
359
- return e.to.trim() || (n.to = t.sendToRequired), e.subject.trim() || (n.subject = t.sendSubjectRequired), e.body.trim() || (n.body = t.sendBodyRequired), n;
360
- }
361
- function L(e) {
362
- return Object.keys(e).length > 0;
363
- }
364
- function R(e) {
365
- return e.split(",").map((e) => e.trim()).filter(Boolean);
366
- }
367
- function z(e, t, n) {
368
- let r = {};
369
- if (e.mode === "partial") {
370
- let i = y(e.amountPaid, n);
371
- (!i || i <= 0) && (r.amountPaid = t.paymentAmountInvalid);
372
- }
373
- return r;
155
+ function E(e, t) {
156
+ return {
157
+ tax_status: e.taxable ? "taxable" : "non_taxable",
158
+ tax_rate_value: e.taxable ? f(t) : void 0
159
+ };
374
160
  }
375
- function B(e) {
376
- return Object.keys(e).length > 0;
161
+ function D({ lineItem: e, currency: t, taxRate: n, unitNamesById: r }) {
162
+ let i = e.measureUnitId ? r[e.measureUnitId] : void 0, { tax_status: o, tax_rate_value: s } = E(e, n);
163
+ return {
164
+ quantity: a(e.quantity),
165
+ tax_status: o,
166
+ product: {
167
+ name: e.name,
168
+ price: {
169
+ currency: t,
170
+ value: c(e.price, t)
171
+ },
172
+ measure_unit: i ? { name: i } : void 0,
173
+ type: "product"
174
+ },
175
+ tax_rate_value: s
176
+ };
377
177
  }
378
- function V(e, t) {
178
+ function O({ lineItem: e, currency: t, taxRate: n, unitNamesById: r }) {
179
+ let i = e.measureUnitId && r[e.measureUnitId] || e.measureUnitName || void 0, { tax_status: o, tax_rate_value: s } = E(e, n);
379
180
  return {
380
- ...u,
381
- to: e?.counterpart_contact?.email ?? "",
382
- subject: e?.document_id ? `${t.sendSubjectDefault} ${e.document_id}` : t.sendSubjectDefault,
383
- body: t.sendBodyDefault
181
+ quantity: a(e.quantity),
182
+ tax_status: o,
183
+ product: {
184
+ name: e.name,
185
+ type: e.productType,
186
+ measure_unit: i ? { name: i } : void 0,
187
+ price: {
188
+ currency: t,
189
+ value: c(e.price, t)
190
+ }
191
+ },
192
+ tax_rate_value: s
384
193
  };
385
194
  }
386
- function H() {
195
+ function k({ lineItem: e, currency: t, units: n }) {
196
+ let r = e.product.measure_unit;
387
197
  return {
388
- ...d,
389
- paidAt: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
198
+ id: e.id,
199
+ productId: e.product.id,
200
+ name: e.product.name,
201
+ quantity: String(e.quantity),
202
+ price: s(e.product.price?.value ?? 0, t),
203
+ measureUnitId: j(r?.id ?? "", r?.name ?? "", n),
204
+ measureUnitName: r?.name ?? "",
205
+ productType: e.product.type ?? "product",
206
+ taxable: p(e.tax_status)
390
207
  };
391
208
  }
392
- function U() {
393
- return [
394
- "draft",
395
- "issued",
396
- "failed",
397
- "accepted",
398
- "expired",
399
- "declined",
400
- "recurring",
401
- "partially_paid",
402
- "paid",
403
- "overdue",
404
- "uncollectible",
405
- "canceled"
406
- ].map((e) => ({
407
- value: e,
408
- label: e.split("_").map((e) => `${e.slice(0, 1).toUpperCase()}${e.slice(1)}`).join(" ")
409
- }));
209
+ function A(e, t) {
210
+ if (!t) return;
211
+ let n = t.toLowerCase();
212
+ return e.find((e) => e.name.toLowerCase() === n);
213
+ }
214
+ function j(e, t, n) {
215
+ return n?.length ? ((e ? n.find((t) => t.id === e) : void 0) ?? A(n, t))?.id ?? (t ? "" : e) : e;
216
+ }
217
+ function M(e, t) {
218
+ let n = !1, r = e.map((e) => {
219
+ let r = j(e.measureUnitId, e.measureUnitName, t);
220
+ return r === e.measureUnitId ? e : (n = !0, {
221
+ ...e,
222
+ measureUnitId: r
223
+ });
224
+ });
225
+ return n ? r : e;
226
+ }
227
+ function N(n) {
228
+ return new Intl.NumberFormat().format(t / 10 ** e(n));
229
+ }
230
+ function P(e, { currency: n, messages: r }) {
231
+ let i = {};
232
+ for (let a of e) {
233
+ let e = {};
234
+ a.name.length > 100 && (e.name = r.lineItemNameTooLong), c(a.price, n) > t && (e.price = r.lineItemPriceTooHigh.replace("{maxAmount}", N(n))), Object.keys(e).length > 0 && (i[a.id] = e);
235
+ }
236
+ return Object.keys(i).length > 0 ? i : void 0;
237
+ }
238
+ function F(e) {
239
+ if (!e) return;
240
+ let t = Object.values(e), n = [
241
+ "name",
242
+ "quantity",
243
+ "price",
244
+ "measureUnit"
245
+ ].map((e) => t.find((t) => t[e])?.[e]).filter((e) => !!e);
246
+ return n.length > 0 ? n : void 0;
410
247
  }
411
248
  //#endregion
412
- export { d as EMPTY_RECEIVABLE_PAYMENT_VALUES, u as EMPTY_RECEIVABLE_SEND_VALUES, C as buildReceivableActions, T as buildReceivableDetailsView, w as buildReceivableRows, h as coerceEnabledTabs, f as createEmptyReceivableFormValues, n as createLineItem, H as defaultPaymentValues, V as defaultSendValues, _ as formatDate, v as formatMoney, y as fromMajorUnits, b as getDocumentTitle, x as getDocumentTypeLabel, F as getPaymentTermOptions, S as getStatusTone, B as hasPaymentErrors, k as hasReceivableFormErrors, L as hasSendErrors, A as receivableFormValuesToCreatePayload, N as receivableFormValuesToLineItemChanges, M as receivableFormValuesToUpdatePayload, j as receivableToFormValues, g as resolveInitialTab, R as splitEmailList, U as statusFilterOptions, m as tabForType, p as typeForTab, z as validatePaymentValues, O as validateReceivableForm, I as validateSendValues };
249
+ export { T as buildLineItemControls, C as commitLineItemField, d as commitTaxRateInput, l as convertPriceInput, _ as createLineItem, s as formatPriceInput, h as getCurrencySymbol, n as getNumberSeparators, y as isBlankLineItem, p as isLineItemTaxable, x as lineItemFromProduct, D as lineItemToCreatePayload, O as lineItemToUpdatePayload, a as parseQuantity, c as priceInputToMinorUnits, M as reconcileMeasureUnits, k as responseLineItemToFormValues, S as sanitizeLineItemPatch, i as sanitizeQuantityInput, u as sanitizeTaxRateInput, w as stepLineItemQuantity, b as stripBlankLineItems, F as summarizeLineItemErrors, m as taxRateFromLineItems, f as taxRateToMinorUnits, v as toSheetLineItem, P as validateLineItems };