@zeniai/client-epic-state 5.0.69-betaAR4 → 5.0.69-betaAR5

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 (66) hide show
  1. package/lib/commonStateTypes/filterPrimitives.d.ts +23 -0
  2. package/lib/commonStateTypes/filterPrimitives.js +21 -0
  3. package/lib/entity/account/accountSelector.d.ts +26 -0
  4. package/lib/entity/account/accountSelector.js +47 -1
  5. package/lib/entity/account/accountState.d.ts +5 -0
  6. package/lib/entity/account/accountState.js +11 -4
  7. package/lib/entity/approvalRule/approvalRulePayload.d.ts +5 -27
  8. package/lib/entity/approvalRule/approvalRulePayload.js +10 -131
  9. package/lib/entity/approvalRule/approvalRuleSelector.d.ts +1 -25
  10. package/lib/entity/approvalRule/approvalRuleSelector.js +0 -40
  11. package/lib/entity/approvalRule/approvalRuleState.d.ts +7 -48
  12. package/lib/entity/class/classSelector.d.ts +35 -0
  13. package/lib/entity/class/classSelector.js +50 -0
  14. package/lib/esm/commonStateTypes/filterPrimitives.js +20 -0
  15. package/lib/esm/entity/account/accountSelector.js +46 -1
  16. package/lib/esm/entity/account/accountState.js +7 -1
  17. package/lib/esm/entity/approvalRule/approvalRulePayload.js +10 -131
  18. package/lib/esm/entity/approvalRule/approvalRuleSelector.js +0 -35
  19. package/lib/esm/entity/class/classSelector.js +48 -0
  20. package/lib/esm/index.js +11 -6
  21. package/lib/esm/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
  22. package/lib/esm/view/companyView/helpers/cockpitHelpers.js +1 -1
  23. package/lib/esm/view/companyView/selector/companyManagementViewSelector.js +1 -1
  24. package/lib/esm/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
  25. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +11 -1
  26. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +69 -12
  27. package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +245 -0
  28. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +7 -11
  29. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +16 -61
  30. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +2 -7
  31. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +7 -11
  32. package/lib/esm/view/spendManagement/spendManagementFilterHelpers.js +4 -2
  33. package/lib/esm/view/subscriptionView/subscriptionViewSelector.js +1 -1
  34. package/lib/esm/view/taskManager/taskListView/taskListReducer.js +1 -1
  35. package/lib/index.d.ts +9 -8
  36. package/lib/index.js +41 -38
  37. package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
  38. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  39. package/lib/view/companyView/helpers/cockpitHelpers.js +1 -1
  40. package/lib/view/companyView/selector/companyManagementViewSelector.js +1 -1
  41. package/lib/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
  42. package/lib/view/companyView/types/cockpitTypes.d.ts +2 -2
  43. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +5 -1
  44. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +12 -2
  45. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +4 -1
  46. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +71 -12
  47. package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +66 -0
  48. package/lib/view/expenseAutomationView/transactionFilterHelpers.js +249 -0
  49. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -0
  50. package/lib/view/people/peopleTypes.d.ts +1 -1
  51. package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
  52. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +6 -10
  53. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +1 -9
  54. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +16 -61
  55. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +5 -31
  56. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +2 -7
  57. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  58. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistory.d.ts +1 -1
  59. package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +1 -1
  60. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +6 -10
  61. package/lib/view/spendManagement/spendManagementFilterHelpers.d.ts +12 -3
  62. package/lib/view/spendManagement/spendManagementFilterHelpers.js +4 -2
  63. package/lib/view/subscriptionView/subscriptionViewSelector.js +1 -1
  64. package/lib/view/taskManager/taskListView/taskList.d.ts +4 -4
  65. package/lib/view/taskManager/taskListView/taskListReducer.js +1 -1
  66. package/package.json +1 -1
@@ -4,14 +4,33 @@ import { toMonthYearPeriodId } from '../../../commonStateTypes/timePeriod';
4
4
  import { getCurrentTenant, getIsAccountingClassesEnabled, getIsAccountingProjectsEnabled, } from '../../../entity/tenant/tenantSelector';
5
5
  import { getTransactionWithCOT } from '../../../entity/transaction/transactionHelper';
6
6
  import { getSupportedTransactionsByIds } from '../../../entity/transaction/transactionSelector';
7
+ import { applyTransactionFilters, } from '../transactionFilterHelpers';
7
8
  import { getAccountList, getNestedAccountListHierarchy, getUncategorizedAccounts, } from '../../accountList/accountListSelector';
