@zeniai/client-epic-state 5.2.83 → 5.2.85

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.
@@ -1,4 +1,3 @@
1
- import { isCustomerTransaction, } from '../../../entity/transaction/stateTypes/customerTransaction';
2
1
  import { isVendorTransaction } from '../../../entity/transaction/stateTypes/vendorTransaction';
3
2
  import { isEntityMatching, mergeTransactionAndEntityRecommendationsWithCOT, toLineEntity, } from '../../transactionDetail/transactionDetailLocalDataHelper';
4
3
  import { isAccountUncategorized } from '../../transactionDetail/transactionDetailLocalDataHelper';
@@ -209,10 +208,7 @@ const buildLineItemById = (transaction, recommendations) => {
209
208
  logo: accountLine.vendor.logo,
210
209
  }
211
210
  : undefined;
212
- const customer = accountLine.customer ??
213
- (isCustomerTransaction(transaction) === true
214
- ? transaction.customer
215
- : undefined);
211
+ const customer = accountLine.customer;
216
212
  record.customer =
217
213
  customer != null && Boolean(customer.id) && Boolean(customer.name)
218
214
  ? {
@@ -59,59 +59,11 @@ export const localDataToSaveInvoicingSubscriptionPayload = (localData, shippingA
59
59
  };
60
60
  };
61
61
  const toEstimateDate = (value) => value != null && value !== '' ? date(value) : undefined;
62
- const isItemLevelCoupon = (discount) => discount.entity_type === 'item_level_coupon';
63
- const isCoupon = (discount) => discount.entity_type === 'document_level_coupon' ||
64
- discount.entity_type === 'item_level_coupon';
65
- /**
66
- * Name the coupon behind a line's discount. Exact when the API links a coupon
67
- * row to its line (`line_item_id`); otherwise only when a single item-level
68
- * coupon applies, since then every discounted line got that one.
69
- */
70
- const lineDiscountLabel = (lineItem, discounts) => {
71
- if (lineItem.discount_amount <= 0) {
72
- return undefined;
73
- }
74
- const itemCoupons = discounts.filter(isItemLevelCoupon);
75
- const linked = lineItem.id != null
76
- ? itemCoupons.filter((coupon) => coupon.line_item_id === lineItem.id)
77
- : [];
78
- if (linked.length > 0) {
79
- return [...new Set(linked.map((coupon) => coupon.description))].join(', ');
80
- }
81
- const names = [...new Set(itemCoupons.map((coupon) => coupon.description))];
82
- return names.length === 1 ? names[0] : undefined;
83
- };
84
- /**
85
- * One row per coupon. An item-level coupon comes back once per line it
86
- * discounted, so its rows are summed; listing each would read as the same
87
- * discount taken several times.
88
- */
89
- const mergeCouponRows = (discounts) => {
90
- const rowsByCoupon = new Map();
91
- discounts.filter(isCoupon).forEach((coupon) => {
92
- // The API sends `entity_id: ""` when it has none; key those by name so
93
- // two unrelated coupons are not merged into one row.
94
- const couponKey = coupon.entity_id != null && coupon.entity_id !== ''
95
- ? coupon.entity_id
96
- : coupon.description;
97
- const key = `${coupon.entity_type}:${couponKey}`;
98
- const row = rowsByCoupon.get(key);
99
- rowsByCoupon.set(key, {
100
- amount: Math.round(((row?.amount ?? 0) + coupon.amount) * 100) / 100,
101
- description: coupon.description,
102
- });
103
- });
104
- return [...rowsByCoupon.values()];
105
- };
106
62
  const mapInvoiceEstimate = (payload, money) => payload == null
107
63
  ? undefined
