@tesouro/embedded-components-react 0.5.194 → 0.5.196

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