@tesouro/embedded-components-react 0.5.200 → 0.5.201

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.
@@ -42,6 +42,23 @@ function l(t, r, i, a = n()) {
42
42
  return s(Math.round(o * 10 ** e(i)), i);
43
43
  }
44
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
+ }
54
+ function p(e) {
55
+ return (e ?? "taxable") === "taxable";
56
+ }
57
+ function m(e) {
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) {
45
62
  try {
46
63
  return new Intl.NumberFormat(void 0, {
47
64
  style: "currency",
@@ -51,38 +68,40 @@ function u(e) {
51
68
  return e;
52
69
  }
53
70
  }
54
- function d() {
71
+ function g() {
55
72
  return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(16).slice(2)}`;
56
73
  }
57
- function f(e = "USD") {
74
+ function _(e = "USD") {
58
75
  return {
59
- id: d(),
76
+ id: g(),
60
77
  productId: "",
61
78
  name: "",
62
79
  quantity: "1",
63
80
  price: s(0, e),
64
81
  measureUnitId: "",
65
82
  measureUnitName: "",
66
- productType: "product"
83
+ productType: "product",
84
+ taxable: !0
67
85
  };
68
86
  }
69
- function p({ id: e, name: t, quantity: n, price: r, measureUnitId: i }) {
87
+ function v({ id: e, name: t, quantity: n, price: r, measureUnitId: i, taxable: a }) {
70
88
  return {
71
89
  id: e,
72
90
  name: t,
73
91
  quantity: n,
74
92
  price: r,
75
- unit: i
93
+ unit: i,
94
+ taxable: a
76
95
  };
77
96
  }
78
- function m(e) {
97
+ function y(e) {
79
98
  return !e.name.trim();
80
99
  }
81
- function h(e) {
82
- let t = e.filter((e) => !m(e));
100
+ function b(e) {
101
+ let t = e.filter((e) => !y(e));
83
102
  return t.length > 0 ? t : e.slice(0, 1);
84
103
  }
85
- function g({ product: e, currency: t, unitNamesById: n }) {
104
+ function x({ product: e, currency: t, unitNamesById: n }) {
86
105
  let r = e.measure_unit_id ?? "";
87
106
  return {
88
107
  productId: e.id,
@@ -96,13 +115,13 @@ function g({ product: e, currency: t, unitNamesById: n }) {
96
115
  } : {}
97
116
  };
98
117
  }
99
- function _(e) {
118
+ function S(e) {
100
119
  return e.quantity === void 0 ? e : {
101
120
  ...e,
102
121
  quantity: i(e.quantity)
103
122
  };
104
123
  }
105
- function v({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n() }) {
124
+ function C({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n() }) {
106
125
  if (t === "price") return {
107
126
  kind: "update",
108
127
  patch: { price: s(c(e.price, l, u), l) }
@@ -116,54 +135,64 @@ function v({ lineItem: e, field: t, rowCount: r, currency: l, separators: u = n(
116
135
  patch: { quantity: String(d) }
117
136
  };
118
137
  }
119
- function y({ lineItem: e, step: t, rowCount: n }) {
120
- if (m(e)) return;
138
+ function w({ lineItem: e, step: t, rowCount: n }) {
139
+ if (y(e)) return;
121
140
  let r = o(Math.max(0, a(e.quantity)) + t);
122
141
  return r <= 0 && n > 1 ? { kind: "remove" } : {
123
142
  kind: "update",
124
143
  patch: { quantity: String(Math.max(n > 1 ? 0 : 1, r)) }
125
144
  };
126
145
  }
127
- function b(e) {
146
+ function T(e) {
128
147
  return Object.fromEntries(e.map((t) => {
129
- let n = !m(t), r = a(t.quantity);
148
+ let n = !y(t), r = a(t.quantity);
130
149
  return [t.id, {
131
150
  canDecreaseQuantity: n && (e.length > 1 || r > 1),
132
151
  canIncreaseQuantity: n
133
152
  }];
134
153
  }));
135
154
  }
136
- function x({ lineItem: e, currency: t, unitNamesById: n }) {
137
- let r = e.measureUnitId ? n[e.measureUnitId] : void 0;
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
+ };
160
+ }
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);
138
163
  return {
139
164
  quantity: a(e.quantity),
165
+ tax_status: o,
140
166
  product: {
141
167
  name: e.name,
142
168
  price: {
143
169
  currency: t,
144
170
  value: c(e.price, t)
145
171
  },
146
- measure_unit: r ? { name: r } : void 0,
172
+ measure_unit: i ? { name: i } : void 0,
147
173
  type: "product"
148
- }
174
+ },
175
+ tax_rate_value: s
149
176
  };
150
177
  }
151
- function S({ lineItem: e, currency: t, unitNamesById: n }) {
152
- let r = e.measureUnitId && n[e.measureUnitId] || e.measureUnitName || void 0;
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);
153
180
  return {
154
181
  quantity: a(e.quantity),
182
+ tax_status: o,
155
183
  product: {
156
184
  name: e.name,
157
185
  type: e.productType,
158
- measure_unit: r ? { name: r } : void 0,
186
+ measure_unit: i ? { name: i } : void 0,
159
187
  price: {
160
188
  currency: t,
161
189
  value: c(e.price, t)
162
190
  }
163
- }
191
+ },
192
+ tax_rate_value: s
164
193
  };
165
194
  }
166
- function C({ lineItem: e, currency: t, units: n }) {
195
+ function k({ lineItem: e, currency: t, units: n }) {
167
196
  let r = e.product.measure_unit;
168
197
  return {
169
198
  id: e.id,
@@ -171,22 +200,23 @@ function C({ lineItem: e, currency: t, units: n }) {
171
200
  name: e.product.name,
172
201
  quantity: String(e.quantity),
173
202
  price: s(e.product.price?.value ?? 0, t),
174
- measureUnitId: T(r?.id ?? "", r?.name ?? "", n),
203
+ measureUnitId: j(r?.id ?? "", r?.name ?? "", n),
175
204
  measureUnitName: r?.name ?? "",
176
- productType: e.product.type ?? "product"
205
+ productType: e.product.type ?? "product",
206
+ taxable: p(e.tax_status)
177
207
  };
178
208
  }
179
- function w(e, t) {
209
+ function A(e, t) {
180
210
  if (!t) return;
181
211
  let n = t.toLowerCase();
182
212
  return e.find((e) => e.name.toLowerCase() === n);
183
213
  }
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;
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;
186
216
  }
187
- function E(e, t) {
217
+ function M(e, t) {
188
218
  let n = !1, r = e.map((e) => {
189
- let r = T(e.measureUnitId, e.measureUnitName, t);
219
+ let r = j(e.measureUnitId, e.measureUnitName, t);
190
220
  return r === e.measureUnitId ? e : (n = !0, {
191
221
  ...e,
192
222
  measureUnitId: r
@@ -194,18 +224,18 @@ function E(e, t) {
194
224
  });
195
225
  return n ? r : e;
196
226
  }
197
- function D(n) {
227
+ function N(n) {
198
228
  return new Intl.NumberFormat().format(t / 10 ** e(n));
199
229
  }
200
- function O(e, { currency: n, messages: r }) {
230
+ function P(e, { currency: n, messages: r }) {
201
231
  let i = {};
202
232
  for (let a of e) {
203
233
  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);
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);
205
235
  }
206
236
  return Object.keys(i).length > 0 ? i : void 0;
207
237
  }
208
- function k(e) {
238
+ function F(e) {
209
239
  if (!e) return;
210
240
  let t = Object.values(e), n = [
211
241
  "name",
@@ -216,4 +246,4 @@ function k(e) {
216
246
  return n.length > 0 ? n : void 0;
217
247
  }
218
248
  //#endregion
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 };
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 };
@@ -1,20 +1,20 @@
1
1
  import { minorExponentForCurrency as e } from "../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
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";
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
4
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/index6.js
5
- var l = {
5
+ var u = {
6
6
  to: "",
7
7
  cc: "",
8
8
  bcc: "",
9
9
  subject: "",
10
10
  body: ""
11
- }, u = {
11
+ }, d = {
12
12
  mode: "full",
13
13
  amountPaid: "",
14
14
  paidAt: "",
15
15
  comment: ""
16
16
  };
17
- function d() {
17
+ function f() {
18
18
  return {
19
19
  type: "invoice",
20
20
  customerId: "",
@@ -24,16 +24,17 @@ function d() {
24
24
  openingNote: "",
25
25
  closingNote: "",
26
26
  paymentTermsId: "",
27
+ taxRate: "",
27
28
  lineItems: [n()]
28
29
  };
29
30
  }
30
- function f(e) {
31
+ function p(e) {
31
32
  return e === "quotes" ? "quote" : e === "credit_notes" ? "credit_note" : "invoice";
32
33
  }
33
- function p(e) {
34
+ function m(e) {
34
35
  return e === "quote" ? "quotes" : e === "credit_note" ? "credit_notes" : "invoices";
35
36
  }
36
- function m(e) {
37
+ function h(e) {
37
38
  return (e?.length ? e : [
38
39
  "invoices",
39
40
  "quotes",
@@ -44,10 +45,10 @@ function m(e) {
44
45
  "credit_notes"
45
46
  ].includes(e) && n.indexOf(e) === t);
46
47
  }
47
- function h({ defaultTab: e, enabledTabs: t }) {
48
+ function g({ defaultTab: e, enabledTabs: t }) {
48
49
  return e && t.includes(e) ? e : t[0] ?? "invoices";
49
50
  }
50
- function g(e, n) {
51
+ function _(e, n) {
51
52
  let r = t(e);
52
53
  return r ? new Intl.DateTimeFormat(void 0, {
53
54
  day: "numeric",
@@ -55,28 +56,28 @@ function g(e, n) {
55
56
  year: "numeric"
56
57
  }).format(r) : n;
57
58
  }
58
- function _({ amount: t, currency: n, fallback: r }) {
59
+ function v({ amount: t, currency: n, fallback: r }) {
59
60
  return t == null || !n ? r : new Intl.NumberFormat(void 0, {
60
61
  currency: n,
61
62
  style: "currency"
62
63
  }).format(t / 10 ** e(n));
63
64
  }
64
- function v(t, n) {
65
+ function y(t, n) {
65
66
  let r = Number(t);
66
67
  if (!Number.isFinite(r)) return;
67
68
  let i = n ? e(n) : 2;
68
69
  return Math.round(r * 10 ** i);
69
70
  }
70
- function y(e, t) {
71
+ function b(e, t) {
71
72
  return e.document_id || t.untitledDocument;
72
73
  }
73
- function b(e, t) {
74
+ function x(e, t) {
74
75
  return e === "quote" ? t.quoteType : e === "credit_note" ? t.creditNoteType : t.invoiceType;
75
76
  }
76
- function x(e) {
77
+ function S(e) {
77
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";
78
79
  }
79
- function S(e) {
80
+ function C(e) {
80
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 && [
81
82
  "issued",
82
83
  "overdue",
@@ -106,48 +107,48 @@ function S(e) {
106
107
  ].includes(e.status) && !a
107
108
  };
108
109
  }
109
- function C({ receivables: e, messages: t }) {
110
+ function w({ receivables: e, messages: t }) {
110
111
  return e.map((e) => {
111
112
  let n = e.type === "invoice" ? e.amount_due : void 0;
112
113
  return {
113
114
  id: e.id,
114
115
  type: e.type,
115
- documentLabel: y(e, t),
116
+ documentLabel: b(e, t),
116
117
  customerLabel: e.counterpart_name || t.unknownCustomer,
117
118
  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: _({
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({
122
123
  amount: e.total_amount,
123
124
  currency: e.currency,
124
125
  fallback: t.notAvailable
125
126
  }),
126
- amountDueLabel: _({
127
+ amountDueLabel: v({
127
128
  amount: n,
128
129
  currency: e.currency,
129
130
  fallback: t.notAvailable
130
131
  }),
131
- actions: S(e)
132
+ actions: C(e)
132
133
  };
133
134
  });
134
135
  }
135
- function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
136
+ function T({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
136
137
  if (!e) return;
137
138
  let a = e.type === "invoice" ? e.amount_due : void 0, o = e.type === "quote" ? e.expiry_date : e.due_date;
138
139
  return {
139
140
  id: e.id,
140
141
  type: e.type,
141
- title: y(e, i),
142
+ title: b(e, i),
142
143
  customerLabel: e.counterpart_name || i.unknownCustomer,
143
144
  status: e.status,
144
- statusTone: x(e.status),
145
- totalLabel: _({
145
+ statusTone: S(e.status),
146
+ totalLabel: v({
146
147
  amount: e.total_amount,
147
148
  currency: e.currency,
148
149
  fallback: i.notAvailable
149
150
  }),
150
- amountDueLabel: _({
151
+ amountDueLabel: v({
151
152
  amount: a,
152
153
  currency: e.currency,
153
154
  fallback: i.notAvailable
@@ -156,11 +157,11 @@ function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
156
157
  summaryItems: [
157
158
  {
158
159
  label: i.summaryDocumentType,
159
- value: b(e.type, i)
160
+ value: x(e.type, i)
160
161
  },
161
162
  {
162
163
  label: i.summaryDocumentNumber,
163
- value: y(e, i)
164
+ value: b(e, i)
164
165
  },
165
166
  {
166
167
  label: i.summaryCustomer,
@@ -168,23 +169,23 @@ function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
168
169
  },
169
170
  {
170
171
  label: i.summaryIssued,
171
- value: g(e.issue_date, i.notAvailable)
172
+ value: _(e.issue_date, i.notAvailable)
172
173
  },
173
174
  {
174
175
  label: i.summaryDue,
175
- value: g(o, i.notAvailable)
176
+ value: _(o, i.notAvailable)
176
177
  },
177
178
  {
178
179
  label: i.summaryCreated,
179
- value: g(e.created_at, i.notAvailable)
180
+ value: _(e.created_at, i.notAvailable)
180
181
  },
181
182
  {
182
183
  label: i.summaryUpdated,
183
- value: g(e.updated_at, i.notAvailable)
184
+ value: _(e.updated_at, i.notAvailable)
184
185
  },
185
186
  {
186
187
  label: i.summaryTotal,
187
- value: _({
188
+ value: v({
188
189
  amount: e.total_amount,
189
190
  currency: e.currency,
190
191
  fallback: i.notAvailable
@@ -192,7 +193,7 @@ function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
192
193
  },
193
194
  {
194
195
  label: i.summaryAmountDue,
195
- value: _({
196
+ value: v({
196
197
  amount: a,
197
198
  currency: e.currency,
198
199
  fallback: i.notAvailable
@@ -203,12 +204,12 @@ function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
203
204
  id: t.product.id || String(n),
204
205
  name: t.product.name,
205
206
  quantityLabel: String(t.quantity),
206
- unitPriceLabel: _({
207
+ unitPriceLabel: v({
207
208
  amount: t.product.price?.value,
208
209
  currency: t.product.price?.currency || e.currency,
209
210
  fallback: i.notAvailable
210
211
  }),
211
- totalLabel: _({
212
+ totalLabel: v({
212
213
  amount: t.total_after_tax ?? t.total_before_tax,
213
214
  currency: e.currency,
214
215
  fallback: i.notAvailable
@@ -216,23 +217,23 @@ function w({ receivable: e, history: t, mails: n, pdfUrl: r, messages: i }) {
216
217
  })),
217
218
  activityItems: t.map((e) => ({
218
219
  id: e.id,
219
- title: T(e.event_type, i),
220
+ title: E(e.event_type, i),
220
221
  description: e.event_type,
221
- timestampLabel: g(e.timestamp, i.notAvailable)
222
+ timestampLabel: _(e.timestamp, i.notAvailable)
222
223
  })),
223
224
  mailItems: n.map((e) => ({
224
225
  id: e.id,
225
226
  statusLabel: e.status,
226
- recipientsLabel: E(e, i),
227
- sentAtLabel: g(e.created_at, i.notAvailable)
227
+ recipientsLabel: D(e, i),
228
+ sentAtLabel: _(e.created_at, i.notAvailable)
228
229
  })),
229
- actions: S(e)
230
+ actions: C(e)
230
231
  };
231
232
  }
232
- function T(e, t) {
233
+ function E(e, t) {
233
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;
234
235
  }
235
- function E(e, t) {
236
+ function D(e, t) {
236
237
  let n = [
237
238
  ...e.recipients?.to ?? [],
238
239
  ...e.recipients?.cc ?? [],
@@ -240,22 +241,23 @@ function E(e, t) {
240
241
  ].map((e) => e.email).filter(Boolean);
241
242
  return n.length > 0 ? n.join(", ") : t.recipientsNone;
242
243
  }
243
- function D({ values: e, billingAddressId: t, messages: n }) {
244
+ function O({ values: e, billingAddressId: t, messages: n }) {
244
245
  let r = {};
245
246
  e.customerId ? t || (r.customerId = n.customerAddressRequired) : r.customerId = n.customerRequired, e.currency || (r.currency = n.currencyRequired);
246
- let i = c(e.lineItems, {
247
+ let i = l(e.lineItems, {
247
248
  currency: e.currency,
248
249
  messages: n
249
250
  });
250
251
  return i && (r.lineItems = i, r.lineItemsSummary = s(i)), r;
251
252
  }
252
- function O(e) {
253
+ function k(e) {
253
254
  return Object.keys(e).length > 0;
254
255
  }
255
- function k({ values: e, billingAddressId: t, unitNamesById: n }) {
256
+ function A({ values: e, billingAddressId: t, unitNamesById: n }) {
256
257
  let a = e.lineItems.filter((e) => !r(e)).map((t) => i({
257
258
  lineItem: t,
258
259
  currency: e.currency,
260
+ taxRate: e.taxRate,
259
261
  unitNamesById: n
260
262
  })), o = {
261
263
  counterpart_billing_address_id: t,
@@ -276,26 +278,27 @@ function k({ values: e, billingAddressId: t, unitNamesById: n }) {
276
278
  type: "invoice"
277
279
  };
278
280
  }
279
- function A(e, t) {
281
+ function j(e, t) {
280
282
  let r = e.type === "quote" ? "quote" : "invoice", i = e.type === "invoice" ? e.payment_terms?.id ?? "" : "", a = e.line_items.map((n) => o({
281
283
  lineItem: n,
282
284
  currency: e.currency,
283
285
  units: t
284
286
  }));
285
287
  return {
286
- ...d(),
288
+ ...f(),
287
289
  type: r,
288
290
  customerId: e.counterpart_id,
289
291
  currency: e.currency,
290
- issueDate: N(e.issue_date),
291
- dueDate: N(e.type === "quote" ? e.expiry_date : e.due_date),
292
+ issueDate: P(e.issue_date),
293
+ dueDate: P(e.type === "quote" ? e.expiry_date : e.due_date),
292
294
  openingNote: e.memo ?? "",
293
295
  closingNote: e.footer ?? "",
294
296
  paymentTermsId: i,
297
+ taxRate: c(e.line_items),
295
298
  lineItems: a.length > 0 ? a : [n(e.currency)]
296
299
  };
297
300
  }
298
- function j({ values: e, billingAddressId: t, lineItemChanges: n }) {
301
+ function M({ values: e, billingAddressId: t, lineItemChanges: n }) {
299
302
  let r = {
300
303
  counterpart_billing_address_id: t,
301
304
  counterpart_id: e.customerId,
@@ -317,75 +320,76 @@ function j({ values: e, billingAddressId: t, lineItemChanges: n }) {
317
320
  payment_terms: !e.paymentTermsId && e.dueDate ? { term_final: { end_date: e.dueDate } } : void 0
318
321
  } };
319
322
  }
320
- function M({ values: e, originalLineItems: t, originalCurrency: n, unitNamesById: i, units: s }) {
321
- let c = (e, t) => a({
323
+ function N({ values: e, originalLineItems: t, originalCurrency: n, unitNamesById: i, units: s }) {
324
+ let l = (e, t, n) => a({
322
325
  lineItem: e,
323
326
  currency: t,
327
+ taxRate: n,
324
328
  unitNamesById: i
325
- }), l = new Map(t.map((e) => [e.id, JSON.stringify(c(o({
329
+ }), u = c(t), d = new Map(t.map((e) => [e.id, JSON.stringify(l(o({
326
330
  lineItem: e,
327
331
  currency: n,
328
332
  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);
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);
331
335
  if (n === void 0) return [];
332
- let r = c(t, e.currency);
336
+ let r = l(t, e.currency, e.taxRate);
333
337
  return n === JSON.stringify(r) ? [] : [{
334
338
  id: t.id,
335
339
  data: r
336
340
  }];
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 } : {}
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 } : {}
342
346
  };
343
347
  }
344
- function N(e) {
348
+ function P(e) {
345
349
  return e?.slice(0, 10) ?? "";
346
350
  }
347
- function P(e) {
351
+ function F(e) {
348
352
  return (e ?? []).map((e) => ({
349
353
  value: e.id,
350
354
  label: e.name
351
355
  }));
352
356
  }
353
- function F(e, t) {
357
+ function I(e, t) {
354
358
  let n = {};
355
359
  return e.to.trim() || (n.to = t.sendToRequired), e.subject.trim() || (n.subject = t.sendSubjectRequired), e.body.trim() || (n.body = t.sendBodyRequired), n;
356
360
  }
357
- function I(e) {
361
+ function L(e) {
358
362
  return Object.keys(e).length > 0;
359
363
  }
360
- function L(e) {
364
+ function R(e) {
361
365
  return e.split(",").map((e) => e.trim()).filter(Boolean);
362
366
  }
363
- function R(e, t, n) {
367
+ function z(e, t, n) {
364
368
  let r = {};
365
369
  if (e.mode === "partial") {
366
- let i = v(e.amountPaid, n);
370
+ let i = y(e.amountPaid, n);
367
371
  (!i || i <= 0) && (r.amountPaid = t.paymentAmountInvalid);
368
372
  }
369
373
  return r;
370
374
  }
371
- function z(e) {
375
+ function B(e) {
372
376
  return Object.keys(e).length > 0;
373
377
  }
374
- function B(e, t) {
378
+ function V(e, t) {
375
379
  return {
376
- ...l,
380
+ ...u,
377
381
  to: e?.counterpart_contact?.email ?? "",
378
382
  subject: e?.document_id ? `${t.sendSubjectDefault} ${e.document_id}` : t.sendSubjectDefault,
379
383
  body: t.sendBodyDefault
380
384
  };
381
385
  }
382
- function V() {
386
+ function H() {
383
387
  return {
384
- ...u,
388
+ ...d,
385
389
  paidAt: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)
386
390
  };
387
391
  }
388
- function H() {
392
+ function U() {
389
393
  return [
390
394
  "draft",
391
395
  "issued",
@@ -405,4 +409,4 @@ function H() {
405
409
  }));
406
410
  }
407
411
  //#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 };
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 };