8
9
  import { getClassList, getNestedClassListHierarchy, } from '../../classList/classListSelector';
9
10
  import { getProjectList } from '../../projectList/projectListSelector';
10
11
  import { getAllSteps } from '../selectorTypes/expenseAutomationViewSelectorTypes';
12
+ export const toTransactionView = (transaction, transactionLocalData) => {
13
+ return {
14
+ id: transaction.id,
15
+ date: transaction.date,
16
+ amount: transaction.amount,
17
+ vendorName: transaction.vendorName,
18
+ customerName: transaction.customerName,
19
+ vendorId: transaction.vendorId,
20
+ customerId: transaction.customerId,
21
+ description: transaction.description,
22
+ memo: transaction.memo,
23
+ type: transaction.type,
24
+ typeName: transaction.typeName,
25
+ createTime: transaction.createTime,
26
+ transaction: transaction,
27
+ transactionLocalData,
28
+ };
29
+ };
11
30
  export function getExpenseAutomationTransactionView(state) {
12
31
  const { accountState, classState, classListState, accountListState, expenseAutomationTransactionsViewState, expenseAutomationViewState, projectState, projectListState, transactionState, monthEndCloseChecksState, monthEndCloseChecksViewState, } = state;
13
32
  const { selectedTransactionCategorizationCompletedSubTab, selectedTransactionCategorizationTab, } = expenseAutomationTransactionsViewState;
14
- const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId, } = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTransactionCategorizationTab];
33
+ const { uiState, refreshStatus, saveStatus, markAsNotMiscategorizedStatus, transactionIdsBySelectedPeriod, transactionReviewLocalDataById, selectedCheckBoxTransactionIds, transactionIdsWithUnsavedData, uploadReceiptStatusById, selectedTransactionId, selectedTransactionLineId, filters, } = expenseAutomationTransactionsViewState.transactionCategorizationView[selectedTransactionCategorizationTab];
15
34
  const uncategorizedIncomeExpense = getUncategorizedAccounts(accountState, accountListState, 'accountList');
16
35
  const accountList = getAccountList(accountState, accountListState, 'accountList');
17
36
  const classList = getClassList(classState, classListState);
