@zeniai/client-epic-state 5.1.69 → 5.1.70-betaRD1

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 (129) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +2 -0
  2. package/lib/entity/jeSchedules/jeSchedulesPayload.js +2 -0
  3. package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +4 -0
  4. package/lib/entity/jeSchedules/jeSchedulesSelector.js +11 -1
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -0
  6. package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.d.ts +2 -0
  7. package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.js +2 -0
  8. package/lib/entity/transaction/stateTypes/scheduleTransaction.d.ts +2 -0
  9. package/lib/epic.d.ts +5 -1
  10. package/lib/epic.js +5 -1
  11. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +2 -0
  12. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +11 -1
  13. package/lib/esm/entity/transaction/payloadTypes/scheduleTransactionPayload.js +2 -0
  14. package/lib/esm/epic.js +5 -1
  15. package/lib/esm/index.js +14 -11
  16. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +15 -2
  17. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +21 -0
  18. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +110 -0
  19. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +73 -0
  20. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +22 -0
  21. package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +140 -0
  22. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +126 -6
  23. package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +1 -0
  24. package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +70 -0
  25. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +78 -11
  26. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +3 -6
  27. package/lib/esm/view/invoicing/couponView/couponViewEpics.js +0 -3
  28. package/lib/esm/view/invoicing/couponView/couponViewReducer.js +7 -1
  29. package/lib/esm/view/invoicing/couponView/couponViewSelector.js +27 -14
  30. package/lib/esm/view/invoicing/invoiceList/fetchInvoiceListEpic.js +7 -5
  31. package/lib/esm/view/invoicing/invoiceList/fetchInvoiceListPageEpic.js +2 -1
  32. package/lib/esm/view/invoicing/invoiceList/invoiceListReducer.js +62 -36
  33. package/lib/esm/view/invoicing/invoiceList/invoiceListSelector.js +19 -15
  34. package/lib/esm/view/invoicing/invoiceList/invoiceListState.js +10 -0
  35. package/lib/esm/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListEpic.js +0 -3
  36. package/lib/esm/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.js +7 -1
  37. package/lib/esm/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewSelector.js +23 -13
  38. package/lib/esm/view/invoicing/invoicingCustomerDetailView/fetchInvoicingCustomerDetailPageEpic.js +3 -2
  39. package/lib/esm/view/invoicing/invoicingCustomerDetailView/invoicingCustomerDetailViewSelector.js +1 -1
  40. package/lib/esm/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListEpic.js +0 -3
  41. package/lib/esm/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.js +7 -1
  42. package/lib/esm/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.js +25 -12
  43. package/lib/esm/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListEpic.js +0 -3
  44. package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.js +7 -1
  45. package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewSelector.js +23 -13
  46. package/lib/esm/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListEpic.js +0 -3
  47. package/lib/esm/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.js +7 -1
  48. package/lib/esm/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewSelector.js +22 -12
  49. package/lib/esm/view/invoicing/invoicingTransactionListView/epics/fetchInvoicingTransactionListEpic.js +7 -5
  50. package/lib/esm/view/invoicing/invoicingTransactionListView/epics/fetchInvoicingTransactionListPageEpic.js +2 -1
  51. package/lib/esm/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewReducer.js +56 -25
  52. package/lib/esm/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewSelector.js +15 -11
  53. package/lib/esm/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewState.js +10 -0
  54. package/lib/index.d.ts +16 -13
  55. package/lib/index.js +73 -48
  56. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +14 -1
  57. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +8 -0
  58. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +25 -0
  59. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +45 -0
  60. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +114 -0
  61. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +8 -0
  62. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +77 -0
  63. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
  64. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +26 -0
  65. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +36 -0
  66. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +145 -0
  67. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -0
  68. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +38 -8
  69. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +128 -7
  70. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +25 -0
  71. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +2 -0
  72. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +29 -4
  73. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +10 -0
  74. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +75 -0
  75. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.d.ts +1 -0
  76. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +80 -11
  77. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +52 -6
  78. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +5 -8
  79. package/lib/view/invoicing/couponView/couponViewEpics.js +0 -3
  80. package/lib/view/invoicing/couponView/couponViewReducer.d.ts +1 -1
  81. package/lib/view/invoicing/couponView/couponViewReducer.js +8 -2
  82. package/lib/view/invoicing/couponView/couponViewSelector.d.ts +1 -0
  83. package/lib/view/invoicing/couponView/couponViewSelector.js +27 -14
  84. package/lib/view/invoicing/couponView/couponViewState.d.ts +2 -1
  85. package/lib/view/invoicing/invoiceList/fetchInvoiceListEpic.d.ts +1 -1
  86. package/lib/view/invoicing/invoiceList/fetchInvoiceListEpic.js +7 -5
  87. package/lib/view/invoicing/invoiceList/fetchInvoiceListPageEpic.js +2 -1
  88. package/lib/view/invoicing/invoiceList/invoiceListReducer.d.ts +5 -4
  89. package/lib/view/invoicing/invoiceList/invoiceListReducer.js +63 -37
  90. package/lib/view/invoicing/invoiceList/invoiceListSelector.d.ts +1 -0
  91. package/lib/view/invoicing/invoiceList/invoiceListSelector.js +19 -15
  92. package/lib/view/invoicing/invoiceList/invoiceListState.d.ts +20 -7
  93. package/lib/view/invoicing/invoiceList/invoiceListState.js +13 -1
  94. package/lib/view/invoicing/invoicingCreditNoteListView/epics/fetchInvoicingCreditNoteListEpic.js +0 -3
  95. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.d.ts +1 -1
  96. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewReducer.js +8 -2
  97. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewSelector.d.ts +1 -0
  98. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewSelector.js +23 -13
  99. package/lib/view/invoicing/invoicingCreditNoteListView/invoicingCreditNoteListViewState.d.ts +2 -1
  100. package/lib/view/invoicing/invoicingCustomerDetailView/fetchInvoicingCustomerDetailPageEpic.js +3 -2
  101. package/lib/view/invoicing/invoicingCustomerDetailView/invoicingCustomerDetailViewSelector.js +1 -1
  102. package/lib/view/invoicing/invoicingCustomerListView/epics/fetchInvoicingCustomerListEpic.js +0 -3
  103. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.d.ts +1 -1
  104. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewReducer.js +8 -2
  105. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.d.ts +1 -0
  106. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewSelector.js +25 -12
  107. package/lib/view/invoicing/invoicingCustomerListView/invoicingCustomerListViewState.d.ts +2 -1
  108. package/lib/view/invoicing/invoicingDunningCaseListView/epics/fetchInvoicingDunningCaseListEpic.js +0 -3
  109. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.d.ts +1 -1
  110. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.js +8 -2
  111. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewSelector.d.ts +1 -0
  112. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewSelector.js +23 -13
  113. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.d.ts +2 -1
  114. package/lib/view/invoicing/invoicingSubscriptionListView/epics/fetchInvoicingSubscriptionListEpic.js +0 -3
  115. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.d.ts +1 -1
  116. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.js +8 -2
  117. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewSelector.d.ts +1 -0
  118. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewSelector.js +22 -12
  119. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewState.d.ts +3 -1
  120. package/lib/view/invoicing/invoicingTransactionListView/epics/fetchInvoicingTransactionListEpic.d.ts +1 -1
  121. package/lib/view/invoicing/invoicingTransactionListView/epics/fetchInvoicingTransactionListEpic.js +7 -5
  122. package/lib/view/invoicing/invoicingTransactionListView/epics/fetchInvoicingTransactionListPageEpic.js +2 -1
  123. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewReducer.d.ts +1 -1
  124. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewReducer.js +57 -26
  125. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewSelector.d.ts +1 -0
  126. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewSelector.js +15 -11
  127. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewState.d.ts +18 -4
  128. package/lib/view/invoicing/invoicingTransactionListView/invoicingTransactionListViewState.js +13 -1
  129. package/package.json +1 -1
