@zeniai/client-epic-state 5.2.14 → 5.2.16
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/accountRecon/accountReconReducer.d.ts +2 -1
- package/lib/entity/accountRecon/accountReconReducer.js +22 -10
- package/lib/entity/accountRecon/accountReconSelector.d.ts +1 -0
- package/lib/entity/accountRecon/accountReconSelector.js +1 -0
- package/lib/entity/approvalRule/approvalRuleConflict.d.ts +13 -0
- package/lib/entity/approvalRule/approvalRuleConflict.js +16 -1
- package/lib/entity/jeSchedules/jeScheduleHelper.d.ts +1 -0
- package/lib/entity/jeSchedules/jeScheduleHelper.js +7 -0
- package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +78 -1
- package/lib/entity/jeSchedules/jeSchedulesPayload.js +183 -4
- package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +4 -2
- package/lib/entity/jeSchedules/jeSchedulesReducer.js +30 -2
- package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +11 -2
- package/lib/entity/jeSchedules/jeSchedulesSelector.js +38 -3
- package/lib/entity/jeSchedules/jeSchedulesState.d.ts +123 -1
- package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +24 -1
- package/lib/entity/jeSchedules/jeSchedulesTypes.js +96 -1
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.d.ts +2 -0
- package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.js +2 -0
- package/lib/entity/transaction/stateTypes/scheduleTransaction.d.ts +2 -0
- package/lib/epic.d.ts +10 -1
- package/lib/epic.js +18 -0
- package/lib/esm/entity/accountRecon/accountReconReducer.js +22 -10
- package/lib/esm/entity/accountRecon/accountReconSelector.js +1 -0
- package/lib/esm/entity/approvalRule/approvalRuleConflict.js +16 -1
- package/lib/esm/entity/jeSchedules/jeScheduleHelper.js +6 -0
- package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +183 -5
- package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +30 -2
- package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +36 -2
- package/lib/esm/entity/jeSchedules/jeSchedulesTypes.js +86 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/esm/entity/transaction/payloadTypes/scheduleTransactionPayload.js +2 -0
- package/lib/esm/epic.js +18 -0
- package/lib/esm/index.js +16 -10
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/confirmStatementMappingEpic.js +2 -2
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/deleteCombinedStatementEpic.js +54 -0
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/fetchReconciliationViewEpic.js +1 -1
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/updateCombinedStatementInfoEpic.js +3 -6
- package/lib/esm/view/expenseAutomationView/epics/common/fetchAllExpenseAutomationTabsEpic.js +6 -3
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +9 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +41 -5
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.js +45 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/ignoreRecommendedJeScheduleEpic.js +14 -2
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.js +104 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +25 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +138 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +79 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.js +180 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.js +111 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +28 -0
- package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +140 -0
- package/lib/esm/view/expenseAutomationView/helpers/reconciliationHelpers.js +12 -0
- package/lib/esm/view/expenseAutomationView/payload/jeSchedulesPayload.js +55 -0
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +319 -29
- package/lib/esm/view/expenseAutomationView/reducers/reconciliationViewReducer.js +20 -2
- package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +1 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeAccountSettingsViewSelector.js +1 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +106 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +327 -22
- package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +5 -6
- package/lib/esm/view/scheduleView/scheduleListView/epics/fetchAccruedScheduleListEpic.js +1 -1
- package/lib/esm/view/scheduleView/scheduleListView/epics/fetchDownloadSchedulesEpic.js +7 -2
- package/lib/esm/view/scheduleView/scheduleListView/scheduleListReducer.js +5 -3
- package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewSelector.js +20 -1
- package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewSelector.js +20 -1
- package/lib/index.d.ts +18 -13
- package/lib/index.js +92 -47
- package/lib/view/expenseAutomationView/epics/accountRecon/confirmStatementMappingEpic.d.ts +10 -2
- package/lib/view/expenseAutomationView/epics/accountRecon/confirmStatementMappingEpic.js +1 -1
- package/lib/view/expenseAutomationView/epics/accountRecon/deleteCombinedStatementEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/deleteCombinedStatementEpic.js +58 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/fetchReconciliationViewEpic.js +1 -1
- package/lib/view/expenseAutomationView/epics/accountRecon/updateCombinedStatementInfoEpic.js +3 -6
- package/lib/view/expenseAutomationView/epics/common/fetchAllExpenseAutomationTabsEpic.js +6 -3
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +9 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.d.ts +3 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +39 -3
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.d.ts +21 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.js +49 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/ignoreRecommendedJeScheduleEpic.js +14 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.js +108 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +29 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +9 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +142 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +83 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.d.ts +13 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.js +187 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.d.ts +65 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.js +115 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +32 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +36 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +145 -0
- package/lib/view/expenseAutomationView/helpers/reconciliationHelpers.d.ts +6 -0
- package/lib/view/expenseAutomationView/helpers/reconciliationHelpers.js +13 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +86 -3
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.js +58 -1
- package/lib/view/expenseAutomationView/payload/reconciliationPayload.d.ts +4 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +93 -12
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +321 -29
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +1 -1
- package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.d.ts +6 -1
- package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.js +22 -4
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +2 -2
- package/lib/view/expenseAutomationView/selectorTypes/jeAccountSettingsViewSelectorTypes.d.ts +1 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +42 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +2 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +41 -7
- package/lib/view/expenseAutomationView/selectors/jeAccountSettingsViewSelector.js +1 -0
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +21 -0
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +112 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.d.ts +34 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +335 -21
- package/lib/view/expenseAutomationView/types/completedSubTab.d.ts +1 -1
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +83 -8
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +8 -8
- package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
- package/lib/view/scheduleView/scheduleListView/epics/fetchAccruedScheduleListEpic.js +1 -1
- package/lib/view/scheduleView/scheduleListView/epics/fetchDownloadSchedulesEpic.js +7 -2
- package/lib/view/scheduleView/scheduleListView/scheduleListReducer.d.ts +4 -2
- package/lib/view/scheduleView/scheduleListView/scheduleListReducer.js +5 -3
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewSelector.js +20 -1
- package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewSelectorTypes.d.ts +3 -0
- package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewSelector.js +20 -1
- package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewSelectorTypes.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveNewScheduleEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const timePeriod_1 = require("../../../../../commonStateTypes/timePeriod");
|
|
7
|
+
const tenantSelector_1 = require("../../../../../entity/tenant/tenantSelector");
|
|
8
|
+
const rootActions_1 = require("../../../../../rootActions");
|
|
9
|
+
const jeSchedulesReducer_1 = require("../../../../../entity/jeSchedules/jeSchedulesReducer");
|
|
10
|
+
const jeSchedulesTypes_1 = require("../../../../../entity/jeSchedules/jeSchedulesTypes");
|
|
11
|
+
const snackbarReducer_1 = require("../../../../../entity/snackbar/snackbarReducer");
|
|
12
|
+
const transactionSelector_1 = require("../../../../../entity/transaction/transactionSelector");
|
|
13
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
14
|
+
const newScheduleLocalDataHelper_1 = require("../../../helpers/newScheduleLocalDataHelper");
|
|
15
|
+
const jeSchedulesViewReducer_1 = require("../../../reducers/jeSchedulesViewReducer");
|
|
16
|
+
const FAILURE_REASON_MESSAGES = {
|
|
17
|
+
missing_third_party_id: 'This transaction is missing a QuickBooks reference and cannot be scheduled.',
|
|
18
|
+
// The form cannot satisfy this: the vendor field is hard-disabled and inherited from the base
|
|
19
|
+
// transaction, so the fix is on the transaction, not here.
|
|
20
|
+
missing_vendor: 'This transaction has no vendor and cannot be scheduled. Add a vendor to the transaction first.',
|
|
21
|
+
};
|
|
22
|
+
const saveNewScheduleEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.saveNewSchedule.match), (0, operators_1.mergeMap)((action) => {
|
|
23
|
+
const { scheduleType } = action.payload;
|
|
24
|
+
const state = state$.value;
|
|
25
|
+
const localData = state.expenseAutomationJESchedulesViewState.newSchedule
|
|
26
|
+
.newScheduleState[scheduleType];
|
|
27
|
+
const { selectedBaseTransactionId } = localData;
|
|
28
|
+
const transaction = selectedBaseTransactionId != null
|
|
29
|
+
? (0, transactionSelector_1.getScheduleTransactionById)(state.transactionState, (0, jeSchedulesTypes_1.getJEScheduleTransactionKey)(selectedBaseTransactionId))
|
|
30
|
+
: undefined;
|
|
31
|
+
if (transaction == null) {
|
|
32
|
+
return (0, rxjs_1.from)([
|
|
33
|
+
(0, jeSchedulesViewReducer_1.saveNewScheduleFailure)({
|
|
34
|
+
status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'No base transaction selected for this schedule.'),
|
|
35
|
+
}),
|
|
36
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
37
|
+
messageSection: 'create_schedule',
|
|
38
|
+
messageText: 'failed',
|
|
39
|
+
type: 'error',
|
|
40
|
+
variables: [
|
|
41
|
+
{
|
|
42
|
+
variableName: '_api-error_',
|
|
43
|
+
variableValue: 'No base transaction selected.',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
const result = (0, newScheduleLocalDataHelper_1.prepareNewSchedulePayload)(transaction, localData, scheduleType);
|
|
50
|
+
if (!result.ok) {
|
|
51
|
+
const message = FAILURE_REASON_MESSAGES[result.reason];
|
|
52
|
+
return (0, rxjs_1.from)([
|
|
53
|
+
(0, jeSchedulesViewReducer_1.saveNewScheduleFailure)({
|
|
54
|
+
status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', message),
|
|
55
|
+
}),
|
|
56
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
57
|
+
messageSection: 'create_schedule',
|
|
58
|
+
messageText: 'failed',
|
|
59
|
+
type: 'error',
|
|
60
|
+
variables: [{ variableName: '_api-error_', variableValue: message }],
|
|
61
|
+
}),
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
|
|
65
|
+
const queryParam = {
|
|
66
|
+
je_schedule_type: scheduleType,
|
|
67
|
+
};
|
|
68
|
+
const payload = { ...result.payload };
|
|
69
|
+
// convertToPeriod destructures, so an unset period would throw here and take the epic
|
|
70
|
+
// subscription down for the whole session -- a missed refresh is the cheaper failure.
|
|
71
|
+
const selectedMonthYear = state.expenseAutomationViewState.selectedPeriodByTenantId[(0, tenantSelector_1.getCurrentTenant)(state).tenantId];
|
|
72
|
+
const selectedPeriod = selectedMonthYear != null
|
|
73
|
+
? (0, timePeriod_1.convertToPeriod)(selectedMonthYear)
|
|
74
|
+
: undefined;
|
|
75
|
+
const periodStart = selectedPeriod != null
|
|
76
|
+
? (0, timePeriod_1.toAbsoluteDay)(selectedPeriod.start)
|
|
77
|
+
: undefined;
|
|
78
|
+
const periodEnd = selectedPeriod != null ? (0, timePeriod_1.toAbsoluteDay)(selectedPeriod.end) : undefined;
|
|
79
|
+
return zeniAPI
|
|
80
|
+
.postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules?query=${encodeURIComponent(JSON.stringify(queryParam))}`, payload)
|
|
81
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
82
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
83
|
+
const successActions = [
|
|
84
|
+
(0, jeSchedulesReducer_1.updateJESchedules)(response.data.je_schedules),
|
|
85
|
+
(0, jeSchedulesReducer_1.updateJESchedulesDetails)(response.data.je_schedules, response.data.scheduled_journal_entries),
|
|
86
|
+
(0, jeSchedulesViewReducer_1.resetNewScheduleLocalData)({ scheduleType }),
|
|
87
|
+
(0, jeSchedulesViewReducer_1.saveNewScheduleSuccess)(),
|
|
88
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
89
|
+
messageSection: 'create_schedule',
|
|
90
|
+
messageText: 'success',
|
|
91
|
+
type: 'success',
|
|
92
|
+
variables: [
|
|
93
|
+
{ variableName: '_vendor_name_', variableValue: vendorName },
|
|
94
|
+
],
|
|
95
|
+
}),
|
|
96
|
+
];
|
|
97
|
+
// Writing the entity is not enough: the list reads
|
|
98
|
+
// jeScheduleTransactionKeysByPeriodAndTab, which is rebuilt wholesale per fetch, so
|
|
99
|
+
// without this the new schedule stays invisible until some later fetch. The page
|
|
100
|
+
// only refetches when the save also changes tab, so saving from the tab the row
|
|
101
|
+
// lands on showed nothing. Same reasoning as createOneTimeAccrualEpic.
|
|
102
|
+
if (periodStart != null && periodEnd != null) {
|
|
103
|
+
successActions.push((0, jeSchedulesViewReducer_1.fetchJeSchedules)({ start: periodStart, end: periodEnd }, true));
|
|
104
|
+
}
|
|
105
|
+
return (0, rxjs_1.from)(successActions);
|
|
106
|
+
}
|
|
107
|
+
return (0, rxjs_1.from)([
|
|
108
|
+
(0, jeSchedulesViewReducer_1.saveNewScheduleFailure)({ status: response.status }),
|
|
109
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
110
|
+
messageSection: 'create_schedule',
|
|
111
|
+
messageText: 'failed',
|
|
112
|
+
type: 'error',
|
|
113
|
+
variables: [
|
|
114
|
+
{
|
|
115
|
+
variableName: '_api-error_',
|
|
116
|
+
variableValue: response.status.message,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
}),
|
|
120
|
+
]);
|
|
121
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.from)([
|
|
122
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
123
|
+
messageSection: 'create_schedule',
|
|
124
|
+
messageText: 'failed',
|
|
125
|
+
type: 'error',
|
|
126
|
+
variables: [
|
|
127
|
+
{
|
|
128
|
+
variableName: '_api-error_',
|
|
129
|
+
variableValue: JSON.stringify(error),
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
}),
|
|
133
|
+
(0, jeSchedulesViewReducer_1.saveNewScheduleFailure)({
|
|
134
|
+
status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Save New Schedule REST API call errored out ${JSON.stringify(error)}`),
|
|
135
|
+
}),
|
|
136
|
+
])),
|
|
137
|
+
// A tenant switch clears the store while this request is still in flight.
|
|
138
|
+
// Without this the old tenant's response is written back into the freshly
|
|
139
|
+
// cleared store and stays on screen under the new tenant.
|
|
140
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
|
|
141
|
+
}));
|
|
142
|
+
exports.saveNewScheduleEpic = saveNewScheduleEpic;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { updateScheduleTransactions } from '../../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { RootState } from '../../../../../reducer';
|
|
5
|
+
import { ZeniAPI } from '../../../../../zeniAPI';
|
|
6
|
+
import { searchTransactionsForNewSchedule, searchTransactionsForNewScheduleFailure, searchTransactionsForNewScheduleSuccess } from '../../../reducers/jeSchedulesViewReducer';
|
|
7
|
+
export type ActionType = ReturnType<typeof searchTransactionsForNewSchedule> | ReturnType<typeof searchTransactionsForNewScheduleSuccess> | ReturnType<typeof searchTransactionsForNewScheduleFailure> | ReturnType<typeof updateScheduleTransactions>;
|
|
8
|
+
export declare const searchTransactionsForNewScheduleEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchTransactionsForNewScheduleEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const jeSchedulesTypes_1 = require("../../../../../entity/jeSchedules/jeSchedulesTypes");
|
|
7
|
+
const transactionType_1 = require("../../../../../entity/transaction/stateTypes/transactionType");
|
|
8
|
+
const transactionReducer_1 = require("../../../../../entity/transaction/transactionReducer");
|
|
9
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
10
|
+
const jeSchedulesViewReducer_1 = require("../../../reducers/jeSchedulesViewReducer");
|
|
11
|
+
const jeSchedulesViewState_1 = require("../../../types/jeSchedulesViewState");
|
|
12
|
+
/**
|
|
13
|
+
* Dropdown-sized result set. The endpoint is paginated — it takes a `page_token` $skip offset and
|
|
14
|
+
* returns `next_page_token` — but nothing here reads or sends those, so this is the whole result
|
|
15
|
+
* set the form ever sees. 20 rather than the backend's default of 10 because a text search for one
|
|
16
|
+
* known transaction was running out of room; the cap server-side is 100 if this needs raising again
|
|
17
|
+
* before infinite scroll is wired up.
|
|
18
|
+
*/
|
|
19
|
+
const NEW_SCHEDULE_SEARCH_PAGE_SIZE = 20;
|
|
20
|
+
/** Fallback when the backend sends a null currency for a search result. */
|
|
21
|
+
const DEFAULT_CURRENCY_CODE = 'USD';
|
|
22
|
+
const DEFAULT_CURRENCY_SYMBOL = '$';
|
|
23
|
+
const searchTransactionsForNewScheduleEpic = (actions$, _state$, zeniAPI) => {
|
|
24
|
+
const searchActions$ = actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.searchTransactionsForNewSchedule.match));
|
|
25
|
+
/** No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP. */
|
|
26
|
+
const newSearchTooShortOrClear$ = searchActions$.pipe((0, operators_1.filter)((action) => action.payload.query.trim().length < jeSchedulesViewState_1.MIN_NEW_SCHEDULE_SEARCH_LENGTH));
|
|
27
|
+
const newSearchDebounced$ = searchActions$.pipe((0, operators_1.filter)((action) => action.payload.query.trim().length >= jeSchedulesViewState_1.MIN_NEW_SCHEDULE_SEARCH_LENGTH), (0, operators_1.debounceTime)(300));
|
|
28
|
+
return (0, rxjs_1.merge)(newSearchTooShortOrClear$, newSearchDebounced$).pipe((0, operators_1.switchMap)((action) => {
|
|
29
|
+
const query = action.payload.query.trim();
|
|
30
|
+
if (query.length < jeSchedulesViewState_1.MIN_NEW_SCHEDULE_SEARCH_LENGTH) {
|
|
31
|
+
return rxjs_1.EMPTY;
|
|
32
|
+
}
|
|
33
|
+
const queryParam = {
|
|
34
|
+
page_size: NEW_SCHEDULE_SEARCH_PAGE_SIZE,
|
|
35
|
+
search_text: query,
|
|
36
|
+
je_schedule_type: action.payload.scheduleType,
|
|
37
|
+
};
|
|
38
|
+
return zeniAPI
|
|
39
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules/base_transaction_search?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
40
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
41
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
42
|
+
const { transactions } = response.data;
|
|
43
|
+
const transactionsPerCurrency = {};
|
|
44
|
+
transactions.forEach((transaction) => {
|
|
45
|
+
const { currency_code, currency_symbol } = transaction;
|
|
46
|
+
const currencyCode = currency_code ?? DEFAULT_CURRENCY_CODE;
|
|
47
|
+
const existing = transactionsPerCurrency[currencyCode];
|
|
48
|
+
transactionsPerCurrency[currencyCode] =
|
|
49
|
+
existing != null
|
|
50
|
+
? {
|
|
51
|
+
currencySymbol: existing.currencySymbol,
|
|
52
|
+
transactions: [...existing.transactions, transaction],
|
|
53
|
+
}
|
|
54
|
+
: {
|
|
55
|
+
currencySymbol: currency_code == null
|
|
56
|
+
? DEFAULT_CURRENCY_SYMBOL
|
|
57
|
+
: currency_symbol,
|
|
58
|
+
transactions: [transaction],
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const actionsOut = Object.keys(transactionsPerCurrency).map((currencyCode) => {
|
|
62
|
+
const perCurrency = transactionsPerCurrency[currencyCode];
|
|
63
|
+
return (0, transactionReducer_1.updateScheduleTransactions)(perCurrency.transactions, currencyCode, perCurrency.currencySymbol, 'merge');
|
|
64
|
+
});
|
|
65
|
+
actionsOut.push((0, jeSchedulesViewReducer_1.searchTransactionsForNewScheduleSuccess)({
|
|
66
|
+
searchResults: transactions.map((transaction) => (0, jeSchedulesTypes_1.getJEScheduleTransactionKey)({
|
|
67
|
+
id: transaction.transaction_id,
|
|
68
|
+
type: (0, transactionType_1.toTransactionType)(transaction.transaction_type),
|
|
69
|
+
lineId: transaction.line_id,
|
|
70
|
+
})),
|
|
71
|
+
}));
|
|
72
|
+
return (0, rxjs_1.from)(actionsOut);
|
|
73
|
+
}
|
|
74
|
+
return (0, rxjs_1.of)((0, jeSchedulesViewReducer_1.searchTransactionsForNewScheduleFailure)({
|
|
75
|
+
status: response.status,
|
|
76
|
+
}));
|
|
77
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, jeSchedulesViewReducer_1.searchTransactionsForNewScheduleFailure)({
|
|
78
|
+
status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Search transactions for new schedule errored: ' +
|
|
79
|
+
JSON.stringify(error)),
|
|
80
|
+
}))));
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
83
|
+
exports.searchTransactionsForNewScheduleEpic = searchTransactionsForNewScheduleEpic;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { updateJEOneTimeAccruals } from '../../../../entity/jeSchedules/jeSchedulesReducer';
|
|
4
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
5
|
+
import { RootState } from '../../../../reducer';
|
|
6
|
+
import { clearAll } from '../../../../rootActions';
|
|
7
|
+
import { ZeniAPI } from '../../../../zeniAPI';
|
|
8
|
+
import { fetchJeSchedules, ignoreOneTimeAccrual, oneTimeAccrualActionFailure, oneTimeAccrualActionSuccess, promoteOneTimeAccrual, revertOneTimeAccrual } from '../../reducers/jeSchedulesViewReducer';
|
|
9
|
+
export type ActionType = ReturnType<typeof clearAll> | ReturnType<typeof promoteOneTimeAccrual> | ReturnType<typeof revertOneTimeAccrual> | ReturnType<typeof ignoreOneTimeAccrual> | ReturnType<typeof oneTimeAccrualActionSuccess> | ReturnType<typeof oneTimeAccrualActionFailure> | ReturnType<typeof updateJEOneTimeAccruals> | ReturnType<typeof fetchJeSchedules> | ReturnType<typeof openSnackbar>;
|
|
10
|
+
export declare const promoteOneTimeAccrualEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
11
|
+
export declare const ignoreOneTimeAccrualEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
12
|
+
export declare const revertOneTimeAccrualEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
13
|
+
export declare const oneTimeAccrualActionsEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.oneTimeAccrualActionsEpic = exports.revertOneTimeAccrualEpic = exports.ignoreOneTimeAccrualEpic = exports.promoteOneTimeAccrualEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const timePeriod_1 = require("../../../../commonStateTypes/timePeriod");
|
|
7
|
+
const jeScheduleHelper_1 = require("../../../../entity/jeSchedules/jeScheduleHelper");
|
|
8
|
+
const jeSchedulesReducer_1 = require("../../../../entity/jeSchedules/jeSchedulesReducer");
|
|
9
|
+
const jeSchedulesSelector_1 = require("../../../../entity/jeSchedules/jeSchedulesSelector");
|
|
10
|
+
const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
|
|
11
|
+
const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
|
|
12
|
+
const rootActions_1 = require("../../../../rootActions");
|
|
13
|
+
const responsePayload_1 = require("../../../../responsePayload");
|
|
14
|
+
const jeSchedulesViewReducer_1 = require("../../reducers/jeSchedulesViewReducer");
|
|
15
|
+
/**
|
|
16
|
+
* The page the accrual came from, so a promoted or ignored row lands in the right bucket. Guarded
|
|
17
|
+
* because convertToPeriod destructures: an unset period would throw and take the epic subscription
|
|
18
|
+
* down for the session, and a missed refresh is the cheaper failure.
|
|
19
|
+
*
|
|
20
|
+
* Read state$.value at response time rather than the snapshot taken when the action was dispatched:
|
|
21
|
+
* if the user changes month while the request is in flight, the snapshot refreshes the month they
|
|
22
|
+
* have left and the month they are now looking at stays stale.
|
|
23
|
+
*/
|
|
24
|
+
function refreshCurrentPage(state) {
|
|
25
|
+
const selectedMonthYear = state.expenseAutomationViewState.selectedPeriodByTenantId[(0, tenantSelector_1.getCurrentTenant)(state).tenantId];
|
|
26
|
+
if (selectedMonthYear == null) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const period = (0, timePeriod_1.convertToPeriod)(selectedMonthYear);
|
|
30
|
+
const start = (0, timePeriod_1.toAbsoluteDay)(period.start);
|
|
31
|
+
const end = (0, timePeriod_1.toAbsoluteDay)(period.end);
|
|
32
|
+
if (start == null || end == null) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [(0, jeSchedulesViewReducer_1.fetchJeSchedules)({ start, end }, true)];
|
|
36
|
+
}
|
|
37
|
+
function failureActions(
|
|
38
|
+
// Per action, not fixed: every failure used to read "Save schedule failed", so skipping or
|
|
39
|
+
// reverting an accrual reported an operation the user had not performed.
|
|
40
|
+
messageSection, accrualId, message, status) {
|
|
41
|
+
return [
|
|
42
|
+
(0, jeSchedulesViewReducer_1.oneTimeAccrualActionFailure)({
|
|
43
|
+
accrualId,
|
|
44
|
+
status: status ?? (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', message),
|
|
45
|
+
}),
|
|
46
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
47
|
+
messageSection,
|
|
48
|
+
messageText: 'failed',
|
|
49
|
+
type: 'error',
|
|
50
|
+
variables: [{ variableName: '_api-error_', variableValue: message }],
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
const promoteOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.promoteOneTimeAccrual.match), (0, operators_1.mergeMap)((action) => {
|
|
55
|
+
const state = state$.value;
|
|
56
|
+
const { accrualId, amount, edits } = action.payload;
|
|
57
|
+
const accrual = (0, jeSchedulesSelector_1.getJEOneTimeAccrualByKey)((0, jeScheduleHelper_1.generateJEOneTimeAccrualKey)(accrualId), state.jeSchedulesState);
|
|
58
|
+
// An edited value wins; anything untouched falls back to the stored draft, which is what the
|
|
59
|
+
// list's inline Post sends.
|
|
60
|
+
const debitAccountId = edits?.jeDebitAccountId ?? accrual?.jeDebitAccountId;
|
|
61
|
+
const creditAccountId = edits?.jeCreditAccountId ?? accrual?.jeCreditAccountId;
|
|
62
|
+
if (debitAccountId == null || creditAccountId == null) {
|
|
63
|
+
// Promote posts a journal entry, so it cannot proceed without both sides of it.
|
|
64
|
+
return (0, rxjs_1.from)(failureActions('save_schedule', accrualId, 'This accrual is missing an expense or liability account.'));
|
|
65
|
+
}
|
|
66
|
+
// vendor_id, vendor_name and service_month are deliberately absent: promote takes them from
|
|
67
|
+
// the stored draft and ignores them in the body, so sending them would imply a reassignment
|
|
68
|
+
// that never happens.
|
|
69
|
+
// Untouched falls back to the stored policy, so posting without editing cannot silently
|
|
70
|
+
// flip a scheduled reversal to on-bill-match.
|
|
71
|
+
const reverseNextMonth = edits?.reverseNextMonth ??
|
|
72
|
+
accrual?.reversalPolicy === 'scheduled_date';
|
|
73
|
+
const expectedReversalDate = edits?.expectedReversalDate ?? accrual?.expectedReversalDate;
|
|
74
|
+
const debitClassId = edits?.jeDebitAccountingClassId ?? accrual?.jeDebitAccountingClassId;
|
|
75
|
+
const debitClassName = edits?.jeDebitAccountingClassName ??
|
|
76
|
+
accrual?.jeDebitAccountingClassName;
|
|
77
|
+
const payload = {
|
|
78
|
+
amount,
|
|
79
|
+
memo: edits?.memo ?? accrual?.memo ?? '',
|
|
80
|
+
je_debit_account_id: debitAccountId,
|
|
81
|
+
je_credit_account_id: creditAccountId,
|
|
82
|
+
...(debitClassId != null ? { je_debit_accounting_class_id: debitClassId } : {}),
|
|
83
|
+
...(debitClassName != null
|
|
84
|
+
? { je_debit_accounting_class_name: debitClassName }
|
|
85
|
+
: {}),
|
|
86
|
+
// Mirrors the create payload: reverse_next_month alone decides the policy, and the date is
|
|
87
|
+
// only meaningful when it is true -- agent-je derives the reversal from the bill otherwise.
|
|
88
|
+
reverse_next_month: reverseNextMonth,
|
|
89
|
+
...(reverseNextMonth && expectedReversalDate != null
|
|
90
|
+
? {
|
|
91
|
+
expected_reversal_date: expectedReversalDate.format(timePeriod_1.DEFAULT_DATE_FORMAT),
|
|
92
|
+
}
|
|
93
|
+
: {}),
|
|
94
|
+
};
|
|
95
|
+
return zeniAPI
|
|
96
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}`, { ...payload })
|
|
97
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
98
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
99
|
+
return (0, rxjs_1.from)([
|
|
100
|
+
(0, jeSchedulesReducer_1.updateJEOneTimeAccruals)([response.data.accrual]),
|
|
101
|
+
(0, jeSchedulesViewReducer_1.oneTimeAccrualActionSuccess)({ accrualId }),
|
|
102
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
103
|
+
messageSection: 'save_schedule',
|
|
104
|
+
messageText: 'success',
|
|
105
|
+
type: 'success',
|
|
106
|
+
variables: [
|
|
107
|
+
{
|
|
108
|
+
variableName: '_vendor_name_',
|
|
109
|
+
variableValue: accrual?.vendorName ?? '',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
}),
|
|
113
|
+
...refreshCurrentPage(state$.value),
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
return (0, rxjs_1.from)(failureActions('save_schedule', accrualId, response.status.message, response.status));
|
|
117
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.from)(failureActions('save_schedule', accrualId, `Promote accrual REST API call errored out ${JSON.stringify(error)}`))),
|
|
118
|
+
// A tenant switch clears the store while this request is still in flight.
|
|
119
|
+
// Without this the old tenant's response is written back into the freshly
|
|
120
|
+
// cleared store and stays on screen under the new tenant.
|
|
121
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
|
|
122
|
+
}));
|
|
123
|
+
exports.promoteOneTimeAccrualEpic = promoteOneTimeAccrualEpic;
|
|
124
|
+
const ignoreOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.ignoreOneTimeAccrual.match), (0, operators_1.mergeMap)((action) => {
|
|
125
|
+
const { accrualId, reason, note } = action.payload;
|
|
126
|
+
// `scope` is deliberately never sent: the API returns 400 on it, which is why the design's
|
|
127
|
+
// "Apply to" selector cannot be built yet.
|
|
128
|
+
const payload = {
|
|
129
|
+
reason,
|
|
130
|
+
...(note != null && note !== '' ? { note } : {}),
|
|
131
|
+
};
|
|
132
|
+
return zeniAPI
|
|
133
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}/ignore`, { ...payload })
|
|
134
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
135
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
136
|
+
return (0, rxjs_1.from)([
|
|
137
|
+
(0, jeSchedulesReducer_1.updateJEOneTimeAccruals)([response.data.accrual]),
|
|
138
|
+
(0, jeSchedulesViewReducer_1.oneTimeAccrualActionSuccess)({ accrualId }),
|
|
139
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
140
|
+
messageSection: 'ignore_accrual',
|
|
141
|
+
messageText: 'success',
|
|
142
|
+
type: 'success',
|
|
143
|
+
}),
|
|
144
|
+
...refreshCurrentPage(state$.value),
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
return (0, rxjs_1.from)(failureActions('ignore_accrual', accrualId, response.status.message, response.status));
|
|
148
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.from)(failureActions('ignore_accrual', accrualId, `Ignore accrual REST API call errored out ${JSON.stringify(error)}`))),
|
|
149
|
+
// A tenant switch clears the store while this request is still in flight.
|
|
150
|
+
// Without this the old tenant's response is written back into the freshly
|
|
151
|
+
// cleared store and stays on screen under the new tenant.
|
|
152
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
|
|
153
|
+
}));
|
|
154
|
+
exports.ignoreOneTimeAccrualEpic = ignoreOneTimeAccrualEpic;
|
|
155
|
+
const revertOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.revertOneTimeAccrual.match), (0, operators_1.mergeMap)((action) => {
|
|
156
|
+
const { accrualId, reason, note } = action.payload;
|
|
157
|
+
// Deletes the accrual's journal entry in QBO and soft-deletes the row. `scope` is never sent:
|
|
158
|
+
// the endpoint 400s on it, exactly as ignore does.
|
|
159
|
+
const payload = {
|
|
160
|
+
reason,
|
|
161
|
+
...(note != null && note !== '' ? { note } : {}),
|
|
162
|
+
};
|
|
163
|
+
return zeniAPI
|
|
164
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}/revert`, { ...payload })
|
|
165
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
166
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
167
|
+
return (0, rxjs_1.from)([
|
|
168
|
+
(0, jeSchedulesReducer_1.updateJEOneTimeAccruals)([response.data.accrual]),
|
|
169
|
+
(0, jeSchedulesViewReducer_1.oneTimeAccrualActionSuccess)({ accrualId }),
|
|
170
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
171
|
+
messageSection: 'revert_accrual',
|
|
172
|
+
messageText: 'success',
|
|
173
|
+
type: 'success',
|
|
174
|
+
}),
|
|
175
|
+
...refreshCurrentPage(state$.value),
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
return (0, rxjs_1.from)(failureActions('revert_accrual', accrualId, response.status.message, response.status));
|
|
179
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.from)(failureActions('revert_accrual', accrualId, `Revert accrual REST API call errored out ${JSON.stringify(error)}`))),
|
|
180
|
+
// A tenant switch clears the store while this request is still in flight.
|
|
181
|
+
// Without this the old tenant's response is written back into the freshly
|
|
182
|
+
// cleared store and stays on screen under the new tenant.
|
|
183
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
|
|
184
|
+
}));
|
|
185
|
+
exports.revertOneTimeAccrualEpic = revertOneTimeAccrualEpic;
|
|
186
|
+
const oneTimeAccrualActionsEpic = (actions$, state$, zeniAPI) => (0, rxjs_1.merge)((0, exports.promoteOneTimeAccrualEpic)(actions$, state$, zeniAPI), (0, exports.ignoreOneTimeAccrualEpic)(actions$, state$, zeniAPI), (0, exports.revertOneTimeAccrualEpic)(actions$, state$, zeniAPI));
|
|
187
|
+
exports.oneTimeAccrualActionsEpic = oneTimeAccrualActionsEpic;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { updateJESchedules, updateJESchedulesDetails } from '../../../../entity/jeSchedules/jeSchedulesReducer';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { JEScheduleKey, JEScheduleTransactionKey } from '../../../../entity/jeSchedules/jeSchedulesTypes';
|
|
5
|
+
import { RootState } from '../../../../reducer';
|
|
6
|
+
import { clearAll } from '../../../../rootActions';
|
|
7
|
+
import { ZeniAPI } from '../../../../zeniAPI';
|
|
8
|
+
import { fetchMonthEndCloseChecks } from '../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer';
|
|
9
|
+
import { removeJeAccruedScheduleKey, removeJeScheduleTransactionKey, revertJeSchedule, revertJeScheduleFailure, revertJeScheduleSuccess } from '../../reducers/jeSchedulesViewReducer';
|
|
10
|
+
export type ActionType = ReturnType<typeof clearAll> | ReturnType<typeof fetchMonthEndCloseChecks> | ReturnType<typeof openSnackbar> | ReturnType<typeof removeJeAccruedScheduleKey> | ReturnType<typeof removeJeScheduleTransactionKey> | ReturnType<typeof revertJeSchedule> | ReturnType<typeof revertJeScheduleFailure> | ReturnType<typeof revertJeScheduleSuccess> | ReturnType<typeof updateJESchedules> | ReturnType<typeof updateJESchedulesDetails>;
|
|
11
|
+
/**
|
|
12
|
+
* Undo a posted prepaid / fixed-asset / accrued schedule: deletes its posted QBO journal entry, then
|
|
13
|
+
* soft-deletes the scheduled entries and the schedule itself.
|
|
14
|
+
*
|
|
15
|
+
* Two or more posted journal entries answer 409 and leave the schedule intact, so the failure is
|
|
16
|
+
* surfaced rather than swallowed. Accrued has one extra rejection of its own — the endpoint refuses
|
|
17
|
+
* once a bill has been linked, because the reversal is already on the books — and that arrives the
|
|
18
|
+
* same way, as an error on the row.
|
|
19
|
+
*
|
|
20
|
+
* A one-time accrual is not this action: it is a Mongo row behind the accruals gateway, and goes
|
|
21
|
+
* through revertOneTimeAccrual instead. So `accrued_expenses` here always means an accrued
|
|
22
|
+
* *schedule*, which is what makes it a safe discriminator for the removal below.
|
|
23
|
+
*/
|
|
24
|
+
export declare const revertJeScheduleEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
|
|
25
|
+
payload: {
|
|
26
|
+
messageSection: import("../../../..").SnackbarMessageSections;
|
|
27
|
+
messageText: import("../../../..").SnackbarMessageSectionTexts;
|
|
28
|
+
type: import("../../../..").SnackbarMessageType;
|
|
29
|
+
showStatusIcon?: boolean;
|
|
30
|
+
variables?: {
|
|
31
|
+
variableName: string;
|
|
32
|
+
variableValue: string;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
type: "snackbar/openSnackbar";
|
|
36
|
+
} | {
|
|
37
|
+
payload: {
|
|
38
|
+
period: import("../../../..").MonthYearPeriod;
|
|
39
|
+
refreshViewInBackground: boolean;
|
|
40
|
+
tenantId: import("../../../..").ID;
|
|
41
|
+
};
|
|
42
|
+
type: "monthEndCloseChecksView/fetchMonthEndCloseChecks";
|
|
43
|
+
} | {
|
|
44
|
+
payload: {
|
|
45
|
+
jeScheduleKey: `${string}_expense_${string}` | `${string}_check_${string}` | `${string}_invoice_${string}` | `${string}_payment_${string}` | `${string}_credit_memo_${string}` | `${string}_sales_receipt_${string}` | `${string}_delayed_credit_${string}` | `${string}_delayed_charge_${string}` | `${string}_refund_${string}` | `${string}_bill_${string}` | `${string}_bill_payment_${string}` | `${string}_bill_payment_check_${string}` | `${string}_bill_payment_credit_card_${string}` | `${string}_vendor_credit_${string}` | `${string}_credit_card_credit_${string}` | `${string}_transfer_${string}` | `${string}_credit_card_payment_${string}` | `${string}_deposit_${string}` | `${string}_journal_entry_${string}`;
|
|
46
|
+
selectedPeriod: import("../../../..").MonthYearPeriod;
|
|
47
|
+
};
|
|
48
|
+
type: "expenseAutomationJESchedulesView/removeJeScheduleTransactionKey";
|
|
49
|
+
} | {
|
|
50
|
+
payload: {
|
|
51
|
+
jeAccruedScheduleKey: `${string}_${string}`;
|
|
52
|
+
};
|
|
53
|
+
type: "expenseAutomationJESchedulesView/removeJeAccruedScheduleKey";
|
|
54
|
+
} | {
|
|
55
|
+
payload: {
|
|
56
|
+
jeScheduleTransactionKey: JEScheduleKey | JEScheduleTransactionKey;
|
|
57
|
+
status: import("../../../../zeniAPIStatus").ZeniAPIStatus;
|
|
58
|
+
};
|
|
59
|
+
type: "expenseAutomationJESchedulesView/revertJeScheduleFailure";
|
|
60
|
+
} | {
|
|
61
|
+
payload: {
|
|
62
|
+
jeScheduleTransactionKey: JEScheduleKey | JEScheduleTransactionKey;
|
|
63
|
+
};
|
|
64
|
+
type: "expenseAutomationJESchedulesView/revertJeScheduleSuccess";
|
|
65
|
+
}>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.revertJeScheduleEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
|
|
7
|
+
const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
|
|
8
|
+
const rootActions_1 = require("../../../../rootActions");
|
|
9
|
+
const responsePayload_1 = require("../../../../responsePayload");
|
|
10
|
+
const monthEndCloseChecksViewReducer_1 = require("../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer");
|
|
11
|
+
const jeSchedulesViewReducer_1 = require("../../reducers/jeSchedulesViewReducer");
|
|
12
|
+
/**
|
|
13
|
+
* Undo a posted prepaid / fixed-asset / accrued schedule: deletes its posted QBO journal entry, then
|
|
14
|
+
* soft-deletes the scheduled entries and the schedule itself.
|
|
15
|
+
*
|
|
16
|
+
* Two or more posted journal entries answer 409 and leave the schedule intact, so the failure is
|
|
17
|
+
* surfaced rather than swallowed. Accrued has one extra rejection of its own — the endpoint refuses
|
|
18
|
+
* once a bill has been linked, because the reversal is already on the books — and that arrives the
|
|
19
|
+
* same way, as an error on the row.
|
|
20
|
+
*
|
|
21
|
+
* A one-time accrual is not this action: it is a Mongo row behind the accruals gateway, and goes
|
|
22
|
+
* through revertOneTimeAccrual instead. So `accrued_expenses` here always means an accrued
|
|
23
|
+
* *schedule*, which is what makes it a safe discriminator for the removal below.
|
|
24
|
+
*/
|
|
25
|
+
const revertJeScheduleEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.revertJeSchedule.match), (0, operators_1.mergeMap)((action) => {
|
|
26
|
+
const state = state$.value;
|
|
27
|
+
const { expenseAutomationViewState: { selectedPeriodByTenantId }, } = state;
|
|
28
|
+
const { jeScheduleId, jeScheduleTransactionKey, reason, note, scheduleType } = action.payload;
|
|
29
|
+
const currentTenant = (0, tenantSelector_1.getCurrentTenant)(state);
|
|
30
|
+
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
31
|
+
// Feedback nested under je_schedules[0], the same shape ignore takes -- the two endpoints were
|
|
32
|
+
// made symmetric server-side. A flat {reason, note} body, which this epic used to send while
|
|
33
|
+
// revert validated the whole body as feedback, now answers 400 "Request body must contain at
|
|
34
|
+
// least one of je_schedules".
|
|
35
|
+
//
|
|
36
|
+
// Only the id and the feedback: the rest of the fat blob is read from Datastore, not the
|
|
37
|
+
// request. The id is optional server-side but sent anyway, because it is validated against the
|
|
38
|
+
// URL and so turns a mismatch into a 400 rather than a revert of the wrong schedule.
|
|
39
|
+
// `action` is stamped server-side.
|
|
40
|
+
const payload = {
|
|
41
|
+
je_schedules: [
|
|
42
|
+
{
|
|
43
|
+
je_schedule_id: jeScheduleId,
|
|
44
|
+
feedback: {
|
|
45
|
+
reason,
|
|
46
|
+
...(note != null && note !== '' ? { note } : {}),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
return zeniAPI
|
|
52
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules/${jeScheduleId}/revert`, payload)
|
|
53
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
54
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
55
|
+
// Deliberately not written to the entity store. A reverted schedule is soft-deleted,
|
|
56
|
+
// so the endpoint returns its flat entity json -- `vendor_id` as a bare field, no
|
|
57
|
+
// nested `vendor` or `base_transaction` -- rather than the list DTO those mappers
|
|
58
|
+
// expect. Feeding it to updateJESchedules threw inside doUpdateVendors on
|
|
59
|
+
// `payload.vendor.vendor_id`, and because that happens mid-dispatch it killed the
|
|
60
|
+
// rest of this array: the row kept spinning and no snackbar appeared. The row is
|
|
61
|
+
// removed from the list below regardless, so there is nothing worth storing.
|
|
62
|
+
return (0, rxjs_1.from)([
|
|
63
|
+
(0, jeSchedulesViewReducer_1.revertJeScheduleSuccess)({ jeScheduleTransactionKey }),
|
|
64
|
+
// Accrued keys live in their own per-tab map, so the transaction-key removal cannot
|
|
65
|
+
// reach them -- a reverted accrued schedule would sit on the list until the next
|
|
66
|
+
// fetch. The key carried here is a JEScheduleKey for that type.
|
|
67
|
+
scheduleType === 'accrued_expenses'
|
|
68
|
+
? (0, jeSchedulesViewReducer_1.removeJeAccruedScheduleKey)(jeScheduleTransactionKey)
|
|
69
|
+
: (0, jeSchedulesViewReducer_1.removeJeScheduleTransactionKey)(jeScheduleTransactionKey, selectedPeriod),
|
|
70
|
+
(0, monthEndCloseChecksViewReducer_1.fetchMonthEndCloseChecks)({
|
|
71
|
+
tenantId: currentTenant.tenantId,
|
|
72
|
+
period: selectedPeriod,
|
|
73
|
+
refreshViewInBackground: true,
|
|
74
|
+
}),
|
|
75
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
76
|
+
messageSection: 'revert_schedule',
|
|
77
|
+
messageText: 'success',
|
|
78
|
+
type: 'success',
|
|
79
|
+
}),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
return (0, rxjs_1.from)([
|
|
83
|
+
(0, jeSchedulesViewReducer_1.revertJeScheduleFailure)({
|
|
84
|
+
jeScheduleTransactionKey,
|
|
85
|
+
status: response.status,
|
|
86
|
+
}),
|
|
87
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
88
|
+
messageSection: 'revert_schedule',
|
|
89
|
+
messageText: 'failed',
|
|
90
|
+
type: 'error',
|
|
91
|
+
variables: [
|
|
92
|
+
{
|
|
93
|
+
variableName: '_api-error_',
|
|
94
|
+
variableValue: response.status.message,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
]);
|
|
99
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.from)([
|
|
100
|
+
(0, jeSchedulesViewReducer_1.revertJeScheduleFailure)({
|
|
101
|
+
jeScheduleTransactionKey,
|
|
102
|
+
status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Revert schedule REST API call errored out ${JSON.stringify(error)}`),
|
|
103
|
+
}),
|
|
104
|
+
(0, snackbarReducer_1.openSnackbar)({
|
|
105
|
+
messageSection: 'revert_schedule',
|
|
106
|
+
messageText: 'failed',
|
|
107
|
+
type: 'error',
|
|
108
|
+
}),
|
|
109
|
+
])),
|
|
110
|
+
// A tenant switch clears the store while this request is still in flight.
|
|
111
|
+
// Without this the old tenant's response is written back into the freshly
|
|
112
|
+
// cleared store and stays on screen under the new tenant.
|
|
113
|
+
(0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
|
|
114
|
+
}));
|
|
115
|
+
exports.revertJeScheduleEpic = revertJeScheduleEpic;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { RootState } from '../../../../reducer';
|
|
4
|
+
import { fetchJeSchedulesPage, updateJESchedulesUIState } from '../../reducers/jeSchedulesViewReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof fetchJeSchedulesPage> | ReturnType<typeof updateJESchedulesUIState>;
|
|
6
|
+
export declare const switchJESchedulesTabEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|