@zeniai/client-epic-state 5.2.14-betaRD0 → 5.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/lib/entity/jeSchedules/jeScheduleHelper.d.ts +0 -1
  2. package/lib/entity/jeSchedules/jeScheduleHelper.js +0 -7
  3. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +1 -78
  4. package/lib/entity/jeSchedules/jeSchedulesPayload.js +4 -183
  5. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +2 -4
  6. package/lib/entity/jeSchedules/jeSchedulesReducer.js +2 -30
  7. package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +2 -11
  8. package/lib/entity/jeSchedules/jeSchedulesSelector.js +3 -38
  9. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +1 -123
  10. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -24
  11. package/lib/entity/jeSchedules/jeSchedulesTypes.js +1 -96
  12. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  13. package/lib/entity/snackbar/snackbarTypes.js +0 -3
  14. package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.d.ts +0 -2
  15. package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.js +0 -2
  16. package/lib/entity/transaction/stateTypes/scheduleTransaction.d.ts +0 -2
  17. package/lib/epic.d.ts +1 -9
  18. package/lib/epic.js +0 -16
  19. package/lib/esm/entity/jeSchedules/jeScheduleHelper.js +0 -6
  20. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +5 -183
  21. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +2 -30
  22. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +2 -36
  23. package/lib/esm/entity/jeSchedules/jeSchedulesTypes.js +0 -86
  24. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -3
  25. package/lib/esm/entity/transaction/payloadTypes/scheduleTransactionPayload.js +0 -2
  26. package/lib/esm/epic.js +0 -16
  27. package/lib/esm/index.js +8 -14
  28. package/lib/esm/view/expenseAutomationView/epics/common/fetchAllExpenseAutomationTabsEpic.js +3 -6
  29. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -9
  30. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +5 -41
  31. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/ignoreRecommendedJeScheduleEpic.js +2 -14
  32. package/lib/esm/view/expenseAutomationView/payload/jeSchedulesPayload.js +0 -55
  33. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +29 -319
  34. package/lib/esm/view/expenseAutomationView/selectors/jeAccountSettingsViewSelector.js +0 -1
  35. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +22 -327
  36. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +6 -5
  37. package/lib/esm/view/scheduleView/scheduleListView/epics/fetchAccruedScheduleListEpic.js +1 -1
  38. package/lib/esm/view/scheduleView/scheduleListView/epics/fetchDownloadSchedulesEpic.js +2 -7
  39. package/lib/esm/view/scheduleView/scheduleListView/scheduleListReducer.js +3 -5
  40. package/lib/index.d.ts +12 -17
  41. package/lib/index.js +47 -91
  42. package/lib/view/expenseAutomationView/epics/common/fetchAllExpenseAutomationTabsEpic.js +3 -6
  43. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -9
  44. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.d.ts +2 -3
  45. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +3 -39
  46. package/lib/view/expenseAutomationView/epics/jeSchedule/ignoreRecommendedJeScheduleEpic.js +2 -14
  47. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  48. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +3 -86
  49. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.js +1 -58
  50. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +12 -93
  51. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +29 -321
  52. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +1 -1
  53. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +2 -2
  54. package/lib/view/expenseAutomationView/selectorTypes/jeAccountSettingsViewSelectorTypes.d.ts +0 -1
  55. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +7 -41
  56. package/lib/view/expenseAutomationView/selectors/jeAccountSettingsViewSelector.js +0 -1
  57. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.d.ts +0 -34
  58. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +21 -335
  59. package/lib/view/expenseAutomationView/types/completedSubTab.d.ts +1 -1
  60. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +8 -83
  61. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +8 -8
  62. package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
  63. package/lib/view/scheduleView/scheduleListView/epics/fetchAccruedScheduleListEpic.js +1 -1
  64. package/lib/view/scheduleView/scheduleListView/epics/fetchDownloadSchedulesEpic.js +2 -7
  65. package/lib/view/scheduleView/scheduleListView/scheduleListReducer.d.ts +2 -4
  66. package/lib/view/scheduleView/scheduleListView/scheduleListReducer.js +3 -5
  67. package/package.json +1 -1
  68. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.js +0 -45
  69. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.js +0 -104
  70. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -25
  71. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -138
  72. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -79
  73. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.js +0 -180
  74. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.js +0 -111
  75. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -28
  76. package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -140
  77. package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -1
  78. package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -106
  79. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.d.ts +0 -21
  80. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchOneTimeAccrualEpic.js +0 -49
  81. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.d.ts +0 -9
  82. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/createOneTimeAccrualEpic.js +0 -108
  83. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +0 -8
  84. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -29
  85. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +0 -9
  86. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -142
  87. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +0 -8
  88. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -83
  89. package/lib/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.d.ts +0 -13
  90. package/lib/view/expenseAutomationView/epics/jeSchedule/oneTimeAccrualActionsEpic.js +0 -187
  91. package/lib/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.d.ts +0 -65
  92. package/lib/view/expenseAutomationView/epics/jeSchedule/revertJeScheduleEpic.js +0 -115
  93. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +0 -6
  94. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -32
  95. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +0 -36
  96. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -145
  97. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +0 -42
  98. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -2
  99. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +0 -21
  100. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -112