108
64
  : {
109
65
  amountDue: money(payload.amount_due),
110
66
  couponDiscountTotal: money(payload.coupon_discount_total),
111
- coupons: mergeCouponRows(payload.discounts ?? []).map((coupon) => ({
112
- amount: money(coupon.amount),
113
- description: coupon.description,
114
- })),
115
67
  creditsApplied: money(payload.credits_applied),
116
68
  dueDate: toEstimateDate(payload.due_date),
117
69
  grossSubTotal: money(payload.gross_sub_total),
@@ -122,8 +74,6 @@ const mapInvoiceEstimate = (payload, money) => payload == null
122
74
  dateTo: toEstimateDate(lineItem.date_to),
123
75
  description: lineItem.description,
124
76
  discountAmount: money(lineItem.discount_amount),
125
- discountLabel: lineDiscountLabel(lineItem, payload.discounts ?? []),
126
- grossAmount: money(lineItem.gross_amount ?? lineItem.amount),
127
77
  quantity: lineItem.quantity,
128
78
  taxAmount: lineItem.tax_amount != null
129
79
  ? money(lineItem.tax_amount)
package/lib/index.d.ts CHANGED
@@ -1130,7 +1130,7 @@ export { getInvoicingCustomerFormView } from './view/invoicing/editInvoicingCust
1130
1130
  export type { InvoicingCustomerFormView } from './view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector';
1131
1131
  export { clearInvoicingSubscriptionEstimate, fetchInvoicingSubscriptionEstimate, fetchInvoicingSubscriptionFormPage, initializeInvoicingSubscriptionAddress, resetEditInvoicingSubscriptionDetailView, submitInvoicingSubscriptionForm, updateInvoicingSubscriptionFormDraft, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer';
1132
1132
  export type { SubmitInvoicingSubscriptionFormPayload, UpdateInvoicingSubscriptionFormDraftPayload, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer';
1133
- export type { InvoicingSubscriptionEstimateCoupon, InvoicingSubscriptionEstimateLineItem, InvoicingSubscriptionFormLocalData, InvoicingSubscriptionInvoiceEstimate, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState';
1133
+ export type { InvoicingSubscriptionEstimateLineItem, InvoicingSubscriptionFormLocalData, InvoicingSubscriptionInvoiceEstimate, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState';
1134
1134
  export { INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE, entityToInvoicingSubscriptionFormLocalData, initialInvoicingSubscriptionFormLocalData, invoicingSubscriptionTodayIso, toInvoicingSubscriptionQuantity, } from './view/invoicing/editInvoicingSubscriptionDetailView/invoicingSubscriptionFormConfig';
1135
1135
  export { getEditInvoicingSubscriptionDetailViewState, getInvoicingSubscriptionFormView, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector';
1136
1136
  export type { EditInvoicingSubscriptionDetailView, InvoicingSubscriptionEstimateKind, InvoicingSubscriptionEstimateView, InvoicingSubscriptionFormView, InvoicingSubscriptionOption, } from './view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector';
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasTransactionLocalDataChanges = exports.isAnyItemWithUncategorizedExpenseAccount = exports.getSnackbarMessageForTransactionReview = exports.mergeTabSpecificLineItems = exports.getLineItemsByTransactionIdsFromLocalData = exports.getLineItemsByTransactionsIdsFromResponse = exports.checkIfAllLineItemsAreCategoryClassFilled = exports.setEntityRecommendationForLineIdInLocalData = exports.toSetAllLineItemsToCategoryClass = exports.toTransactionDetailLocalData = exports.shouldAutoSelectAndAdd = exports.MAX_SELECTION_LIMIT = exports.filterAutoTabLineItems = exports.removeTransactionFromTabView = exports.getPendingReviewLineIdsFromTransaction = void 0;
4
- const customerTransaction_1 = require("../../../entity/transaction/stateTypes/customerTransaction");
5
4
  const vendorTransaction_1 = require("../../../entity/transaction/stateTypes/vendorTransaction");
6
5
  const transactionDetailLocalDataHelper_1 = require("../../transactionDetail/transactionDetailLocalDataHelper");
7
6
  const transactionDetailLocalDataHelper_2 = require("../../transactionDetail/transactionDetailLocalDataHelper");
@@ -217,10 +216,7 @@ const buildLineItemById = (transaction, recommendations) => {
217
216
  logo: accountLine.vendor.logo,
218
217
  }
219
218
  : undefined;
220
- const customer = accountLine.customer ??
221
- ((0, customerTransaction_1.isCustomerTransaction)(transaction) === true
222
- ? transaction.customer
223
- : undefined);
219
+ const customer = accountLine.customer;
224
220
  record.customer =
225
221
  customer != null && Boolean(customer.id) && Boolean(customer.name)
226
222
  ? {
@@ -82,17 +82,8 @@ interface InvoicingSubscriptionEstimateLineItemPayload {
82
82
  unit_amount: number;
83
83
  date_from?: string;
84
84
  date_to?: string;
85
- gross_amount?: number;
86
- id?: string;
87
85
  tax_amount?: number | null;
88
86
  }
89
- interface InvoicingSubscriptionEstimateDiscountPayload {
90
- amount: number;
91
- description: string;
92
- entity_type: string;
93
- entity_id?: string;
94
- line_item_id?: string | null;
95
- }
96
87
  interface InvoicingSubscriptionInvoiceEstimatePayload {
97
88
  amount_due: number;
98
89
  coupon_discount_total: number;
@@ -103,7 +94,6 @@ interface InvoicingSubscriptionInvoiceEstimatePayload {
103
94
  sub_total: number;
104
95
  tax: number | null;
105
96
  total: number;
106
- discounts?: InvoicingSubscriptionEstimateDiscountPayload[];
107
97
  due_date?: string;
108
98
  invoice_date?: string;
109
99
  }
@@ -63,59 +63,11 @@ const localDataToSaveInvoicingSubscriptionPayload = (localData, shippingAddress)
63
63
  };
64
64
  exports.localDataToSaveInvoicingSubscriptionPayload = localDataToSaveInvoicingSubscriptionPayload;
65
65
  const toEstimateDate = (value) => value != null && value !== '' ? (0, zeniDayJS_1.date)(value) : undefined;
66
- const isItemLevelCoupon = (discount) => discount.entity_type === 'item_level_coupon';
67
- const isCoupon = (discount) => discount.entity_type === 'document_level_coupon' ||
68
- discount.entity_type === 'item_level_coupon';
69
- /**
70
- * Name the coupon behind a line's discount. Exact when the API links a coupon
71
- * row to its line (`line_item_id`); otherwise only when a single item-level
72
- * coupon applies, since then every discounted line got that one.
73
- */
74
- const lineDiscountLabel = (lineItem, discounts) => {
75
- if (lineItem.discount_amount <= 0) {
76
- return undefined;
77
- }
78
- const itemCoupons = discounts.filter(isItemLevelCoupon);
79
- const linked = lineItem.id != null
80
- ? itemCoupons.filter((coupon) => coupon.line_item_id === lineItem.id)
81
- : [];
82
- if (linked.length > 0) {
83
- return [...new Set(linked.map((coupon) => coupon.description))].join(', ');
84
- }
85
- const names = [...new Set(itemCoupons.map((coupon) => coupon.description))];
86
- return names.length === 1 ? names[0] : undefined;
87
- };
88
- /**
89
- * One row per coupon. An item-level coupon comes back once per line it
90
- * discounted, so its rows are summed; listing each would read as the same
91
- * discount taken several times.
92
- */
93
- const mergeCouponRows = (discounts) => {
94
- const rowsByCoupon = new Map();
95
- discounts.filter(isCoupon).forEach((coupon) => {
96
- // The API sends `entity_id: ""` when it has none; key those by name so
97
- // two unrelated coupons are not merged into one row.
98
- const couponKey = coupon.entity_id != null && coupon.entity_id !== ''
99
- ? coupon.entity_id
100
- : coupon.description;
101
- const key = `${coupon.entity_type}:${couponKey}`;
102
- const row = rowsByCoupon.get(key);
103
- rowsByCoupon.set(key, {
104
- amount: Math.round(((row?.amount ?? 0) + coupon.amount) * 100) / 100,
105
- description: coupon.description,
106
- });
107
- });
108
- return [...rowsByCoupon.values()];
109
- };
110
66
  const mapInvoiceEstimate = (payload, money) => payload == null
111
67
  ? undefined
112
68
  : {
113
69
  amountDue: money(payload.amount_due),
114
70
  couponDiscountTotal: money(payload.coupon_discount_total),
115
- coupons: mergeCouponRows(payload.discounts ?? []).map((coupon) => ({
116
- amount: money(coupon.amount),
117
- description: coupon.description,
118
- })),
119
71
  creditsApplied: money(payload.credits_applied),
120
72
  dueDate: toEstimateDate(payload.due_date),
121
73
  grossSubTotal: money(payload.gross_sub_total),
@@ -126,8 +78,6 @@ const mapInvoiceEstimate = (payload, money) => payload == null
126
78
  dateTo: toEstimateDate(lineItem.date_to),
127
79
  description: lineItem.description,
128
80
  discountAmount: money(lineItem.discount_amount),
129
- discountLabel: lineDiscountLabel(lineItem, payload.discounts ?? []),
130
- grossAmount: money(lineItem.gross_amount ?? lineItem.amount),
131
81
  quantity: lineItem.quantity,
132
82
  taxAmount: lineItem.tax_amount != null
133
83
  ? money(lineItem.tax_amount)
@@ -41,32 +41,19 @@ export interface InvoicingSubscriptionFormLocalData {
41
41
  setupFee?: Amount;
42
42
  }
43
43
  export interface InvoicingSubscriptionEstimateLineItem {
44
- /** After the line's own (item-level) coupons. */
45
44
  amount: Amount;
46
45
  description: string;
47
- /** Item-level coupons on this line; invoice-level coupons are not spread here. */
48
46
  discountAmount: Amount;
49
- /** Before any coupon, so the lines add up to `grossSubTotal`. */
50
- grossAmount: Amount;
51
47
  quantity: number;
52
48
  unitAmount: Amount;
53
49
  dateFrom?: ZeniDate;
54
50
  dateTo?: ZeniDate;
55
- /** The coupon behind `discountAmount`, when it can be told; see the mapper. */
56
- discountLabel?: string;
57
51
  taxAmount?: Amount;
58
52
  }
59
- /** A coupon the estimate applies, named, for the totals. */
60
- export interface InvoicingSubscriptionEstimateCoupon {
61
- amount: Amount;
62
- description: string;
63
- }
64
53
  /** An invoice the save would raise now, or the next one it would raise later. */
65
54
  export interface InvoicingSubscriptionInvoiceEstimate {
66
55
  amountDue: Amount;
67
56
  couponDiscountTotal: Amount;
68
- /** Item- and invoice-level coupons, one row each; they sum to `couponDiscountTotal`. */
69
- coupons: InvoicingSubscriptionEstimateCoupon[];
70
57
  /** Refundable credits plus excess payments; promotional credits are separate. */
71
58
  creditsApplied: Amount;
72
59
  grossSubTotal: Amount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.2.83",
3
+ "version": "5.2.85",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",