@@ -0,0 +1,140 @@
1
+ import { toAmount } from '../../../commonStateTypes/amount';
2
+ import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
3
+ import { MONTH_YEAR_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
4
+ import { LAST_SCHEDULE_DAY_OF_MONTH } from '../../../commonStateTypes/timePeriod';
5
+ import { getPostingDateAndStatusForIndex } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
6
+ import { mapScheduleTransactionToBaseScheduleTransactionPayload, } from '../../scheduleView/scheduleDetailView/scheduleDetailPayload';
7
+ const getNewScheduleMemo = (vendorName, schedulePostingDate, currentPeriod, totalPeriod, assetId) => {
8
+ const addAsset = assetId != null && assetId !== '' ? ` - ${assetId}` : '';
9
+ return `${vendorName} - ${schedulePostingDate.format(MONTH_YEAR_FORMAT)} (${currentPeriod} of ${totalPeriod})${addAsset}`;
10
+ };
11
+ /**
12
+ * Computes the month-by-month JE schedule breakdown for a brand-new schedule
13
+ * (no linked transaction yet) — replicates createNewSchedulesHelper's math
14
+ * (scheduleDetailLocalDataHelper.ts) exactly: lump-sum total split evenly
15
+ * across months with the rounding remainder absorbed by the last month, and a
16
+ * running balance that decrements each month and is forced to exactly 0 on
17
+ * the last row.
18
+ */
19
+ export const computeNewScheduleJeDetails = (localData, totalAmount, vendorName) => {
20
+ const period = localData.selectedMonths;
21
+ const startingMonth = localData.selectedDate;
22
+ if (startingMonth == null || period == null) {
23
+ return [];
24
+ }
25
+ const assetId = 'assetId' in localData ? localData.assetId : undefined;
26
+ const averageAmount = Math.abs(Math.round((totalAmount.amount / period) * 100) / 100);
27
+ const lastMonthAmount = Math.abs(Math.round((Math.abs(totalAmount.amount) - averageAmount * (period - 1)) * 100) / 100);
28
+ let runningBalance = Math.abs(totalAmount.amount);
29
+ const negativeNumbers = totalAmount.amount < 0 || runningBalance < 0;
30
+ const newJeDetails = [];
31
+ for (let index = 0; index < period; index++) {
32
+ if (runningBalance > averageAmount) {
33
+ runningBalance = Math.round((runningBalance - averageAmount) * 100) / 100;
34
+ }
35
+ else {
36
+ runningBalance = 0;
37
+ }
38
+ const amount = index === period - 1 ? lastMonthAmount : averageAmount;
39
+ runningBalance = index === period - 1 ? 0 : runningBalance;
40
+ const schedulePostingDate = startingMonth.add(index, 'month');
41
+ const { postingDate, postingStatus } = getPostingDateAndStatusForIndex(schedulePostingDate.month(), schedulePostingDate.year(), localData.lastDayOfMonth === true
42
+ ? undefined
43
+ : localData.selectedDayOfMonth);
44
+ newJeDetails.push({
45
+ postingDate,
46
+ amount: toAmount(negativeNumbers ? -amount : amount, totalAmount.currencyCode, totalAmount.currencySymbol),
47
+ runningBalance: toAmount(negativeNumbers ? -runningBalance : runningBalance, totalAmount.currencyCode, totalAmount.currencySymbol),
48
+ postingStatus,
49
+ memo: getNewScheduleMemo(vendorName, schedulePostingDate, index + 1, period, assetId),
50
+ jeLink: { type: 'unknown' },
51
+ });
52
+ }
53
+ return newJeDetails;
54
+ };
55
+ const mapNewJeDetailsToScheduledJournalEntryPayload = (jeScheduleDetails) => jeScheduleDetails.map((journalEntry) => ({
56
+ status: {
57
+ code: journalEntry.postingStatus,
58
+ label: journalEntry.postingStatus,
59
+ },
60
+ transaction_memo: journalEntry.memo,
61
+ third_party_id: journalEntry.jeLink.thirdPartyTransactionId ?? null,
62
+ expected_post_date: journalEntry.postingDate.format(DEFAULT_DATE_FORMAT),
63
+ amount: journalEntry.amount.amount,
64
+ balance: journalEntry.runningBalance.amount,
65
+ // Brand-new schedule — there is no prior scheduled-journal-entry history
66
+ // to cross-reference (unlike the legacy edit flow's equivalent mapper).
67
+ scheduled_journal_entry_id: null,
68
+ actual_post_date: null,
69
+ is_platform_generated: null,
70
+ je_schedule_id: null,
71
+ update_time: null,
72
+ create_time: null,
73
+ }));
74
+ /**
75
+ * Builds a savable schedule payload directly from a Base Transaction search
76
+ * result and the New Schedule form's local data — bypassing the legacy
77
+ * getJEScheduledTransactionByJEScheduleTransactionKey selector entirely,
78
+ * since that selector throws unless the entity has already round-tripped
79
+ * through a real GET /1.0/schedules/:id. A brand-new schedule has no such
80
+ * history, so this reads only from data already in hand (the selected
81
+ * transaction/line plus what the user filled into the form).
82
+ */
83
+ export const prepareNewSchedulePayload = (transaction, localData, scheduleType) => {
84
+ if (transaction.thirdPartyTransactionId == null ||
85
+ transaction.thirdPartyTransactionId === '') {
86
+ return { ok: false, reason: 'missing_third_party_id' };
87
+ }
88
+ const scheduleTransaction = transaction;
89
+ const vendorId = localData.selectedVendor?.id ?? transaction.vendorId ?? '';
90
+ const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
91
+ if (vendorId === '' || vendorName === '') {
92
+ return { ok: false, reason: 'missing_vendor' };
93
+ }
94
+ const vendor = {
95
+ vendor_id: vendorId,
96
+ vendor_name: vendorName,
97
+ };
98
+ const jeScheduleDetails = computeNewScheduleJeDetails(localData, scheduleTransaction.amount, vendorName);
99
+ const postingDate = localData.selectedDayOfMonth ??
100
+ (localData.lastDayOfMonth === true ? LAST_SCHEDULE_DAY_OF_MONTH : null);
101
+ const firstJEScheduleDate = jeScheduleDetails.length > 0
102
+ ? jeScheduleDetails[0].postingDate.format(DEFAULT_DATE_FORMAT)
103
+ : null;
104
+ const lastJEScheduleDate = jeScheduleDetails.length > 0
105
+ ? jeScheduleDetails[jeScheduleDetails.length - 1].postingDate.format(DEFAULT_DATE_FORMAT)
106
+ : null;
107
+ const isFixedAssets = scheduleType === 'fixed_assets';
108
+ const assetId = 'assetId' in localData ? localData.assetId : undefined;
109
+ const selectedAccumulatedDepreciationCategory = 'selectedAccumulatedDepreciationCategory' in localData
110
+ ? localData.selectedAccumulatedDepreciationCategory
111
+ : undefined;
112
+ const status = { code: 'new', label: 'New' };
113
+ const jeSchedulePayload = {
114
+ status,
115
+ vendor,
116
+ currency_code: scheduleTransaction.currency.currencyCode,
117
+ currency_symbol: scheduleTransaction.currency.currencySymbol,
118
+ period: localData.selectedMonths ?? null,
119
+ je_schedule_type: scheduleType,
120
+ posting_date: postingDate,
121
+ balance: scheduleTransaction.amount.amount,
122
+ start_date: firstJEScheduleDate,
123
+ end_date: lastJEScheduleDate,
124
+ je_credit_accounting_class_id: scheduleTransaction.classBase?.classId ?? null,
125
+ je_credit_account_id: isFixedAssets
126
+ ? (selectedAccumulatedDepreciationCategory ?? null)
127
+ : scheduleTransaction.account.accountId,
128
+ je_debit_account_id: localData.selectedAccount ?? null,
129
+ je_debit_accounting_class_id: localData.selectedClass ?? null,
130
+ other_attributes: assetId != null ? { asset_id: assetId } : {},
131
+ base_transaction: mapScheduleTransactionToBaseScheduleTransactionPayload(scheduleTransaction),
132
+ };
133
+ return {
134
+ ok: true,
135
+ payload: {
136
+ je_schedules: [jeSchedulePayload],
137
+ scheduled_journal_entries: mapNewJeDetailsToScheduledJournalEntryPayload(jeScheduleDetails),
138
+ },
139
+ };
140
+ };
@@ -4,6 +4,7 @@ import { toMonthYearPeriodId, } from '../../../commonStateTypes/timePeriod';
4
4
  import { mapAccountBasePayloadToAccountBase, mapAccountMetadataPayloadToAccountMetadata, } from '../../../entity/account/accountPayload';
5
5
  import { getJEScheduleTransactionDetailKeyPayload, } from '../../../entity/jeSchedules/jeSchedulesPayload';
6
6
  import { mapAccountTypeRecommendationPayloadToAccountRecommendationByType, } from '../../accountMappingView/accountTypeRecommendation/accountTypeRecommendationPayload';
7
+ import { MIN_NEW_SCHEDULE_SEARCH_LENGTH, } from '../types/jeSchedulesViewState';
7
8
  export const accountSettingsInitialState = {
8
9
  localData: {
9
10
  selectedPrepaidExpensesAccountIds: [],
@@ -35,6 +36,19 @@ export const accountSettingsInitialState = {
35
36
  accruedExpensesNestedAccountListHierarchy: [],
36
37
  accruedExpensesRecommendations: [],
37
38
  };
39
+ export const getBaseNewScheduleLocalData = (scheduleType) => ({
40
+ scheduleType,
41
+ jeScheduleDetails: [],
42
+ });
43
+ export const newScheduleInitialState = {
44
+ fixed_assets: getBaseNewScheduleLocalData('fixed_assets'),
45
+ prepaid_expenses: getBaseNewScheduleLocalData('prepaid_expenses'),
46
+ };
47
+ export const searchTransactionsInitialState = {
48
+ searchResults: [],
49
+ fetchState: 'Not-Started',
50
+ error: undefined,
51
+ };
38
52
  export const initialState = {
39
53
  jeScheduleTransactionKeysByPeriod: {},
40
54
  failedJeScheduleTransactionKeysByPeriod: {},
@@ -42,9 +56,12 @@ export const initialState = {
42
56
  ignoreStatusById: {},
43
57
  jeScheduleLocalDataById: {},
44
58
  uiState: {
45
- searchString: '',
59
+ createdGroupCollapsed: false,
60
+ pendingGroupCollapsed: false,
46
61
  scrollPosition: { scrollTop: 0, scrollLeft: undefined },
47
- selectedMainTab: 'pending_review',
62
+ searchString: '',
63
+ selectedJETypeFilter: null,
64
+ selectedPageTab: 'schedules',
48
65
  sortKey: 'transactionDate',
49
66
  sortOrder: 'descending',
50
67
  totalCount: 0,
@@ -55,6 +72,13 @@ export const initialState = {
55
72
  error: undefined,
56
73
  },
57
74
  accountSettings: accountSettingsInitialState,
75
+ newSchedule: {
76
+ newScheduleState: newScheduleInitialState,
77
+ saveStatus: { fetchState: 'Not-Started', error: undefined },
78
+ searchTransactions: searchTransactionsInitialState,
79
+ fetchState: 'Not-Started',
80
+ error: undefined,
81
+ },
58
82
  fetchState: 'Not-Started',
59
83
  error: undefined,
60
84
  hasValidState() {
@@ -121,8 +145,8 @@ const expenseAutomationJESchedulesView = createSlice({
121
145
  else {
122
146
  draft.fetchState = 'Error';
123
147
  draft.error = status;
148
+ draft.jeScheduleTransactionKeysByPeriod[toMonthYearPeriodId(selectedPeriod)] = [];
124
149
  }
125
- draft.jeScheduleTransactionKeysByPeriod[toMonthYearPeriodId(selectedPeriod)] = [];
126
150
  },
127
151
  retryJeSchedule(draft, action) {
128
152
  const { scheduledJournalEntryID } = action.payload;
@@ -368,6 +392,91 @@ const expenseAutomationJESchedulesView = createSlice({
368
392
  clearJeAccountSettingsLocalData(draft) {
369
393
  draft.accountSettings.localData = accountSettingsInitialState.localData;
370
394
  },
395
+ initializeNewSchedule: {
396
+ prepare({ scheduleType, }) {
397
+ return { payload: { scheduleType } };
398
+ },
399
+ reducer() {
400
+ // Purely an epic-trigger action — the epic fans out the account/class
401
+ // list fetches plus resetNewScheduleLocalData.
402
+ },
403
+ },
404
+ resetNewScheduleLocalData: {
405
+ prepare({ scheduleType, }) {
406
+ return { payload: { scheduleType } };
407
+ },
408
+ reducer(draft, action) {
409
+ const { scheduleType } = action.payload;
410
+ draft.newSchedule.newScheduleState[scheduleType] =
411
+ getBaseNewScheduleLocalData(scheduleType);
412
+ },
413
+ },
414
+ updateNewScheduleLocalData(draft, action) {
415
+ const { scheduleType, localData } = action.payload;
416
+ draft.newSchedule.newScheduleState[scheduleType] = {
417
+ ...draft.newSchedule.newScheduleState[scheduleType],
418
+ ...localData,
419
+ };
420
+ },
421
+ searchTransactionsForNewSchedule: {
422
+ prepare({ query, scheduleType, }) {
423
+ return { payload: { query, scheduleType } };
424
+ },
425
+ reducer(draft, action) {
426
+ const trimmed = action.payload.query.trim();
427
+ // Cleared or too-short query: no API (see epic) — reset immediately.
428
+ if (trimmed.length < MIN_NEW_SCHEDULE_SEARCH_LENGTH) {
429
+ draft.newSchedule.searchTransactions = searchTransactionsInitialState;
430
+ return;
431
+ }
432
+ draft.newSchedule.searchTransactions = {
433
+ ...draft.newSchedule.searchTransactions,
434
+ searchString: action.payload.query,
435
+ fetchState: 'In-Progress',
436
+ };
437
+ },
438
+ },
439
+ searchTransactionsForNewScheduleSuccess(draft, action) {
440
+ draft.newSchedule.searchTransactions = {
441
+ ...draft.newSchedule.searchTransactions,
442
+ searchResults: action.payload.searchResults,
443
+ fetchState: 'Completed',
444
+ error: undefined,
445
+ };
446
+ },
447
+ searchTransactionsForNewScheduleFailure(draft, action) {
448
+ draft.newSchedule.searchTransactions = {
449
+ ...draft.newSchedule.searchTransactions,
450
+ fetchState: 'Error',
451
+ error: action.payload.status,
452
+ };
453
+ },
454
+ clearSearchTransactionsForNewSchedule(draft) {
455
+ draft.newSchedule.searchTransactions = searchTransactionsInitialState;
456
+ },
457
+ saveNewSchedule: {
458
+ prepare({ scheduleType, }) {
459
+ return { payload: { scheduleType } };
460
+ },
461
+ reducer(draft) {
462
+ draft.newSchedule.saveStatus = {
463
+ fetchState: 'In-Progress',
464
+ error: undefined,
465
+ };
466
+ },
467
+ },
468
+ saveNewScheduleSuccess(draft) {
469
+ draft.newSchedule.saveStatus = {
470
+ fetchState: 'Completed',
471
+ error: undefined,
472
+ };
473
+ },
474
+ saveNewScheduleFailure(draft, action) {
475
+ draft.newSchedule.saveStatus = {
476
+ fetchState: 'Error',
477
+ error: action.payload.status,
478
+ };
479
+ },
371
480
  updateJESchedulesUIState(draft, action) {
372
481
  if (action.payload.sortKey != null) {
373
482
  draft.uiState.sortKey = action.payload.sortKey;
@@ -381,16 +490,27 @@ const expenseAutomationJESchedulesView = createSlice({
381
490
  if (action.payload.scrollPosition != null) {
382
491
  draft.uiState.scrollPosition = action.payload.scrollPosition;
383
492
  }
384
- if (action.payload.selectedMainTab != null) {
385
- draft.uiState.selectedMainTab = action.payload.selectedMainTab;
493
+ if (action.payload.selectedPageTab != null) {
494
+ draft.uiState.selectedPageTab = action.payload.selectedPageTab;
386
495
  }
387
496
  },
497
+ updateJEScheduleTypeFilter(draft, action) {
498
+ draft.uiState.selectedJETypeFilter = action.payload;
499
+ },
500
+ toggleJEPendingGroupCollapsed(draft) {
501
+ draft.uiState.pendingGroupCollapsed =
502
+ !draft.uiState.pendingGroupCollapsed;
503
+ },
504
+ toggleJECreatedGroupCollapsed(draft) {
505
+ draft.uiState.createdGroupCollapsed =
506
+ !draft.uiState.createdGroupCollapsed;
507
+ },
388
508
  clearExpenseAutomationJESchedulesView(draft) {
389
509
  Object.assign(draft, initialState);
390
510
  },
391
511
  },
392
512
  });
393
- export const { clearExpenseAutomationJESchedulesView, clearJeAccountSettingsLocalData, clearJeScheduleLocalData, fetchAccountSettingsListForAccountTypes, fetchJeSchedules, fetchJeSchedulesFailure, fetchJeSchedulesPage, fetchJeSchedulesSuccess, fetchRecommendationForAccountSettings, ignoreRecommendedJeSchedule, ignoreRecommendedJeScheduleFailure, ignoreRecommendedJeScheduleSuccess, initializeAccountSettingsView, initializeJeScheduleLocalData, removeFailedJeScheduleTransactionKey, removeJeScheduleLocalDataById, removeJeScheduleTransactionKey, retryJeSchedule, retryJeScheduleFailure, retryJeScheduleSuccess, saveAccountSettings, saveAccountSettingsFailure, saveAccountSettingsLocalData, saveAccountSettingsSuccess, updateAccountSettingsListForAccountTypes, updateAccountSettingsListForAccountTypesFailure, updateJESchedulesUIState, updateJeScheduleLocalDataById, updateJeScheduleTransactionKeys, updateRecommendationForAccountSettings, updateRecommendationForAccountSettingsFailure, } = expenseAutomationJESchedulesView.actions;
513
+ export const { clearExpenseAutomationJESchedulesView, clearJeAccountSettingsLocalData, clearJeScheduleLocalData, clearSearchTransactionsForNewSchedule, fetchAccountSettingsListForAccountTypes, fetchJeSchedules, fetchJeSchedulesFailure, fetchJeSchedulesPage, fetchJeSchedulesSuccess, fetchRecommendationForAccountSettings, ignoreRecommendedJeSchedule, ignoreRecommendedJeScheduleFailure, ignoreRecommendedJeScheduleSuccess, initializeAccountSettingsView, initializeJeScheduleLocalData, initializeNewSchedule, removeFailedJeScheduleTransactionKey, removeJeScheduleLocalDataById, removeJeScheduleTransactionKey, resetNewScheduleLocalData, retryJeSchedule, retryJeScheduleFailure, retryJeScheduleSuccess, saveAccountSettings, saveAccountSettingsFailure, saveAccountSettingsLocalData, saveAccountSettingsSuccess, saveNewSchedule, saveNewScheduleFailure, saveNewScheduleSuccess, searchTransactionsForNewSchedule, searchTransactionsForNewScheduleFailure, searchTransactionsForNewScheduleSuccess, toggleJECreatedGroupCollapsed, toggleJEPendingGroupCollapsed, updateAccountSettingsListForAccountTypes, updateAccountSettingsListForAccountTypesFailure, updateJESchedulesUIState, updateJEScheduleTypeFilter, updateJeScheduleLocalDataById, updateJeScheduleTransactionKeys, updateNewScheduleLocalData, updateRecommendationForAccountSettings, updateRecommendationForAccountSettingsFailure, } = expenseAutomationJESchedulesView.actions;
394
514
  export default expenseAutomationJESchedulesView.reducer;
395
515
  const doUpdateRecommendationForAccountSettings = (draft, payload) => {
396
516
  const { prepaidExpensesRecommendations, fixedAssetsRecommendations, accruedExpensesRecommendations, } = mapAccountTypeRecommendationPayloadToAccountRecommendationByType(payload);
@@ -0,0 +1,70 @@
1
+ import { getAccountIdsForTypes } from '../../../entity/account/accountSelector';
2
+ import { getScheduleTransactionById } from '../../../entity/transaction/transactionSelector';
3
+ import { getAccountIdsForLabel, getAccountList, getNestedAccountListHierarchy, } from '../../accountList/accountListSelector';
4
+ import { getClassList, getNestedClassListHierarchy, } from '../../classList/classListSelector';
5
+ import { getAccountsTypesForScheduleDetails } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
6
+ import { filterNestedAccountHierarchyById } from '../../scheduleView/scheduleDetailView/scheduleDetailSelector';
7
+ import { getAccountLabelForScheduleType, getAccountsTypesForScheduleEpics, } from '../../scheduleView/scheduleListView/scheduleListHelper';
8
+ /**
9
+ * The Base Transaction search is shared across schedule types (one search
10
+ * box, not one per prepaid_expenses/fixed_assets) — split out from
11
+ * getNewScheduleView so a consumer can read it without supplying an
12
+ * otherwise-irrelevant scheduleType.
13
+ */
14
+ export const getNewScheduleSearchTransactionsView = (state) => {
15
+ const { searchTransactions } = state.expenseAutomationJESchedulesViewState.newSchedule;
16
+ const searchTransactionsResults = searchTransactions.searchResults
17
+ .map((key) => getScheduleTransactionById(state.transactionState, key))
18
+ .filter((transaction) => transaction != null);
19
+ return {
20
+ searchTransactionsResults,
21
+ searchTransactionsFetchState: {
22
+ fetchState: searchTransactions.fetchState,
23
+ error: searchTransactions.error,
24
+ },
25
+ searchTransactionsString: searchTransactions.searchString,
26
+ };
27
+ };
28
+ export const getNewScheduleView = (state, scheduleType) => {
29
+ const { accountState, accountListState, classState, classListState } = state;
30
+ const { newSchedule } = state.expenseAutomationJESchedulesViewState;
31
+ const searchTransactionsView = getNewScheduleSearchTransactionsView(state);
32
+ const accountType = getAccountsTypesForScheduleEpics();
33
+ const newScheduleAccountTypes = getAccountsTypesForScheduleDetails(scheduleType);
34
+ const newScheduleAccountIds = getAccountIdsForTypes(accountState, newScheduleAccountTypes);
35
+ const allAccountList = getAccountList(accountState, accountListState, accountType.accountListKey);
36
+ const filteredAccounts = allAccountList.accounts.filter((account) => newScheduleAccountIds.includes(account.accountId));
37
+ const accountListNestedAccountHierarchy = filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), filteredAccounts.map((account) => account.accountId));
38
+ const allClassList = getClassList(classState, classListState);
39
+ const classListNestedAccountHierarchy = getNestedClassListHierarchy(classListState);
40
+ let allDepreciationAccountList;
41
+ let allDepreciationAccountListNestedAccountHierarchy;
42
+ if (scheduleType === 'fixed_assets') {
43
+ const depreciationCategoryIds = getAccountIdsForTypes(accountState, [
44
+ 'fixed_assets',
45
+ 'other_assets',
46
+ ]);
47
+ const accountLabel = getAccountLabelForScheduleType('fixed_assets');
48
+ const fixedAssetLabelAccountIds = accountLabel != null
49
+ ? getAccountIdsForLabel(accountListState, accountType.accountListKey, accountLabel)
50
+ : [];
51
+ allDepreciationAccountList = allAccountList.accounts.filter((account) => depreciationCategoryIds.includes(account.accountId) &&
52
+ !fixedAssetLabelAccountIds.includes(account.accountId));
53
+ allDepreciationAccountListNestedAccountHierarchy =
54
+ filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), allDepreciationAccountList.map((account) => account.accountId));
55
+ }
56
+ return {
57
+ scheduleType,
58
+ accountListNestedAccountHierarchy,
59
+ allAccountList: filteredAccounts,
60
+ allClassList: allClassList.classes,
61
+ allDepreciationAccountList,
62
+ allDepreciationAccountListNestedAccountHierarchy,
63
+ classListNestedAccountHierarchy,
64
+ newScheduleLocalData: newSchedule.newScheduleState[scheduleType],
65
+ saveStatus: newSchedule.saveStatus,
66
+ ...searchTransactionsView,
67
+ fetchState: newSchedule.fetchState,
68
+ error: newSchedule.error,
69
+ };
70
+ };
@@ -4,6 +4,7 @@ import { reduceAnyFetchState } from '../../../commonStateTypes/reduceFetchState'
4
4
  import { LAST_SCHEDULE_DAY_OF_MONTH, toMonthYearPeriodId, } from '../../../commonStateTypes/timePeriod';
5
5
  import { getAccountIdsForTypes } from '../../../entity/account/accountSelector';
6
6
  import { getJEScheduledTransactionByJEScheduleTransactionKey, } from '../../../entity/jeSchedules/jeSchedulesSelector';
7
+ import { ALL_SCHEDULES_TYPES, } from '../../../entity/jeSchedules/jeSchedulesTypes';
7
8
  import { getCurrentTenant } from '../../../entity/tenant/tenantSelector';
8
9
  import { getAccountIdsForLabel, getAccountList, getNestedAccountListHierarchy, getUncategorizedAccounts, } from '../../accountList/accountListSelector';
9
10
  import { getClassList, getNestedClassListHierarchy, } from '../../classList/classListSelector';
@@ -12,6 +13,20 @@ import { filterNestedAccountHierarchyById } from '../../scheduleView/scheduleDet
12
13
  import { getAccountLabelForScheduleType, getAccountsTypesForScheduleList, } from '../../scheduleView/scheduleListView/scheduleListHelper';
13
14
  import { getAllSteps } from '../selectorTypes/expenseAutomationViewSelectorTypes';
14
15
  import { getJEAccountSettingsView } from './jeAccountSettingsViewSelector';
16
+ import { getNewScheduleView } from './jeNewScheduleViewSelector';
17
+ // Matches the AI-automation user addresses webc's schedule list row already
18
+ // checks (JEScheduleReadOnlyListRow/JEScheduleDraftListRow "Method" column,
19
+ // strings.ts aiBotEmail/botEmail) to determine whether a schedule was
20
+ // created by the AI accountant vs. a human.
21
+ const AI_BOT_EMAIL = 'ai@zeni.ai';
22
+ const BOT_EMAIL = 'bot@zeni.ai';
23
+ // Exported (rather than kept as a closure inside the selector) so it can be
24
+ // unit-tested directly — confidenceScore is a separate, more narrowly
25
+ // populated field that can be null on a schedule the bot user created,
26
+ // which previously caused these schedules to display as "AI Accountant" in
27
+ // the list but count under "Manual" in the KPI summary.
28
+ export const isAiAccountantSchedule = (schedule) => schedule.createdByUser?.email === AI_BOT_EMAIL ||
29
+ schedule.createdByUser?.email === BOT_EMAIL;
15
30
  function getJEScheduleSortAccessor(sortKey) {
16
31
  switch (sortKey) {
17
32
  case 'vendor':
@@ -53,7 +68,7 @@ function getJEScheduleSortAccessor(sortKey) {
53
68
  case 'totalAmount':
54
69
  return (s) => s.baseTransaction.amount.amount;
55
70
  case 'transactionDate':
56
- return (s) => s.baseTransaction.date.valueOf();
71
+ return (s) => s.createTime?.valueOf();
57
72
  case 'memo':
58
73
  return (s) => s.baseTransaction.memo?.toLowerCase();
59
74
  default:
@@ -68,8 +83,12 @@ export function getExpenseAutomationJESchedulesView(state) {
68
83
  const jeScheduledTransaction = [];
69
84
  const failedJeScheduledTransaction = [];
70
85
  const { accountState, accountListState, classState, classListState, expenseAutomationJESchedulesViewState, expenseAutomationViewState, monthEndCloseChecksState, monthEndCloseChecksViewState, } = state;
71
- const { jeScheduleTransactionKeysByPeriod, failedJeScheduleTransactionKeysByPeriod, jeScheduleLocalDataById, postStatusById, ignoreStatusById, uiState, error, fetchState, refreshStatus, } = expenseAutomationJESchedulesViewState;
86
+ const { jeScheduleTransactionKeysByPeriod, failedJeScheduleTransactionKeysByPeriod, jeScheduleLocalDataById, postStatusById, ignoreStatusById, uiState, error, fetchState, refreshStatus, newSchedule, } = expenseAutomationJESchedulesViewState;
72
87
  const accountSettingsView = getJEAccountSettingsView(state);
88
+ const newScheduleView = newSchedule.selectedDetailScheduleType === 'fixed_assets' ||
89
+ newSchedule.selectedDetailScheduleType === 'prepaid_expenses'
90
+ ? getNewScheduleView(state, newSchedule.selectedDetailScheduleType)
91
+ : undefined;
73
92
  const currentTenant = getCurrentTenant(state);
74
93
  const { selectedPeriodByTenantId } = expenseAutomationViewState;
75
94
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
@@ -113,11 +132,7 @@ export function getExpenseAutomationJESchedulesView(state) {
113
132
  const jeScheduleDetails = getJEScheduledTransactionByJEScheduleTransactionKey(jeScheduleKey, state);
114
133
  failedJeScheduledTransaction.push(jeScheduleDetails);
115
134
  });
116
- const { sortKey, sortOrder } = uiState;
117
- const draftSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft'), sortKey, sortOrder);
118
- const ongoingSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'ongoing'), sortKey, sortOrder);
119
- const completedSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'completed' ||
120
- schedule.status.code === 'marked_as_completed'), sortKey, sortOrder);
135
+ const { sortKey, sortOrder, selectedJETypeFilter } = uiState;
121
136
  const unsortedResolveSchedules = [];
122
137
  failedJeScheduledTransaction.forEach((schedule) => {
123
138
  schedule.scheduledJournalEntry.forEach((journalEntry) => {
@@ -130,9 +145,42 @@ export function getExpenseAutomationJESchedulesView(state) {
130
145
  const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules, sortKey, sortOrder);
131
146
  const validResolveForPending = unsortedResolveSchedules.filter((r) => jeScheduleLocalDataById[r.scheduledJournalEntry.scheduledJournalEntryID] != null);
132
147
  const pendingReviewSchedules = sortJEScheduledTransactions([
133
- ...jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft'),
148
+ ...jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft' &&
149
+ (selectedJETypeFilter == null ||
150
+ schedule.jeScheduleType === selectedJETypeFilter)),
134
151
  ...validResolveForPending,
135
152
  ], sortKey, sortOrder);
153
+ const createdSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => (schedule.status.code === 'ongoing' ||
154
+ schedule.status.code === 'completed' ||
155
+ schedule.status.code === 'marked_as_completed') &&
156
+ (selectedJETypeFilter == null ||
157
+ schedule.jeScheduleType === selectedJETypeFilter)), sortKey, sortOrder);
158
+ // KPI summary — derived from unfiltered schedules so counts are always accurate
159
+ const allSchedules = jeScheduledTransaction;
160
+ const sumAmount = (schedules) => schedules.reduce((total, schedule) => total + (schedule.baseTransaction.amount.amount ?? 0), 0);
161
+ const pendingReviewTotal = sumAmount(pendingReviewSchedules);
162
+ const createdTotal = sumAmount(createdSchedules);
163
+ const aiAccountantSchedules = allSchedules.filter(isAiAccountantSchedule);
164
+ const manualSchedules = allSchedules.filter((schedule) => !isAiAccountantSchedule(schedule));
165
+ const pendingUnfiltered = allSchedules.filter((schedule) => schedule.status.code === 'draft');
166
+ const kpiSummary = {
167
+ aiAccountant: {
168
+ count: aiAccountantSchedules.length,
169
+ amount: sumAmount(aiAccountantSchedules),
170
+ },
171
+ manual: {
172
+ count: manualSchedules.length,
173
+ amount: sumAmount(manualSchedules),
174
+ },
175
+ needsReview: {
176
+ count: pendingUnfiltered.length,
177
+ amount: sumAmount(pendingUnfiltered),
178
+ },
179
+ total: {
180
+ count: allSchedules.length,
181
+ amount: sumAmount(allSchedules),
182
+ },
183
+ };
136
184
  const allSteps = monthYearPeriodId != null
137
185
  ? getAllSteps(monthEndCloseChecksState, monthYearPeriodId, currentTenant.tenantId)
138
186
  : [];
@@ -145,6 +193,22 @@ export function getExpenseAutomationJESchedulesView(state) {
145
193
  { fetchState, error },
146
194
  monthEndFetchState,
147
195
  ]);
196
+ const countByType = (schedules) => {
197
+ const counts = ALL_SCHEDULES_TYPES.reduce((acc, type) => ({ ...acc, [type]: 0 }), {});
198
+ schedules.forEach((schedule) => {
199
+ if (schedule.jeScheduleType != null) {
200
+ counts[schedule.jeScheduleType] += 1;
201
+ }
202
+ });
203
+ return counts;
204
+ };
205
+ const jeScheduleTypeCounts = {
206
+ active: countByType(allSchedules.filter((schedule) => schedule.status.code === 'draft' ||
207
+ schedule.status.code === 'ongoing' ||
208
+ schedule.status.code === 'completed' ||
209
+ schedule.status.code === 'marked_as_completed')),
210
+ ongoing: countByType(allSchedules.filter((schedule) => schedule.status.code === 'ongoing')),
211
+ };
148
212
  return {
149
213
  uncategorizedAccounts,
150
214
  allDepreciationAccountList: filteredDepAccounts,
@@ -153,12 +217,15 @@ export function getExpenseAutomationJESchedulesView(state) {
153
217
  allAccountList: filteredAccounts,
154
218
  accountListNestedAccountHierarchy,
155
219
  allClassList: allClasses,
156
- completedSchedules,
157
- draftSchedules,
158
- ongoingSchedules,
220
+ createdSchedules,
221
+ createdTotal,
222
+ jeScheduleTypeCounts,
223
+ kpiSummary,
159
224
  pendingReviewSchedules,
225
+ pendingReviewTotal,
160
226
  resolveSchedules: resolveSchedules,
161
227
  accountSettingsView,
228
+ newScheduleView,
162
229
  postStatusById: postStatusById,
163
230
  ignoreStatusById: ignoreStatusById,
164
231
  fetchState: reducedFetchStatus.fetchState,
@@ -16,9 +16,6 @@ const JE_SCHEDULE_SORT_KEYS = [
16
16
  'memo',
17
17
  ];
18
18
  export const toJEScheduleSortKey = (v) => stringToUnion(v, JE_SCHEDULE_SORT_KEYS);
19
- const JE_SCHEDULE_MAIN_TABS = [
20
- 'pending_review',
21
- 'ongoing',
22
- 'completed',
23
- ];
24
- export const toJEScheduleMainTab = (v) => stringToUnion(v, JE_SCHEDULE_MAIN_TABS);
19
+ const JE_PAGE_TABS = ['schedules', 'existing_schedules'];
20
+ export const toJEPageTab = (v) => stringToUnion(v, JE_PAGE_TABS);
21
+ export const MIN_NEW_SCHEDULE_SEARCH_LENGTH = 2;
@@ -13,9 +13,6 @@ const shouldFetch = (fetchStateAndError, cacheOverride) => cacheOverride ||
13
13
  fetchStateAndError.fetchState !== 'In-Progress');
14
14
  const buildQuery = (filters, cursor, sort) => {
15
15
  const params = new URLSearchParams();
16
- if (filters.status != null && filters.status.length > 0) {
17
- params.set('status', filters.status);
18
- }
19
16
  if (filters.search != null && filters.search.length > 0) {
20
17
  params.set('search', filters.search);
21
18
  }
@@ -9,6 +9,7 @@ function couponStatusToTabCountKey(status) {
9
9
  export const initialState = {
10
10
  fetchState: 'Not-Started',
11
11
  error: undefined,
12
+ activeTab: 'all',
12
13
  ids: [],
13
14
  nextCursor: null,
14
15
  filters: {},
@@ -87,6 +88,11 @@ const couponView = createSlice({
87
88
  updateInvoicingCouponFilters(draft, action) {
88
89
  draft.filters = action.payload;
89
90
  },
91
+ // Select a status tab. The list API ignores `status` (returns all statuses),
92
+ // so the selector filters rows to this tab client-side — no refetch needed.
93
+ setInvoicingCouponActiveTab(draft, action) {
94
+ draft.activeTab = action.payload;
95
+ },
90
96
  // Reflect a newly created coupon in the cached discounts list + tab counts
91
97
  // so the list page shows it without refetching from the server. Edits keep
92
98
  // the same id/counts, so only creates dispatch this.
@@ -105,5 +111,5 @@ const couponView = createSlice({
105
111
  },
106
112
  },
107
113
  });
108
- export const { fetchInvoicingCouponList, fetchInvoicingCouponListPage, updateInvoicingCouponList, updateInvoicingCouponListFailure, fetchInvoicingCouponCounts, updateInvoicingCouponCounts, updateInvoicingCouponCountsFailure, updateInvoicingCouponFilters, addInvoicingCouponToList, clearInvoicingCouponView, } = couponView.actions;
114
+ export const { fetchInvoicingCouponList, fetchInvoicingCouponListPage, updateInvoicingCouponList, updateInvoicingCouponListFailure, fetchInvoicingCouponCounts, updateInvoicingCouponCounts, updateInvoicingCouponCountsFailure, updateInvoicingCouponFilters, setInvoicingCouponActiveTab, addInvoicingCouponToList, clearInvoicingCouponView, } = couponView.actions;
109
115
  export default couponView.reducer;
@@ -17,18 +17,31 @@ export const getInvoicingCouponCounts = (state) => state.invoicingCouponViewStat
17
17
  * array (and the wrapping view object) keep referential identity until the
18
18
  * coupon entity slice or the list-view slice actually change.
19
19
  */
20
- export const getInvoicingCouponListView = createSelector((state) => state.invoicingCouponState, (state) => state.invoicingCouponViewState, (couponState, listViewState) => ({
21
- columns: INVOICING_COUPON_COLUMNS,
22
- coupons: listViewState.ids
20
+ export const getInvoicingCouponListView = createSelector((state) => state.invoicingCouponState, (state) => state.invoicingCouponViewState, (couponState, listViewState) => {
21
+ const { activeTab } = listViewState;
22
+ const allCoupons = listViewState.ids
23
23
  .map((id) => couponState.couponByID[id])
24
- .filter((item) => item != null),
25
- count: listViewState.counts,
26
- countsFetchState: listViewState.countsFetchState,
27
- filters: listViewState.filters,
28
- nextCursor: listViewState.nextCursor,
29
- tabIds: INVOICING_COUPON_TABS,
30
- fetchState: listViewState.fetchState,
31
- error: listViewState.error,
32
- sort: listViewState.sort,
33
- version: 1.0,
34
- }));
24
+ .filter((item) => item != null);
25
+ // The list API ignores `status`, so it returns every status; filter to the
26
+ // active tab client-side. 'all' shows everything, 'active' shows only active
27
+ // coupons, and 'inactive' shows every non-active status (undefined included).
28
+ const coupons = activeTab === 'all'
29
+ ? allCoupons
30
+ : allCoupons.filter((coupon) => activeTab === 'active'
31
+ ? coupon.status === 'active'
32
+ : coupon.status !== 'active');
33
+ return {
34
+ activeTab,
35
+ columns: INVOICING_COUPON_COLUMNS,
36
+ coupons,
37
+ count: listViewState.counts,
38
+ countsFetchState: listViewState.countsFetchState,
39
+ filters: listViewState.filters,
40
+ nextCursor: listViewState.nextCursor,
41
+ tabIds: INVOICING_COUPON_TABS,
42
+ fetchState: listViewState.fetchState,
43
+ error: listViewState.error,
44
+ sort: listViewState.sort,
45
+ version: 1.0,
46
+ };
47
+ });