@@ -1,180 +0,0 @@
1
- import { from, merge } from 'rxjs';
2
- import { catchError, filter, mergeMap, takeUntil } from 'rxjs/operators';
3
- import { DEFAULT_DATE_FORMAT, convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/timePeriod';
4
- import { generateJEOneTimeAccrualKey } from '../../../../entity/jeSchedules/jeScheduleHelper';
5
- import { updateJEOneTimeAccruals } from '../../../../entity/jeSchedules/jeSchedulesReducer';
6
- import { getJEOneTimeAccrualByKey } from '../../../../entity/jeSchedules/jeSchedulesSelector';
7
- import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
8
- import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
9
- import { clearAll } from '../../../../rootActions';
10
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
11
- import { fetchJeSchedules, ignoreOneTimeAccrual, oneTimeAccrualActionFailure, oneTimeAccrualActionSuccess, promoteOneTimeAccrual, revertOneTimeAccrual, } from '../../reducers/jeSchedulesViewReducer';
12
- /**
13
- * The page the accrual came from, so a promoted or ignored row lands in the right bucket. Guarded
14
- * because convertToPeriod destructures: an unset period would throw and take the epic subscription
15
- * down for the session, and a missed refresh is the cheaper failure.
16
- *
17
- * Read state$.value at response time rather than the snapshot taken when the action was dispatched:
18
- * if the user changes month while the request is in flight, the snapshot refreshes the month they
19
- * have left and the month they are now looking at stays stale.
20
- */
21
- function refreshCurrentPage(state) {
22
- const selectedMonthYear = state.expenseAutomationViewState.selectedPeriodByTenantId[getCurrentTenant(state).tenantId];
23
- if (selectedMonthYear == null) {
24
- return [];
25
- }
26
- const period = convertToPeriod(selectedMonthYear);
27
- const start = toAbsoluteDay(period.start);
28
- const end = toAbsoluteDay(period.end);
29
- if (start == null || end == null) {
30
- return [];
31
- }
32
- return [fetchJeSchedules({ start, end }, true)];
33
- }
34
- function failureActions(
35
- // Per action, not fixed: every failure used to read "Save schedule failed", so skipping or
36
- // reverting an accrual reported an operation the user had not performed.
37
- messageSection, accrualId, message, status) {
38
- return [
39
- oneTimeAccrualActionFailure({
40
- accrualId,
41
- status: status ?? createZeniAPIStatus('Unexpected Error', message),
42
- }),
43
- openSnackbar({
44
- messageSection,
45
- messageText: 'failed',
46
- type: 'error',
47
- variables: [{ variableName: '_api-error_', variableValue: message }],
48
- }),
49
- ];
50
- }
51
- export const promoteOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(promoteOneTimeAccrual.match), mergeMap((action) => {
52
- const state = state$.value;
53
- const { accrualId, amount, edits } = action.payload;
54
- const accrual = getJEOneTimeAccrualByKey(generateJEOneTimeAccrualKey(accrualId), state.jeSchedulesState);
55
- // An edited value wins; anything untouched falls back to the stored draft, which is what the
56
- // list's inline Post sends.
57
- const debitAccountId = edits?.jeDebitAccountId ?? accrual?.jeDebitAccountId;
58
- const creditAccountId = edits?.jeCreditAccountId ?? accrual?.jeCreditAccountId;
59
- if (debitAccountId == null || creditAccountId == null) {
60
- // Promote posts a journal entry, so it cannot proceed without both sides of it.
61
- return from(failureActions('save_schedule', accrualId, 'This accrual is missing an expense or liability account.'));
62
- }
63
- // vendor_id, vendor_name and service_month are deliberately absent: promote takes them from
64
- // the stored draft and ignores them in the body, so sending them would imply a reassignment
65
- // that never happens.
66
- // Untouched falls back to the stored policy, so posting without editing cannot silently
67
- // flip a scheduled reversal to on-bill-match.
68
- const reverseNextMonth = edits?.reverseNextMonth ??
69
- accrual?.reversalPolicy === 'scheduled_date';
70
- const expectedReversalDate = edits?.expectedReversalDate ?? accrual?.expectedReversalDate;
71
- const debitClassId = edits?.jeDebitAccountingClassId ?? accrual?.jeDebitAccountingClassId;
72
- const debitClassName = edits?.jeDebitAccountingClassName ??
73
- accrual?.jeDebitAccountingClassName;
74
- const payload = {
75
- amount,
76
- memo: edits?.memo ?? accrual?.memo ?? '',
77
- je_debit_account_id: debitAccountId,
78
- je_credit_account_id: creditAccountId,
79
- ...(debitClassId != null ? { je_debit_accounting_class_id: debitClassId } : {}),
80
- ...(debitClassName != null
81
- ? { je_debit_accounting_class_name: debitClassName }
82
- : {}),
83
- // Mirrors the create payload: reverse_next_month alone decides the policy, and the date is
84
- // only meaningful when it is true -- agent-je derives the reversal from the bill otherwise.
85
- reverse_next_month: reverseNextMonth,
86
- ...(reverseNextMonth && expectedReversalDate != null
87
- ? {
88
- expected_reversal_date: expectedReversalDate.format(DEFAULT_DATE_FORMAT),
89
- }
90
- : {}),
91
- };
92
- return zeniAPI
93
- .putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}`, { ...payload })
94
- .pipe(mergeMap((response) => {
95
- if (isSuccessResponse(response) && response.data != null) {
96
- return from([
97
- updateJEOneTimeAccruals([response.data.accrual]),
98
- oneTimeAccrualActionSuccess({ accrualId }),
99
- openSnackbar({
100
- messageSection: 'save_schedule',
101
- messageText: 'success',
102
- type: 'success',
103
- variables: [
104
- {
105
- variableName: '_vendor_name_',
106
- variableValue: accrual?.vendorName ?? '',
107
- },
108
- ],
109
- }),
110
- ...refreshCurrentPage(state$.value),
111
- ]);
112
- }
113
- return from(failureActions('save_schedule', accrualId, response.status.message, response.status));
114
- }), catchError((error) => from(failureActions('save_schedule', accrualId, `Promote accrual REST API call errored out ${JSON.stringify(error)}`))),
115
- // A tenant switch clears the store while this request is still in flight.
116
- // Without this the old tenant's response is written back into the freshly
117
- // cleared store and stays on screen under the new tenant.
118
- takeUntil(actions$.pipe(filter(clearAll.match))));
119
- }));
120
- export const ignoreOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(ignoreOneTimeAccrual.match), mergeMap((action) => {
121
- const { accrualId, reason, note } = action.payload;
122
- // `scope` is deliberately never sent: the API returns 400 on it, which is why the design's
123
- // "Apply to" selector cannot be built yet.
124
- const payload = {
125
- reason,
126
- ...(note != null && note !== '' ? { note } : {}),
127
- };
128
- return zeniAPI
129
- .putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}/ignore`, { ...payload })
130
- .pipe(mergeMap((response) => {
131
- if (isSuccessResponse(response) && response.data != null) {
132
- return from([
133
- updateJEOneTimeAccruals([response.data.accrual]),
134
- oneTimeAccrualActionSuccess({ accrualId }),
135
- openSnackbar({
136
- messageSection: 'ignore_accrual',
137
- messageText: 'success',
138
- type: 'success',
139
- }),
140
- ...refreshCurrentPage(state$.value),
141
- ]);
142
- }
143
- return from(failureActions('ignore_accrual', accrualId, response.status.message, response.status));
144
- }), catchError((error) => from(failureActions('ignore_accrual', accrualId, `Ignore accrual REST API call errored out ${JSON.stringify(error)}`))),
145
- // A tenant switch clears the store while this request is still in flight.
146
- // Without this the old tenant's response is written back into the freshly
147
- // cleared store and stays on screen under the new tenant.
148
- takeUntil(actions$.pipe(filter(clearAll.match))));
149
- }));
150
- export const revertOneTimeAccrualEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(revertOneTimeAccrual.match), mergeMap((action) => {
151
- const { accrualId, reason, note } = action.payload;
152
- // Deletes the accrual's journal entry in QBO and soft-deletes the row. `scope` is never sent:
153
- // the endpoint 400s on it, exactly as ignore does.
154
- const payload = {
155
- reason,
156
- ...(note != null && note !== '' ? { note } : {}),
157
- };
158
- return zeniAPI
159
- .putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}/revert`, { ...payload })
160
- .pipe(mergeMap((response) => {
161
- if (isSuccessResponse(response) && response.data != null) {
162
- return from([
163
- updateJEOneTimeAccruals([response.data.accrual]),
164
- oneTimeAccrualActionSuccess({ accrualId }),
165
- openSnackbar({
166
- messageSection: 'revert_accrual',
167
- messageText: 'success',
168
- type: 'success',
169
- }),
170
- ...refreshCurrentPage(state$.value),
171
- ]);
172
- }
173
- return from(failureActions('revert_accrual', accrualId, response.status.message, response.status));
174
- }), catchError((error) => from(failureActions('revert_accrual', accrualId, `Revert accrual REST API call errored out ${JSON.stringify(error)}`))),
175
- // A tenant switch clears the store while this request is still in flight.
176
- // Without this the old tenant's response is written back into the freshly
177
- // cleared store and stays on screen under the new tenant.
178
- takeUntil(actions$.pipe(filter(clearAll.match))));
179
- }));
180
- export const oneTimeAccrualActionsEpic = (actions$, state$, zeniAPI) => merge(promoteOneTimeAccrualEpic(actions$, state$, zeniAPI), ignoreOneTimeAccrualEpic(actions$, state$, zeniAPI), revertOneTimeAccrualEpic(actions$, state$, zeniAPI));
@@ -1,111 +0,0 @@
1
- import { from } from 'rxjs';
2
- import { catchError, filter, mergeMap, takeUntil } from 'rxjs/operators';
3
- import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
- import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
- import { clearAll } from '../../../../rootActions';
6
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
7
- import { fetchMonthEndCloseChecks } from '../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer';
8
- import { removeJeAccruedScheduleKey, removeJeScheduleTransactionKey, revertJeSchedule, revertJeScheduleFailure, revertJeScheduleSuccess, } from '../../reducers/jeSchedulesViewReducer';
9
- /**
10
- * Undo a posted prepaid / fixed-asset / accrued schedule: deletes its posted QBO journal entry, then
11
- * soft-deletes the scheduled entries and the schedule itself.
12
- *
13
- * Two or more posted journal entries answer 409 and leave the schedule intact, so the failure is
14
- * surfaced rather than swallowed. Accrued has one extra rejection of its own — the endpoint refuses
15
- * once a bill has been linked, because the reversal is already on the books — and that arrives the
16
- * same way, as an error on the row.
17
- *
18
- * A one-time accrual is not this action: it is a Mongo row behind the accruals gateway, and goes
19
- * through revertOneTimeAccrual instead. So `accrued_expenses` here always means an accrued
20
- * *schedule*, which is what makes it a safe discriminator for the removal below.
21
- */
22
- export const revertJeScheduleEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(revertJeSchedule.match), mergeMap((action) => {
23
- const state = state$.value;
24
- const { expenseAutomationViewState: { selectedPeriodByTenantId }, } = state;
25
- const { jeScheduleId, jeScheduleTransactionKey, reason, note, scheduleType } = action.payload;
26
- const currentTenant = getCurrentTenant(state);
27
- const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
28
- // Feedback nested under je_schedules[0], the same shape ignore takes -- the two endpoints were
29
- // made symmetric server-side. A flat {reason, note} body, which this epic used to send while
30
- // revert validated the whole body as feedback, now answers 400 "Request body must contain at
31
- // least one of je_schedules".
32
- //
33
- // Only the id and the feedback: the rest of the fat blob is read from Datastore, not the
34
- // request. The id is optional server-side but sent anyway, because it is validated against the
35
- // URL and so turns a mismatch into a 400 rather than a revert of the wrong schedule.
36
- // `action` is stamped server-side.
37
- const payload = {
38
- je_schedules: [
39
- {
40
- je_schedule_id: jeScheduleId,
41
- feedback: {
42
- reason,
43
- ...(note != null && note !== '' ? { note } : {}),
44
- },
45
- },
46
- ],
47
- };
48
- return zeniAPI
49
- .putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules/${jeScheduleId}/revert`, payload)
50
- .pipe(mergeMap((response) => {
51
- if (isSuccessResponse(response) && response.data != null) {
52
- // Deliberately not written to the entity store. A reverted schedule is soft-deleted,
53
- // so the endpoint returns its flat entity json -- `vendor_id` as a bare field, no
54
- // nested `vendor` or `base_transaction` -- rather than the list DTO those mappers
55
- // expect. Feeding it to updateJESchedules threw inside doUpdateVendors on
56
- // `payload.vendor.vendor_id`, and because that happens mid-dispatch it killed the
57
- // rest of this array: the row kept spinning and no snackbar appeared. The row is
58
- // removed from the list below regardless, so there is nothing worth storing.
59
- return from([
60
- revertJeScheduleSuccess({ jeScheduleTransactionKey }),
61
- // Accrued keys live in their own per-tab map, so the transaction-key removal cannot
62
- // reach them -- a reverted accrued schedule would sit on the list until the next
63
- // fetch. The key carried here is a JEScheduleKey for that type.
64
- scheduleType === 'accrued_expenses'
65
- ? removeJeAccruedScheduleKey(jeScheduleTransactionKey)
66
- : removeJeScheduleTransactionKey(jeScheduleTransactionKey, selectedPeriod),
67
- fetchMonthEndCloseChecks({
68
- tenantId: currentTenant.tenantId,
69
- period: selectedPeriod,
70
- refreshViewInBackground: true,
71
- }),
72
- openSnackbar({
73
- messageSection: 'revert_schedule',
74
- messageText: 'success',
75
- type: 'success',
76
- }),
77
- ]);
78
- }
79
- return from([
80
- revertJeScheduleFailure({
81
- jeScheduleTransactionKey,
82
- status: response.status,
83
- }),
84
- openSnackbar({
85
- messageSection: 'revert_schedule',
86
- messageText: 'failed',
87
- type: 'error',
88
- variables: [
89
- {
90
- variableName: '_api-error_',
91
- variableValue: response.status.message,
92
- },
93
- ],
94
- }),
95
- ]);
96
- }), catchError((error) => from([
97
- revertJeScheduleFailure({
98
- jeScheduleTransactionKey,
99
- status: createZeniAPIStatus('Unexpected Error', `Revert schedule REST API call errored out ${JSON.stringify(error)}`),
100
- }),
101
- openSnackbar({
102
- messageSection: 'revert_schedule',
103
- messageText: 'failed',
104
- type: 'error',
105
- }),
106
- ])),
107
- // A tenant switch clears the store while this request is still in flight.
108
- // Without this the old tenant's response is written back into the freshly
109
- // cleared store and stays on screen under the new tenant.
110
- takeUntil(actions$.pipe(filter(clearAll.match))));
111
- }));
@@ -1,28 +0,0 @@
1
- import { EMPTY, of } from 'rxjs';
2
- import { filter, mergeMap } from 'rxjs/operators';
3
- import { convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/timePeriod';
4
- import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
- import { fetchJeSchedulesPage, updateJESchedulesUIState, } from '../../reducers/jeSchedulesViewReducer';
6
- export const switchJESchedulesTabEpic = (actions$, state$) => actions$.pipe(filter(updateJESchedulesUIState.match), filter((action) => action.payload.selectedPageTab != null), mergeMap(() => {
7
- const state = state$.value;
8
- const { fetchState, refreshStatus } = state.expenseAutomationJESchedulesViewState;
9
- if (fetchState === 'In-Progress' ||
10
- refreshStatus.fetchState === 'In-Progress') {
11
- return EMPTY;
12
- }
13
- const currentTenant = getCurrentTenant(state);
14
- const selectedPeriod = state.expenseAutomationViewState.selectedPeriodByTenantId[currentTenant.tenantId];
15
- // convertToPeriod destructures, so an unset period throws and takes this epic's subscription
16
- // down for the rest of the session -- every later tab switch would then stop refreshing. A
17
- // skipped refresh is the cheaper failure, as in refreshCurrentPage.
18
- if (selectedPeriod == null) {
19
- return EMPTY;
20
- }
21
- const period = convertToPeriod(selectedPeriod);
22
- const timePeriodStart = toAbsoluteDay(period.start);
23
- const timePeriodEnd = toAbsoluteDay(period.end);
24
- if (timePeriodStart == null || timePeriodEnd == null) {
25
- return EMPTY;
26
- }
27
- return of(fetchJeSchedulesPage({ start: timePeriodStart, end: timePeriodEnd }, true));
28
- }));
@@ -1,140 +0,0 @@
1
- import { toAmount } from '../../../commonStateTypes/amount';
2
- import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/timePeriod';
3
- import { MONTH_YEAR_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
4
- import { LAST_SCHEDULE_DAY_OF_MONTH } from '../../../commonStateTypes/timePeriod';
5
- import { getPostingDateAndStatusForIndex } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
6
- import { mapScheduleTransactionToBaseScheduleTransactionPayload, } from '../../scheduleView/scheduleDetailView/scheduleDetailPayload';
7
- const getNewScheduleMemo = (vendorName, schedulePostingDate, currentPeriod, totalPeriod, assetId) => {
8
- const addAsset = assetId != null && assetId !== '' ? ` - ${assetId}` : '';
9
- return `${vendorName} - ${schedulePostingDate.format(MONTH_YEAR_FORMAT)} (${currentPeriod} of ${totalPeriod})${addAsset}`;
10
- };
11
- /**
12
- * Computes the month-by-month JE schedule breakdown for a brand-new schedule
13
- * (no linked transaction yet) — replicates createNewSchedulesHelper's math
14
- * (scheduleDetailLocalDataHelper.ts) exactly: lump-sum total split evenly
15
- * across months with the rounding remainder absorbed by the last month, and a
16
- * running balance that decrements each month and is forced to exactly 0 on
17
- * the last row.
18
- */
19
- export const computeNewScheduleJeDetails = (localData, totalAmount, vendorName) => {
20
- const period = localData.selectedMonths;
21
- const startingMonth = localData.selectedDate;
22
- if (startingMonth == null || period == null) {
23
- return [];
24
- }
25
- const assetId = 'assetId' in localData ? localData.assetId : undefined;
26
- const averageAmount = Math.abs(Math.round((totalAmount.amount / period) * 100) / 100);
27
- const lastMonthAmount = Math.abs(Math.round((Math.abs(totalAmount.amount) - averageAmount * (period - 1)) * 100) / 100);
28
- let runningBalance = Math.abs(totalAmount.amount);
29
- const negativeNumbers = totalAmount.amount < 0 || runningBalance < 0;
30
- const newJeDetails = [];
31
- for (let index = 0; index < period; index++) {
32
- if (runningBalance > averageAmount) {
33
- runningBalance = Math.round((runningBalance - averageAmount) * 100) / 100;
34
- }
35
- else {
36
- runningBalance = 0;
37
- }
38
- const amount = index === period - 1 ? lastMonthAmount : averageAmount;
39
- runningBalance = index === period - 1 ? 0 : runningBalance;
40
- const schedulePostingDate = startingMonth.add(index, 'month');
41
- const { postingDate, postingStatus } = getPostingDateAndStatusForIndex(schedulePostingDate.month(), schedulePostingDate.year(), localData.lastDayOfMonth === true
42
- ? undefined
43
- : localData.selectedDayOfMonth);
44
- newJeDetails.push({
45
- postingDate,
46
- amount: toAmount(negativeNumbers ? -amount : amount, totalAmount.currencyCode, totalAmount.currencySymbol),
47
- runningBalance: toAmount(negativeNumbers ? -runningBalance : runningBalance, totalAmount.currencyCode, totalAmount.currencySymbol),
48
- postingStatus,
49
- memo: getNewScheduleMemo(vendorName, schedulePostingDate, index + 1, period, assetId),
50
- jeLink: { type: 'unknown' },
51
- });
52
- }
53
- return newJeDetails;
54
- };
55
- const mapNewJeDetailsToScheduledJournalEntryPayload = (jeScheduleDetails) => jeScheduleDetails.map((journalEntry) => ({
56
- status: {
57
- code: journalEntry.postingStatus,
58
- label: journalEntry.postingStatus,
59
- },
60
- transaction_memo: journalEntry.memo,
61
- third_party_id: journalEntry.jeLink.thirdPartyTransactionId ?? null,
62
- expected_post_date: journalEntry.postingDate.format(DEFAULT_DATE_FORMAT),
63
- amount: journalEntry.amount.amount,
64
- balance: journalEntry.runningBalance.amount,
65
- // Brand-new schedule — there is no prior scheduled-journal-entry history
66
- // to cross-reference (unlike the legacy edit flow's equivalent mapper).
67
- scheduled_journal_entry_id: null,
68
- actual_post_date: null,
69
- is_platform_generated: null,
70
- je_schedule_id: null,
71
- update_time: null,
72
- create_time: null,
73
- }));
74
- /**
75
- * Builds a savable schedule payload directly from a Base Transaction search
76
- * result and the New Schedule form's local data — bypassing the legacy
77
- * getJEScheduledTransactionByJEScheduleTransactionKey selector entirely,
78
- * since that selector throws unless the entity has already round-tripped
79
- * through a real GET /1.0/schedules/:id. A brand-new schedule has no such
80
- * history, so this reads only from data already in hand (the selected
81
- * transaction/line plus what the user filled into the form).
82
- */
83
- export const prepareNewSchedulePayload = (transaction, localData, scheduleType) => {
84
- if (transaction.thirdPartyTransactionId == null ||
85
- transaction.thirdPartyTransactionId === '') {
86
- return { ok: false, reason: 'missing_third_party_id' };
87
- }
88
- const scheduleTransaction = transaction;
89
- const vendorId = localData.selectedVendor?.id ?? transaction.vendorId ?? '';
90
- const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
91
- if (vendorId === '' || vendorName === '') {
92
- return { ok: false, reason: 'missing_vendor' };
93
- }
94
- const vendor = {
95
- vendor_id: vendorId,
96
- vendor_name: vendorName,
97
- };
98
- const jeScheduleDetails = computeNewScheduleJeDetails(localData, scheduleTransaction.amount, vendorName);
99
- const postingDate = localData.selectedDayOfMonth ??
100
- (localData.lastDayOfMonth === true ? LAST_SCHEDULE_DAY_OF_MONTH : null);
101
- const firstJEScheduleDate = jeScheduleDetails.length > 0
102
- ? jeScheduleDetails[0].postingDate.format(DEFAULT_DATE_FORMAT)
103
- : null;
104
- const lastJEScheduleDate = jeScheduleDetails.length > 0
105
- ? jeScheduleDetails[jeScheduleDetails.length - 1].postingDate.format(DEFAULT_DATE_FORMAT)
106
- : null;
107
- const isFixedAssets = scheduleType === 'fixed_assets';
108
- const assetId = 'assetId' in localData ? localData.assetId : undefined;
109
- const selectedAccumulatedDepreciationCategory = 'selectedAccumulatedDepreciationCategory' in localData
110
- ? localData.selectedAccumulatedDepreciationCategory
111
- : undefined;
112
- const status = { code: 'new', label: 'New' };
113
- const jeSchedulePayload = {
114
- status,
115
- vendor,
116
- currency_code: scheduleTransaction.currency.currencyCode,
117
- currency_symbol: scheduleTransaction.currency.currencySymbol,
118
- period: localData.selectedMonths ?? null,
119
- je_schedule_type: scheduleType,
120
- posting_date: postingDate,
121
- balance: scheduleTransaction.amount.amount,
122
- start_date: firstJEScheduleDate,
123
- end_date: lastJEScheduleDate,
124
- je_credit_accounting_class_id: scheduleTransaction.classBase?.classId ?? null,
125
- je_credit_account_id: isFixedAssets
126
- ? (selectedAccumulatedDepreciationCategory ?? null)
127
- : scheduleTransaction.account.accountId,
128
- je_debit_account_id: localData.selectedAccount ?? null,
129
- je_debit_accounting_class_id: localData.selectedClass ?? null,
130
- other_attributes: assetId != null ? { asset_id: assetId } : {},
131
- base_transaction: mapScheduleTransactionToBaseScheduleTransactionPayload(scheduleTransaction),
132
- };
133
- return {
134
- ok: true,
135
- payload: {
136
- je_schedules: [jeSchedulePayload],
137
- scheduled_journal_entries: mapNewJeDetailsToScheduledJournalEntryPayload(jeScheduleDetails),
138
- },
139
- };
140
- };
@@ -1,106 +0,0 @@
1
- import { getAccountIdsForLabels, getAccountIdsForTypes, } from '../../../entity/account/accountSelector';
2
- import { getScheduleTransactionById } from '../../../entity/transaction/transactionSelector';
3
- import { getAccountIdsForLabel, getAccountList, getNestedAccountListHierarchy, } from '../../accountList/accountListSelector';
4
- import { getClassList, getNestedClassListHierarchy, } from '../../classList/classListSelector';
5
- import { getAccountsTypesForScheduleDetails } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
6
- import { filterNestedAccountHierarchyById } from '../../scheduleView/scheduleDetailView/scheduleDetailSelector';
7
- import { getAccountLabelForScheduleType, getAccountsTypesForScheduleEpics, } from '../../scheduleView/scheduleListView/scheduleListHelper';
8
- /**
9
- * The Base Transaction search is shared across schedule types (one search
10
- * box, not one per prepaid_expenses/fixed_assets) — split out from
11
- * getNewScheduleView so a consumer can read it without supplying an
12
- * otherwise-irrelevant scheduleType.
13
- */
14
- export const getNewScheduleSearchTransactionsView = (state) => {
15
- const { searchTransactions } = state.expenseAutomationJESchedulesViewState.newSchedule;
16
- const searchTransactionsResults = searchTransactions.searchResults
17
- .map((key) => getScheduleTransactionById(state.transactionState, key))
18
- .filter((transaction) => transaction != null);
19
- return {
20
- searchTransactionsResults,
21
- searchTransactionsFetchState: {
22
- fetchState: searchTransactions.fetchState,
23
- error: searchTransactions.error,
24
- },
25
- searchTransactionsString: searchTransactions.searchString,
26
- };
27
- };
28
- const ACCRUED_EXPENSE_ACCOUNT_LABELS = ['accrued_expenses'];
29
- /**
30
- * Account + class options and request status shared by both accrual creation forms — the one-time
31
- * accrual and the recurring accrued schedule.
32
- *
33
- * getAccountsTypesForScheduleDetails('accrued_expenses') deliberately includes
34
- * other_current_liabilities, because the accrued liability accounts live there —
35
- * so the debit list has to subtract them back out, and the credit list keeps only
36
- * them. Mirrors getScheduleAccruedDetailView, which is the form this one is
37
- * modelled on.
38
- */
39
- export const getNewAccrualAccountsView = (state) => {
40
- const { accountState, accountListState, classState, classListState } = state;
41
- const { newSchedule } = state.expenseAutomationJESchedulesViewState;
42
- const accountType = getAccountsTypesForScheduleEpics();
43
- const accrualAccountIds = getAccountIdsForTypes(accountState, getAccountsTypesForScheduleDetails('accrued_expenses'));
44
- const accruedCategoryIds = getAccountIdsForLabels(accountState, ACCRUED_EXPENSE_ACCOUNT_LABELS);
45
- const allAccountList = getAccountList(accountState, accountListState, accountType.accountListKey);
46
- const nestedAccountHierarchy = getNestedAccountListHierarchy(accountListState, accountType.accountListKey);
47
- const debitAccounts = allAccountList.accounts.filter((account) => accrualAccountIds.includes(account.accountId) &&
48
- !accruedCategoryIds.includes(account.accountId));
49
- const creditAccounts = allAccountList.accounts.filter((account) => accruedCategoryIds.includes(account.accountId));
50
- const allClassList = getClassList(classState, classListState);
51
- return {
52
- accountListNestedAccountHierarchy: filterNestedAccountHierarchyById(nestedAccountHierarchy, debitAccounts.map((account) => account.accountId)),
53
- accruedAccountListNestedAccountHierarchy: filterNestedAccountHierarchyById(nestedAccountHierarchy, creditAccounts.map((account) => account.accountId)),
54
- allAccountList: debitAccounts,
55
- allAccruedExpenseList: creditAccounts,
56
- allClassList: allClassList.classes,
57
- classListNestedAccountHierarchy: getNestedClassListHierarchy(classListState),
58
- createStatus: newSchedule.createOneTimeAccrualStatus,
59
- // The recurring accrued schedule saves through the accrued detail epics that the Vendor tab
60
- // already uses, so its status is that slice's updateStatus rather than anything new here.
61
- accruedScheduleSaveStatus: state.scheduleAccruedDetailState.updateStatus,
62
- };
63
- };
64
- export const getNewScheduleView = (state, scheduleType) => {
65
- const { accountState, accountListState, classState, classListState } = state;
66
- const { newSchedule } = state.expenseAutomationJESchedulesViewState;
67
- const searchTransactionsView = getNewScheduleSearchTransactionsView(state);
68
- const accountType = getAccountsTypesForScheduleEpics();
69
- const newScheduleAccountTypes = getAccountsTypesForScheduleDetails(scheduleType);
70
- const newScheduleAccountIds = getAccountIdsForTypes(accountState, newScheduleAccountTypes);
71
- const allAccountList = getAccountList(accountState, accountListState, accountType.accountListKey);
72
- const filteredAccounts = allAccountList.accounts.filter((account) => newScheduleAccountIds.includes(account.accountId));
73
- const accountListNestedAccountHierarchy = filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), filteredAccounts.map((account) => account.accountId));
74
- const allClassList = getClassList(classState, classListState);
75
- const classListNestedAccountHierarchy = getNestedClassListHierarchy(classListState);
76
- let allDepreciationAccountList;
77
- let allDepreciationAccountListNestedAccountHierarchy;
78
- if (scheduleType === 'fixed_assets') {
79
- const depreciationCategoryIds = getAccountIdsForTypes(accountState, [
80
- 'fixed_assets',
81
- 'other_assets',
82
- ]);
83
- const accountLabel = getAccountLabelForScheduleType('fixed_assets');
84
- const fixedAssetLabelAccountIds = accountLabel != null
85
- ? getAccountIdsForLabel(accountListState, accountType.accountListKey, accountLabel)
86
- : [];
87
- allDepreciationAccountList = allAccountList.accounts.filter((account) => depreciationCategoryIds.includes(account.accountId) &&
88
- !fixedAssetLabelAccountIds.includes(account.accountId));
89
- allDepreciationAccountListNestedAccountHierarchy =
90
- filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), allDepreciationAccountList.map((account) => account.accountId));
91
- }
92
- return {
93
- scheduleType,
94
- accountListNestedAccountHierarchy,
95
- allAccountList: filteredAccounts,
96
- allClassList: allClassList.classes,
97
- allDepreciationAccountList,
98
- allDepreciationAccountListNestedAccountHierarchy,
99
- classListNestedAccountHierarchy,
100
- newScheduleLocalData: newSchedule.newScheduleState[scheduleType],
101
- saveStatus: newSchedule.saveStatus,
102
- ...searchTransactionsView,
103
- fetchState: newSchedule.fetchState,
104
- error: newSchedule.error,
105
- };
106
- };
@@ -1,21 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateJEOneTimeAccruals } from '../../../../entity/jeSchedules/jeSchedulesReducer';
4
- import { RootState } from '../../../../reducer';
5
- import { clearAll } from '../../../../rootActions';
6
- import { ZeniAPI } from '../../../../zeniAPI';
7
- import { fetchOneTimeAccrual, fetchOneTimeAccrualFailure, fetchOneTimeAccrualSuccess } from '../../reducers/jeSchedulesViewReducer';
8
- export type ActionType = ReturnType<typeof clearAll> | ReturnType<typeof fetchOneTimeAccrual> | ReturnType<typeof fetchOneTimeAccrualFailure> | ReturnType<typeof fetchOneTimeAccrualSuccess> | ReturnType<typeof updateJEOneTimeAccruals>;
9
- /**
10
- * Read one accrual by id so its detail page can render from a URL alone.
11
- *
12
- * Every other row on this page arrives with the JE Schedules list, and the accrual detail page used
13
- * to render only from what that list had already put in the store -- so opening its URL directly, on
14
- * a refresh or a shared link, had nothing to render and showed not-found. This is the read that
15
- * makes the URL self-sufficient.
16
- *
17
- * The response is the same `{accrual}` envelope promote / ignore / revert return, and it goes through
18
- * the same `updateJEOneTimeAccruals`, so a page loaded cold holds exactly the entity a page reached
19
- * through the list holds.
20
- */
21
- export declare const fetchOneTimeAccrualEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchOneTimeAccrualEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const jeSchedulesReducer_1 = require("../../../../entity/jeSchedules/jeSchedulesReducer");
7
- const responsePayload_1 = require("../../../../responsePayload");
8
- const rootActions_1 = require("../../../../rootActions");
9
- const jeSchedulesViewReducer_1 = require("../../reducers/jeSchedulesViewReducer");
10
- /**
11
- * Read one accrual by id so its detail page can render from a URL alone.
12
- *
13
- * Every other row on this page arrives with the JE Schedules list, and the accrual detail page used
14
- * to render only from what that list had already put in the store -- so opening its URL directly, on
15
- * a refresh or a shared link, had nothing to render and showed not-found. This is the read that
16
- * makes the URL self-sufficient.
17
- *
18
- * The response is the same `{accrual}` envelope promote / ignore / revert return, and it goes through
19
- * the same `updateJEOneTimeAccruals`, so a page loaded cold holds exactly the entity a page reached
20
- * through the list holds.
21
- */
22
- const fetchOneTimeAccrualEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.fetchOneTimeAccrual.match), (0, operators_1.mergeMap)((action) => {
23
- const { accrualId } = action.payload;
24
- return zeniAPI
25
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accruals/${accrualId}`)
26
- .pipe((0, operators_1.mergeMap)((response) => {
27
- if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
28
- return (0, rxjs_1.from)([
29
- (0, jeSchedulesReducer_1.updateJEOneTimeAccruals)([response.data.accrual]),
30
- (0, jeSchedulesViewReducer_1.fetchOneTimeAccrualSuccess)({ accrualId }),
31
- ]);
32
- }
33
- // A deleted or ignored accrual answers 404 here, the same as an id that never existed.
34
- // Both end as an error state the page turns into not-found, rather than a spinner that
35
- // never resolves.
36
- return (0, rxjs_1.from)([
37
- (0, jeSchedulesViewReducer_1.fetchOneTimeAccrualFailure)({ accrualId, status: response.status }),
38
- ]);
39
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.from)([
40
- (0, jeSchedulesViewReducer_1.fetchOneTimeAccrualFailure)({
41
- accrualId,
42
- status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Fetch one-time accrual REST API call errored out ${JSON.stringify(error)}`),
43
- }),
44
- ])),
45
- // A tenant switch clears the store while this request is in flight. Without this the old
46
- // tenant's accrual is written back into the freshly cleared store.
47
- (0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))));
48
- }));
49
- exports.fetchOneTimeAccrualEpic = fetchOneTimeAccrualEpic;