@@ -30,20 +49,58 @@ export function getExpenseAutomationTransactionView(state) {
30
49
  ? transactionIdsBySelectedPeriod[monthYearPeriodId]
31
50
  : null;
32
51
  const transactionIds = transactionIdsForSelectedPeriod ?? [];
33
- const transactionLocalData = transactionIds
34
- .map((transactionId) => {
52
+ const transactions = getSupportedTransactionsByIds(transactionState, transactionIds);
53
+ const transactionsWithCOT = transactions.map((transaction) => getTransactionWithCOT(transaction));
54
+ const transactionLocalDataMap = new Map();
55
+ transactionIds.forEach((transactionId) => {
35
56
  const transactionData = transactionReviewLocalDataById[transactionId];
36
57
  if (transactionData != null) {
37
- return {
58
+ transactionLocalDataMap.set(transactionId, {
38
59
  transactionId,
39
60
  transactionReviewLocalData: transactionData.transactionReviewLocalData,
40
- };
61
+ });
41
62
  }
42
- return null;
43
- })
44
- .filter((transaction) => transaction != null);
45
- const transactions = getSupportedTransactionsByIds(transactionState, transactionIds);
46
- const transactionsWithCOT = transactions.map((transaction) => getTransactionWithCOT(transaction));
63
+ });
64
+ // Step 2: Convert to TransactionView and apply advanced filters
65
+ const transactionViews = transactionsWithCOT.map((transaction) => {
66
+ const localData = transactionLocalDataMap.get(transaction.id);
67
+ return toTransactionView(transaction, localData);
68
+ });
69
+ // Apply TC-specific filters (lives under expenseAutomationView, independent
70
+ // of the Spend Management filter pipeline).
71
+ const filteredTransactionViews = applyTransactionFilters(transactionViews, filters);
72
+ // Convert back to TransactionWithCOT for return
73
+ const filteredTransactionsWithCOT = filteredTransactionViews.map((view) => view.transaction);
74
+ // Get transactionLocalData for filtered transactions
75
+ // Also include transactionLocalData for transactions that don't exist in transactionState
76
+ // but have local data (to match original behavior)
77
+ const filteredTransactionIds = new Set(filteredTransactionViews.map((view) => view.id));
78
+ // Pre-compute the membership set once. The previous implementation called
79
+ // `transactions.some(t => t.id === transactionId)` inside the per-id loop,
80
+ // turning the pipeline into O(n × m) — measurable on tenants with large
81
+ // transaction lists since this selector runs on every Redux dispatch.
82
+ const transactionExistsById = new Set(transactions.map((t) => t.id));
83
+ // `.flatMap` returns `X[]` directly when the callback returns `[]` for the
84
+ // skip case, so we don't need the trailing `.filter((d): d is X => …)` type
85
+ // predicate that the previous `map → filter` pipeline required.
86
+ const filteredTransactionLocalData = transactionIds.flatMap((transactionId) => {
87
+ const transactionData = transactionReviewLocalDataById[transactionId];
88
+ if (transactionData == null) {
89
+ return [];
90
+ }
91
+ // Include if transaction is in filtered results, or if transaction doesn't exist in state
92
+ // (to maintain backward compatibility with tests)
93
+ const transactionExists = transactionExistsById.has(transactionId);
94
+ if (filteredTransactionIds.has(transactionId) || !transactionExists) {
95
+ return [
96
+ {
97
+ transactionId,
98
+ transactionReviewLocalData: transactionData.transactionReviewLocalData,
99
+ },
100
+ ];
101
+ }
102
+ return [];
103
+ });
47
104
  const monthEndFetchState = monthYearPeriodId != null
48
105
  ? (monthEndCloseChecksViewState.monthEndCloseChecksViewByTenantId[currentTenant.tenantId]?.[monthYearPeriodId] ?? { fetchState: 'Not-Started', error: undefined })
49
106
  : { fetchState: 'Not-Started', error: undefined };
@@ -107,7 +164,7 @@ export function getExpenseAutomationTransactionView(state) {
107
164
  version: 0,
108
165
  fetchState: fetchStatus.fetchState,
109
166
  error: fetchStatus.error,
110
- transactions: transactionsWithCOT,
167
+ transactions: filteredTransactionsWithCOT,
111
168
  selectedCheckBoxTransactionIds,
112
169
  transactionIdsWithUnsavedData,
113
170
  uncategorizedAccounts: uncategorizedIncomeExpense,
@@ -118,7 +175,7 @@ export function getExpenseAutomationTransactionView(state) {
118
175
  classHierarchyList,
119
176
  isAccountingProjectsEnabled,
120
177
  projectList,
121
- transactionLocalData,
178
+ transactionLocalData: filteredTransactionLocalData,
122
179
  uiState,
123
180
  refreshStatus,
124
181
  saveStatus,
@@ -0,0 +1,245 @@
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-value semantics — pinning these down explicitly so the
180
+ // asymmetry isn't surprising:
181
+ //
182
+ // not_equal: a missing value IS NOT EQUAL to any candidate, so the
183
+ // transaction matches the filter (passes through).
184
+ // equal: a missing value is not equal to any candidate, so the
185
+ // transaction does NOT match (filtered out).
186
+ // less_than / greater_than: SQL-style three-valued logic — comparing
187
+ // against a missing value is "unknown", which we treat as
188
+ // "does not match" (filtered out). A user setting
189
+ // "amount < $1000" probably wants transactions with a
190
+ // concrete amount that satisfies the bound, not rows
191
+ // where the amount can't be determined.
192
+ // in_between: same as the single-sided comparators — missing values
193
+ // are filtered out.
194
+ //
195
+ // Only the `not_equal` branch returns `true` here; everything else
196
+ // falls through to the `false` below.
197
+ return category.matchingOperator === 'not_equal';
198
+ }
199
+ if (category.field === 'amount') {
200
+ return matchAmount(Number(value), category);
201
+ }
202
+ const valueStr = value.toString();
203
+ const valueInList = category.values.some((v) => v.toString() === valueStr);
204
+ return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
205
+ };
206
+ /**
207
+ * TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
208
+ * `TransactionView` items against a `TransactionFilters` object using the
209
+ * AND/OR combination semantics from `categoryCombinationOperator`.
210
+ *
211
+ * Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
212
+ * inside the Expense Automation feature group.
213
+ */
214
+ export const applyTransactionFilters = (transactions, filters) => {
215
+ if (filters?.categories == null || filters.categories.length === 0) {
216
+ return transactions;
217
+ }
218
+ // Mirrors the predicate used by `getTransactionAppliedFiltersCount` on the
219
+ // webc side. A half-filled category — e.g. `in_between` with only the
220
+ // `min` typed — would otherwise survive the filter pass and produce zero
221
+ // matches because `Number("")` collapses to `0`, artificially emptying
222
+ // the list while editing. Skipping such categories keeps the filtered
223
+ // view stable while the user finishes typing.
224
+ const activeCategories = filters.categories.filter((c) => {
225
+ if (c.field == null || c.values.length === 0) {
226
+ return false;
227
+ }
228
+ if (c.field === 'amount' && c.matchingOperator === 'in_between') {
229
+ return (c.values.length >= 2 &&
230
+ String(c.values[0] ?? '').trim() !== '' &&
231
+ String(c.values[1] ?? '').trim() !== '');
232
+ }
233
+ return String(c.values[0] ?? '').trim() !== '';
234
+ });
235
+ if (activeCategories.length === 0) {
236
+ return transactions;
237
+ }
238
+ const op = filters.categoryCombinationOperator;
239
+ return transactions.filter((txn) => {
240
+ if (op === 'AND') {
241
+ return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
242
+ }
243
+ return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
244
+ });
245
+ };
@@ -1,6 +1,6 @@
1
1
  import { from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
- import { getAmountCriteria, getApprovalRuleById, getDepartmentCriteria, getVendorCriteria, } from '../../../../../entity/approvalRule/approvalRuleSelector';
3
+ import { getApprovalRuleById } from '../../../../../entity/approvalRule/approvalRuleSelector';
4
4
  import { clearBillPaySetupApproverViewUpdateData, initializeBillPaySetupApproverViewUpdateData, saveBillPaySetupApproverViewUpdateData, } from '../billPaySetupApproverViewReducer';
5
5
  export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state$) => actions$.pipe(filter(initializeBillPaySetupApproverViewUpdateData.match), mergeMap((action) => {
6
6
  const { approvalRuleId } = action.payload;
@@ -8,20 +8,16 @@ export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state
8
8
  if (approvalRuleId != null) {
9
9
  const approvalRule = getApprovalRuleById(state$.value.approvalRuleState, approvalRuleId);
10
10
  if (approvalRule != null) {
11
+ const criteria = approvalRule.criteria[0];
12
+ const range = criteria?.range;
11
13
  const billPaySetupApproverViewUpdateData = {
12
14
  approvalRuleId,
13
15
  steps: approvalRule.steps,
14
16
  criteria: {
15
- amount: getAmountCriteria(approvalRule.criteria),
16
- vendor: getVendorCriteria(approvalRule.criteria),
17
- department: getDepartmentCriteria(approvalRule.criteria),
17
+ rangeType: criteria?.rangeType,
18
+ rangeEntity: criteria?.rangeEntity,
19
+ range,
18
20
  },
19
- // Approval Rules 3.0 — seed rule-level fields so the form can
20
- // round-trip them on edit. Each may be undefined on legacy rules.
21
- name: approvalRule.name,
22
- description: approvalRule.description,
23
- separationOfDuties: approvalRule.separationOfDuties,
24
- isFallback: approvalRule.isFallback,
25
21
  };
26
22
  fetchActions.push(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewUpdateData));
27
23
  }
@@ -29,7 +25,7 @@ export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state
29
25
  else {
30
26
  const billPaySetupApproverViewCreateData = {
31
27
  steps: [],
32
- criteria: {},
28
+ criteria: undefined,
33
29
  };
34
30
  fetchActions.push(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewCreateData));
35
31
  }
@@ -1,48 +1,20 @@
1
1
  export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
2
- // Form-side criteria is a structured object with optional slots for
3
- // amount / vendor / department; flatten it into the wire format's
4
- // `conditions[]` array.
5
- let criteriaPayload;
2
+ let criteriaPayload = [];
6
3
  if (approverViewUpdateData.criteria != null) {
7
- const { amount, vendor, department } = approverViewUpdateData.criteria;
8
- const conditions = [];
9
- if (amount?.min != null) {
10
- conditions.push({
11
- field: 'amount',
12
- type: 'gte',
13
- value: amount.min.amount,
14
- });
15
- }
16
- if (amount?.max != null) {
17
- conditions.push({
18
- field: 'amount',
19
- type: 'lte',
20
- value: amount.max.amount,
21
- });
22
- }
23
- if (vendor != null && vendor.vendorIds.length > 0) {
24
- conditions.push({
25
- field: 'vendor_id',
26
- type: vendor.operator === 'is_not' ? 'not_in' : 'in',
27
- value: vendor.vendorIds,
28
- });
29
- }
30
- if (department != null && department.departmentIds.length > 0) {
31
- conditions.push({
32
- field: 'department_id',
33
- type: department.operator === 'is_not' ? 'not_in' : 'in',
34
- value: department.departmentIds,
35
- });
36
- }
37
- if (conditions.length > 0) {
38
- const currency = amount?.min ?? amount?.max ?? null;
39
- criteriaPayload = {
40
- conditions,
41
- criteria_operator: 'and',
42
- currency_code: currency?.currencyCode ?? 'USD',
43
- currency_symbol: currency?.currencySymbol ?? '$',
44
- };
45
- }
4
+ const criteria = approverViewUpdateData.criteria;
5
+ const { rangeType, rangeEntity, range } = criteria;
6
+ const { min, max } = range;
7
+ const { currencyCode, currencySymbol } = min;
8
+ criteriaPayload = [
9
+ {
10
+ type: rangeType,
11
+ range_entity: rangeEntity,
12
+ min: min.amount,
13
+ max: max?.amount ?? null,
14
+ currency_code: currencyCode,
15
+ currency_symbol: currencySymbol,
16
+ },
17
+ ];
46
18
  }
47
19
  const steps = approverViewUpdateData.steps.map((step) => {
48
20
  return {
@@ -63,27 +35,10 @@ export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
63
35
  });
64
36
  const isUpdate = approverViewUpdateData.approvalRuleId != null;
65
37
  const payload = {
38
+ criteria: criteriaPayload,
66
39
  steps,
67
40
  is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
68
41
  };
69
- if (criteriaPayload != null) {
70
- payload.criteria = criteriaPayload;
71
- }
72
- // Approval Rules 3.0 — surface rule-level fields when the form set them.
73
- // Send only what the user actually entered: an undefined value means
74
- // "no opinion" and stays off the wire.
75
- if (approverViewUpdateData.name != null) {
76
- payload.name = approverViewUpdateData.name;
77
- }
78
- if (approverViewUpdateData.description != null) {
79
- payload.description = approverViewUpdateData.description;
80
- }
81
- if (approverViewUpdateData.separationOfDuties != null) {
82
- payload.separation_of_duties = approverViewUpdateData.separationOfDuties;
83
- }
84
- if (approverViewUpdateData.isFallback != null) {
85
- payload.is_fallback = approverViewUpdateData.isFallback;
86
- }
87
42
  if (isUpdate) {
88
43
  payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
89
44
  }
@@ -1,6 +1,5 @@
1
1
  import recordGet from 'lodash/get';
2
2
  import has from 'lodash/has';
3
- import { getAmountCriteria } from '../../../../entity/approvalRule/approvalRuleSelector';
4
3
  import { reduceFetchState } from '../../../../commonStateTypes/reduceFetchState';
5
4
  import { getBankAccountByBankAccountId, getBankAccountsByBankAccountIds, } from '../../../../entity/bankAccount/bankAccountSelector';
6
5
  import { getContactById, getContactsByIds, } from '../../../../entity/billPay/contact/contactSelector';
@@ -682,13 +681,9 @@ export const getDefaultWithdrawFromAccount = (state, depositAccounts, companyId,
682
681
  export const checkIfCreatorIsApprover = (billAmount, approvalRules, signedInUser) => {
683
682
  let isCreatorAlsoApprover = false;
684
683
  const approvalRule = approvalRules.find((rule) => {
685
- const amountCriteria = getAmountCriteria(rule.criteria);
686
- if (amountCriteria?.min == null) {
687
- return false;
688
- }
689
- const { min, max } = amountCriteria;
684
+ const { max, min } = rule.criteria[0].range;
690
685
  return (billAmount > min.amount &&
691
- (max?.amount != null ? billAmount <= max.amount : true));
686
+ (max?.amount != null ? billAmount <= max?.amount : true));
692
687
  });
693
688
  if (approvalRule != null) {
694
689
  const requireApprovalSteps = approvalRule.steps.filter((step) => step.action === 'require_approval');
@@ -1,6 +1,6 @@
1
1
  import { from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
- import { getAmountCriteria, getApprovalRuleById, getDepartmentCriteria, getVendorCriteria, } from '../../../../../entity/approvalRule/approvalRuleSelector';
3
+ import { getApprovalRuleById } from '../../../../../entity/approvalRule/approvalRuleSelector';
4
4
  import { clearRemiSetupApproverViewUpdateData, initializeRemiSetupApproverViewUpdateData, saveRemiSetupApproverViewUpdateData, } from '../remiSetupApproverViewReducer';
5
5
  export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$) => actions$.pipe(filter(initializeRemiSetupApproverViewUpdateData.match), mergeMap((action) => {
6
6
  const { approvalRuleId } = action.payload;
@@ -8,20 +8,16 @@ export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$)
8
8
  if (approvalRuleId != null) {
9
9
  const approvalRule = getApprovalRuleById(state$.value.approvalRuleState, approvalRuleId);
10
10
  if (approvalRule != null) {
11
+ const criteria = approvalRule.criteria[0];
12
+ const range = criteria?.range;
11
13
  const remiSetupApproverViewUpdateData = {
12
14
  approvalRuleId,
13
15
  steps: approvalRule.steps,
14
16
  criteria: {
15
- amount: getAmountCriteria(approvalRule.criteria),
16
- vendor: getVendorCriteria(approvalRule.criteria),
17
- department: getDepartmentCriteria(approvalRule.criteria),
17
+ rangeType: criteria?.rangeType,
18
+ rangeEntity: criteria?.rangeEntity,
19
+ range,
18
20
  },
19
- // Approval Rules 3.0 — seed rule-level fields so the form can
20
- // round-trip them on edit. Each may be undefined on legacy rules.
21
- name: approvalRule.name,
22
- description: approvalRule.description,
23
- separationOfDuties: approvalRule.separationOfDuties,
24
- isFallback: approvalRule.isFallback,
25
21
  };
26
22
  fetchActions.push(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewUpdateData));
27
23
  }
@@ -29,7 +25,7 @@ export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$)
29
25
  else {
30
26
  const remiSetupApproverViewCreateData = {
31
27
  steps: [],
32
- criteria: {},
28
+ criteria: undefined,
33
29
  };
34
30
  fetchActions.push(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewCreateData));
35
31
  }
@@ -8,6 +8,8 @@ import { getActualPaymentDate } from './helpers';
8
8
  import { getApproversOrRejectors as getApproversOrRejectorsForReimbursement, } from './reimbursement/remiListView/remiListSelector';
9
9
  import { ALL_REMI_TABS, getRemiListKey, } from './reimbursement/remiListView/remiListState';
10
10
  //filters items against filter values representing a range. ex: date (from-to), amount(1k<-->5k)
11
+ // Spend Management uses only equal/not_equal — TC amount operators
12
+ // (inBetween, lessThan, greaterThan) live in the TC filter pipeline.
11
13
  const filterItemOnRangeCategoryType = (valueForItem, currentFilter) => {
12
14
  let doesItemFallInValueRange = false;
13
15
  const filterField = currentFilter.field;
@@ -41,7 +43,7 @@ const filterItemOnCategoriesWithSingleValue = (categoryValue, currentFilter, ran
41
43
  return filterItemOnRangeCategoryType(categoryValue, currentFilter);
42
44
  }
43
45
  // if filter category is not rangeType
44
- if (currentFilter.matchingOperator === 'not-equal') {
46
+ if (currentFilter.matchingOperator === 'not_equal') {
45
47
  return currentFilter.values.indexOf(categoryValue.toString()) === -1;
46
48
  }
47
49
  return currentFilter.values.indexOf(categoryValue.toString()) > -1;
@@ -115,7 +117,7 @@ export const applyAdvancedFiltersOnList = (entity, allItems, filters, filteredIt
115
117
  ? getCategoryValueForTaskList(key, item)
116
118
  : getCategoryValueForPaymentHistory(key, item);
117
119
  if (categoryValue == null) {
118
- if (currentFilter.matchingOperator === 'not-equal') {
120
+ if (currentFilter.matchingOperator === 'not_equal') {
119
121
  return true;
120
122
  }
121
123
  return false;
@@ -208,7 +208,7 @@ const applyAdvancedFiltersOnCompaniesList = (allCompanies, filters, filteredComp
208
208
  const key = currentFilter.field;
209
209
  const categoryValue = getCategoryValueForCompany(key, company);
210
210
  if (categoryValue == null) {
211
- if (currentFilter.matchingOperator === 'not-equal') {
211
+ if (currentFilter.matchingOperator === 'not_equal') {
212
212
  return true;
213
213
  }
214
214
  return false;
@@ -66,7 +66,7 @@ export const initialState = {
66
66
  categories: [
67
67
  {
68
68
  field: 'status',
69
- matchingOperator: 'not-equal',
69
+ matchingOperator: 'not_equal',
70
70
  values: ['resolved'],
71
71
  valuesCombinationOperator: 'ANY',
72
72
  },