@zeniai/client-epic-state 5.1.61-betaDI0 → 5.1.62-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.
- package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +2 -0
- package/lib/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +4 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -0
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/entity/tenant/tenantReducer.d.ts +4 -1
- package/lib/entity/tenant/tenantReducer.js +8 -2
- package/lib/entity/tenant/tenantSelector.d.ts +1 -0
- package/lib/entity/tenant/tenantSelector.js +4 -0
- package/lib/entity/transaction/scheduleTransactionHelper.d.ts +15 -0
- package/lib/entity/transaction/scheduleTransactionHelper.js +43 -0
- package/lib/epic.d.ts +8 -1
- package/lib/epic.js +8 -1
- package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/esm/entity/tenant/tenantReducer.js +7 -1
- package/lib/esm/entity/tenant/tenantSelector.js +3 -0
- package/lib/esm/entity/transaction/scheduleTransactionHelper.js +39 -0
- package/lib/esm/epic.js +8 -1
- package/lib/esm/index.js +9 -6
- package/lib/esm/view/companyView/companyViewReducer.js +68 -1
- package/lib/esm/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +56 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +37 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +73 -0
- package/lib/esm/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/esm/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +15 -2
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +21 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +110 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +44 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +22 -0
- package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +152 -0
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +126 -6
- package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +1 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +71 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +65 -11
- package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +3 -6
- package/lib/index.d.ts +11 -8
- package/lib/index.js +70 -48
- package/lib/view/companyView/companyViewReducer.d.ts +9 -1
- package/lib/view/companyView/companyViewReducer.js +70 -3
- package/lib/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.d.ts +10 -0
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +60 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.d.ts +11 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +41 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.d.ts +13 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +77 -0
- package/lib/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.d.ts +2 -0
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +14 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +25 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +45 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +114 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +48 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +26 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +43 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +158 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +36 -8
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +128 -7
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +25 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +2 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +29 -4
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +10 -0
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +76 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +65 -11
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +53 -6
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +5 -8
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EMPTY, from, merge, of } from 'rxjs';
|
|
2
|
+
import { catchError, debounceTime, filter, mergeMap, switchMap, } from 'rxjs/operators';
|
|
3
|
+
import { updateTransactions } from '../../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
5
|
+
import { searchTransactionsForNewSchedule, searchTransactionsForNewScheduleFailure, searchTransactionsForNewScheduleSuccess, } from '../../../reducers/jeSchedulesViewReducer';
|
|
6
|
+
import { MIN_NEW_SCHEDULE_SEARCH_LENGTH } from '../../../types/jeSchedulesViewState';
|
|
7
|
+
/** Dropdown-sized result set — no pagination for Base Transaction search. */
|
|
8
|
+
const NEW_SCHEDULE_SEARCH_PAGE_SIZE = 10;
|
|
9
|
+
export const searchTransactionsForNewScheduleEpic = (actions$, _state$, zeniAPI) => {
|
|
10
|
+
const searchActions$ = actions$.pipe(filter(searchTransactionsForNewSchedule.match));
|
|
11
|
+
/** No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP. */
|
|
12
|
+
const newSearchTooShortOrClear$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length < MIN_NEW_SCHEDULE_SEARCH_LENGTH));
|
|
13
|
+
const newSearchDebounced$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length >= MIN_NEW_SCHEDULE_SEARCH_LENGTH), debounceTime(300));
|
|
14
|
+
return merge(newSearchTooShortOrClear$, newSearchDebounced$).pipe(switchMap((action) => {
|
|
15
|
+
const query = action.payload.query.trim();
|
|
16
|
+
if (query.length < MIN_NEW_SCHEDULE_SEARCH_LENGTH) {
|
|
17
|
+
return EMPTY;
|
|
18
|
+
}
|
|
19
|
+
const queryParam = {
|
|
20
|
+
page_size: NEW_SCHEDULE_SEARCH_PAGE_SIZE,
|
|
21
|
+
search_text: query,
|
|
22
|
+
};
|
|
23
|
+
return zeniAPI
|
|
24
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules/base_transaction_search?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
25
|
+
.pipe(mergeMap((response) => {
|
|
26
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
27
|
+
const { transactions } = response.data;
|
|
28
|
+
const actionsOut = [
|
|
29
|
+
updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
|
|
30
|
+
searchTransactionsForNewScheduleSuccess({
|
|
31
|
+
searchResults: transactions.map((transaction) => transaction.transaction_id),
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
return from(actionsOut);
|
|
35
|
+
}
|
|
36
|
+
return of(searchTransactionsForNewScheduleFailure({
|
|
37
|
+
status: response.status,
|
|
38
|
+
}));
|
|
39
|
+
}), catchError((error) => of(searchTransactionsForNewScheduleFailure({
|
|
40
|
+
status: createZeniAPIStatus('Unexpected Error', 'Search transactions for new schedule errored: ' +
|
|
41
|
+
JSON.stringify(error)),
|
|
42
|
+
}))));
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EMPTY, of } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { fetchJeSchedulesPage, updateJESchedulesUIState, } from '../../reducers/jeSchedulesViewReducer';
|
|
6
|
+
export const switchJESchedulesTabEpic = (actions$, state$) => actions$.pipe(filter(updateJESchedulesUIState.match), filter((action) => action.payload.selectedPageTab != null), mergeMap(() => {
|
|
7
|
+
const state = state$.value;
|
|
8
|
+
const { fetchState, refreshStatus } = state.expenseAutomationJESchedulesViewState;
|
|
9
|
+
if (fetchState === 'In-Progress' ||
|
|
10
|
+
refreshStatus.fetchState === 'In-Progress') {
|
|
11
|
+
return EMPTY;
|
|
12
|
+
}
|
|
13
|
+
const currentTenant = getCurrentTenant(state);
|
|
14
|
+
const selectedPeriod = state.expenseAutomationViewState.selectedPeriodByTenantId[currentTenant.tenantId];
|
|
15
|
+
const period = convertToPeriod(selectedPeriod);
|
|
16
|
+
const timePeriodStart = toAbsoluteDay(period.start);
|
|
17
|
+
const timePeriodEnd = toAbsoluteDay(period.end);
|
|
18
|
+
if (timePeriodStart == null || timePeriodEnd == null) {
|
|
19
|
+
return EMPTY;
|
|
20
|
+
}
|
|
21
|
+
return of(fetchJeSchedulesPage({ start: timePeriodStart, end: timePeriodEnd }, true));
|
|
22
|
+
}));
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { mapSupportedTransactionLineToScheduleTransaction } from '../../../entity/transaction/scheduleTransactionHelper';
|
|
6
|
+
import { getPostingDateAndStatusForIndex } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
|
|
7
|
+
import { mapScheduleTransactionToBaseScheduleTransactionPayload, } from '../../scheduleView/scheduleDetailView/scheduleDetailPayload';
|
|
8
|
+
const getNewScheduleMemo = (vendorName, schedulePostingDate, currentPeriod, totalPeriod, assetId) => {
|
|
9
|
+
const addAsset = assetId != null && assetId !== '' ? ` - ${assetId}` : '';
|
|
10
|
+
return `${vendorName} - ${schedulePostingDate.format(MONTH_YEAR_FORMAT)} (${currentPeriod} of ${totalPeriod})${addAsset}`;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Computes the month-by-month JE schedule breakdown for a brand-new schedule
|
|
14
|
+
* (no linked transaction yet) — replicates createNewSchedulesHelper's math
|
|
15
|
+
* (scheduleDetailLocalDataHelper.ts) exactly: lump-sum total split evenly
|
|
16
|
+
* across months with the rounding remainder absorbed by the last month, and a
|
|
17
|
+
* running balance that decrements each month and is forced to exactly 0 on
|
|
18
|
+
* the last row.
|
|
19
|
+
*/
|
|
20
|
+
export const computeNewScheduleJeDetails = (localData, totalAmount, vendorName) => {
|
|
21
|
+
const period = localData.selectedMonths;
|
|
22
|
+
const startingMonth = localData.selectedDate;
|
|
23
|
+
if (startingMonth == null || period == null) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const assetId = 'assetId' in localData ? localData.assetId : undefined;
|
|
27
|
+
const averageAmount = Math.abs(Math.round((totalAmount.amount / period) * 100) / 100);
|
|
28
|
+
const lastMonthAmount = Math.abs(Math.round((Math.abs(totalAmount.amount) - averageAmount * (period - 1)) * 100) / 100);
|
|
29
|
+
let runningBalance = Math.abs(totalAmount.amount);
|
|
30
|
+
const negativeNumbers = totalAmount.amount < 0 || runningBalance < 0;
|
|
31
|
+
const newJeDetails = [];
|
|
32
|
+
for (let index = 0; index < period; index++) {
|
|
33
|
+
if (runningBalance > averageAmount) {
|
|
34
|
+
runningBalance = Math.round((runningBalance - averageAmount) * 100) / 100;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
runningBalance = 0;
|
|
38
|
+
}
|
|
39
|
+
const amount = index === period - 1 ? lastMonthAmount : averageAmount;
|
|
40
|
+
runningBalance = index === period - 1 ? 0 : runningBalance;
|
|
41
|
+
const schedulePostingDate = startingMonth.add(index, 'month');
|
|
42
|
+
const { postingDate, postingStatus } = getPostingDateAndStatusForIndex(schedulePostingDate.month(), schedulePostingDate.year(), localData.lastDayOfMonth === true
|
|
43
|
+
? undefined
|
|
44
|
+
: localData.selectedDayOfMonth);
|
|
45
|
+
newJeDetails.push({
|
|
46
|
+
postingDate,
|
|
47
|
+
amount: toAmount(negativeNumbers ? -amount : amount, totalAmount.currencyCode, totalAmount.currencySymbol),
|
|
48
|
+
runningBalance: toAmount(negativeNumbers ? -runningBalance : runningBalance, totalAmount.currencyCode, totalAmount.currencySymbol),
|
|
49
|
+
postingStatus,
|
|
50
|
+
memo: getNewScheduleMemo(vendorName, schedulePostingDate, index + 1, period, assetId),
|
|
51
|
+
jeLink: { type: 'unknown' },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return newJeDetails;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Whether a Base Transaction search result can be selected for a new
|
|
58
|
+
* schedule this round — restricted to single-line transactions since the
|
|
59
|
+
* search/list endpoint's `lines` may not reflect the transaction's full line
|
|
60
|
+
* set, and there is no line-picker UI yet.
|
|
61
|
+
*/
|
|
62
|
+
export const isSupportedTransactionSelectableForNewSchedule = (transaction) => transaction.totalLinesCount === 1 && transaction.lines?.length === 1;
|
|
63
|
+
const mapNewJeDetailsToScheduledJournalEntryPayload = (jeScheduleDetails) => jeScheduleDetails.map((journalEntry) => ({
|
|
64
|
+
status: {
|
|
65
|
+
code: journalEntry.postingStatus,
|
|
66
|
+
label: journalEntry.postingStatus,
|
|
67
|
+
},
|
|
68
|
+
transaction_memo: journalEntry.memo,
|
|
69
|
+
third_party_id: journalEntry.jeLink.thirdPartyTransactionId ?? null,
|
|
70
|
+
expected_post_date: journalEntry.postingDate.format(DEFAULT_DATE_FORMAT),
|
|
71
|
+
amount: journalEntry.amount.amount,
|
|
72
|
+
balance: journalEntry.runningBalance.amount,
|
|
73
|
+
// Brand-new schedule — there is no prior scheduled-journal-entry history
|
|
74
|
+
// to cross-reference (unlike the legacy edit flow's equivalent mapper).
|
|
75
|
+
scheduled_journal_entry_id: null,
|
|
76
|
+
actual_post_date: null,
|
|
77
|
+
is_platform_generated: null,
|
|
78
|
+
je_schedule_id: null,
|
|
79
|
+
update_time: null,
|
|
80
|
+
create_time: null,
|
|
81
|
+
}));
|
|
82
|
+
/**
|
|
83
|
+
* Builds a savable schedule payload directly from a Base Transaction search
|
|
84
|
+
* result and the New Schedule form's local data — bypassing the legacy
|
|
85
|
+
* getJEScheduledTransactionByJEScheduleTransactionKey selector entirely,
|
|
86
|
+
* since that selector throws unless the entity has already round-tripped
|
|
87
|
+
* through a real GET /1.0/schedules/:id. A brand-new schedule has no such
|
|
88
|
+
* history, so this reads only from data already in hand (the selected
|
|
89
|
+
* transaction/line plus what the user filled into the form).
|
|
90
|
+
*/
|
|
91
|
+
export const prepareNewSchedulePayload = (transaction, localData, scheduleType) => {
|
|
92
|
+
const [firstLine] = transaction.lines ?? [];
|
|
93
|
+
if (!isSupportedTransactionSelectableForNewSchedule(transaction) ||
|
|
94
|
+
firstLine == null) {
|
|
95
|
+
return { ok: false, reason: 'multi_line_not_supported' };
|
|
96
|
+
}
|
|
97
|
+
const scheduleTransaction = mapSupportedTransactionLineToScheduleTransaction(transaction, firstLine.id);
|
|
98
|
+
if (scheduleTransaction == null) {
|
|
99
|
+
return { ok: false, reason: 'missing_third_party_id' };
|
|
100
|
+
}
|
|
101
|
+
const vendorId = localData.selectedVendor?.id ?? transaction.vendorId ?? '';
|
|
102
|
+
const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
|
|
103
|
+
if (vendorId === '' || vendorName === '') {
|
|
104
|
+
return { ok: false, reason: 'missing_vendor' };
|
|
105
|
+
}
|
|
106
|
+
const vendor = {
|
|
107
|
+
vendor_id: vendorId,
|
|
108
|
+
vendor_name: vendorName,
|
|
109
|
+
};
|
|
110
|
+
const jeScheduleDetails = computeNewScheduleJeDetails(localData, scheduleTransaction.amount, vendorName);
|
|
111
|
+
const postingDate = localData.selectedDayOfMonth ??
|
|
112
|
+
(localData.lastDayOfMonth === true ? LAST_SCHEDULE_DAY_OF_MONTH : null);
|
|
113
|
+
const firstJEScheduleDate = jeScheduleDetails.length > 0
|
|
114
|
+
? jeScheduleDetails[0].postingDate.format(DEFAULT_DATE_FORMAT)
|
|
115
|
+
: null;
|
|
116
|
+
const lastJEScheduleDate = jeScheduleDetails.length > 0
|
|
117
|
+
? jeScheduleDetails[jeScheduleDetails.length - 1].postingDate.format(DEFAULT_DATE_FORMAT)
|
|
118
|
+
: null;
|
|
119
|
+
const isFixedAssets = scheduleType === 'fixed_assets';
|
|
120
|
+
const assetId = 'assetId' in localData ? localData.assetId : undefined;
|
|
121
|
+
const selectedAccumulatedDepreciationCategory = 'selectedAccumulatedDepreciationCategory' in localData
|
|
122
|
+
? localData.selectedAccumulatedDepreciationCategory
|
|
123
|
+
: undefined;
|
|
124
|
+
const status = { code: 'new', label: 'New' };
|
|
125
|
+
const jeSchedulePayload = {
|
|
126
|
+
status,
|
|
127
|
+
vendor,
|
|
128
|
+
currency_code: scheduleTransaction.currency.currencyCode,
|
|
129
|
+
currency_symbol: scheduleTransaction.currency.currencySymbol,
|
|
130
|
+
period: localData.selectedMonths ?? null,
|
|
131
|
+
je_schedule_type: scheduleType,
|
|
132
|
+
posting_date: postingDate,
|
|
133
|
+
balance: scheduleTransaction.amount.amount,
|
|
134
|
+
start_date: firstJEScheduleDate,
|
|
135
|
+
end_date: lastJEScheduleDate,
|
|
136
|
+
je_credit_accounting_class_id: scheduleTransaction.classBase?.classId ?? null,
|
|
137
|
+
je_credit_account_id: isFixedAssets
|
|
138
|
+
? (selectedAccumulatedDepreciationCategory ?? null)
|
|
139
|
+
: scheduleTransaction.account.accountId,
|
|
140
|
+
je_debit_account_id: localData.selectedAccount ?? null,
|
|
141
|
+
je_debit_accounting_class_id: localData.selectedClass ?? null,
|
|
142
|
+
other_attributes: assetId != null ? { asset_id: assetId } : {},
|
|
143
|
+
base_transaction: mapScheduleTransactionToBaseScheduleTransactionPayload(scheduleTransaction),
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
payload: {
|
|
148
|
+
je_schedules: [jeSchedulePayload],
|
|
149
|
+
scheduled_journal_entries: mapNewJeDetailsToScheduledJournalEntryPayload(jeScheduleDetails),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|
|
@@ -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
|
-
|
|
59
|
+
createdGroupCollapsed: false,
|
|
60
|
+
pendingGroupCollapsed: false,
|
|
46
61
|
scrollPosition: { scrollTop: 0, scrollLeft: undefined },
|
|
47
|
-
|
|
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 }) {
|
|
423
|
+
return { payload: { query } };
|
|
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.
|
|
385
|
-
draft.uiState.
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getAccountIdsForTypes } from '../../../entity/account/accountSelector';
|
|
2
|
+
import { getSupportedTransactionsByIds } 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
|
+
import { isSupportedTransactionSelectableForNewSchedule } from '../helpers/newScheduleLocalDataHelper';
|
|
9
|
+
/**
|
|
10
|
+
* The Base Transaction search is shared across schedule types (one search
|
|
11
|
+
* box, not one per prepaid_expenses/fixed_assets) — split out from
|
|
12
|
+
* getNewScheduleView so a consumer can read it without supplying an
|
|
13
|
+
* otherwise-irrelevant scheduleType.
|
|
14
|
+
*/
|
|
15
|
+
export const getNewScheduleSearchTransactionsView = (state) => {
|
|
16
|
+
const { searchTransactions } = state.expenseAutomationJESchedulesViewState.newSchedule;
|
|
17
|
+
const searchTransactionsResults = getSupportedTransactionsByIds(state.transactionState, searchTransactions.searchResults);
|
|
18
|
+
return {
|
|
19
|
+
searchTransactionsResults,
|
|
20
|
+
selectableBaseTransactionIds: searchTransactionsResults
|
|
21
|
+
.filter(isSupportedTransactionSelectableForNewSchedule)
|
|
22
|
+
.map((transaction) => transaction.id),
|
|
23
|
+
searchTransactionsFetchState: {
|
|
24
|
+
fetchState: searchTransactions.fetchState,
|
|
25
|
+
error: searchTransactions.error,
|
|
26
|
+
},
|
|
27
|
+
searchTransactionsString: searchTransactions.searchString,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const getNewScheduleView = (state, scheduleType) => {
|
|
31
|
+
const { accountState, accountListState, classState, classListState } = state;
|
|
32
|
+
const { newSchedule } = state.expenseAutomationJESchedulesViewState;
|
|
33
|
+
const searchTransactionsView = getNewScheduleSearchTransactionsView(state);
|
|
34
|
+
const accountType = getAccountsTypesForScheduleEpics();
|
|
35
|
+
const newScheduleAccountTypes = getAccountsTypesForScheduleDetails(scheduleType);
|
|
36
|
+
const newScheduleAccountIds = getAccountIdsForTypes(accountState, newScheduleAccountTypes);
|
|
37
|
+
const allAccountList = getAccountList(accountState, accountListState, accountType.accountListKey);
|
|
38
|
+
const filteredAccounts = allAccountList.accounts.filter((account) => newScheduleAccountIds.includes(account.accountId));
|
|
39
|
+
const accountListNestedAccountHierarchy = filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), filteredAccounts.map((account) => account.accountId));
|
|
40
|
+
const allClassList = getClassList(classState, classListState);
|
|
41
|
+
const classListNestedAccountHierarchy = getNestedClassListHierarchy(classListState);
|
|
42
|
+
let allDepreciationAccountList;
|
|
43
|
+
let allDepreciationAccountListNestedAccountHierarchy;
|
|
44
|
+
if (scheduleType === 'fixed_assets') {
|
|
45
|
+
const depreciationCategoryIds = getAccountIdsForTypes(accountState, [
|
|
46
|
+
'fixed_assets',
|
|
47
|
+
'other_assets',
|
|
48
|
+
]);
|
|
49
|
+
const accountLabel = getAccountLabelForScheduleType('fixed_assets');
|
|
50
|
+
const fixedAssetLabelAccountIds = accountLabel != null
|
|
51
|
+
? getAccountIdsForLabel(accountListState, accountType.accountListKey, accountLabel)
|
|
52
|
+
: [];
|
|
53
|
+
allDepreciationAccountList = allAccountList.accounts.filter((account) => depreciationCategoryIds.includes(account.accountId) &&
|
|
54
|
+
!fixedAssetLabelAccountIds.includes(account.accountId));
|
|
55
|
+
allDepreciationAccountListNestedAccountHierarchy =
|
|
56
|
+
filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), allDepreciationAccountList.map((account) => account.accountId));
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
scheduleType,
|
|
60
|
+
accountListNestedAccountHierarchy,
|
|
61
|
+
allAccountList: filteredAccounts,
|
|
62
|
+
allClassList: allClassList.classes,
|
|
63
|
+
allDepreciationAccountList,
|
|
64
|
+
allDepreciationAccountListNestedAccountHierarchy,
|
|
65
|
+
classListNestedAccountHierarchy,
|
|
66
|
+
newScheduleLocalData: newSchedule.newScheduleState[scheduleType],
|
|
67
|
+
...searchTransactionsView,
|
|
68
|
+
fetchState: newSchedule.fetchState,
|
|
69
|
+
error: newSchedule.error,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -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,7 @@ 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';
|
|
15
17
|
function getJEScheduleSortAccessor(sortKey) {
|
|
16
18
|
switch (sortKey) {
|
|
17
19
|
case 'vendor':
|
|
@@ -53,7 +55,7 @@ function getJEScheduleSortAccessor(sortKey) {
|
|
|
53
55
|
case 'totalAmount':
|
|
54
56
|
return (s) => s.baseTransaction.amount.amount;
|
|
55
57
|
case 'transactionDate':
|
|
56
|
-
return (s) => s.
|
|
58
|
+
return (s) => s.createTime?.valueOf();
|
|
57
59
|
case 'memo':
|
|
58
60
|
return (s) => s.baseTransaction.memo?.toLowerCase();
|
|
59
61
|
default:
|
|
@@ -68,8 +70,12 @@ export function getExpenseAutomationJESchedulesView(state) {
|
|
|
68
70
|
const jeScheduledTransaction = [];
|
|
69
71
|
const failedJeScheduledTransaction = [];
|
|
70
72
|
const { accountState, accountListState, classState, classListState, expenseAutomationJESchedulesViewState, expenseAutomationViewState, monthEndCloseChecksState, monthEndCloseChecksViewState, } = state;
|
|
71
|
-
const { jeScheduleTransactionKeysByPeriod, failedJeScheduleTransactionKeysByPeriod, jeScheduleLocalDataById, postStatusById, ignoreStatusById, uiState, error, fetchState, refreshStatus, } = expenseAutomationJESchedulesViewState;
|
|
73
|
+
const { jeScheduleTransactionKeysByPeriod, failedJeScheduleTransactionKeysByPeriod, jeScheduleLocalDataById, postStatusById, ignoreStatusById, uiState, error, fetchState, refreshStatus, newSchedule, } = expenseAutomationJESchedulesViewState;
|
|
72
74
|
const accountSettingsView = getJEAccountSettingsView(state);
|
|
75
|
+
const newScheduleView = newSchedule.selectedDetailScheduleType === 'fixed_assets' ||
|
|
76
|
+
newSchedule.selectedDetailScheduleType === 'prepaid_expenses'
|
|
77
|
+
? getNewScheduleView(state, newSchedule.selectedDetailScheduleType)
|
|
78
|
+
: undefined;
|
|
73
79
|
const currentTenant = getCurrentTenant(state);
|
|
74
80
|
const { selectedPeriodByTenantId } = expenseAutomationViewState;
|
|
75
81
|
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
@@ -113,11 +119,7 @@ export function getExpenseAutomationJESchedulesView(state) {
|
|
|
113
119
|
const jeScheduleDetails = getJEScheduledTransactionByJEScheduleTransactionKey(jeScheduleKey, state);
|
|
114
120
|
failedJeScheduledTransaction.push(jeScheduleDetails);
|
|
115
121
|
});
|
|
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);
|
|
122
|
+
const { sortKey, sortOrder, selectedJETypeFilter } = uiState;
|
|
121
123
|
const unsortedResolveSchedules = [];
|
|
122
124
|
failedJeScheduledTransaction.forEach((schedule) => {
|
|
123
125
|
schedule.scheduledJournalEntry.forEach((journalEntry) => {
|
|
@@ -130,9 +132,42 @@ export function getExpenseAutomationJESchedulesView(state) {
|
|
|
130
132
|
const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules, sortKey, sortOrder);
|
|
131
133
|
const validResolveForPending = unsortedResolveSchedules.filter((r) => jeScheduleLocalDataById[r.scheduledJournalEntry.scheduledJournalEntryID] != null);
|
|
132
134
|
const pendingReviewSchedules = sortJEScheduledTransactions([
|
|
133
|
-
...jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft'
|
|
135
|
+
...jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft' &&
|
|
136
|
+
(selectedJETypeFilter == null ||
|
|
137
|
+
schedule.jeScheduleType === selectedJETypeFilter)),
|
|
134
138
|
...validResolveForPending,
|
|
135
139
|
], sortKey, sortOrder);
|
|
140
|
+
const createdSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => (schedule.status.code === 'ongoing' ||
|
|
141
|
+
schedule.status.code === 'completed' ||
|
|
142
|
+
schedule.status.code === 'marked_as_completed') &&
|
|
143
|
+
(selectedJETypeFilter == null ||
|
|
144
|
+
schedule.jeScheduleType === selectedJETypeFilter)), sortKey, sortOrder);
|
|
145
|
+
// KPI summary — derived from unfiltered schedules so counts are always accurate
|
|
146
|
+
const allSchedules = jeScheduledTransaction;
|
|
147
|
+
const sumAmount = (schedules) => schedules.reduce((total, schedule) => total + (schedule.baseTransaction.amount.amount ?? 0), 0);
|
|
148
|
+
const pendingReviewTotal = sumAmount(pendingReviewSchedules);
|
|
149
|
+
const createdTotal = sumAmount(createdSchedules);
|
|
150
|
+
const aiAccountantSchedules = allSchedules.filter((schedule) => schedule.confidenceScore != null);
|
|
151
|
+
const pendingUnfiltered = allSchedules.filter((schedule) => schedule.status.code === 'draft');
|
|
152
|
+
const kpiSummary = {
|
|
153
|
+
aiAccountant: {
|
|
154
|
+
count: aiAccountantSchedules.length,
|
|
155
|
+
amount: sumAmount(aiAccountantSchedules),
|
|
156
|
+
},
|
|
157
|
+
manual: {
|
|
158
|
+
count: allSchedules.filter((schedule) => schedule.confidenceScore == null)
|
|
159
|
+
.length,
|
|
160
|
+
amount: sumAmount(allSchedules.filter((schedule) => schedule.confidenceScore == null)),
|
|
161
|
+
},
|
|
162
|
+
needsReview: {
|
|
163
|
+
count: pendingUnfiltered.length,
|
|
164
|
+
amount: sumAmount(pendingUnfiltered),
|
|
165
|
+
},
|
|
166
|
+
total: {
|
|
167
|
+
count: allSchedules.length,
|
|
168
|
+
amount: sumAmount(allSchedules),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
136
171
|
const allSteps = monthYearPeriodId != null
|
|
137
172
|
? getAllSteps(monthEndCloseChecksState, monthYearPeriodId, currentTenant.tenantId)
|
|
138
173
|
: [];
|
|
@@ -145,6 +180,22 @@ export function getExpenseAutomationJESchedulesView(state) {
|
|
|
145
180
|
{ fetchState, error },
|
|
146
181
|
monthEndFetchState,
|
|
147
182
|
]);
|
|
183
|
+
const countByType = (schedules) => {
|
|
184
|
+
const counts = ALL_SCHEDULES_TYPES.reduce((acc, type) => ({ ...acc, [type]: 0 }), {});
|
|
185
|
+
schedules.forEach((schedule) => {
|
|
186
|
+
if (schedule.jeScheduleType != null) {
|
|
187
|
+
counts[schedule.jeScheduleType] += 1;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return counts;
|
|
191
|
+
};
|
|
192
|
+
const jeScheduleTypeCounts = {
|
|
193
|
+
active: countByType(allSchedules.filter((schedule) => schedule.status.code === 'draft' ||
|
|
194
|
+
schedule.status.code === 'ongoing' ||
|
|
195
|
+
schedule.status.code === 'completed' ||
|
|
196
|
+
schedule.status.code === 'marked_as_completed')),
|
|
197
|
+
ongoing: countByType(allSchedules.filter((schedule) => schedule.status.code === 'ongoing')),
|
|
198
|
+
};
|
|
148
199
|
return {
|
|
149
200
|
uncategorizedAccounts,
|
|
150
201
|
allDepreciationAccountList: filteredDepAccounts,
|
|
@@ -153,12 +204,15 @@ export function getExpenseAutomationJESchedulesView(state) {
|
|
|
153
204
|
allAccountList: filteredAccounts,
|
|
154
205
|
accountListNestedAccountHierarchy,
|
|
155
206
|
allClassList: allClasses,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
207
|
+
createdSchedules,
|
|
208
|
+
createdTotal,
|
|
209
|
+
jeScheduleTypeCounts,
|
|
210
|
+
kpiSummary,
|
|
159
211
|
pendingReviewSchedules,
|
|
212
|
+
pendingReviewTotal,
|
|
160
213
|
resolveSchedules: resolveSchedules,
|
|
161
214
|
accountSettingsView,
|
|
215
|
+
newScheduleView,
|
|
162
216
|
postStatusById: postStatusById,
|
|
163
217
|
ignoreStatusById: ignoreStatusById,
|
|
164
218
|
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
|
|
20
|
-
|
|
21
|
-
|
|
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;
|