@zeniai/client-epic-state 4.19.82 → 4.19.84-betaVR1
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/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/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/epic.d.ts +12 -1
- package/lib/epic.js +12 -1
- package/lib/esm/entity/account/accountPayload.js +2 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/esm/epic.js +12 -1
- package/lib/esm/index.js +5 -3
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +24 -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 +47 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +34 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +57 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +68 -0
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +42 -0
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
- package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +147 -1
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +401 -1
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +20 -1
- package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +224 -1
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/esm/zeniAPI.js +0 -2
- package/lib/index.d.ts +6 -4
- package/lib/index.js +66 -31
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +15 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +28 -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 +51 -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 +38 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +62 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +72 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +13 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +47 -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/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +107 -0
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +158 -0
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +70 -3
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +403 -2
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +21 -2
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +69 -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 +223 -0
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +124 -0
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
- package/lib/zeniAPI.js +0 -2
- package/package.json +2 -2
- package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
4
|
+
import { bulkUploadReceipts, bulkUploadReceiptsFailure, bulkUploadReceiptsSuccess, } from '../../reducers/missingReceiptsViewReducer';
|
|
5
|
+
export const bulkUploadReceiptsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceipts.match), mergeMap((action) => {
|
|
6
|
+
const { files } = action.payload;
|
|
7
|
+
const formData = new FormData();
|
|
8
|
+
for (const file of files) {
|
|
9
|
+
formData.append('files', file, file.name);
|
|
10
|
+
}
|
|
11
|
+
return zeniAPI
|
|
12
|
+
.postFormData(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipts/bulk-upload`, formData)
|
|
13
|
+
.pipe(mergeMap((response) => {
|
|
14
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
15
|
+
return of(bulkUploadReceiptsSuccess({
|
|
16
|
+
batchId: response.data.batch_id,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
return of(bulkUploadReceiptsFailure({ error: response.status }));
|
|
20
|
+
}), catchError((error) => of(bulkUploadReceiptsFailure({
|
|
21
|
+
error: createZeniAPIStatus('Unexpected Error', 'Bulk upload receipts API call errored out: ' +
|
|
22
|
+
JSON.stringify(error)),
|
|
23
|
+
}))));
|
|
24
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { catchError, exhaustMap, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
5
|
+
import { confirmBulkUploadMatch, confirmBulkUploadMatchFailure, confirmBulkUploadMatchSuccess, } from '../../reducers/missingReceiptsViewReducer';
|
|
6
|
+
export const confirmBulkUploadMatchEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(confirmBulkUploadMatch.match), exhaustMap((action) => {
|
|
7
|
+
const { batchId, attachmentId, transactionId, transactionType, fileName } = action.payload;
|
|
8
|
+
return zeniAPI
|
|
9
|
+
.postAndGetJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipts/manual-match`, {
|
|
10
|
+
attachment_id: attachmentId,
|
|
11
|
+
transaction_id: transactionId,
|
|
12
|
+
transaction_type: transactionType,
|
|
13
|
+
file_name: fileName,
|
|
14
|
+
})
|
|
15
|
+
.pipe(mergeMap((response) => {
|
|
16
|
+
if (isSuccessResponse(response)) {
|
|
17
|
+
return from([
|
|
18
|
+
confirmBulkUploadMatchSuccess({
|
|
19
|
+
batchId,
|
|
20
|
+
attachmentId,
|
|
21
|
+
transactionId,
|
|
22
|
+
}),
|
|
23
|
+
openSnackbar({
|
|
24
|
+
messageSection: 'receipt_match',
|
|
25
|
+
messageText: 'success',
|
|
26
|
+
type: 'success',
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
return from([
|
|
31
|
+
confirmBulkUploadMatchFailure({ error: response.status }),
|
|
32
|
+
openSnackbar({
|
|
33
|
+
messageSection: 'receipt_match',
|
|
34
|
+
messageText: 'failed',
|
|
35
|
+
type: 'error',
|
|
36
|
+
}),
|
|
37
|
+
]);
|
|
38
|
+
}), catchError((error) => from([
|
|
39
|
+
confirmBulkUploadMatchFailure({
|
|
40
|
+
error: createZeniAPIStatus('Unexpected Error', 'Confirm bulk upload match errored out: ' +
|
|
41
|
+
JSON.stringify(error)),
|
|
42
|
+
}),
|
|
43
|
+
openSnackbar({
|
|
44
|
+
messageSection: 'receipt_match',
|
|
45
|
+
messageText: 'failed',
|
|
46
|
+
type: 'error',
|
|
47
|
+
}),
|
|
48
|
+
])));
|
|
49
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EMPTY, from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
5
|
+
import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, shouldFetchBatchDetailsForBatchId, toBatchDetails, } from '../../payload/missingReceiptsPayload';
|
|
6
|
+
import { fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsFailure, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, } from '../../reducers/missingReceiptsViewReducer';
|
|
7
|
+
export const fetchBulkUploadBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatchDetails.match), mergeMap(() => {
|
|
8
|
+
const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
9
|
+
const { currentBatchId } = bulkUpload;
|
|
10
|
+
if (currentBatchId == null) {
|
|
11
|
+
return of(fetchBulkUploadBatchDetailsFailure({
|
|
12
|
+
error: createZeniAPIStatus('Unexpected Error', 'No current batch ID available'),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
if (!shouldFetchBatchDetailsForBatchId(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentBatchId)) {
|
|
16
|
+
return EMPTY;
|
|
17
|
+
}
|
|
18
|
+
return zeniAPI
|
|
19
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${currentBatchId}`)
|
|
20
|
+
.pipe(mergeMap((response) => {
|
|
21
|
+
if (!isSuccessResponse(response) ||
|
|
22
|
+
response.data == null ||
|
|
23
|
+
!isBatchDetailsApiStatusCompleted(response.data.status)) {
|
|
24
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
25
|
+
return EMPTY;
|
|
26
|
+
}
|
|
27
|
+
return of(fetchBulkUploadBatchDetailsFailure({ error: response.status }));
|
|
28
|
+
}
|
|
29
|
+
const actions = [];
|
|
30
|
+
const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
|
|
31
|
+
if (transactionPayloads.length > 0) {
|
|
32
|
+
actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
|
|
33
|
+
}
|
|
34
|
+
actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
35
|
+
actions.push(fetchBulkUploadBatches(true));
|
|
36
|
+
return from(actions);
|
|
37
|
+
}), catchError((error) => of(fetchBulkUploadBatchDetailsFailure({
|
|
38
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch batch details errored out: ' + JSON.stringify(error)),
|
|
39
|
+
}))));
|
|
40
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { convertToPeriod, toMonthYearPeriodId, } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
6
|
+
import { toBatchListItem, } from '../../payload/missingReceiptsPayload';
|
|
7
|
+
import { fetchBulkUploadBatches, fetchBulkUploadBatchesFailure, fetchBulkUploadBatchesSuccess, } from '../../reducers/missingReceiptsViewReducer';
|
|
8
|
+
export const fetchBulkUploadBatchesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatches.match), switchMap((action) => {
|
|
9
|
+
const { cacheOverride } = action.payload;
|
|
10
|
+
const state = state$.value;
|
|
11
|
+
const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload }, } = state;
|
|
12
|
+
const currentTenant = getCurrentTenant(state);
|
|
13
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
14
|
+
const periodId = toMonthYearPeriodId(selectedPeriod);
|
|
15
|
+
const existingBatches = bulkUpload.batchListByPeriod[periodId] ?? [];
|
|
16
|
+
if (cacheOverride !== true && existingBatches.length > 0) {
|
|
17
|
+
return of(fetchBulkUploadBatchesSuccess({
|
|
18
|
+
batchList: existingBatches,
|
|
19
|
+
selectedPeriod,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
const period = convertToPeriod(selectedPeriod);
|
|
23
|
+
const queryParam = {
|
|
24
|
+
start_date: period.start,
|
|
25
|
+
end_date: period.end,
|
|
26
|
+
sort_order: 'desc',
|
|
27
|
+
};
|
|
28
|
+
return zeniAPI
|
|
29
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
30
|
+
.pipe(mergeMap((response) => {
|
|
31
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
32
|
+
/** Full list (all statuses) for UI; batch-details epics filter to `completed` only. */
|
|
33
|
+
return of(fetchBulkUploadBatchesSuccess({
|
|
34
|
+
batchList: response.data.batches.map(toBatchListItem),
|
|
35
|
+
selectedPeriod,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
return of(fetchBulkUploadBatchesFailure({
|
|
39
|
+
error: response.status,
|
|
40
|
+
selectedPeriod,
|
|
41
|
+
}));
|
|
42
|
+
}), catchError((error) => of(fetchBulkUploadBatchesFailure({
|
|
43
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch bulk upload batches errored out: ' +
|
|
44
|
+
JSON.stringify(error)),
|
|
45
|
+
selectedPeriod,
|
|
46
|
+
}))));
|
|
47
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { convertToPeriod, toMonthYearPeriodId, } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
6
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
7
|
+
import { fetchCompletedTransactions, fetchCompletedTransactionsFailure, fetchCompletedTransactionsSuccess, getCompletedTransactionsCacheKey, } from '../../reducers/missingReceiptsViewReducer';
|
|
8
|
+
export const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchCompletedTransactions.match), switchMap((action) => {
|
|
9
|
+
const state = state$.value;
|
|
10
|
+
const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload }, } = state;
|
|
11
|
+
const currentTenant = getCurrentTenant(state);
|
|
12
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
13
|
+
const periodId = toMonthYearPeriodId(selectedPeriod);
|
|
14
|
+
const isInitialLoad = action.payload.pageToken == null;
|
|
15
|
+
const cacheKey = getCompletedTransactionsCacheKey(periodId, bulkUpload.sortKey, bulkUpload.sortOrder, bulkUpload.completedSubTab);
|
|
16
|
+
const existingData = bulkUpload.completedTransactionsByPeriod[cacheKey];
|
|
17
|
+
if (isInitialLoad &&
|
|
18
|
+
action.payload.cacheOverride !== true &&
|
|
19
|
+
existingData != null &&
|
|
20
|
+
existingData.transactionIds.length > 0) {
|
|
21
|
+
return from([]);
|
|
22
|
+
}
|
|
23
|
+
const period = convertToPeriod(selectedPeriod);
|
|
24
|
+
const queryPayload = {
|
|
25
|
+
start_date: period.start,
|
|
26
|
+
end_date: period.end,
|
|
27
|
+
sort_by: bulkUpload.sortKey,
|
|
28
|
+
sort_order: bulkUpload.sortOrder === 'ascending' ? 'asc' : 'desc',
|
|
29
|
+
page_token: action.payload.pageToken ?? null,
|
|
30
|
+
page_size: 25,
|
|
31
|
+
};
|
|
32
|
+
if (bulkUpload.completedSubTab !== 'all') {
|
|
33
|
+
queryPayload.match_type = bulkUpload.completedSubTab;
|
|
34
|
+
}
|
|
35
|
+
const encodedQuery = encodeURIComponent(JSON.stringify(queryPayload));
|
|
36
|
+
return zeniAPI
|
|
37
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipt-agent/transactions/completed?query=${encodedQuery}`)
|
|
38
|
+
.pipe(mergeMap((response) => {
|
|
39
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
40
|
+
const transactionIds = response.data.transactions.map((t) => t.transaction_id);
|
|
41
|
+
const updateActions = [];
|
|
42
|
+
updateActions.push(updateTransactions(response.data.transactions, (value) => value.transaction_id));
|
|
43
|
+
updateActions.push(fetchCompletedTransactionsSuccess({
|
|
44
|
+
isInitialLoad,
|
|
45
|
+
transactionIds,
|
|
46
|
+
nextPageToken: response.data.next_page_token,
|
|
47
|
+
totalCount: response.data.total_count,
|
|
48
|
+
selectedPeriod,
|
|
49
|
+
}));
|
|
50
|
+
return from(updateActions);
|
|
51
|
+
}
|
|
52
|
+
return of(fetchCompletedTransactionsFailure({
|
|
53
|
+
error: response.status,
|
|
54
|
+
selectedPeriod,
|
|
55
|
+
}));
|
|
56
|
+
}), catchError((error) => of(fetchCompletedTransactionsFailure({
|
|
57
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch completed transactions errored: ' +
|
|
58
|
+
JSON.stringify(error)),
|
|
59
|
+
selectedPeriod,
|
|
60
|
+
}))));
|
|
61
|
+
}));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { concat, of } from 'rxjs';
|
|
2
|
+
import { catchError, exhaustMap, filter } from 'rxjs/operators';
|
|
3
|
+
import { toMonthYearPeriodId } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { createZeniAPIStatus } from '../../../../responsePayload';
|
|
6
|
+
import { filterBatchListItemsForBatchDetailsFetch } from '../../payload/missingReceiptsPayload';
|
|
7
|
+
import { fetchMoreBatchDetails, fetchMoreBatchDetailsComplete, fetchMoreBatchDetailsFailure, } from '../../reducers/missingReceiptsViewReducer';
|
|
8
|
+
import { fetchBatchDetailsByIds } from './fetchMultipleBatchDetailsEpic';
|
|
9
|
+
const MORE_BATCH_PAGE_SIZE = 1;
|
|
10
|
+
export const fetchMoreBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchMoreBatchDetails.match),
|
|
11
|
+
/** One page at a time — avoids duplicate loads if IO + scroll fallback both fire. */
|
|
12
|
+
exhaustMap(() => {
|
|
13
|
+
const state = state$.value;
|
|
14
|
+
const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload }, } = state;
|
|
15
|
+
const currentTenant = getCurrentTenant(state);
|
|
16
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
17
|
+
if (selectedPeriod == null) {
|
|
18
|
+
return of(fetchMoreBatchDetailsComplete());
|
|
19
|
+
}
|
|
20
|
+
const periodId = toMonthYearPeriodId(selectedPeriod);
|
|
21
|
+
const batchList = bulkUpload.batchListByPeriod[periodId] ?? [];
|
|
22
|
+
const failedIds = new Set(bulkUpload.failedBatchDetailIds);
|
|
23
|
+
const unfetchedBatches = filterBatchListItemsForBatchDetailsFetch(batchList).filter((batch) => bulkUpload.batchDetailsById[batch.batchId] == null &&
|
|
24
|
+
!failedIds.has(batch.batchId));
|
|
25
|
+
const unfetchedBatchIds = unfetchedBatches.map((batch) => batch.batchId);
|
|
26
|
+
if (unfetchedBatchIds.length === 0) {
|
|
27
|
+
return of(fetchMoreBatchDetailsComplete());
|
|
28
|
+
}
|
|
29
|
+
const nextPage = unfetchedBatchIds.slice(0, MORE_BATCH_PAGE_SIZE);
|
|
30
|
+
return concat(fetchBatchDetailsByIds(nextPage, zeniAPI), of(fetchMoreBatchDetailsComplete())).pipe(catchError((error) => of(fetchMoreBatchDetailsFailure({
|
|
31
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch more batch details errored out: ' +
|
|
32
|
+
JSON.stringify(error)),
|
|
33
|
+
}))));
|
|
34
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EMPTY, concat, from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
5
|
+
import { extractTransactionPayloadsFromBatchFiles, filterBatchListItemsForBatchDetailsFetch, isBatchDetailsApiStatusCompleted, shouldFetchBatchDetailsForBatchId, toBatchDetails, } from '../../payload/missingReceiptsPayload';
|
|
6
|
+
import { batchDetailFetchFailed, fetchBulkUploadBatchDetails, fetchBulkUploadBatchesSuccess, fetchMoreBatchDetailsComplete, setInitialBatchDetailsLoading, storeBatchDetails, } from '../../reducers/missingReceiptsViewReducer';
|
|
7
|
+
const INITIAL_BATCH_PAGE_SIZE = 1;
|
|
8
|
+
export function fetchBatchDetailsByIds(batchIds, zeniAPI) {
|
|
9
|
+
if (batchIds.length === 0) {
|
|
10
|
+
return EMPTY;
|
|
11
|
+
}
|
|
12
|
+
return from(batchIds).pipe(mergeMap((batchId) => zeniAPI
|
|
13
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
|
|
14
|
+
.pipe(mergeMap((response) => {
|
|
15
|
+
if (!isSuccessResponse(response) ||
|
|
16
|
+
response.data == null ||
|
|
17
|
+
!isBatchDetailsApiStatusCompleted(response.data.status)) {
|
|
18
|
+
return EMPTY;
|
|
19
|
+
}
|
|
20
|
+
const actions = [];
|
|
21
|
+
const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
|
|
22
|
+
if (transactionPayloads.length > 0) {
|
|
23
|
+
actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
|
|
24
|
+
}
|
|
25
|
+
actions.push(storeBatchDetails(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
26
|
+
return from(actions);
|
|
27
|
+
}), catchError((error) => {
|
|
28
|
+
console.error(`Failed to fetch batch details for ${batchId}:`, createZeniAPIStatus('Unexpected Error', 'Fetch batch details errored out: ' +
|
|
29
|
+
JSON.stringify(error)));
|
|
30
|
+
return of(batchDetailFetchFailed({ batchId }));
|
|
31
|
+
})), 5));
|
|
32
|
+
}
|
|
33
|
+
export const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatchesSuccess.match), mergeMap((action) => {
|
|
34
|
+
const batchList = action.payload.batchList;
|
|
35
|
+
const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
36
|
+
/** Only completed list rows may trigger batch-details API; preserve platform order. */
|
|
37
|
+
const completedBatchesMissingDetails = filterBatchListItemsForBatchDetailsFetch(batchList).filter((batch) => batchDetailsById[batch.batchId] == null);
|
|
38
|
+
const completedBatchIds = completedBatchesMissingDetails.map((batch) => batch.batchId);
|
|
39
|
+
const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
|
|
40
|
+
if (batchIdsToFetch.length === 0) {
|
|
41
|
+
/**
|
|
42
|
+
* List refresh can complete while no row is `completed` yet (multi-fetch skips), or
|
|
43
|
+
* `currentBatchId` may not appear in the filtered list but still needs `GET /batches/:id`.
|
|
44
|
+
* Fall back to the single-batch-details epic so `phase` and details can resolve.
|
|
45
|
+
*/
|
|
46
|
+
const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
47
|
+
const currentId = bulkUpload.currentBatchId;
|
|
48
|
+
if (currentId != null &&
|
|
49
|
+
bulkUpload.phase === 'matching' &&
|
|
50
|
+
bulkUpload.batchDetailsById[currentId] == null &&
|
|
51
|
+
shouldFetchBatchDetailsForBatchId(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentId)) {
|
|
52
|
+
return of(fetchBulkUploadBatchDetails());
|
|
53
|
+
}
|
|
54
|
+
return EMPTY;
|
|
55
|
+
}
|
|
56
|
+
return concat(of(setInitialBatchDetailsLoading()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), of(fetchMoreBatchDetailsComplete()));
|
|
57
|
+
}));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { from, merge, of } from 'rxjs';
|
|
2
|
+
import { catchError, debounceTime, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { convertToPeriod } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
6
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
7
|
+
import { supportedTransactionPayloadToManualSearchResult } from '../../payload/missingReceiptsPayload';
|
|
8
|
+
import { searchTransactionsForManualMatch, searchTransactionsForManualMatchFailure, searchTransactionsForManualMatchSuccess, } from '../../reducers/missingReceiptsViewReducer';
|
|
9
|
+
import { toTransactionsSortKey } from '../../types/transactionsViewState';
|
|
10
|
+
/**
|
|
11
|
+
* `auto_categorized` for manual transaction search (Unmatched).
|
|
12
|
+
* Backend contract TBD — align with `fetchTransactionCategorizationEpic` (`selectedTab === 'autoCategorized'`)
|
|
13
|
+
* when the expense-automation API documents the intended filter for this flow.
|
|
14
|
+
*/
|
|
15
|
+
export const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
|
|
16
|
+
export const searchTransactionsForManualMatchEpic = (actions$, state$, zeniAPI) => {
|
|
17
|
+
const searchActions$ = actions$.pipe(filter(searchTransactionsForManualMatch.match));
|
|
18
|
+
const pagination$ = searchActions$.pipe(filter((a) => a.payload.pageToken != null));
|
|
19
|
+
const newSearch$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null), debounceTime(300));
|
|
20
|
+
return merge(pagination$, newSearch$).pipe(switchMap((action) => {
|
|
21
|
+
const { query, pageToken } = action.payload;
|
|
22
|
+
const state = state$.value;
|
|
23
|
+
const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
|
|
24
|
+
const currentTenant = getCurrentTenant(state);
|
|
25
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
26
|
+
if (selectedPeriod == null) {
|
|
27
|
+
return of(searchTransactionsForManualMatchFailure({
|
|
28
|
+
error: createZeniAPIStatus('Unexpected Error', 'Manual search requires a selected accounting period.'),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
const period = convertToPeriod(selectedPeriod);
|
|
32
|
+
const queryParam = {
|
|
33
|
+
start_date: period.start,
|
|
34
|
+
end_date: period.end,
|
|
35
|
+
auto_categorized: MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED,
|
|
36
|
+
sort_by: toTransactionsSortKey(sortKey),
|
|
37
|
+
sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
|
|
38
|
+
page_token: pageToken ?? null,
|
|
39
|
+
page_size: manualSearch.pageSize,
|
|
40
|
+
search_text: query,
|
|
41
|
+
};
|
|
42
|
+
return zeniAPI
|
|
43
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
44
|
+
.pipe(mergeMap((response) => {
|
|
45
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
46
|
+
const { transactions, next_page_token, total_count } = response.data;
|
|
47
|
+
const append = pageToken != null;
|
|
48
|
+
const results = transactions.map(supportedTransactionPayloadToManualSearchResult);
|
|
49
|
+
const actionsOut = [
|
|
50
|
+
updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
|
|
51
|
+
searchTransactionsForManualMatchSuccess({
|
|
52
|
+
append,
|
|
53
|
+
nextPageToken: next_page_token ?? null,
|
|
54
|
+
results,
|
|
55
|
+
totalCount: total_count,
|
|
56
|
+
}),
|
|
57
|
+
];
|
|
58
|
+
return from(actionsOut);
|
|
59
|
+
}
|
|
60
|
+
return of(searchTransactionsForManualMatchFailure({
|
|
61
|
+
error: response.status,
|
|
62
|
+
}));
|
|
63
|
+
}), catchError((error) => of(searchTransactionsForManualMatchFailure({
|
|
64
|
+
error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
|
|
65
|
+
JSON.stringify(error)),
|
|
66
|
+
}))));
|
|
67
|
+
}));
|
|
68
|
+
};
|
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,42 @@
|
|
|
1
|
+
import { EMPTY, from, merge, of, timer } from 'rxjs';
|
|
2
|
+
import { catchError, debounceTime, filter, mergeMap, switchMap, takeUntil, } from 'rxjs/operators';
|
|
3
|
+
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { isSuccessResponse } from '../../../../responsePayload';
|
|
5
|
+
import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
|
|
6
|
+
import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, } from '../../reducers/missingReceiptsViewReducer';
|
|
7
|
+
/** First poll after upload; then interval while batch not resolved via Pusher or API. */
|
|
8
|
+
const FALLBACK_FIRST_DELAY_MS = 30000;
|
|
9
|
+
const FALLBACK_POLL_INTERVAL_MS = 10000;
|
|
10
|
+
/**
|
|
11
|
+
* On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
|
|
12
|
+
* and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
|
|
13
|
+
*/
|
|
14
|
+
export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
|
|
15
|
+
fetchBulkUploadBatches({
|
|
16
|
+
cacheOverride: true,
|
|
17
|
+
invalidateBatchDetailsCache: true,
|
|
18
|
+
}),
|
|
19
|
+
requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
|
|
20
|
+
])));
|
|
21
|
+
export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
|
|
22
|
+
const { batchId } = action.payload;
|
|
23
|
+
return timer(FALLBACK_FIRST_DELAY_MS, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId)), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))), switchMap(() => zeniAPI
|
|
24
|
+
.getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
|
|
25
|
+
.pipe(mergeMap((response) => {
|
|
26
|
+
/** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
|
|
27
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
28
|
+
if (isBatchDetailsApiStatusCompleted(response.data.status)) {
|
|
29
|
+
const actions = [];
|
|
30
|
+
const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
|
|
31
|
+
if (transactionPayloads.length > 0) {
|
|
32
|
+
actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
|
|
33
|
+
}
|
|
34
|
+
actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
35
|
+
actions.push(fetchBulkUploadBatches(true));
|
|
36
|
+
actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
|
|
37
|
+
return from(actions);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return EMPTY;
|
|
41
|
+
}), catchError(() => of()))));
|
|
42
|
+
}));
|
|
@@ -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
|
+
}));
|
|
@@ -1 +1,147 @@
|
|
|
1
|
-
|
|
1
|
+
import { toURL } from '../../../commonPayloadTypes/urlPayload';
|
|
2
|
+
import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
|
|
3
|
+
// -- Converter functions --
|
|
4
|
+
export function toBatchFile(payload, filesEndPoint) {
|
|
5
|
+
return {
|
|
6
|
+
attachmentId: payload.attachment_id,
|
|
7
|
+
candidates: payload.candidates?.map((c) => ({
|
|
8
|
+
transactionId: c.transaction_id,
|
|
9
|
+
matchScore: c.match_score,
|
|
10
|
+
})),
|
|
11
|
+
fileDownloadUrl: payload.file_id != null && filesEndPoint != null
|
|
12
|
+
? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
|
|
13
|
+
: null,
|
|
14
|
+
fileId: payload.file_id,
|
|
15
|
+
filePreviewUrl: payload.file_preview_url,
|
|
16
|
+
filename: payload.filename,
|
|
17
|
+
matchSource: payload.match_source,
|
|
18
|
+
matchedTransactionId: payload.matched_transaction?.transaction_id,
|
|
19
|
+
status: payload.status,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function extractTransactionPayloadsFromBatchFiles(files) {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const payloads = [];
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
if (file.matched_transaction != null) {
|
|
27
|
+
const id = file.matched_transaction.transaction_id;
|
|
28
|
+
if (!seen.has(id)) {
|
|
29
|
+
seen.add(id);
|
|
30
|
+
payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (file.candidates != null) {
|
|
34
|
+
for (const candidate of file.candidates) {
|
|
35
|
+
const id = candidate.transaction_id;
|
|
36
|
+
if (!seen.has(id)) {
|
|
37
|
+
seen.add(id);
|
|
38
|
+
payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return payloads;
|
|
44
|
+
}
|
|
45
|
+
function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
|
|
46
|
+
return {
|
|
47
|
+
transaction_id: payload.transaction_id,
|
|
48
|
+
transaction_type: payload.transaction_type ?? 'expense',
|
|
49
|
+
transaction_date: payload.transaction_date ?? '',
|
|
50
|
+
currency_code: payload.currency_code,
|
|
51
|
+
total_amount: payload.amount,
|
|
52
|
+
vendor_name: payload.vendor_name,
|
|
53
|
+
logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function toBatchSummary(payload) {
|
|
57
|
+
return {
|
|
58
|
+
failed: payload.failed,
|
|
59
|
+
matched: payload.matched,
|
|
60
|
+
noMatch: payload.no_match,
|
|
61
|
+
possibleMatches: payload.possible_matches,
|
|
62
|
+
total: payload.total,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function toBatchDetails(payload, filesEndPoint) {
|
|
66
|
+
return {
|
|
67
|
+
batchId: payload.batch_id,
|
|
68
|
+
createdAt: payload.created_at,
|
|
69
|
+
files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
|
|
70
|
+
status: payload.status,
|
|
71
|
+
summary: toBatchSummary(payload.summary),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Batch list `status` is a string from the API — compare case-insensitively. */
|
|
75
|
+
export function isBatchListStatusCompleted(status) {
|
|
76
|
+
return status.toLowerCase() === 'completed';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
|
|
80
|
+
* `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
|
|
81
|
+
* statuses for UI; only `completed` rows should trigger batch-details requests.
|
|
82
|
+
*/
|
|
83
|
+
export function filterBatchListItemsForBatchDetailsFetch(batches) {
|
|
84
|
+
return batches.filter((b) => isBatchListStatusCompleted(b.status));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Batch details API response `status` field — only completed payloads should be stored from
|
|
88
|
+
* multi-batch fetch paths (list can be briefly stale vs. live processing state).
|
|
89
|
+
*/
|
|
90
|
+
export function isBatchDetailsApiStatusCompleted(status) {
|
|
91
|
+
return status.toLowerCase() === 'completed';
|
|
92
|
+
}
|
|
93
|
+
export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
|
|
94
|
+
for (const list of Object.values(batchListByPeriod)) {
|
|
95
|
+
const found = list.find((b) => b.batchId === batchId);
|
|
96
|
+
if (found != null) {
|
|
97
|
+
return found;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Whether it is appropriate to call `GET .../batches/:id` for details.
|
|
104
|
+
* Skips when live batch status or batch list row indicates the batch is not completed yet.
|
|
105
|
+
* When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
|
|
106
|
+
*/
|
|
107
|
+
export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
|
|
108
|
+
const live = batchStatusById[batchId]?.status;
|
|
109
|
+
if (live === 'completed') {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
if (live === 'pending' || live === 'processing') {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
|
|
116
|
+
if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
export function toBatchListItem(payload) {
|
|
122
|
+
return {
|
|
123
|
+
batchId: payload.batch_id,
|
|
124
|
+
createdAt: payload.created_at,
|
|
125
|
+
failedCount: payload.failed_count,
|
|
126
|
+
matchedCount: payload.matched_count,
|
|
127
|
+
noMatchCount: payload.no_match_count,
|
|
128
|
+
possibleMatchesCount: payload.possible_matches_count,
|
|
129
|
+
status: payload.status,
|
|
130
|
+
totalFiles: payload.total_files,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
|
|
134
|
+
export function supportedTransactionPayloadToManualSearchResult(payload) {
|
|
135
|
+
const amountPayload = getTransactionPayloadAmount(payload);
|
|
136
|
+
return {
|
|
137
|
+
amount: amountPayload.amount,
|
|
138
|
+
currencyCode: amountPayload.currencyCode,
|
|
139
|
+
entityId: payload.vendor_id ?? payload.customer_id ?? '',
|
|
140
|
+
memo: payload.transaction_memo ?? '',
|
|
141
|
+
transactionDate: payload.transaction_date,
|
|
142
|
+
transactionId: payload.transaction_id,
|
|
143
|
+
transactionType: payload.transaction_type,
|
|
144
|
+
vendorName: payload.vendor_name ?? '',
|
|
145
|
+
vendorLogo: toURL(payload.logo)?.href,
|
|
146
|
+
};
|
|
147
|
+
}
|