@tesouro/embedded-components-react 0.5.200 → 0.5.202

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