@zeniai/client-epic-state 5.0.64-betaAR2 → 5.0.64-betaML1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/commonStateTypes/viewAndReport/viewAndReport.d.ts +2 -2
  2. package/lib/commonStateTypes/viewAndReport/viewAndReport.js +2 -0
  3. package/lib/entity/account/accountSelector.d.ts +10 -20
  4. package/lib/entity/account/accountSelector.js +14 -35
  5. package/lib/entity/account/accountState.d.ts +1 -6
  6. package/lib/entity/account/accountState.js +4 -11
  7. package/lib/entity/accountGroup/accountGroupState.d.ts +1 -1
  8. package/lib/entity/class/classReducer.d.ts +4 -4
  9. package/lib/entity/class/classSelector.d.ts +0 -5
  10. package/lib/entity/class/classSelector.js +0 -8
  11. package/lib/entity/class/classState.d.ts +1 -1
  12. package/lib/entity/forecast/forecastState.d.ts +1 -1
  13. package/lib/entity/sectionAccountsView/sectionAccountsView.d.ts +1 -1
  14. package/lib/entity/sectionClassesViewV2/sectionClassesView.d.ts +1 -1
  15. package/lib/entity/sectionClassesViewV2/sectionClassesViewReducer.d.ts +2 -2
  16. package/lib/entity/sectionProjectView/sectionProjectView.d.ts +1 -1
  17. package/lib/entity/sectionProjectView/sectionProjectViewReducer.d.ts +2 -2
  18. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  19. package/lib/entity/snackbar/snackbarTypes.js +2 -0
  20. package/lib/entity/transaction/payloadTypes/transactionPayload.d.ts +4 -0
  21. package/lib/entity/transaction/payloadTypes/transactionPayload.js +10 -0
  22. package/lib/entity/transaction/stateTypes/transaction.d.ts +3 -0
  23. package/lib/epic.d.ts +3 -1
  24. package/lib/epic.js +3 -1
  25. package/lib/esm/commonStateTypes/viewAndReport/viewAndReport.js +2 -0
  26. package/lib/esm/entity/account/accountSelector.js +12 -33
  27. package/lib/esm/entity/account/accountState.js +1 -7
  28. package/lib/esm/entity/class/classSelector.js +0 -7
  29. package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
  30. package/lib/esm/entity/transaction/payloadTypes/transactionPayload.js +10 -0
  31. package/lib/esm/epic.js +3 -1
  32. package/lib/esm/index.js +6 -12
  33. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/createTransferEntryEpic.js +81 -0
  34. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.js +8 -1
  35. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransferAccountsEpic.js +30 -0
  36. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +79 -11
  37. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +38 -58
  38. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +5 -0
  39. package/lib/esm/view/spendManagement/spendManagementFilterHelpers.js +0 -2
  40. package/lib/esm/view/transactionDetail/epics/transactionDetailEpic.js +10 -0
  41. package/lib/esm/view/transactionDetail/transactionDetailSelector.js +24 -2
  42. package/lib/index.d.ts +7 -9
  43. package/lib/index.js +42 -41
  44. package/lib/tsconfig.typecheck.tsbuildinfo +1 -1
  45. package/lib/view/auditReportView/auditReportViewState.d.ts +1 -1
  46. package/lib/view/billPayCard/billPayCardSelector.d.ts +1 -1
  47. package/lib/view/cardBalance/cardBalanceSelector.d.ts +1 -1
  48. package/lib/view/cashBalance/cashBalanceSelector.d.ts +1 -1
  49. package/lib/view/cashInCashOut/cashInCashOutSelector.d.ts +1 -1
  50. package/lib/view/cashPosition/cashPositionSelector.d.ts +1 -1
  51. package/lib/view/dashboard/dashboardReducer.d.ts +2 -2
  52. package/lib/view/expenseAutomationView/epics/transactionCategorization/createTransferEntryEpic.d.ts +9 -0
  53. package/lib/view/expenseAutomationView/epics/transactionCategorization/createTransferEntryEpic.js +85 -0
  54. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.d.ts +2 -2
  55. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.js +7 -0
  56. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransferAccountsEpic.d.ts +8 -0
  57. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransferAccountsEpic.js +34 -0
  58. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  59. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +22 -7
  60. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +80 -12
  61. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +4 -1
  62. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +3 -4
  63. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +39 -60
  64. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +18 -3
  65. package/lib/view/expenseAutomationView/types/transactionsViewState.js +6 -1
  66. package/lib/view/financeStatement/financeStatementReducer.d.ts +1 -1
  67. package/lib/view/globalMerchantView/globalMerchantViewReducer.d.ts +2 -2
  68. package/lib/view/reimbursementCard/reimbursementCardSelector.d.ts +1 -1
  69. package/lib/view/reportsResync/reportsResyncReducer.d.ts +2 -2
  70. package/lib/view/spendManagement/spendManagementFilterHelpers.js +0 -2
  71. package/lib/view/tasksCard/tasksCardSelector.d.ts +1 -1
  72. package/lib/view/topEx/topExSelector.d.ts +1 -1
  73. package/lib/view/transactionDetail/epics/transactionDetailEpic.d.ts +2 -1
  74. package/lib/view/transactionDetail/epics/transactionDetailEpic.js +10 -0
  75. package/lib/view/transactionDetail/transactionDetailPayload.d.ts +1 -1
  76. package/lib/view/transactionDetail/transactionDetailSelector.d.ts +6 -1
  77. package/lib/view/transactionDetail/transactionDetailSelector.js +23 -1
  78. package/package.json +1 -1
  79. package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +0 -186
  80. package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +0 -65
  81. package/lib/view/expenseAutomationView/transactionFilterHelpers.js +0 -190
