@zeniai/client-epic-state 5.0.69-betaAR2 → 5.0.69-betaAR4
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 +0 -26
- package/lib/entity/account/accountSelector.js +1 -47
- package/lib/entity/account/accountState.d.ts +0 -5
- package/lib/entity/account/accountState.js +4 -11
- package/lib/entity/approvalRule/approvalRulePayload.d.ts +27 -5
- package/lib/entity/approvalRule/approvalRulePayload.js +131 -10
- package/lib/entity/approvalRule/approvalRuleSelector.d.ts +25 -1
- package/lib/entity/approvalRule/approvalRuleSelector.js +40 -0
- package/lib/entity/approvalRule/approvalRuleState.d.ts +48 -7
- package/lib/entity/class/classSelector.d.ts +0 -35
- package/lib/entity/class/classSelector.js +0 -50
- package/lib/esm/entity/account/accountSelector.js +1 -46
- package/lib/esm/entity/account/accountState.js +1 -7
- package/lib/esm/entity/approvalRule/approvalRulePayload.js +131 -10
- package/lib/esm/entity/approvalRule/approvalRuleSelector.js +35 -0
- package/lib/esm/entity/class/classSelector.js +0 -48
- package/lib/esm/index.js +6 -11
- 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 -69
- package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +11 -7
- package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +61 -16
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
- package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +11 -7
- 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 +8 -9
- package/lib/index.js +38 -41
- package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
- package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
- 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 +2 -2
- 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 -71
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +0 -2
- package/lib/view/people/peopleTypes.d.ts +1 -1
- package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +10 -6
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +9 -1
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +61 -16
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +31 -5
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
- package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.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/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +10 -6
- 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 +4 -4
- package/lib/view/taskManager/taskListView/taskListReducer.js +1 -1
- package/package.json +1 -1
- package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +0 -228
- package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +0 -65
- package/lib/view/expenseAutomationView/transactionFilterHelpers.js +0 -232
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Narrowing type-guard for "has a non-empty string here". Used in place of
|
|
3
|
-
* raw `if (foo)` truthiness checks on `string | null | undefined` values so
|
|
4
|
-
* the `@typescript-eslint/strict-boolean-expressions` lint stays clean —
|
|
5
|
-
* empty strings should explicitly fall through to the next candidate
|
|
6
|
-
* (vendorName → customerName → localData.vendor.name → ...) rather than
|
|
7
|
-
* being implicitly coerced to falsy.
|
|
8
|
-
*/
|
|
9
|
-
const isNonEmptyString = (s) => s != null && s !== '';
|
|
10
|
-
export const TRANSACTION_FILTER_CATEGORIES = [
|
|
11
|
-
{ value: 'payment_account_name', type: 'dropdown' },
|
|
12
|
-
{ value: 'payment_account_type', type: 'dropdown' },
|
|
13
|
-
{ value: 'payee', type: 'searchAutocomplete' },
|
|
14
|
-
{ value: 'category', type: 'dropdown' },
|
|
15
|
-
{ value: 'class', type: 'dropdown' },
|
|
16
|
-
{ value: 'amount', type: 'numberRange' },
|
|
17
|
-
];
|
|
18
|
-
/**
|
|
19
|
-
* Resolve the comparable value for a transaction against a given filter field.
|
|
20
|
-
* Returns undefined when the transaction doesn't carry the field — callers
|
|
21
|
-
* decide whether absence counts as a match (for 'not_equal' it does).
|
|
22
|
-
*/
|
|
23
|
-
const getCategoryValueForTransaction = (key, transaction) => {
|
|
24
|
-
switch (key) {
|
|
25
|
-
case 'amount': {
|
|
26
|
-
// Prefer transactionLocalData line items (sum). Fall back to lines on
|
|
27
|
-
// the transaction itself. Final fallback: transaction-level amount.
|
|
28
|
-
const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
29
|
-
if (localDataForAmount?.lineItemById) {
|
|
30
|
-
const lineItems = Object.values(localDataForAmount.lineItemById);
|
|
31
|
-
if (lineItems.length > 0) {
|
|
32
|
-
return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (transaction.transaction.lines &&
|
|
36
|
-
transaction.transaction.lines.length > 0) {
|
|
37
|
-
return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
|
|
38
|
-
}
|
|
39
|
-
return transaction.amount.amount;
|
|
40
|
-
}
|
|
41
|
-
case 'payee': {
|
|
42
|
-
if (isNonEmptyString(transaction.vendorName)) {
|
|
43
|
-
return transaction.vendorName;
|
|
44
|
-
}
|
|
45
|
-
if (isNonEmptyString(transaction.customerName)) {
|
|
46
|
-
return transaction.customerName;
|
|
47
|
-
}
|
|
48
|
-
const localData = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
49
|
-
const vendorName = localData?.vendor?.name;
|
|
50
|
-
if (isNonEmptyString(vendorName)) {
|
|
51
|
-
return vendorName;
|
|
52
|
-
}
|
|
53
|
-
const customerName = localData?.customer?.name;
|
|
54
|
-
if (isNonEmptyString(customerName)) {
|
|
55
|
-
return customerName;
|
|
56
|
-
}
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
case 'payment_account_name': {
|
|
60
|
-
// Match what TransactionCategorizationListRow renders for the cell.
|
|
61
|
-
return transaction.transaction.account?.accountName;
|
|
62
|
-
}
|
|
63
|
-
case 'payment_account_type': {
|
|
64
|
-
// Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
|
|
65
|
-
// option values use the same enum; row uses `paymentTypeName` for the
|
|
66
|
-
// human label.
|
|
67
|
-
return transaction.transaction.paymentType;
|
|
68
|
-
}
|
|
69
|
-
case 'category': {
|
|
70
|
-
const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
71
|
-
if (localDataForCategory != null) {
|
|
72
|
-
const firstLineItem = Object.values(localDataForCategory.lineItemById)[0];
|
|
73
|
-
const accountId = firstLineItem?.account?.accountId;
|
|
74
|
-
if (isNonEmptyString(accountId)) {
|
|
75
|
-
return accountId;
|
|
76
|
-
}
|
|
77
|
-
const qboId = firstLineItem?.account?.qboId;
|
|
78
|
-
if (isNonEmptyString(qboId)) {
|
|
79
|
-
return qboId;
|
|
80
|
-
}
|
|
81
|
-
const accountName = firstLineItem?.account?.accountName;
|
|
82
|
-
if (isNonEmptyString(accountName)) {
|
|
83
|
-
return accountName;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const firstLineForCategory = transaction.transaction.lines?.[0];
|
|
87
|
-
if (firstLineForCategory?.type ===
|
|
88
|
-
'transaction_with_account_and_class_line' ||
|
|
89
|
-
firstLineForCategory?.type ===
|
|
90
|
-
'transaction_with_product_or_service_line' ||
|
|
91
|
-
firstLineForCategory?.type === 'journal_entry_transaction_line') {
|
|
92
|
-
const account = firstLineForCategory.account;
|
|
93
|
-
return account?.accountId ?? account?.qboId ?? account?.accountName;
|
|
94
|
-
}
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
case 'class': {
|
|
98
|
-
const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
99
|
-
if (localDataForClass != null) {
|
|
100
|
-
const firstLineItemForClass = Object.values(localDataForClass.lineItemById)[0];
|
|
101
|
-
const classId = firstLineItemForClass?.class?.classId;
|
|
102
|
-
if (isNonEmptyString(classId)) {
|
|
103
|
-
return classId;
|
|
104
|
-
}
|
|
105
|
-
const qboId = firstLineItemForClass?.class?.qboId;
|
|
106
|
-
if (isNonEmptyString(qboId)) {
|
|
107
|
-
return qboId;
|
|
108
|
-
}
|
|
109
|
-
const className = firstLineItemForClass?.class?.className;
|
|
110
|
-
if (isNonEmptyString(className)) {
|
|
111
|
-
return className;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const firstLineForClass = transaction.transaction.lines?.[0];
|
|
115
|
-
if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
|
|
116
|
-
firstLineForClass?.type ===
|
|
117
|
-
'transaction_with_product_or_service_line' ||
|
|
118
|
-
firstLineForClass?.type === 'journal_entry_transaction_line') {
|
|
119
|
-
const classData = firstLineForClass.class;
|
|
120
|
-
return classData?.classId ?? classData?.qboId ?? classData?.className;
|
|
121
|
-
}
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
default:
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* TC-only amount matcher. Supports all five operators TC defines, including
|
|
130
|
-
* the legacy "1000<->5000" range-string form (kept for backward compatibility
|
|
131
|
-
* with persisted filter state that may still contain that encoding).
|
|
132
|
-
*
|
|
133
|
-
* The `'equal' | 'not_equal'` branch matches if `amount` equals ANY of the
|
|
134
|
-
* configured values (consistent with how non-amount filters interpret a
|
|
135
|
-
* multi-value `values` array). `.some()` over the values array also makes
|
|
136
|
-
* the empty-values case behave correctly — empty array → `matched = false`
|
|
137
|
-
* — though in practice `applyTransactionFilters` strips empty-values
|
|
138
|
-
* categories before they reach this matcher. The trailing
|
|
139
|
-
* `op === 'not_equal' ? !matched : matched` line inverts for `not_equal`.
|
|
140
|
-
*/
|
|
141
|
-
const matchAmount = (amount, category) => {
|
|
142
|
-
const op = category.matchingOperator;
|
|
143
|
-
const values = category.values;
|
|
144
|
-
let matched = false;
|
|
145
|
-
if (op === 'in_between') {
|
|
146
|
-
if (values.length >= 2) {
|
|
147
|
-
const min = Number(values[0]);
|
|
148
|
-
const max = Number(values[1]);
|
|
149
|
-
matched = amount >= min && amount <= max;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else if (op === 'less_than') {
|
|
153
|
-
if (values.length >= 1) {
|
|
154
|
-
matched = amount < Number(values[0]);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else if (op === 'greater_than') {
|
|
158
|
-
if (values.length >= 1) {
|
|
159
|
-
matched = amount > Number(values[0]);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (op === 'equal' || op === 'not_equal') {
|
|
163
|
-
matched = values.some((v) => {
|
|
164
|
-
const s = String(v);
|
|
165
|
-
// Backward compatibility: legacy "low<->high" range-string form
|
|
166
|
-
// persisted under `matchingOperator: 'equal'`.
|
|
167
|
-
if (s.includes('<->')) {
|
|
168
|
-
const parts = s.split('<->');
|
|
169
|
-
return (amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? ''));
|
|
170
|
-
}
|
|
171
|
-
return amount === Number(v);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return op === 'not_equal' ? !matched : matched;
|
|
175
|
-
};
|
|
176
|
-
const transactionMatchesCategory = (transaction, category) => {
|
|
177
|
-
const value = getCategoryValueForTransaction(category.field, transaction);
|
|
178
|
-
if (value == null) {
|
|
179
|
-
// Absent values count as a match only under 'not_equal'.
|
|
180
|
-
return category.matchingOperator === 'not_equal';
|
|
181
|
-
}
|
|
182
|
-
if (category.field === 'amount') {
|
|
183
|
-
return matchAmount(Number(value), category);
|
|
184
|
-
}
|
|
185
|
-
const valueStr = value.toString();
|
|
186
|
-
const valueInList = category.values.some((v) => v.toString() === valueStr);
|
|
187
|
-
return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
|
|
191
|
-
* `TransactionView` items against a `TransactionFilters` object using the
|
|
192
|
-
* AND/OR combination semantics from `categoryCombinationOperator`.
|
|
193
|
-
*
|
|
194
|
-
* Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
|
|
195
|
-
* inside the Expense Automation feature group.
|
|
196
|
-
*/
|
|
197
|
-
export const applyTransactionFilters = (transactions, filters) => {
|
|
198
|
-
if (filters?.categories == null || filters.categories.length === 0) {
|
|
199
|
-
return transactions;
|
|
200
|
-
}
|
|
201
|
-
// Mirrors the predicate used by `getTransactionAppliedFiltersCount` on the
|
|
202
|
-
// webc side. A half-filled category — e.g. `in_between` with only the
|
|
203
|
-
// `min` typed — would otherwise survive the filter pass and produce zero
|
|
204
|
-
// matches because `Number("")` collapses to `0`, artificially emptying
|
|
205
|
-
// the list while editing. Skipping such categories keeps the filtered
|
|
206
|
-
// view stable while the user finishes typing.
|
|
207
|
-
const activeCategories = filters.categories.filter((c) => {
|
|
208
|
-
if (c.field == null || c.values.length === 0) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
if (c.field === 'amount' && c.matchingOperator === 'in_between') {
|
|
212
|
-
return (c.values.length >= 2 &&
|
|
213
|
-
String(c.values[0] ?? '').trim() !== '' &&
|
|
214
|
-
String(c.values[1] ?? '').trim() !== '');
|
|
215
|
-
}
|
|
216
|
-
return String(c.values[0] ?? '').trim() !== '';
|
|
217
|
-
});
|
|
218
|
-
if (activeCategories.length === 0) {
|
|
219
|
-
return transactions;
|
|
220
|
-
}
|
|
221
|
-
const op = filters.categoryCombinationOperator;
|
|
222
|
-
return transactions.filter((txn) => {
|
|
223
|
-
if (op === 'AND') {
|
|
224
|
-
return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
|
|
225
|
-
}
|
|
226
|
-
return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
|
|
227
|
-
});
|
|
228
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Filter machinery for the Transaction Categorization feature inside
|
|
3
|
-
* Expense Automation. Intentionally self-contained — does NOT import anything
|
|
4
|
-
* from `view/spendManagement/*`, because Transaction Categorization is not a
|
|
5
|
-
* Spend Management product. Generic primitives (`CategoryCombinationOperator`,
|
|
6
|
-
* `FilterCategoryType`) are redeclared locally rather than imported across the
|
|
7
|
-
* feature boundary; their definitions happen to coincide with the
|
|
8
|
-
* spend-management equivalents, which is fine — they're the same primitive
|
|
9
|
-
* concept used independently by both feature groups.
|
|
10
|
-
*/
|
|
11
|
-
import { Amount } from '../../commonStateTypes/amount';
|
|
12
|
-
import { ID } from '../../commonStateTypes/common';
|
|
13
|
-
import { TransactionType } from '../../entity/transaction/stateTypes/transactionType';
|
|
14
|
-
import { SupportedTransactionWithCOT } from '../../entity/transaction/transactionState';
|
|
15
|
-
import { ZeniDate } from '../../zeniDayJS';
|
|
16
|
-
import { TransactionReviewLocalDataSelectorView } from './selectorTypes/transactionsViewSelectorTypes';
|
|
17
|
-
/** Local copy of the generic combination operator — independent of SM. */
|
|
18
|
-
export type CategoryCombinationOperator = 'AND' | 'OR';
|
|
19
|
-
/** Local copy of the generic filter category-input type — independent of SM. */
|
|
20
|
-
export type FilterCategoryType = 'searchAutocomplete' | 'user' | 'dateRange' | 'numberRange' | 'dropdown';
|
|
21
|
-
export type TransactionFilterEntityType = 'transaction_categorization' | 'customer' | 'vendor' | 'merchant';
|
|
22
|
-
export type TransactionFilterCategoryField = 'payment_account_name' | 'payment_account_type' | 'payee' | 'category' | 'class' | 'amount';
|
|
23
|
-
export interface TransactionFilterCategoryDropdownOption {
|
|
24
|
-
value: TransactionFilterCategoryField;
|
|
25
|
-
multiple?: boolean;
|
|
26
|
-
type?: FilterCategoryType;
|
|
27
|
-
}
|
|
28
|
-
export declare const TRANSACTION_FILTER_CATEGORIES: TransactionFilterCategoryDropdownOption[];
|
|
29
|
-
/** Amount filter operators for transaction_categorization. */
|
|
30
|
-
export type TransactionFilterAmountMatchingOperator = 'equal' | 'not_equal' | 'less_than' | 'greater_than' | 'in_between';
|
|
31
|
-
export interface TransactionFilterCategory {
|
|
32
|
-
field: TransactionFilterCategoryField;
|
|
33
|
-
matchingOperator: TransactionFilterAmountMatchingOperator;
|
|
34
|
-
values: (string | number)[];
|
|
35
|
-
valuesCombinationOperator: 'ANY';
|
|
36
|
-
}
|
|
37
|
-
export interface TransactionFilters {
|
|
38
|
-
categories: TransactionFilterCategory[];
|
|
39
|
-
categoryCombinationOperator: CategoryCombinationOperator;
|
|
40
|
-
}
|
|
41
|
-
export interface TransactionView {
|
|
42
|
-
amount: Amount;
|
|
43
|
-
createTime: ZeniDate;
|
|
44
|
-
date: ZeniDate;
|
|
45
|
-
description: string;
|
|
46
|
-
id: ID;
|
|
47
|
-
memo: string;
|
|
48
|
-
transaction: SupportedTransactionWithCOT;
|
|
49
|
-
type: TransactionType;
|
|
50
|
-
customerId?: ID;
|
|
51
|
-
customerName?: string;
|
|
52
|
-
transactionLocalData?: TransactionReviewLocalDataSelectorView;
|
|
53
|
-
typeName?: string;
|
|
54
|
-
vendorId?: ID;
|
|
55
|
-
vendorName?: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
|
|
59
|
-
* `TransactionView` items against a `TransactionFilters` object using the
|
|
60
|
-
* AND/OR combination semantics from `categoryCombinationOperator`.
|
|
61
|
-
*
|
|
62
|
-
* Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
|
|
63
|
-
* inside the Expense Automation feature group.
|
|
64
|
-
*/
|
|
65
|
-
export declare const applyTransactionFilters: (transactions: TransactionView[], filters?: TransactionFilters) => TransactionView[];
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyTransactionFilters = exports.TRANSACTION_FILTER_CATEGORIES = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Narrowing type-guard for "has a non-empty string here". Used in place of
|
|
6
|
-
* raw `if (foo)` truthiness checks on `string | null | undefined` values so
|
|
7
|
-
* the `@typescript-eslint/strict-boolean-expressions` lint stays clean —
|
|
8
|
-
* empty strings should explicitly fall through to the next candidate
|
|
9
|
-
* (vendorName → customerName → localData.vendor.name → ...) rather than
|
|
10
|
-
* being implicitly coerced to falsy.
|
|
11
|
-
*/
|
|
12
|
-
const isNonEmptyString = (s) => s != null && s !== '';
|
|
13
|
-
exports.TRANSACTION_FILTER_CATEGORIES = [
|
|
14
|
-
{ value: 'payment_account_name', type: 'dropdown' },
|
|
15
|
-
{ value: 'payment_account_type', type: 'dropdown' },
|
|
16
|
-
{ value: 'payee', type: 'searchAutocomplete' },
|
|
17
|
-
{ value: 'category', type: 'dropdown' },
|
|
18
|
-
{ value: 'class', type: 'dropdown' },
|
|
19
|
-
{ value: 'amount', type: 'numberRange' },
|
|
20
|
-
];
|
|
21
|
-
/**
|
|
22
|
-
* Resolve the comparable value for a transaction against a given filter field.
|
|
23
|
-
* Returns undefined when the transaction doesn't carry the field — callers
|
|
24
|
-
* decide whether absence counts as a match (for 'not_equal' it does).
|
|
25
|
-
*/
|
|
26
|
-
const getCategoryValueForTransaction = (key, transaction) => {
|
|
27
|
-
switch (key) {
|
|
28
|
-
case 'amount': {
|
|
29
|
-
// Prefer transactionLocalData line items (sum). Fall back to lines on
|
|
30
|
-
// the transaction itself. Final fallback: transaction-level amount.
|
|
31
|
-
const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
32
|
-
if (localDataForAmount?.lineItemById) {
|
|
33
|
-
const lineItems = Object.values(localDataForAmount.lineItemById);
|
|
34
|
-
if (lineItems.length > 0) {
|
|
35
|
-
return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (transaction.transaction.lines &&
|
|
39
|
-
transaction.transaction.lines.length > 0) {
|
|
40
|
-
return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
|
|
41
|
-
}
|
|
42
|
-
return transaction.amount.amount;
|
|
43
|
-
}
|
|
44
|
-
case 'payee': {
|
|
45
|
-
if (isNonEmptyString(transaction.vendorName)) {
|
|
46
|
-
return transaction.vendorName;
|
|
47
|
-
}
|
|
48
|
-
if (isNonEmptyString(transaction.customerName)) {
|
|
49
|
-
return transaction.customerName;
|
|
50
|
-
}
|
|
51
|
-
const localData = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
52
|
-
const vendorName = localData?.vendor?.name;
|
|
53
|
-
if (isNonEmptyString(vendorName)) {
|
|
54
|
-
return vendorName;
|
|
55
|
-
}
|
|
56
|
-
const customerName = localData?.customer?.name;
|
|
57
|
-
if (isNonEmptyString(customerName)) {
|
|
58
|
-
return customerName;
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
case 'payment_account_name': {
|
|
63
|
-
// Match what TransactionCategorizationListRow renders for the cell.
|
|
64
|
-
return transaction.transaction.account?.accountName;
|
|
65
|
-
}
|
|
66
|
-
case 'payment_account_type': {
|
|
67
|
-
// Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
|
|
68
|
-
// option values use the same enum; row uses `paymentTypeName` for the
|
|
69
|
-
// human label.
|
|
70
|
-
return transaction.transaction.paymentType;
|
|
71
|
-
}
|
|
72
|
-
case 'category': {
|
|
73
|
-
const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
74
|
-
if (localDataForCategory != null) {
|
|
75
|
-
const firstLineItem = Object.values(localDataForCategory.lineItemById)[0];
|
|
76
|
-
const accountId = firstLineItem?.account?.accountId;
|
|
77
|
-
if (isNonEmptyString(accountId)) {
|
|
78
|
-
return accountId;
|
|
79
|
-
}
|
|
80
|
-
const qboId = firstLineItem?.account?.qboId;
|
|
81
|
-
if (isNonEmptyString(qboId)) {
|
|
82
|
-
return qboId;
|
|
83
|
-
}
|
|
84
|
-
const accountName = firstLineItem?.account?.accountName;
|
|
85
|
-
if (isNonEmptyString(accountName)) {
|
|
86
|
-
return accountName;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const firstLineForCategory = transaction.transaction.lines?.[0];
|
|
90
|
-
if (firstLineForCategory?.type ===
|
|
91
|
-
'transaction_with_account_and_class_line' ||
|
|
92
|
-
firstLineForCategory?.type ===
|
|
93
|
-
'transaction_with_product_or_service_line' ||
|
|
94
|
-
firstLineForCategory?.type === 'journal_entry_transaction_line') {
|
|
95
|
-
const account = firstLineForCategory.account;
|
|
96
|
-
return account?.accountId ?? account?.qboId ?? account?.accountName;
|
|
97
|
-
}
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
case 'class': {
|
|
101
|
-
const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
102
|
-
if (localDataForClass != null) {
|
|
103
|
-
const firstLineItemForClass = Object.values(localDataForClass.lineItemById)[0];
|
|
104
|
-
const classId = firstLineItemForClass?.class?.classId;
|
|
105
|
-
if (isNonEmptyString(classId)) {
|
|
106
|
-
return classId;
|
|
107
|
-
}
|
|
108
|
-
const qboId = firstLineItemForClass?.class?.qboId;
|
|
109
|
-
if (isNonEmptyString(qboId)) {
|
|
110
|
-
return qboId;
|
|
111
|
-
}
|
|
112
|
-
const className = firstLineItemForClass?.class?.className;
|
|
113
|
-
if (isNonEmptyString(className)) {
|
|
114
|
-
return className;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const firstLineForClass = transaction.transaction.lines?.[0];
|
|
118
|
-
if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
|
|
119
|
-
firstLineForClass?.type ===
|
|
120
|
-
'transaction_with_product_or_service_line' ||
|
|
121
|
-
firstLineForClass?.type === 'journal_entry_transaction_line') {
|
|
122
|
-
const classData = firstLineForClass.class;
|
|
123
|
-
return classData?.classId ?? classData?.qboId ?? classData?.className;
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
default:
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* TC-only amount matcher. Supports all five operators TC defines, including
|
|
133
|
-
* the legacy "1000<->5000" range-string form (kept for backward compatibility
|
|
134
|
-
* with persisted filter state that may still contain that encoding).
|
|
135
|
-
*
|
|
136
|
-
* The `'equal' | 'not_equal'` branch matches if `amount` equals ANY of the
|
|
137
|
-
* configured values (consistent with how non-amount filters interpret a
|
|
138
|
-
* multi-value `values` array). `.some()` over the values array also makes
|
|
139
|
-
* the empty-values case behave correctly — empty array → `matched = false`
|
|
140
|
-
* — though in practice `applyTransactionFilters` strips empty-values
|
|
141
|
-
* categories before they reach this matcher. The trailing
|
|
142
|
-
* `op === 'not_equal' ? !matched : matched` line inverts for `not_equal`.
|
|
143
|
-
*/
|
|
144
|
-
const matchAmount = (amount, category) => {
|
|
145
|
-
const op = category.matchingOperator;
|
|
146
|
-
const values = category.values;
|
|
147
|
-
let matched = false;
|
|
148
|
-
if (op === 'in_between') {
|
|
149
|
-
if (values.length >= 2) {
|
|
150
|
-
const min = Number(values[0]);
|
|
151
|
-
const max = Number(values[1]);
|
|
152
|
-
matched = amount >= min && amount <= max;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else if (op === 'less_than') {
|
|
156
|
-
if (values.length >= 1) {
|
|
157
|
-
matched = amount < Number(values[0]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else if (op === 'greater_than') {
|
|
161
|
-
if (values.length >= 1) {
|
|
162
|
-
matched = amount > Number(values[0]);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else if (op === 'equal' || op === 'not_equal') {
|
|
166
|
-
matched = values.some((v) => {
|
|
167
|
-
const s = String(v);
|
|
168
|
-
// Backward compatibility: legacy "low<->high" range-string form
|
|
169
|
-
// persisted under `matchingOperator: 'equal'`.
|
|
170
|
-
if (s.includes('<->')) {
|
|
171
|
-
const parts = s.split('<->');
|
|
172
|
-
return (amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? ''));
|
|
173
|
-
}
|
|
174
|
-
return amount === Number(v);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return op === 'not_equal' ? !matched : matched;
|
|
178
|
-
};
|
|
179
|
-
const transactionMatchesCategory = (transaction, category) => {
|
|
180
|
-
const value = getCategoryValueForTransaction(category.field, transaction);
|
|
181
|
-
if (value == null) {
|
|
182
|
-
// Absent values count as a match only under 'not_equal'.
|
|
183
|
-
return category.matchingOperator === 'not_equal';
|
|
184
|
-
}
|
|
185
|
-
if (category.field === 'amount') {
|
|
186
|
-
return matchAmount(Number(value), category);
|
|
187
|
-
}
|
|
188
|
-
const valueStr = value.toString();
|
|
189
|
-
const valueInList = category.values.some((v) => v.toString() === valueStr);
|
|
190
|
-
return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
|
|
194
|
-
* `TransactionView` items against a `TransactionFilters` object using the
|
|
195
|
-
* AND/OR combination semantics from `categoryCombinationOperator`.
|
|
196
|
-
*
|
|
197
|
-
* Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
|
|
198
|
-
* inside the Expense Automation feature group.
|
|
199
|
-
*/
|
|
200
|
-
const applyTransactionFilters = (transactions, filters) => {
|
|
201
|
-
if (filters?.categories == null || filters.categories.length === 0) {
|
|
202
|
-
return transactions;
|
|
203
|
-
}
|
|
204
|
-
// Mirrors the predicate used by `getTransactionAppliedFiltersCount` on the
|
|
205
|
-
// webc side. A half-filled category — e.g. `in_between` with only the
|
|
206
|
-
// `min` typed — would otherwise survive the filter pass and produce zero
|
|
207
|
-
// matches because `Number("")` collapses to `0`, artificially emptying
|
|
208
|
-
// the list while editing. Skipping such categories keeps the filtered
|
|
209
|
-
// view stable while the user finishes typing.
|
|
210
|
-
const activeCategories = filters.categories.filter((c) => {
|
|
211
|
-
if (c.field == null || c.values.length === 0) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
if (c.field === 'amount' && c.matchingOperator === 'in_between') {
|
|
215
|
-
return (c.values.length >= 2 &&
|
|
216
|
-
String(c.values[0] ?? '').trim() !== '' &&
|
|
217
|
-
String(c.values[1] ?? '').trim() !== '');
|
|
218
|
-
}
|
|
219
|
-
return String(c.values[0] ?? '').trim() !== '';
|
|
220
|
-
});
|
|
221
|
-
if (activeCategories.length === 0) {
|
|
222
|
-
return transactions;
|
|
223
|
-
}
|
|
224
|
-
const op = filters.categoryCombinationOperator;
|
|
225
|
-
return transactions.filter((txn) => {
|
|
226
|
-
if (op === 'AND') {
|
|
227
|
-
return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
|
|
228
|
-
}
|
|
229
|
-
return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
exports.applyTransactionFilters = applyTransactionFilters;
|