@zeniai/client-epic-state 4.20.7 → 4.20.8
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/commonStateTypes/coaBalance/additionalBalances/getSummationBalance.d.ts +1 -1
- package/lib/commonStateTypes/coaBalance/coaBalanceType.d.ts +2 -0
- package/lib/commonStateTypes/coaBalance/coaBalanceType.js +6 -0
- package/lib/commonStateTypes/currencyHelper.d.ts +3 -0
- package/lib/commonStateTypes/currencyHelper.js +6 -1
- package/lib/commonStateTypes/reduceFetchState.d.ts +9 -0
- package/lib/commonStateTypes/reduceFetchState.js +26 -0
- package/lib/entity/account/accountPayload.d.ts +2 -0
- package/lib/entity/account/accountPayload.js +2 -0
- package/lib/entity/account/accountState.d.ts +2 -0
- package/lib/entity/customer/customerState.d.ts +0 -2
- package/lib/entity/customer/customerState.js +0 -5
- package/lib/entity/depositAccount/depositAccount.d.ts +1 -1
- package/lib/entity/depositAccount/depositAccount.js +8 -1
- package/lib/entity/reimbursement/reimbursementPayload.d.ts +2 -0
- package/lib/entity/reimbursement/reimbursementPayload.js +7 -0
- package/lib/entity/reimbursement/reimbursementState.d.ts +2 -0
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +2 -0
- package/lib/entity/task/taskPayload.d.ts +1 -0
- package/lib/entity/task/taskPayload.js +1 -0
- package/lib/entity/task/taskState.d.ts +1 -0
- package/lib/entity/userGroups/userGroupsPayload.d.ts +7 -0
- package/lib/entity/userGroups/userGroupsPayload.js +10 -0
- package/lib/entity/userGroups/userGroupsReducer.d.ts +8 -0
- package/lib/entity/userGroups/userGroupsReducer.js +29 -0
- package/lib/entity/userGroups/userGroupsSelector.d.ts +4 -0
- package/lib/entity/userGroups/userGroupsSelector.js +12 -0
- package/lib/entity/userGroups/userGroupsState.d.ts +9 -0
- package/lib/entity/userGroups/userGroupsState.js +2 -0
- package/lib/epic.d.ts +15 -1
- package/lib/epic.js +15 -1
- package/lib/esm/commonStateTypes/coaBalance/coaBalanceType.js +5 -0
- package/lib/esm/commonStateTypes/currencyHelper.js +5 -0
- package/lib/esm/commonStateTypes/reduceFetchState.js +25 -0
- package/lib/esm/entity/account/accountPayload.js +2 -0
- package/lib/esm/entity/customer/customerState.js +1 -4
- package/lib/esm/entity/depositAccount/depositAccount.js +8 -1
- package/lib/esm/entity/reimbursement/reimbursementPayload.js +7 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
- package/lib/esm/entity/task/taskPayload.js +1 -0
- package/lib/esm/entity/userGroups/userGroupsPayload.js +7 -0
- package/lib/esm/entity/userGroups/userGroupsReducer.js +25 -0
- package/lib/esm/entity/userGroups/userGroupsSelector.js +8 -0
- package/lib/esm/entity/userGroups/userGroupsState.js +1 -0
- package/lib/esm/epic.js +15 -1
- package/lib/esm/index.js +19 -10
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/arAgingView/arAgingReport/arAgingReducer.js +1 -1
- package/lib/esm/view/arAgingView/arAgingReport/arAgingSelector.js +1 -1
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +33 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +29 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +49 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +33 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +56 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +12 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +98 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +71 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +86 -0
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
- package/lib/esm/view/expenseAutomationView/helpers/bulkUploadTiming.js +16 -0
- package/lib/esm/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +13 -0
- package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +198 -1
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +456 -2
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +23 -1
- package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +245 -1
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +44 -0
- package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/esm/view/financeStatement/financeStatementReducer.js +11 -8
- package/lib/esm/view/financeStatement/financeStatementSelector.js +24 -9
- package/lib/esm/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +17 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +331 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +9 -0
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +6 -1
- package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
- package/lib/esm/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
- package/lib/esm/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +262 -0
- package/lib/esm/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +9 -7
- package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/esm/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
- package/lib/esm/view/taskManager/taskListView/taskListSelector.js +3 -1
- package/lib/esm/view/userGroupListView/userGroupListViewReducer.js +65 -0
- package/lib/esm/view/userGroupListView/userGroupListViewSelector.js +16 -0
- package/lib/esm/view/userGroupListView/userGroupListViewState.js +1 -0
- package/lib/esm/view/userListView/fetchUserListByTypeEpic.js +11 -0
- package/lib/esm/zeniAPI.js +0 -2
- package/lib/index.d.ts +20 -12
- package/lib/index.js +97 -34
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
- package/lib/view/arAgingView/arAgingReport/arAgingReducer.js +2 -2
- package/lib/view/arAgingView/arAgingReport/arAgingSelector.js +5 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.d.ts +13 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +37 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +18 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +33 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +53 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +37 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +61 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.d.ts +10 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +16 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.d.ts +18 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +102 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +75 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +25 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +92 -0
- package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
- package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
- package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.d.ts +16 -0
- package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.js +19 -0
- package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.d.ts +7 -0
- package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +16 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +123 -0
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +211 -0
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +86 -3
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +457 -2
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +24 -2
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +70 -1
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
- package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
- package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +244 -0
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +146 -0
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +54 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/view/financeStatement/financeStatementReducer.js +11 -8
- package/lib/view/financeStatement/financeStatementSelector.d.ts +2 -0
- package/lib/view/financeStatement/financeStatementSelector.js +24 -9
- package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.d.ts +9 -0
- package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +20 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.d.ts +15 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +335 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.d.ts +111 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +13 -0
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.d.ts +4 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +7 -2
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
- package/lib/view/profitAndLossClassesView/profitAndLossClassesViewState.d.ts +4 -0
- package/lib/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
- package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.d.ts +6 -0
- package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +265 -0
- package/lib/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +8 -6
- package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
- package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.d.ts +1 -0
- package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
- package/lib/view/taskManager/taskListView/taskListSelector.d.ts +2 -0
- package/lib/view/taskManager/taskListView/taskListSelector.js +3 -1
- package/lib/view/userGroupListView/userGroupListViewReducer.d.ts +23 -0
- package/lib/view/userGroupListView/userGroupListViewReducer.js +69 -0
- package/lib/view/userGroupListView/userGroupListViewSelector.d.ts +7 -0
- package/lib/view/userGroupListView/userGroupListViewSelector.js +20 -0
- package/lib/view/userGroupListView/userGroupListViewState.d.ts +8 -0
- package/lib/view/userGroupListView/userGroupListViewState.js +2 -0
- package/lib/view/userListView/fetchUserListByTypeEpic.d.ts +3 -1
- package/lib/view/userListView/fetchUserListByTypeEpic.js +11 -0
- package/lib/view/userListView/userListViewPayload.d.ts +2 -0
- package/lib/zeniAPI.js +0 -2
- package/package.json +3 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EMPTY, concat, from, of } from 'rxjs';
|
|
2
|
+
import { catchError, concatMap, filter, mergeMap, take } from 'rxjs/operators';
|
|
3
|
+
import { isSuccessResponse } from '../../../../responsePayload';
|
|
4
|
+
import { isBatchDetailsStatusPendingOrProcessing, toBatchListItem, } from '../../payload/missingReceiptsPayload';
|
|
5
|
+
import { fetchBulkUploadBatchesSuccess, restoreBulkUploadAutomatchingOnMount, restoreBulkUploadMatchingState, } from '../../reducers/missingReceiptsViewReducer';
|
|
6
|
+
import { BULK_UPLOAD_BATCH_LIST_DATE_RANGE_DAYS } from '../../helpers/bulkUploadTiming';
|
|
7
|
+
import { rollingCalendarDateRangeInclusive } from '../../helpers/rollingCalendarDateRangeInclusive';
|
|
8
|
+
import { toMonthYearPeriodId } from '../../../../commonStateTypes/timePeriod';
|
|
9
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
10
|
+
/**
|
|
11
|
+
* On missing-receipts entry / period switch, hydrate the automatching banner for the logged-in
|
|
12
|
+
* user without relying on UI-driven list fetches (the Missing tab does not fetch the batch list
|
|
13
|
+
* while `phase === 'idle'`). Flow:
|
|
14
|
+
* 1. Call `GET /1.0/batches` (rolling 30-day window).
|
|
15
|
+
* 2. Emit `fetchBulkUploadBatchesSuccess` so `batchListByPeriod` is populated for the selected
|
|
16
|
+
* period (prevents a duplicate list fetch when the user switches to the Unmatched tab).
|
|
17
|
+
* 3. For each `processing|pending` row, call `GET /1.0/batches/:id` in order; for the first row
|
|
18
|
+
* whose details `user_id` matches the logged-in user and whose status is still
|
|
19
|
+
* pending/processing, dispatch `restoreBulkUploadMatchingState` and stop.
|
|
20
|
+
*/
|
|
21
|
+
export const restoreBulkUploadAutomatchingOnMountEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(restoreBulkUploadAutomatchingOnMount.match), mergeMap(() => {
|
|
22
|
+
const state = state$.value;
|
|
23
|
+
const { expenseAutomationMissingReceiptsViewState: { bulkUpload }, expenseAutomationViewState: { selectedPeriodByTenantId }, } = state;
|
|
24
|
+
if (bulkUpload.phase !== 'idle') {
|
|
25
|
+
return EMPTY;
|
|
26
|
+
}
|
|
27
|
+
if (bulkUpload.batchListFetchState.fetchState === 'In-Progress') {
|
|
28
|
+
return EMPTY;
|
|
29
|
+
}
|
|
30
|
+
const loggedInUserId = state.tenantState.loggedInUser?.userId;
|
|
31
|
+
if (loggedInUserId == null) {
|
|
32
|
+
return EMPTY;
|
|
33
|
+
}
|
|
34
|
+
const currentTenant = getCurrentTenant(state);
|
|
35
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
36
|
+
if (selectedPeriod == null) {
|
|
37
|
+
return EMPTY;
|
|
38
|
+
}
|
|
39
|
+
const { end, start } = rollingCalendarDateRangeInclusive(BULK_UPLOAD_BATCH_LIST_DATE_RANGE_DAYS);
|
|
40
|
+
const queryParam = {
|
|
41
|
+
start_date: start,
|
|
42
|
+
end_date: end,
|
|
43
|
+
sort_order: 'desc',
|
|
44
|
+
};
|
|
45
|
+
const listUrl = `${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches?query=${encodeURIComponent(JSON.stringify(queryParam))}`;
|
|
46
|
+
const detailsBaseUrl = `${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/`;
|
|
47
|
+
const periodId = toMonthYearPeriodId(selectedPeriod);
|
|
48
|
+
const alreadyCached = (bulkUpload.batchListByPeriod[periodId] ?? []).length > 0 &&
|
|
49
|
+
bulkUpload.batchListFetchState.fetchState === 'Completed';
|
|
50
|
+
const listSource = alreadyCached
|
|
51
|
+
? of(null)
|
|
52
|
+
: zeniAPI.getJSON(listUrl).pipe(catchError(() => of(null)));
|
|
53
|
+
return listSource.pipe(mergeMap((listResponse) => {
|
|
54
|
+
const batchList = alreadyCached
|
|
55
|
+
? bulkUpload.batchListByPeriod[periodId] ?? []
|
|
56
|
+
: listResponse != null &&
|
|
57
|
+
isSuccessResponse(listResponse) &&
|
|
58
|
+
listResponse.data != null
|
|
59
|
+
? listResponse.data.batches.map(toBatchListItem)
|
|
60
|
+
: null;
|
|
61
|
+
if (batchList == null) {
|
|
62
|
+
return EMPTY;
|
|
63
|
+
}
|
|
64
|
+
const successAction = alreadyCached
|
|
65
|
+
? null
|
|
66
|
+
: fetchBulkUploadBatchesSuccess({
|
|
67
|
+
batchList,
|
|
68
|
+
selectedPeriod,
|
|
69
|
+
});
|
|
70
|
+
const processingBatches = batchList.filter((b) => {
|
|
71
|
+
const status = b.status.toLowerCase();
|
|
72
|
+
return status === 'processing' || status === 'pending';
|
|
73
|
+
});
|
|
74
|
+
const restoreStream = from(processingBatches).pipe(concatMap((batch) => zeniAPI
|
|
75
|
+
.getJSON(`${detailsBaseUrl}${batch.batchId}`)
|
|
76
|
+
.pipe(mergeMap((response) => {
|
|
77
|
+
if (!isSuccessResponse(response) || response.data == null) {
|
|
78
|
+
return EMPTY;
|
|
79
|
+
}
|
|
80
|
+
const data = response.data;
|
|
81
|
+
const detailsUserId = data.user_id;
|
|
82
|
+
if (detailsUserId == null ||
|
|
83
|
+
detailsUserId !== loggedInUserId) {
|
|
84
|
+
return EMPTY;
|
|
85
|
+
}
|
|
86
|
+
if (!isBatchDetailsStatusPendingOrProcessing(data.status)) {
|
|
87
|
+
return EMPTY;
|
|
88
|
+
}
|
|
89
|
+
return of(restoreBulkUploadMatchingState({
|
|
90
|
+
batchId: batch.batchId,
|
|
91
|
+
totalFiles: batch.totalFiles,
|
|
92
|
+
}));
|
|
93
|
+
}), catchError(() => EMPTY))), take(1));
|
|
94
|
+
return successAction != null
|
|
95
|
+
? concat(of(successAction), restoreStream)
|
|
96
|
+
: restoreStream;
|
|
97
|
+
}));
|
|
98
|
+
}));
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { supportedTransactionPayloadToManualSearchResult } from '../../payload/missingReceiptsPayload';
|
|
6
|
+
import { searchTransactionsForManualMatch, searchTransactionsForManualMatchFailure, searchTransactionsForManualMatchSuccess, } from '../../reducers/missingReceiptsViewReducer';
|
|
7
|
+
import { toTransactionsSortKey } from '../../types/transactionsViewState';
|
|
8
|
+
import { rollingCalendarDateRangeInclusive } from '../../helpers/rollingCalendarDateRangeInclusive';
|
|
9
|
+
/**
|
|
10
|
+
* `auto_categorized` for manual transaction search (Unmatched).
|
|
11
|
+
* Backend contract TBD — align with `fetchTransactionCategorizationEpic` (`selectedTab === 'autoCategorized'`)
|
|
12
|
+
* when the expense-automation API documents the intended filter for this flow.
|
|
13
|
+
*/
|
|
14
|
+
export const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
|
|
15
|
+
/** Inclusive rolling window for manual match search (ignores accounting period picker). */
|
|
16
|
+
const MANUAL_SEARCH_TRANSACTION_DATE_RANGE_DAYS = 90;
|
|
17
|
+
export const searchTransactionsForManualMatchEpic = (actions$, state$, zeniAPI) => {
|
|
18
|
+
const searchActions$ = actions$.pipe(filter(searchTransactionsForManualMatch.match));
|
|
19
|
+
const pagination$ = searchActions$.pipe(filter((action) => action.payload.pageToken != null));
|
|
20
|
+
/**
|
|
21
|
+
* No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP.
|
|
22
|
+
*/
|
|
23
|
+
const newSearchTooShortOrClear$ = searchActions$.pipe(filter((action) => action.payload.pageToken == null &&
|
|
24
|
+
action.payload.query.trim().length < 2));
|
|
25
|
+
const newSearchDebounced$ = searchActions$.pipe(filter((action) => action.payload.pageToken == null &&
|
|
26
|
+
action.payload.query.trim().length >= 2), debounceTime(300));
|
|
27
|
+
return merge(pagination$, newSearchTooShortOrClear$, newSearchDebounced$).pipe(switchMap((action) => {
|
|
28
|
+
const { query, pageToken } = action.payload;
|
|
29
|
+
if (pageToken == null && query.trim().length < 2) {
|
|
30
|
+
return EMPTY;
|
|
31
|
+
}
|
|
32
|
+
const state = state$.value;
|
|
33
|
+
const { expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
|
|
34
|
+
const { end, start } = rollingCalendarDateRangeInclusive(MANUAL_SEARCH_TRANSACTION_DATE_RANGE_DAYS);
|
|
35
|
+
const queryParam = {
|
|
36
|
+
start_date: start,
|
|
37
|
+
end_date: end,
|
|
38
|
+
auto_categorized: MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED,
|
|
39
|
+
sort_by: toTransactionsSortKey(sortKey),
|
|
40
|
+
sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
|
|
41
|
+
page_token: pageToken ?? null,
|
|
42
|
+
page_size: manualSearch.pageSize,
|
|
43
|
+
search_text: query,
|
|
44
|
+
};
|
|
45
|
+
return zeniAPI
|
|
46
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
47
|
+
.pipe(mergeMap((response) => {
|
|
48
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
49
|
+
const { transactions, next_page_token, total_count } = response.data;
|
|
50
|
+
const append = pageToken != null;
|
|
51
|
+
const results = transactions.map(supportedTransactionPayloadToManualSearchResult);
|
|
52
|
+
const actionsOut = [
|
|
53
|
+
updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
|
|
54
|
+
searchTransactionsForManualMatchSuccess({
|
|
55
|
+
append,
|
|
56
|
+
nextPageToken: next_page_token ?? null,
|
|
57
|
+
results,
|
|
58
|
+
totalCount: total_count,
|
|
59
|
+
}),
|
|
60
|
+
];
|
|
61
|
+
return from(actionsOut);
|
|
62
|
+
}
|
|
63
|
+
return of(searchTransactionsForManualMatchFailure({
|
|
64
|
+
error: response.status,
|
|
65
|
+
}));
|
|
66
|
+
}), catchError((error) => of(searchTransactionsForManualMatchFailure({
|
|
67
|
+
error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
|
|
68
|
+
JSON.stringify(error)),
|
|
69
|
+
}))));
|
|
70
|
+
}));
|
|
71
|
+
};
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js
CHANGED
|
@@ -12,11 +12,13 @@ export const uploadMissingReceiptSuccessEpic = (actions$, state$) => actions$.pi
|
|
|
12
12
|
updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
|
|
13
13
|
if (currentTenant != null) {
|
|
14
14
|
const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
if (monthEndChecksPeriod != null) {
|
|
16
|
+
updateActions.push(fetchMonthEndCloseChecks({
|
|
17
|
+
tenantId: currentTenant.tenantId,
|
|
18
|
+
period: monthEndChecksPeriod,
|
|
19
|
+
refreshViewInBackground: true,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return from(updateActions);
|
|
22
24
|
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EMPTY, from, merge, of, timer } from 'rxjs';
|
|
2
|
+
import { catchError, debounceTime, filter, mergeMap, switchMap, takeUntil, } from 'rxjs/operators';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
5
|
+
import { isSuccessResponse } from '../../../../responsePayload';
|
|
6
|
+
import { BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS } from '../../helpers/bulkUploadTiming';
|
|
7
|
+
import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
|
|
8
|
+
import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, restoreBulkUploadMatchingState, } from '../../reducers/missingReceiptsViewReducer';
|
|
9
|
+
/** First poll after upload; then interval while batch not resolved via Pusher or API. */
|
|
10
|
+
const FALLBACK_FIRST_DELAY_MS = 30000;
|
|
11
|
+
/** Shorter first poll for restored sessions — batch may already be near completion. */
|
|
12
|
+
const RESTORE_FIRST_DELAY_MS = 5000;
|
|
13
|
+
const FALLBACK_POLL_INTERVAL_MS = 10000;
|
|
14
|
+
/**
|
|
15
|
+
* On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
|
|
16
|
+
* and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
|
|
17
|
+
*/
|
|
18
|
+
export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
|
|
19
|
+
fetchBulkUploadBatches({
|
|
20
|
+
cacheOverride: true,
|
|
21
|
+
invalidateBatchDetailsCache: true,
|
|
22
|
+
}),
|
|
23
|
+
requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
|
|
24
|
+
])));
|
|
25
|
+
/**
|
|
26
|
+
* If Pusher and batch-details are delayed beyond {@link BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS},
|
|
27
|
+
* force `phase` to `completed` (dismiss automatching banner) and refresh the batch list.
|
|
28
|
+
* Cancels when the batch completes normally, bulk state is cleared, or another upload supersedes.
|
|
29
|
+
*/
|
|
30
|
+
export const bulkUploadAutomatchingTimeoutEpic = (actions$, state$) => actions$.pipe(filter((action) => bulkUploadReceiptsSuccess.match(action) ||
|
|
31
|
+
restoreBulkUploadMatchingState.match(action)), mergeMap((action) => {
|
|
32
|
+
const { batchId } = action.payload;
|
|
33
|
+
return timer(BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS).pipe(mergeMap(() => {
|
|
34
|
+
const bulk = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
35
|
+
if (bulk.phase !== 'matching' || bulk.currentBatchId !== batchId) {
|
|
36
|
+
return EMPTY;
|
|
37
|
+
}
|
|
38
|
+
return from([
|
|
39
|
+
bulkUploadAutomatchingTimedOut(batchId),
|
|
40
|
+
fetchBulkUploadBatches({ cacheOverride: true }),
|
|
41
|
+
]);
|
|
42
|
+
}), takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId &&
|
|
43
|
+
a.payload.status === 'completed')), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))));
|
|
44
|
+
}));
|
|
45
|
+
/**
|
|
46
|
+
* Fallback polling when Pusher is slow or unavailable. Network errors on a poll tick show one
|
|
47
|
+
* error snackbar per upload session (first failure only) so the user is not spammed every
|
|
48
|
+
* interval; Pusher or a later successful poll still completes the flow.
|
|
49
|
+
*/
|
|
50
|
+
export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter((action) => bulkUploadReceiptsSuccess.match(action) ||
|
|
51
|
+
restoreBulkUploadMatchingState.match(action)), mergeMap((action) => {
|
|
52
|
+
const { batchId } = action.payload;
|
|
53
|
+
let pollErrorNotified = false;
|
|
54
|
+
const firstDelay = restoreBulkUploadMatchingState.match(action)
|
|
55
|
+
? RESTORE_FIRST_DELAY_MS
|
|
56
|
+
: FALLBACK_FIRST_DELAY_MS;
|
|
57
|
+
return timer(firstDelay, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.batchId === batchId)), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((action) => action.payload.batchId === batchId)), actions$.pipe(filter(bulkUploadAutomatchingTimedOut.match), filter((action) => action.payload.batchId === batchId)))), switchMap(() => zeniAPI
|
|
58
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
|
|
59
|
+
.pipe(mergeMap((response) => {
|
|
60
|
+
/** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
|
|
61
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
62
|
+
if (isBatchDetailsApiStatusCompleted(response.data.status)) {
|
|
63
|
+
const actions = [];
|
|
64
|
+
const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
|
|
65
|
+
if (transactionPayloads.length > 0) {
|
|
66
|
+
actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
|
|
67
|
+
}
|
|
68
|
+
actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
69
|
+
actions.push(fetchBulkUploadBatches({ cacheOverride: true }));
|
|
70
|
+
actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
|
|
71
|
+
return from(actions);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return EMPTY;
|
|
75
|
+
}), catchError(() => {
|
|
76
|
+
if (!pollErrorNotified) {
|
|
77
|
+
pollErrorNotified = true;
|
|
78
|
+
return of(openSnackbar({
|
|
79
|
+
messageSection: 'receipts_upload',
|
|
80
|
+
messageText: 'failed',
|
|
81
|
+
type: 'error',
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return EMPTY;
|
|
85
|
+
}))));
|
|
86
|
+
}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
4
|
+
import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
|
|
5
|
+
import { fetchMonthEndCloseChecks } from '../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer';
|
|
6
|
+
import { uploadTransactionCategorizationReceiptSuccess } from '../../reducers/transactionsViewReducer';
|
|
7
|
+
export const uploadTransactionReceiptSuccessEpic = (actions$, state$) => actions$.pipe(filter(uploadTransactionCategorizationReceiptSuccess.match), mergeMap((action) => {
|
|
8
|
+
const { transactionPayload, updateType } = action.payload;
|
|
9
|
+
const updateActions = [];
|
|
10
|
+
const currentTenant = getCurrentTenant(state$.value);
|
|
11
|
+
const selectedPeriodByTenantId = state$.value.expenseAutomationViewState.selectedPeriodByTenantId;
|
|
12
|
+
updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
|
|
13
|
+
if (currentTenant != null) {
|
|
14
|
+
const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
15
|
+
if (monthEndChecksPeriod != null) {
|
|
16
|
+
updateActions.push(fetchMonthEndCloseChecks({
|
|
17
|
+
tenantId: currentTenant.tenantId,
|
|
18
|
+
period: monthEndChecksPeriod,
|
|
19
|
+
refreshViewInBackground: true,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return from(updateActions);
|
|
24
|
+
}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* After upload API success, hold the bar at 100% this long before transitioning to matching,
|
|
3
|
+
* so the fill animation can complete without an abrupt swap to the auto-matching banner.
|
|
4
|
+
*/
|
|
5
|
+
export const BULK_UPLOAD_BAR_COMPLETE_HOLD_MS = 400;
|
|
6
|
+
/**
|
|
7
|
+
* Max wall-clock wait for Pusher + batch-details resolution after upload. If exceeded, we stop
|
|
8
|
+
* fallback polling, clear the automatching banner (`phase` → completed), and refresh batch list.
|
|
9
|
+
*/
|
|
10
|
+
export const BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS = 300000;
|
|
11
|
+
/**
|
|
12
|
+
* Rolling window (in days) for the bulk-upload batch list API. Period-agnostic — the batch list
|
|
13
|
+
* ignores the accounting month picker. Shared between the regular batch-list fetch and the
|
|
14
|
+
* restore-on-mount hydration so both flows always query the same window.
|
|
15
|
+
*/
|
|
16
|
+
export const BULK_UPLOAD_BATCH_LIST_DATE_RANGE_DAYS = 30;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
|
|
2
|
+
import { dateNow } from '../../../zeniDayJS';
|
|
3
|
+
/**
|
|
4
|
+
* Local calendar dates from (end − (days − 1)) through end, inclusive.
|
|
5
|
+
*/
|
|
6
|
+
export function rollingCalendarDateRangeInclusive(days) {
|
|
7
|
+
const end = dateNow().startOf('day');
|
|
8
|
+
const start = end.subtract(days - 1, 'day');
|
|
9
|
+
return {
|
|
10
|
+
end: end.format(DEFAULT_DATE_FORMAT),
|
|
11
|
+
start: start.format(DEFAULT_DATE_FORMAT),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1 +1,198 @@
|
|
|
1
|
-
|
|
1
|
+
import { toURL } from '../../../commonPayloadTypes/urlPayload';
|
|
2
|
+
import { toAmount } from '../../../commonStateTypes/amount';
|
|
3
|
+
import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
|
|
4
|
+
import { toBatchFileStatus, toBatchStatusValue, toMatchSource, } from '../types/missingReceiptsViewState';
|
|
5
|
+
// -- Converter functions --
|
|
6
|
+
/**
|
|
7
|
+
* Maps batch-details API `files[].status` strings to canonical {@link BatchFileStatus}.
|
|
8
|
+
* Legacy aliases are supported during rollout; unknown strings map to `failed` so Redux never
|
|
9
|
+
* holds untyped status values.
|
|
10
|
+
*/
|
|
11
|
+
export function parseBatchFileStatus(raw) {
|
|
12
|
+
const normalizedStatus = raw.trim().toLowerCase().replace(/-/g, '_');
|
|
13
|
+
switch (normalizedStatus) {
|
|
14
|
+
case 'exact_match':
|
|
15
|
+
case 'matched':
|
|
16
|
+
return 'exact_match';
|
|
17
|
+
case 'possible_matches':
|
|
18
|
+
case 'possible_match':
|
|
19
|
+
case 'possiblematch':
|
|
20
|
+
case 'un_matched':
|
|
21
|
+
case 'unmatched':
|
|
22
|
+
return 'possible_matches';
|
|
23
|
+
case 'no_match':
|
|
24
|
+
case 'nomatch':
|
|
25
|
+
return 'no_match';
|
|
26
|
+
case 'failed':
|
|
27
|
+
return 'failed';
|
|
28
|
+
default:
|
|
29
|
+
return 'failed';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function toBatchFile(payload, filesEndPoint) {
|
|
33
|
+
return {
|
|
34
|
+
attachmentId: payload.attachment_id,
|
|
35
|
+
candidates: payload.candidates?.map((candidate) => ({
|
|
36
|
+
transactionId: candidate.transaction_id,
|
|
37
|
+
matchScore: candidate.match_score,
|
|
38
|
+
})),
|
|
39
|
+
fileDownloadUrl: payload.file_id != null && filesEndPoint != null
|
|
40
|
+
? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
|
|
41
|
+
: null,
|
|
42
|
+
fileId: payload.file_id,
|
|
43
|
+
filePreviewUrl: payload.file_preview_url,
|
|
44
|
+
filename: payload.filename,
|
|
45
|
+
matchSource: payload.match_source != null
|
|
46
|
+
? toMatchSource(payload.match_source)
|
|
47
|
+
: undefined,
|
|
48
|
+
matchedTransactionId: payload.matched_transaction?.transaction_id,
|
|
49
|
+
status: toBatchFileStatus(payload.status),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function extractTransactionPayloadsFromBatchFiles(files) {
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
const payloads = [];
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
if (file.matched_transaction != null) {
|
|
57
|
+
const id = file.matched_transaction.transaction_id;
|
|
58
|
+
if (!seen.has(id)) {
|
|
59
|
+
seen.add(id);
|
|
60
|
+
payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (file.candidates != null) {
|
|
64
|
+
for (const candidate of file.candidates) {
|
|
65
|
+
const id = candidate.transaction_id;
|
|
66
|
+
if (!seen.has(id)) {
|
|
67
|
+
seen.add(id);
|
|
68
|
+
payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return payloads;
|
|
74
|
+
}
|
|
75
|
+
function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
|
|
76
|
+
return {
|
|
77
|
+
transaction_id: payload.transaction_id,
|
|
78
|
+
transaction_type: payload.transaction_type ?? 'expense',
|
|
79
|
+
transaction_date: payload.transaction_date ?? '',
|
|
80
|
+
currency_code: payload.currency_code,
|
|
81
|
+
total_amount: payload.amount,
|
|
82
|
+
vendor_name: payload.vendor_name,
|
|
83
|
+
logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function toBatchSummary(payload) {
|
|
87
|
+
return {
|
|
88
|
+
failed: payload.failed,
|
|
89
|
+
matched: payload.matched,
|
|
90
|
+
noMatch: payload.no_match,
|
|
91
|
+
possibleMatches: payload.possible_matches,
|
|
92
|
+
total: payload.total,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function toBatchDetails(payload, filesEndPoint) {
|
|
96
|
+
return {
|
|
97
|
+
batchId: payload.batch_id,
|
|
98
|
+
createdAt: payload.created_at,
|
|
99
|
+
files: payload.files.map((file) => toBatchFile(file, filesEndPoint)),
|
|
100
|
+
status: toBatchStatusValue(payload.status),
|
|
101
|
+
summary: toBatchSummary(payload.summary),
|
|
102
|
+
...(payload.user_id != null && payload.user_id !== ''
|
|
103
|
+
? { userId: payload.user_id }
|
|
104
|
+
: {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Batch is still in-flight for automatching (GET /batches/:id while not completed). */
|
|
108
|
+
export function isBatchDetailsStatusPendingOrProcessing(status) {
|
|
109
|
+
const s = status.toLowerCase();
|
|
110
|
+
return s === 'processing' || s === 'pending';
|
|
111
|
+
}
|
|
112
|
+
/** Batch list `status` is a string from the API — compare case-insensitively. */
|
|
113
|
+
export function isBatchListStatusCompleted(status) {
|
|
114
|
+
return status.toLowerCase() === 'completed';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
|
|
118
|
+
* `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
|
|
119
|
+
* statuses for UI; only `completed` rows should trigger batch-details requests.
|
|
120
|
+
*/
|
|
121
|
+
export function filterBatchListItemsForBatchDetailsFetch(batches) {
|
|
122
|
+
return batches.filter((batch) => isBatchListStatusCompleted(batch.status));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Batch details API response `status` field — only completed payloads should be stored from
|
|
126
|
+
* multi-batch fetch paths (list can be briefly stale vs. live processing state).
|
|
127
|
+
*/
|
|
128
|
+
export function isBatchDetailsApiStatusCompleted(status) {
|
|
129
|
+
return status.toLowerCase() === 'completed';
|
|
130
|
+
}
|
|
131
|
+
export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
|
|
132
|
+
for (const list of Object.values(batchListByPeriod)) {
|
|
133
|
+
const found = list.find((batch) => batch.batchId === batchId);
|
|
134
|
+
if (found != null) {
|
|
135
|
+
return found;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Whether it is appropriate to call `GET .../batches/:id` for details.
|
|
142
|
+
* Skips when live batch status or batch list row indicates the batch is not completed yet.
|
|
143
|
+
* When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
|
|
144
|
+
*/
|
|
145
|
+
export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
|
|
146
|
+
const live = batchStatusById[batchId]?.status;
|
|
147
|
+
if (live === 'completed') {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (live === 'pending' || live === 'processing') {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
|
|
154
|
+
if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
export function toBatchListItem(payload) {
|
|
160
|
+
return {
|
|
161
|
+
batchId: payload.batch_id,
|
|
162
|
+
createdAt: payload.created_at,
|
|
163
|
+
failedCount: payload.failed_count,
|
|
164
|
+
matchedCount: payload.matched_count,
|
|
165
|
+
noMatchCount: payload.no_match_count,
|
|
166
|
+
possibleMatchesCount: payload.possible_matches_count,
|
|
167
|
+
status: payload.status,
|
|
168
|
+
totalFiles: payload.total_files,
|
|
169
|
+
userId: payload.user_id,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Amount shown in the Unmatched tab manual-search list: **first line only** when `lines` exist.
|
|
174
|
+
* Falls back to transaction-level totals via {@link getTransactionPayloadAmount} when there is
|
|
175
|
+
* no line or no line amount (same currency fields as the rest of the transaction payload).
|
|
176
|
+
*/
|
|
177
|
+
function getManualSearchListAmountFromPayload(payload) {
|
|
178
|
+
const lineAmount = payload.lines?.[0]?.amount;
|
|
179
|
+
if (lineAmount != null) {
|
|
180
|
+
return toAmount(lineAmount, payload.currency_code, payload.currency_symbol);
|
|
181
|
+
}
|
|
182
|
+
return getTransactionPayloadAmount(payload);
|
|
183
|
+
}
|
|
184
|
+
/** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
|
|
185
|
+
export function supportedTransactionPayloadToManualSearchResult(payload) {
|
|
186
|
+
const amountPayload = getManualSearchListAmountFromPayload(payload);
|
|
187
|
+
return {
|
|
188
|
+
amount: amountPayload.amount,
|
|
189
|
+
currencyCode: amountPayload.currencyCode,
|
|
190
|
+
entityId: payload.vendor_id ?? payload.customer_id ?? '',
|
|
191
|
+
memo: payload.transaction_memo ?? '',
|
|
192
|
+
transactionDate: payload.transaction_date,
|
|
193
|
+
transactionId: payload.transaction_id,
|
|
194
|
+
transactionType: payload.transaction_type,
|
|
195
|
+
vendorName: payload.vendor_name ?? '',
|
|
196
|
+
vendorLogo: toURL(payload.logo)?.href,
|
|
197
|
+
};
|
|
198
|
+
}
|