@@ -1,186 +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
- const matchAmount = (amount, category) => {
117
- const op = category.matchingOperator;
118
- const values = category.values;
119
- let matched = false;
120
- if (op === 'in_between') {
121
- if (values.length >= 2) {
122
- const min = Number(values[0]);
123
- const max = Number(values[1]);
124
- matched = amount >= min && amount <= max;
125
- }
126
- }
127
- else if (op === 'less_than') {
128
- if (values.length >= 1) {
129
- matched = amount < Number(values[0]);
130
- }
131
- }
132
- else if (op === 'greater_than') {
133
- if (values.length >= 1) {
134
- matched = amount > Number(values[0]);
135
- }
136
- }
137
- else if (op === 'equal' &&
138
- values.length === 1 &&
139
- String(values[0]).includes('<->')) {
140
- // Backward compatibility: ["1000<->5000"] with matchingOperator "equal".
141
- const parts = String(values[0]).split('<->');
142
- matched =
143
- amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? '');
144
- }
145
- else if (op === 'equal' && values.length === 1) {
146
- matched = amount === Number(values[0]);
147
- }
148
- return op === 'not-equal' ? !matched : matched;
149
- };
150
- const transactionMatchesCategory = (transaction, category) => {
151
- const value = getCategoryValueForTransaction(category.field, transaction);
152
- if (value == null) {
153
- // Absent values count as a match only under 'not-equal'.
154
- return category.matchingOperator === 'not-equal';
155
- }
156
- if (category.field === 'amount') {
157
- return matchAmount(Number(value), category);
158
- }
159
- const valueStr = value.toString();
160
- const valueInList = category.values.some((v) => v.toString() === valueStr);
161
- return category.matchingOperator === 'not-equal' ? !valueInList : valueInList;
162
- };
163
- /**
164
- * TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
165
- * `TransactionView` items against a `TransactionFilters` object using the
166
- * AND/OR combination semantics from `categoryCombinationOperator`.
167
- *
168
- * Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
169
- * inside the Expense Automation feature group.
170
- */
171
- export const applyTransactionFilters = (transactions, filters) => {
172
- if (filters?.categories == null || filters.categories.length === 0) {
173
- return transactions;
174
- }
175
- const activeCategories = filters.categories.filter((c) => c.field != null && c.values.length > 0);
176
- if (activeCategories.length === 0) {
177
- return transactions;
178
- }
179
- const op = filters.categoryCombinationOperator;
180
- return transactions.filter((txn) => {
181
- if (op === 'AND') {
182
- return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
183
- }
184
- return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
185
- });
186
- };
@@ -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,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyTransactionFilters = exports.TRANSACTION_FILTER_CATEGORIES = void 0;
4
- exports.TRANSACTION_FILTER_CATEGORIES = [
5
- { value: 'payment_account_name', type: 'dropdown' },
6
- { value: 'payment_account_type', type: 'dropdown' },
7
- { value: 'payee', type: 'searchAutocomplete' },
8
- { value: 'category', type: 'dropdown' },
9
- { value: 'class', type: 'dropdown' },
10
- { value: 'amount', type: 'numberRange' },
11
- ];
12
- /**
13
- * Resolve the comparable value for a transaction against a given filter field.
14
- * Returns undefined when the transaction doesn't carry the field — callers
15
- * decide whether absence counts as a match (for 'not-equal' it does).
16
- */
17
- const getCategoryValueForTransaction = (key, transaction) => {
18
- switch (key) {
19
- case 'amount': {
20
- // Prefer transactionLocalData line items (sum). Fall back to lines on
21
- // the transaction itself. Final fallback: transaction-level amount.
22
- const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
23
- if (localDataForAmount?.lineItemById) {
24
- const lineItems = Object.values(localDataForAmount.lineItemById);
25
- if (lineItems.length > 0) {
26
- return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
27
- }
28
- }
29
- if (transaction.transaction.lines &&
30
- transaction.transaction.lines.length > 0) {
31
- return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
32
- }
33
- return transaction.amount.amount;
34
- }
35
- case 'payee': {
36
- if (transaction.vendorName) {
37
- return transaction.vendorName;
38
- }
39
- if (transaction.customerName) {
40
- return transaction.customerName;
41
- }
42
- const localData = transaction.transactionLocalData?.transactionReviewLocalData;
43
- if (localData?.vendor?.name) {
44
- return localData.vendor.name;
45
- }
46
- if (localData?.customer?.name) {
47
- return localData.customer.name;
48
- }
49
- return undefined;
50
- }
51
- case 'payment_account_name': {
52
- // Match what TransactionCategorizationListRow renders for the cell.
53
- return transaction.transaction.account?.accountName;
54
- }
55
- case 'payment_account_type': {
56
- // Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
57
- // option values use the same enum; row uses `paymentTypeName` for the
58
- // human label.
59
- return transaction.transaction.paymentType;
60
- }
61
- case 'category': {
62
- const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
63
- if (localDataForCategory) {
64
- const firstLineItem = Object.values(localDataForCategory.lineItemById)[0];
65
- if (firstLineItem?.account?.accountId) {
66
- return firstLineItem.account.accountId;
67
- }
68
- if (firstLineItem?.account?.qboId) {
69
- return firstLineItem.account.qboId;
70
- }
71
- if (firstLineItem?.account?.accountName) {
72
- return firstLineItem.account.accountName;
73
- }
74
- }
75
- const firstLineForCategory = transaction.transaction.lines?.[0];
76
- if (firstLineForCategory?.type ===
77
- 'transaction_with_account_and_class_line' ||
78
- firstLineForCategory?.type ===
79
- 'transaction_with_product_or_service_line' ||
80
- firstLineForCategory?.type === 'journal_entry_transaction_line') {
81
- const account = firstLineForCategory.account;
82
- return account?.accountId ?? account?.qboId ?? account?.accountName;
83
- }
84
- return undefined;
85
- }
86
- case 'class': {
87
- const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
88
- if (localDataForClass) {
89
- const firstLineItemForClass = Object.values(localDataForClass.lineItemById)[0];
90
- if (firstLineItemForClass?.class?.classId) {
91
- return firstLineItemForClass.class.classId;
92
- }
93
- if (firstLineItemForClass?.class?.qboId) {
94
- return firstLineItemForClass.class.qboId;
95
- }
96
- if (firstLineItemForClass?.class?.className) {
97
- return firstLineItemForClass.class.className;
98
- }
99
- }
100
- const firstLineForClass = transaction.transaction.lines?.[0];
101
- if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
102
- firstLineForClass?.type ===
103
- 'transaction_with_product_or_service_line' ||
104
- firstLineForClass?.type === 'journal_entry_transaction_line') {
105
- const classData = firstLineForClass.class;
106
- return classData?.classId ?? classData?.qboId ?? classData?.className;
107
- }
108
- return undefined;
109
- }
110
- default:
111
- return undefined;
112
- }
113
- };
114
- /**
115
- * TC-only amount matcher. Supports all five operators TC defines, including
116
- * the legacy "1000<->5000" range-string form (kept for backward compatibility
117
- * with persisted filter state that may still contain that encoding).
118
- */
119
- const matchAmount = (amount, category) => {
120
- const op = category.matchingOperator;
121
- const values = category.values;
122
- let matched = false;
123
- if (op === 'in_between') {
124
- if (values.length >= 2) {
125
- const min = Number(values[0]);
126
- const max = Number(values[1]);
127
- matched = amount >= min && amount <= max;
128
- }
129
- }
130
- else if (op === 'less_than') {
131
- if (values.length >= 1) {
132
- matched = amount < Number(values[0]);
133
- }
134
- }
135
- else if (op === 'greater_than') {
136
- if (values.length >= 1) {
137
- matched = amount > Number(values[0]);
138
- }
139
- }
140
- else if (op === 'equal' &&
141
- values.length === 1 &&
142
- String(values[0]).includes('<->')) {
143
- // Backward compatibility: ["1000<->5000"] with matchingOperator "equal".
144
- const parts = String(values[0]).split('<->');
145
- matched =
146
- amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? '');
147
- }
148
- else if (op === 'equal' && values.length === 1) {
149
- matched = amount === Number(values[0]);
150
- }
151
- return op === 'not-equal' ? !matched : matched;
152
- };
153
- const transactionMatchesCategory = (transaction, category) => {
154
- const value = getCategoryValueForTransaction(category.field, transaction);
155
- if (value == null) {
156
- // Absent values count as a match only under 'not-equal'.
157
- return category.matchingOperator === 'not-equal';
158
- }
159
- if (category.field === 'amount') {
160
- return matchAmount(Number(value), category);
161
- }
162
- const valueStr = value.toString();
163
- const valueInList = category.values.some((v) => v.toString() === valueStr);
164
- return category.matchingOperator === 'not-equal' ? !valueInList : valueInList;
165
- };
166
- /**
167
- * TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
168
- * `TransactionView` items against a `TransactionFilters` object using the
169
- * AND/OR combination semantics from `categoryCombinationOperator`.
170
- *
171
- * Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
172
- * inside the Expense Automation feature group.
173
- */
174
- const applyTransactionFilters = (transactions, filters) => {
175
- if (filters?.categories == null || filters.categories.length === 0) {
176
- return transactions;
177
- }
178
- const activeCategories = filters.categories.filter((c) => c.field != null && c.values.length > 0);
179
- if (activeCategories.length === 0) {
180
- return transactions;
181
- }
182
- const op = filters.categoryCombinationOperator;
183
- return transactions.filter((txn) => {
184
- if (op === 'AND') {
185
- return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
186
- }
187
- return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
188
- });
189
- };
190
- exports.applyTransactionFilters = applyTransactionFilters;