@zeniai/client-epic-state 5.0.66-betaAR6 → 5.0.66-betaJK2
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.
- package/lib/entity/account/accountSelector.d.ts +1 -20
- package/lib/entity/account/accountSelector.js +1 -35
- package/lib/entity/account/accountState.d.ts +0 -5
- package/lib/entity/account/accountState.js +4 -11
- package/lib/entity/class/classSelector.d.ts +0 -35
- package/lib/entity/class/classSelector.js +0 -44
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.d.ts +2 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +2 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +2 -0
- package/lib/esm/entity/account/accountSelector.js +1 -33
- package/lib/esm/entity/account/accountState.js +1 -7
- package/lib/esm/entity/class/classSelector.js +0 -42
- package/lib/esm/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +2 -0
- package/lib/esm/index.js +4 -10
- package/lib/esm/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
- package/lib/esm/view/companyView/helpers/cockpitHelpers.js +1 -1
- package/lib/esm/view/companyView/selector/companyManagementViewSelector.js +1 -1
- package/lib/esm/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +1 -11
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +12 -64
- package/lib/esm/view/spendManagement/spendManagementFilterHelpers.js +2 -4
- package/lib/esm/view/subscriptionView/subscriptionViewSelector.js +1 -1
- package/lib/esm/view/taskManager/taskListView/taskListReducer.js +1 -1
- package/lib/index.d.ts +5 -7
- package/lib/index.js +32 -41
- package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
- package/lib/view/companyView/helpers/cockpitHelpers.js +1 -1
- package/lib/view/companyView/selector/companyManagementViewSelector.js +1 -1
- package/lib/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
- package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -5
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +2 -12
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +1 -4
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +12 -66
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +0 -2
- package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistory.d.ts +1 -1
- package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +1 -1
- package/lib/view/spendManagement/spendManagementFilterHelpers.d.ts +1 -1
- package/lib/view/spendManagement/spendManagementFilterHelpers.js +2 -4
- package/lib/view/subscriptionView/subscriptionViewSelector.js +1 -1
- package/lib/view/taskManager/taskListView/taskList.d.ts +1 -1
- package/lib/view/taskManager/taskListView/taskListReducer.js +1 -1
- package/package.json +1 -1
- package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +0 -193
- package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
- package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +0 -65
- package/lib/view/expenseAutomationView/transactionFilterHelpers.js +0 -197
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.toTransactionView = void 0;
|
|
7
6
|
exports.getExpenseAutomationTransactionView = getExpenseAutomationTransactionView;
|
|
8
7
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
9
8
|
const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
|
|
@@ -11,34 +10,14 @@ const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
|
|
|
11
10
|
const tenantSelector_1 = require("../../../entity/tenant/tenantSelector");
|
|
12
11
|
const transactionHelper_1 = require("../../../entity/transaction/transactionHelper");
|
|
13
12
|
const transactionSelector_1 = require("../../../entity/transaction/transactionSelector");
|
|
14
|
-
const transactionFilterHelpers_1 = require("../transactionFilterHelpers");
|
|
15
13
|
const accountListSelector_1 = require("../../accountList/accountListSelector");
|
|
16
14
|
const classListSelector_1 = require("../../classList/classListSelector");
|
|
17
15
|
const projectListSelector_1 = require("../../projectList/projectListSelector");
|
|
18
16
|
const expenseAutomationViewSelectorTypes_1 = require("../selectorTypes/expenseAutomationViewSelectorTypes");
|
|
19
|
-
const toTransactionView = (transaction, transactionLocalData) => {
|
|
20
|
-
return {
|
|
21
|
-
id: transaction.id,
|
|
22
|
-
date: transaction.date,
|
|
23
|
-
amount: transaction.amount,
|
|
24
|
-
vendorName: transaction.vendorName,
|
|
25
|
-
customerName: transaction.customerName,
|
|
26
|
-
vendorId: transaction.vendorId,
|
|
27
|
-
customerId: transaction.customerId,
|
|
28
|
-
description: transaction.description,
|
|
29
|
-
memo: transaction.memo,
|
|
30
|
-
type: transaction.type,
|
|
31
|
-
typeName: transaction.typeName,
|
|
32
|
-
createTime: transaction.createTime,
|
|
33
|
-
transaction: transaction,
|
|
34
|
-
transactionLocalData,
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
exports.toTransactionView = toTransactionView;
|
|
38
17
|
function getExpenseAutomationTransactionView(state) {
|
|
39
18
|
const { accountState, classState, classListState, accountListState, expenseAutomationTransactionsViewState, expenseAutomationViewState, projectState, projectListState, transactionState, monthEndCloseChecksState, monthEndCloseChecksViewState, } = state;
|
|
40
19
|
const { selectedTransactionCategorizationCompletedSubTab, selectedTransactionCategorizationTab, } = expenseAutomationTransactionsViewState;
|
|
41
|
-
const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId,
|
|
20
|
+
const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId, } = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTransactionCategorizationTab];
|
|
42
21
|
const uncategorizedIncomeExpense = (0, accountListSelector_1.getUncategorizedAccounts)(accountState, accountListState, 'accountList');
|
|
43
22
|
const accountList = (0, accountListSelector_1.getAccountList)(accountState, accountListState, 'accountList');
|
|
44
23
|
const classList = (0, classListSelector_1.getClassList)(classState, classListState);
|
|
@@ -57,53 +36,20 @@ function getExpenseAutomationTransactionView(state) {
|
|
|
57
36
|
? transactionIdsBySelectedPeriod[monthYearPeriodId]
|
|
58
37
|
: null;
|
|
59
38
|
const transactionIds = transactionIdsForSelectedPeriod ?? [];
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const transactionLocalDataMap = new Map();
|
|
63
|
-
transactionIds.forEach((transactionId) => {
|
|
39
|
+
const transactionLocalData = transactionIds
|
|
40
|
+
.map((transactionId) => {
|
|
64
41
|
const transactionData = transactionReviewLocalDataById[transactionId];
|
|
65
42
|
if (transactionData != null) {
|
|
66
|
-
|
|
43
|
+
return {
|
|
67
44
|
transactionId,
|
|
68
45
|
transactionReviewLocalData: transactionData.transactionReviewLocalData,
|
|
69
|
-
}
|
|
46
|
+
};
|
|
70
47
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
// Apply TC-specific filters (lives under expenseAutomationView, independent
|
|
78
|
-
// of the Spend Management filter pipeline).
|
|
79
|
-
const filteredTransactionViews = (0, transactionFilterHelpers_1.applyTransactionFilters)(transactionViews, filters);
|
|
80
|
-
// Convert back to TransactionWithCOT for return
|
|
81
|
-
const filteredTransactionsWithCOT = filteredTransactionViews.map((view) => view.transaction);
|
|
82
|
-
// Get transactionLocalData for filtered transactions
|
|
83
|
-
// Also include transactionLocalData for transactions that don't exist in transactionState
|
|
84
|
-
// but have local data (to match original behavior)
|
|
85
|
-
const filteredTransactionIds = new Set(filteredTransactionViews.map((view) => view.id));
|
|
86
|
-
// `.flatMap` returns `X[]` directly when the callback returns `[]` for the
|
|
87
|
-
// skip case, so we don't need the trailing `.filter((d): d is X => …)` type
|
|
88
|
-
// predicate that the previous `map → filter` pipeline required.
|
|
89
|
-
const filteredTransactionLocalData = transactionIds.flatMap((transactionId) => {
|
|
90
|
-
const transactionData = transactionReviewLocalDataById[transactionId];
|
|
91
|
-
if (transactionData == null) {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
// Include if transaction is in filtered results, or if transaction doesn't exist in state
|
|
95
|
-
// (to maintain backward compatibility with tests)
|
|
96
|
-
const transactionExists = transactions.some((t) => t.id === transactionId);
|
|
97
|
-
if (filteredTransactionIds.has(transactionId) || !transactionExists) {
|
|
98
|
-
return [
|
|
99
|
-
{
|
|
100
|
-
transactionId,
|
|
101
|
-
transactionReviewLocalData: transactionData.transactionReviewLocalData,
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
return [];
|
|
106
|
-
});
|
|
48
|
+
return null;
|
|
49
|
+
})
|
|
50
|
+
.filter((transaction) => transaction != null);
|
|
51
|
+
const transactions = (0, transactionSelector_1.getSupportedTransactionsByIds)(transactionState, transactionIds);
|
|
52
|
+
const transactionsWithCOT = transactions.map((transaction) => (0, transactionHelper_1.getTransactionWithCOT)(transaction));
|
|
107
53
|
const monthEndFetchState = monthYearPeriodId != null
|
|
108
54
|
? (monthEndCloseChecksViewState.monthEndCloseChecksViewByTenantId[currentTenant.tenantId]?.[monthYearPeriodId] ?? { fetchState: 'Not-Started', error: undefined })
|
|
109
55
|
: { fetchState: 'Not-Started', error: undefined };
|
|
@@ -167,7 +113,7 @@ function getExpenseAutomationTransactionView(state) {
|
|
|
167
113
|
version: 0,
|
|
168
114
|
fetchState: fetchStatus.fetchState,
|
|
169
115
|
error: fetchStatus.error,
|
|
170
|
-
transactions:
|
|
116
|
+
transactions: transactionsWithCOT,
|
|
171
117
|
selectedCheckBoxTransactionIds,
|
|
172
118
|
transactionIdsWithUnsavedData,
|
|
173
119
|
uncategorizedAccounts: uncategorizedIncomeExpense,
|
|
@@ -178,7 +124,7 @@ function getExpenseAutomationTransactionView(state) {
|
|
|
178
124
|
classHierarchyList,
|
|
179
125
|
isAccountingProjectsEnabled,
|
|
180
126
|
projectList,
|
|
181
|
-
transactionLocalData
|
|
127
|
+
transactionLocalData,
|
|
182
128
|
uiState,
|
|
183
129
|
refreshStatus,
|
|
184
130
|
saveStatus,
|
|
@@ -16,7 +16,6 @@ import { VendorBase } from '../../../entity/vendor/vendorState';
|
|
|
16
16
|
import { ZeniAPIStatus } from '../../../responsePayload';
|
|
17
17
|
import { ZeniDate } from '../../../zeniDayJS';
|
|
18
18
|
import { EntityRecommendationKey } from '../../recommendation/recommendationState';
|
|
19
|
-
import { TransactionFilters } from '../transactionFilterHelpers';
|
|
20
19
|
import { TransactionDetailKey } from '../../transactionDetail/transactionDetailState';
|
|
21
20
|
import { CompletedSubTab } from './completedSubTab';
|
|
22
21
|
export declare const toTransactionsSortKey: (v: string) => "date" | "amount" | "vendor" | "project" | "category" | "class" | "payment_account" | "transaction_type" | "memo_and_receipt";
|
|
@@ -94,7 +93,6 @@ export interface SupportedTransactionCategorization {
|
|
|
94
93
|
}
|
|
95
94
|
export declare const initialSupportedTransactionCategorization: SupportedTransactionCategorization;
|
|
96
95
|
export interface TransactionsTabViewState extends FetchedState {
|
|
97
|
-
filters: TransactionFilters;
|
|
98
96
|
markAsNotMiscategorizedStatus: FetchStateAndError;
|
|
99
97
|
refreshStatus: FetchStateAndError;
|
|
100
98
|
saveStatus: FetchStateAndError;
|
|
@@ -45,7 +45,7 @@ export interface BillPayFilters {
|
|
|
45
45
|
}
|
|
46
46
|
export interface BillPayFilterCategory {
|
|
47
47
|
field: BillListViewFilterCategoryField;
|
|
48
|
-
matchingOperator: 'equal' | '
|
|
48
|
+
matchingOperator: 'equal' | 'not-equal';
|
|
49
49
|
values: (string | ZeniDate)[];
|
|
50
50
|
valuesCombinationOperator: 'ANY';
|
|
51
51
|
}
|
package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistory.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface PaymentHistoryFilters {
|
|
|
36
36
|
}
|
|
37
37
|
export interface PaymentHistoryFilterCategory {
|
|
38
38
|
field: PaymentHistoryFilterCategoryField;
|
|
39
|
-
matchingOperator: 'equal' | '
|
|
39
|
+
matchingOperator: 'equal' | 'not-equal';
|
|
40
40
|
values: (string | ZeniDate)[];
|
|
41
41
|
valuesCombinationOperator: 'ANY';
|
|
42
42
|
}
|
|
@@ -46,7 +46,7 @@ export interface ReimbursementFilters {
|
|
|
46
46
|
}
|
|
47
47
|
export interface ReimbursementFilterCategory {
|
|
48
48
|
field: RemiListViewFilterCategoryField;
|
|
49
|
-
matchingOperator: 'equal' | '
|
|
49
|
+
matchingOperator: 'equal' | 'not-equal';
|
|
50
50
|
values: (string | ZeniDate)[];
|
|
51
51
|
valuesCombinationOperator: 'ANY';
|
|
52
52
|
}
|
|
@@ -15,7 +15,7 @@ export type SpendManagementFilterEntityType = 'bill_pay' | 'reimbursement' | 'ta
|
|
|
15
15
|
export type FilterCategoryType = 'searchAutocomplete' | 'user' | 'dateRange' | 'numberRange' | 'dropdown';
|
|
16
16
|
export interface MatchingOperatorDropdownOption {
|
|
17
17
|
label: 'is' | 'is not';
|
|
18
|
-
value: 'equal' | '
|
|
18
|
+
value: 'equal' | 'not-equal';
|
|
19
19
|
}
|
|
20
20
|
export type CategoryCombinationOperator = 'AND' | 'OR';
|
|
21
21
|
export interface BillPayFilterCategoryDropdownOption {
|
|
@@ -14,8 +14,6 @@ const helpers_1 = require("./helpers");
|
|
|
14
14
|
const remiListSelector_1 = require("./reimbursement/remiListView/remiListSelector");
|
|
15
15
|
const remiListState_1 = require("./reimbursement/remiListView/remiListState");
|
|
16
16
|
//filters items against filter values representing a range. ex: date (from-to), amount(1k<-->5k)
|
|
17
|
-
// Spend Management uses only equal/not_equal — TC amount operators
|
|
18
|
-
// (inBetween, lessThan, greaterThan) live in the TC filter pipeline.
|
|
19
17
|
const filterItemOnRangeCategoryType = (valueForItem, currentFilter) => {
|
|
20
18
|
let doesItemFallInValueRange = false;
|
|
21
19
|
const filterField = currentFilter.field;
|
|
@@ -49,7 +47,7 @@ const filterItemOnCategoriesWithSingleValue = (categoryValue, currentFilter, ran
|
|
|
49
47
|
return filterItemOnRangeCategoryType(categoryValue, currentFilter);
|
|
50
48
|
}
|
|
51
49
|
// if filter category is not rangeType
|
|
52
|
-
if (currentFilter.matchingOperator === '
|
|
50
|
+
if (currentFilter.matchingOperator === 'not-equal') {
|
|
53
51
|
return currentFilter.values.indexOf(categoryValue.toString()) === -1;
|
|
54
52
|
}
|
|
55
53
|
return currentFilter.values.indexOf(categoryValue.toString()) > -1;
|
|
@@ -123,7 +121,7 @@ const applyAdvancedFiltersOnList = (entity, allItems, filters, filteredItems = [
|
|
|
123
121
|
? getCategoryValueForTaskList(key, item)
|
|
124
122
|
: getCategoryValueForPaymentHistory(key, item);
|
|
125
123
|
if (categoryValue == null) {
|
|
126
|
-
if (currentFilter.matchingOperator === '
|
|
124
|
+
if (currentFilter.matchingOperator === 'not-equal') {
|
|
127
125
|
return true;
|
|
128
126
|
}
|
|
129
127
|
return false;
|
|
@@ -217,7 +217,7 @@ const applyAdvancedFiltersOnCompaniesList = (allCompanies, filters, filteredComp
|
|
|
217
217
|
const key = currentFilter.field;
|
|
218
218
|
const categoryValue = getCategoryValueForCompany(key, company);
|
|
219
219
|
if (categoryValue == null) {
|
|
220
|
-
if (currentFilter.matchingOperator === '
|
|
220
|
+
if (currentFilter.matchingOperator === 'not-equal') {
|
|
221
221
|
return true;
|
|
222
222
|
}
|
|
223
223
|
return false;
|
|
@@ -44,7 +44,7 @@ export interface TaskListFilters {
|
|
|
44
44
|
}
|
|
45
45
|
export interface TaskFilterCategory {
|
|
46
46
|
field: TaskListFilterCategoryField;
|
|
47
|
-
matchingOperator: 'equal' | '
|
|
47
|
+
matchingOperator: 'equal' | 'not-equal';
|
|
48
48
|
values: (string | ZeniDate)[];
|
|
49
49
|
valuesCombinationOperator: 'ANY';
|
|
50
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.66-
|
|
3
|
+
"version": "5.0.66-betaJK2",
|
|
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",
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
export const TRANSACTION_FILTER_CATEGORIES = [
|
|
2
|
-
{ value: 'payment_account_name', type: 'dropdown' },
|
|
3
|
-
{ value: 'payment_account_type', type: 'dropdown' },
|
|
4
|
-
{ value: 'payee', type: 'searchAutocomplete' },
|
|
5
|
-
{ value: 'category', type: 'dropdown' },
|
|
6
|
-
{ value: 'class', type: 'dropdown' },
|
|
7
|
-
{ value: 'amount', type: 'numberRange' },
|
|
8
|
-
];
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the comparable value for a transaction against a given filter field.
|
|
11
|
-
* Returns undefined when the transaction doesn't carry the field — callers
|
|
12
|
-
* decide whether absence counts as a match (for 'not_equal' it does).
|
|
13
|
-
*/
|
|
14
|
-
const getCategoryValueForTransaction = (key, transaction) => {
|
|
15
|
-
switch (key) {
|
|
16
|
-
case 'amount': {
|
|
17
|
-
// Prefer transactionLocalData line items (sum). Fall back to lines on
|
|
18
|
-
// the transaction itself. Final fallback: transaction-level amount.
|
|
19
|
-
const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
20
|
-
if (localDataForAmount?.lineItemById) {
|
|
21
|
-
const lineItems = Object.values(localDataForAmount.lineItemById);
|
|
22
|
-
if (lineItems.length > 0) {
|
|
23
|
-
return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (transaction.transaction.lines &&
|
|
27
|
-
transaction.transaction.lines.length > 0) {
|
|
28
|
-
return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
|
|
29
|
-
}
|
|
30
|
-
return transaction.amount.amount;
|
|
31
|
-
}
|
|
32
|
-
case 'payee': {
|
|
33
|
-
if (transaction.vendorName) {
|
|
34
|
-
return transaction.vendorName;
|
|
35
|
-
}
|
|
36
|
-
if (transaction.customerName) {
|
|
37
|
-
return transaction.customerName;
|
|
38
|
-
}
|
|
39
|
-
const localData = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
40
|
-
if (localData?.vendor?.name) {
|
|
41
|
-
return localData.vendor.name;
|
|
42
|
-
}
|
|
43
|
-
if (localData?.customer?.name) {
|
|
44
|
-
return localData.customer.name;
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
case 'payment_account_name': {
|
|
49
|
-
// Match what TransactionCategorizationListRow renders for the cell.
|
|
50
|
-
return transaction.transaction.account?.accountName;
|
|
51
|
-
}
|
|
52
|
-
case 'payment_account_type': {
|
|
53
|
-
// Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
|
|
54
|
-
// option values use the same enum; row uses `paymentTypeName` for the
|
|
55
|
-
// human label.
|
|
56
|
-
return transaction.transaction.paymentType;
|
|
57
|
-
}
|
|
58
|
-
case 'category': {
|
|
59
|
-
const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
60
|
-
if (localDataForCategory) {
|
|
61
|
-
const firstLineItem = Object.values(localDataForCategory.lineItemById)[0];
|
|
62
|
-
if (firstLineItem?.account?.accountId) {
|
|
63
|
-
return firstLineItem.account.accountId;
|
|
64
|
-
}
|
|
65
|
-
if (firstLineItem?.account?.qboId) {
|
|
66
|
-
return firstLineItem.account.qboId;
|
|
67
|
-
}
|
|
68
|
-
if (firstLineItem?.account?.accountName) {
|
|
69
|
-
return firstLineItem.account.accountName;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const firstLineForCategory = transaction.transaction.lines?.[0];
|
|
73
|
-
if (firstLineForCategory?.type ===
|
|
74
|
-
'transaction_with_account_and_class_line' ||
|
|
75
|
-
firstLineForCategory?.type ===
|
|
76
|
-
'transaction_with_product_or_service_line' ||
|
|
77
|
-
firstLineForCategory?.type === 'journal_entry_transaction_line') {
|
|
78
|
-
const account = firstLineForCategory.account;
|
|
79
|
-
return account?.accountId ?? account?.qboId ?? account?.accountName;
|
|
80
|
-
}
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
case 'class': {
|
|
84
|
-
const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
85
|
-
if (localDataForClass) {
|
|
86
|
-
const firstLineItemForClass = Object.values(localDataForClass.lineItemById)[0];
|
|
87
|
-
if (firstLineItemForClass?.class?.classId) {
|
|
88
|
-
return firstLineItemForClass.class.classId;
|
|
89
|
-
}
|
|
90
|
-
if (firstLineItemForClass?.class?.qboId) {
|
|
91
|
-
return firstLineItemForClass.class.qboId;
|
|
92
|
-
}
|
|
93
|
-
if (firstLineItemForClass?.class?.className) {
|
|
94
|
-
return firstLineItemForClass.class.className;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const firstLineForClass = transaction.transaction.lines?.[0];
|
|
98
|
-
if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
|
|
99
|
-
firstLineForClass?.type ===
|
|
100
|
-
'transaction_with_product_or_service_line' ||
|
|
101
|
-
firstLineForClass?.type === 'journal_entry_transaction_line') {
|
|
102
|
-
const classData = firstLineForClass.class;
|
|
103
|
-
return classData?.classId ?? classData?.qboId ?? classData?.className;
|
|
104
|
-
}
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
default:
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* TC-only amount matcher. Supports all five operators TC defines, including
|
|
113
|
-
* the legacy "1000<->5000" range-string form (kept for backward compatibility
|
|
114
|
-
* with persisted filter state that may still contain that encoding).
|
|
115
|
-
*
|
|
116
|
-
* The `'equal' | 'not_equal'` branches share the same underlying comparison;
|
|
117
|
-
* the trailing `return op === 'not_equal' ? !matched : matched` line inverts
|
|
118
|
-
* the result for `not_equal`. Without `'not_equal'` listed alongside
|
|
119
|
-
* `'equal'` in the predicate, `matched` would stay `false` for every row and
|
|
120
|
-
* the inversion would silently flip to `true` — turning the "not equal to X"
|
|
121
|
-
* filter into a no-op that includes every transaction.
|
|
122
|
-
*/
|
|
123
|
-
const matchAmount = (amount, category) => {
|
|
124
|
-
const op = category.matchingOperator;
|
|
125
|
-
const values = category.values;
|
|
126
|
-
let matched = false;
|
|
127
|
-
if (op === 'in_between') {
|
|
128
|
-
if (values.length >= 2) {
|
|
129
|
-
const min = Number(values[0]);
|
|
130
|
-
const max = Number(values[1]);
|
|
131
|
-
matched = amount >= min && amount <= max;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else if (op === 'less_than') {
|
|
135
|
-
if (values.length >= 1) {
|
|
136
|
-
matched = amount < Number(values[0]);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (op === 'greater_than') {
|
|
140
|
-
if (values.length >= 1) {
|
|
141
|
-
matched = amount > Number(values[0]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else if ((op === 'equal' || op === 'not_equal') &&
|
|
145
|
-
values.length === 1 &&
|
|
146
|
-
String(values[0]).includes('<->')) {
|
|
147
|
-
// Backward compatibility: ["1000<->5000"] with matchingOperator "equal".
|
|
148
|
-
const parts = String(values[0]).split('<->');
|
|
149
|
-
matched =
|
|
150
|
-
amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? '');
|
|
151
|
-
}
|
|
152
|
-
else if ((op === 'equal' || op === 'not_equal') && values.length === 1) {
|
|
153
|
-
matched = amount === Number(values[0]);
|
|
154
|
-
}
|
|
155
|
-
return op === 'not_equal' ? !matched : matched;
|
|
156
|
-
};
|
|
157
|
-
const transactionMatchesCategory = (transaction, category) => {
|
|
158
|
-
const value = getCategoryValueForTransaction(category.field, transaction);
|
|
159
|
-
if (value == null) {
|
|
160
|
-
// Absent values count as a match only under 'not_equal'.
|
|
161
|
-
return category.matchingOperator === 'not_equal';
|
|
162
|
-
}
|
|
163
|
-
if (category.field === 'amount') {
|
|
164
|
-
return matchAmount(Number(value), category);
|
|
165
|
-
}
|
|
166
|
-
const valueStr = value.toString();
|
|
167
|
-
const valueInList = category.values.some((v) => v.toString() === valueStr);
|
|
168
|
-
return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
|
|
172
|
-
* `TransactionView` items against a `TransactionFilters` object using the
|
|
173
|
-
* AND/OR combination semantics from `categoryCombinationOperator`.
|
|
174
|
-
*
|
|
175
|
-
* Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
|
|
176
|
-
* inside the Expense Automation feature group.
|
|
177
|
-
*/
|
|
178
|
-
export const applyTransactionFilters = (transactions, filters) => {
|
|
179
|
-
if (filters?.categories == null || filters.categories.length === 0) {
|
|
180
|
-
return transactions;
|
|
181
|
-
}
|
|
182
|
-
const activeCategories = filters.categories.filter((c) => c.field != null && c.values.length > 0);
|
|
183
|
-
if (activeCategories.length === 0) {
|
|
184
|
-
return transactions;
|
|
185
|
-
}
|
|
186
|
-
const op = filters.categoryCombinationOperator;
|
|
187
|
-
return transactions.filter((txn) => {
|
|
188
|
-
if (op === 'AND') {
|
|
189
|
-
return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
|
|
190
|
-
}
|
|
191
|
-
return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
|
|
192
|
-
});
|
|
193
|
-
};
|