@zeniai/client-epic-state 5.1.61 → 5.1.62-betaRD2
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/coreEpics.js +3 -2
- package/lib/entity/chargeCard/chargeCard.d.ts +1 -1
- package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +2 -0
- package/lib/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +4 -0
- package/lib/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -0
- package/lib/entity/notificationRegistry/notificationRegistryPayload.d.ts +18 -0
- package/lib/entity/notificationRegistry/notificationRegistryPayload.js +28 -0
- package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +10 -0
- package/lib/entity/notificationRegistry/notificationRegistryReducer.js +50 -0
- package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +2 -0
- package/lib/entity/notificationRegistry/notificationRegistrySelector.js +10 -0
- package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +32 -0
- package/lib/entity/notificationRegistry/notificationRegistryState.js +10 -0
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/entity/tenant/clearAllEpic.d.ts +3 -1
- package/lib/entity/tenant/clearAllEpic.js +4 -0
- package/lib/entity/tenant/tenantReducer.d.ts +4 -1
- package/lib/entity/tenant/tenantReducer.js +8 -2
- package/lib/entity/tenant/tenantSelector.d.ts +1 -0
- package/lib/entity/tenant/tenantSelector.js +4 -0
- package/lib/entity/transaction/scheduleTransactionHelper.d.ts +15 -0
- package/lib/entity/transaction/scheduleTransactionHelper.js +43 -0
- package/lib/epic.d.ts +9 -1
- package/lib/epic.js +9 -1
- package/lib/esm/coreEpics.js +3 -2
- package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +2 -0
- package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +11 -1
- package/lib/esm/entity/notificationRegistry/notificationRegistryPayload.js +24 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +46 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +6 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +5 -0
- package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
- package/lib/esm/entity/tenant/clearAllEpic.js +4 -0
- package/lib/esm/entity/tenant/tenantReducer.js +7 -1
- package/lib/esm/entity/tenant/tenantSelector.js +3 -0
- package/lib/esm/entity/transaction/scheduleTransactionHelper.js +39 -0
- package/lib/esm/epic.js +9 -1
- package/lib/esm/index.js +14 -6
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/companyView/companyViewReducer.js +68 -1
- package/lib/esm/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +56 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +37 -0
- package/lib/esm/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +73 -0
- package/lib/esm/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/esm/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/esm/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +15 -2
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +21 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +110 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +44 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +22 -0
- package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +152 -0
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +126 -6
- package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +1 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +71 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +78 -11
- package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +3 -6
- package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +116 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesEndpoint.js +5 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewPayload.js +36 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +222 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +25 -0
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewState.js +4 -0
- package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +34 -2
- package/lib/esm/view/settingsView/epic/saveNotificationSettingsEpic.js +2 -1
- package/lib/esm/view/settingsView/settingsViewHelpers.js +3 -2
- package/lib/index.d.ts +17 -8
- package/lib/index.js +85 -47
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/view/common/recurringViewHelper.d.ts +2 -2
- package/lib/view/companyView/companyViewReducer.d.ts +9 -1
- package/lib/view/companyView/companyViewReducer.js +70 -3
- package/lib/view/companyView/epic/companyPassport/dismissCapitalizationOnboardingEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.d.ts +10 -0
- package/lib/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js +60 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.d.ts +11 -0
- package/lib/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js +41 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.d.ts +13 -0
- package/lib/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js +77 -0
- package/lib/view/companyView/epic/companyPassport/updateAccountingClassesEnabledEpic.js +2 -1
- package/lib/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js +2 -1
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.d.ts +2 -0
- package/lib/view/companyView/types/companyPassport/companyPassportViewState.js +5 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +14 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +25 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +45 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +114 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +8 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +48 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +6 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +26 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +43 -0
- package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +158 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +36 -8
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +128 -7
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +25 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +2 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +29 -4
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +10 -0
- package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +76 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.d.ts +1 -0
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +80 -11
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +53 -6
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +5 -8
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.d.ts +40 -0
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +120 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.d.ts +2 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesEndpoint.js +9 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.d.ts +7 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewPayload.js +41 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +30 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +226 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +7 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +32 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +14 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.js +8 -0
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.d.ts +9 -1
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +34 -2
- package/lib/view/settingsView/epic/saveNotificationSettingsEpic.js +2 -1
- package/lib/view/settingsView/settingsViewHelpers.d.ts +1 -1
- package/lib/view/settingsView/settingsViewHelpers.js +3 -2
- package/lib/view/settingsView/settingsViewPayload.d.ts +4 -0
- package/lib/view/settingsView/settingsViewState.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/view/companyView/epic/companyPassport/projects/disableAccountingProjectsEpic.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { updateCompanies } from '../../../../../entity/company/companyReducer';
|
|
4
|
+
import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
|
|
5
|
+
import { updateTenantAccountingProjectsEnabled } from '../../../../../entity/tenant/tenantReducer';
|
|
6
|
+
import { getTenantIdByCompanyId } from '../../../../../entity/tenant/tenantSelector';
|
|
7
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
8
|
+
import { disableAccountingProjects, updateAccountingProjectsEnabledFailure, updateAccountingProjectsEnabledSuccess, } from '../../../companyViewReducer';
|
|
9
|
+
export const disableAccountingProjectsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(disableAccountingProjects.match), switchMap((action) => {
|
|
10
|
+
const { companyId } = action.payload;
|
|
11
|
+
const tenantId = getTenantIdByCompanyId(state$.value.tenantState, companyId);
|
|
12
|
+
return zeniAPI
|
|
13
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/companies/${companyId}`, { is_accounting_projects_enabled: false })
|
|
14
|
+
.pipe(mergeMap((response) => {
|
|
15
|
+
const companies = response.data?.companies ?? [];
|
|
16
|
+
if (isSuccessResponse(response) && companies.length > 0) {
|
|
17
|
+
const actions = [
|
|
18
|
+
updateCompanies({
|
|
19
|
+
payload: companies,
|
|
20
|
+
schema: {},
|
|
21
|
+
}),
|
|
22
|
+
];
|
|
23
|
+
if (tenantId != null) {
|
|
24
|
+
actions.push(updateTenantAccountingProjectsEnabled({
|
|
25
|
+
enabled: false,
|
|
26
|
+
tenantId,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
actions.push(updateAccountingProjectsEnabledSuccess());
|
|
30
|
+
actions.push(openSnackbar({
|
|
31
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
32
|
+
messageText: 'success',
|
|
33
|
+
type: 'success',
|
|
34
|
+
}));
|
|
35
|
+
return from(actions);
|
|
36
|
+
}
|
|
37
|
+
return from([
|
|
38
|
+
updateAccountingProjectsEnabledFailure({
|
|
39
|
+
status: response.status,
|
|
40
|
+
}),
|
|
41
|
+
openSnackbar({
|
|
42
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
43
|
+
messageText: 'failed',
|
|
44
|
+
type: 'error',
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
47
|
+
}), catchError((error) => of(updateAccountingProjectsEnabledFailure({
|
|
48
|
+
status: createZeniAPIStatus('Unexpected error', `Update Accounting Projects Enabled errored out - ${error instanceof Error
|
|
49
|
+
? error.message
|
|
50
|
+
: JSON.stringify(error)}`),
|
|
51
|
+
}), openSnackbar({
|
|
52
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
53
|
+
messageText: 'failed',
|
|
54
|
+
type: 'error',
|
|
55
|
+
}))));
|
|
56
|
+
}));
|
package/lib/esm/view/companyView/epic/companyPassport/projects/enableAccountingProjectsEpic.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
5
|
+
import { enableAccountingProjects, requestQboProjectsReconnect, resumeEnableAccountingProjects, updateAccountingProjectsEnabledFailure, } from '../../../companyViewReducer';
|
|
6
|
+
export const enableAccountingProjectsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(enableAccountingProjects.match), switchMap((action) => {
|
|
7
|
+
const { companyId } = action.payload;
|
|
8
|
+
return zeniAPI
|
|
9
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accounting_provider_project_authorization_status`)
|
|
10
|
+
.pipe(mergeMap((response) => {
|
|
11
|
+
if (!isSuccessResponse(response) || response.data == null) {
|
|
12
|
+
return from([
|
|
13
|
+
updateAccountingProjectsEnabledFailure({
|
|
14
|
+
status: response.status,
|
|
15
|
+
}),
|
|
16
|
+
openSnackbar({
|
|
17
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
18
|
+
messageText: 'failed',
|
|
19
|
+
type: 'error',
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
if (response.data.is_accounting_provider_project_apis_authorized !==
|
|
24
|
+
true) {
|
|
25
|
+
return from([requestQboProjectsReconnect()]);
|
|
26
|
+
}
|
|
27
|
+
return from([resumeEnableAccountingProjects(companyId)]);
|
|
28
|
+
}), catchError((error) => of(updateAccountingProjectsEnabledFailure({
|
|
29
|
+
status: createZeniAPIStatus('Unexpected error', `Accounting provider project authorization status errored out - ${error instanceof Error
|
|
30
|
+
? error.message
|
|
31
|
+
: JSON.stringify(error)}`),
|
|
32
|
+
}), openSnackbar({
|
|
33
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
34
|
+
messageText: 'failed',
|
|
35
|
+
type: 'error',
|
|
36
|
+
}))));
|
|
37
|
+
}));
|
package/lib/esm/view/companyView/epic/companyPassport/projects/resumeEnableAccountingProjectsEpic.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { updateTenantAccountingProjectsEnabled } from '../../../../../entity/tenant/tenantReducer';
|
|
5
|
+
import { getTenantIdByCompanyId } from '../../../../../entity/tenant/tenantSelector';
|
|
6
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
7
|
+
import { resumeEnableAccountingProjects, updateAccountingProjectsEnabledFailure, updateAccountingProjectsEnabledSuccess, } from '../../../companyViewReducer';
|
|
8
|
+
export const resumeEnableAccountingProjectsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(resumeEnableAccountingProjects.match), switchMap((action) => {
|
|
9
|
+
const { companyId } = action.payload;
|
|
10
|
+
const tenantId = getTenantIdByCompanyId(state$.value.tenantState, companyId);
|
|
11
|
+
if (tenantId == null) {
|
|
12
|
+
return from([
|
|
13
|
+
updateAccountingProjectsEnabledFailure({
|
|
14
|
+
status: createZeniAPIStatus('Unexpected error', 'Tenant not found for company'),
|
|
15
|
+
}),
|
|
16
|
+
openSnackbar({
|
|
17
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
18
|
+
messageText: 'failed',
|
|
19
|
+
type: 'error',
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
return zeniAPI
|
|
24
|
+
.putAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accounting_provider_project_enablement_status`)
|
|
25
|
+
.pipe(mergeMap((response) => {
|
|
26
|
+
if (!isSuccessResponse(response) || response.data == null) {
|
|
27
|
+
return from([
|
|
28
|
+
updateAccountingProjectsEnabledFailure({
|
|
29
|
+
status: response.status,
|
|
30
|
+
}),
|
|
31
|
+
openSnackbar({
|
|
32
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
33
|
+
messageText: 'failed',
|
|
34
|
+
type: 'error',
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
if (response.data.is_accounting_provider_project_apis_enabled !==
|
|
39
|
+
true ||
|
|
40
|
+
response.data.is_accounting_projects_enabled !== true) {
|
|
41
|
+
return from([
|
|
42
|
+
updateAccountingProjectsEnabledFailure({
|
|
43
|
+
status: createZeniAPIStatus('Projects not enabled in QBO', 'Please enable projects in QBO before enabling in the Zeni dashboard!'),
|
|
44
|
+
}),
|
|
45
|
+
openSnackbar({
|
|
46
|
+
messageSection: 'accounting_projects_qbo_not_enabled',
|
|
47
|
+
messageText: 'failed',
|
|
48
|
+
type: 'error',
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
return from([
|
|
53
|
+
updateTenantAccountingProjectsEnabled({
|
|
54
|
+
enabled: true,
|
|
55
|
+
tenantId,
|
|
56
|
+
}),
|
|
57
|
+
updateAccountingProjectsEnabledSuccess(),
|
|
58
|
+
openSnackbar({
|
|
59
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
60
|
+
messageText: 'success',
|
|
61
|
+
type: 'success',
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
}), catchError((error) => of(updateAccountingProjectsEnabledFailure({
|
|
65
|
+
status: createZeniAPIStatus('Unexpected error', `Accounting provider project enablement status errored out - ${error instanceof Error
|
|
66
|
+
? error.message
|
|
67
|
+
: JSON.stringify(error)}`),
|
|
68
|
+
}), openSnackbar({
|
|
69
|
+
messageSection: 'accounting_projects_enabled_update',
|
|
70
|
+
messageText: 'failed',
|
|
71
|
+
type: 'error',
|
|
72
|
+
}))));
|
|
73
|
+
}));
|
|
@@ -3,11 +3,12 @@ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
|
3
3
|
import { updateCompanies } from '../../../../entity/company/companyReducer';
|
|
4
4
|
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
5
5
|
import { updateTenantAccountingClassesEnabled } from '../../../../entity/tenant/tenantReducer';
|
|
6
|
+
import { getTenantIdByCompanyId } from '../../../../entity/tenant/tenantSelector';
|
|
6
7
|
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
7
8
|
import { updateAccountingClassesEnabled, updateAccountingClassesEnabledFailure, updateAccountingClassesEnabledSuccess, } from '../../companyViewReducer';
|
|
8
9
|
export const updateAccountingClassesEnabledEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(updateAccountingClassesEnabled.match), switchMap((action) => {
|
|
9
10
|
const { companyId, enabled } = action.payload;
|
|
10
|
-
const tenantId =
|
|
11
|
+
const tenantId = getTenantIdByCompanyId(state$.value.tenantState, companyId);
|
|
11
12
|
return zeniAPI
|
|
12
13
|
.putAndGetJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/companies/${companyId}`, { is_accounting_classes_enabled: enabled })
|
|
13
14
|
.pipe(mergeMap((response) => {
|
package/lib/esm/view/companyView/epic/companyPassport/updateCapitalizationAccountThresholdEpic.js
CHANGED
|
@@ -3,11 +3,12 @@ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
|
3
3
|
import { updateCompanies } from '../../../../entity/company/companyReducer';
|
|
4
4
|
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
5
5
|
import { updateTenantCapitalizationAccountOverride, updateTenantCapitalizationOnboardingDismissed, } from '../../../../entity/tenant/tenantReducer';
|
|
6
|
+
import { getTenantIdByCompanyId } from '../../../../entity/tenant/tenantSelector';
|
|
6
7
|
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
7
8
|
import { updateCapitalizationAccountThreshold, updateCapitalizationAccountThresholdFailure, updateCapitalizationAccountThresholdSuccess, } from '../../companyViewReducer';
|
|
8
9
|
export const updateCapitalizationAccountThresholdEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(updateCapitalizationAccountThreshold.match), switchMap((action) => {
|
|
9
10
|
const { companyId, accountId, threshold, dismissOnboardingForAccount, allOverrides, } = action.payload;
|
|
10
|
-
const tenantId =
|
|
11
|
+
const tenantId = getTenantIdByCompanyId(state$.value.tenantState, companyId);
|
|
11
12
|
let finalOverrides;
|
|
12
13
|
if (allOverrides !== undefined) {
|
|
13
14
|
finalOverrides = allOverrides ?? {};
|
|
@@ -5,10 +5,15 @@ export const initialCompanyPassportView = {
|
|
|
5
5
|
fetchState: 'Not-Started',
|
|
6
6
|
error: undefined,
|
|
7
7
|
},
|
|
8
|
+
accountingProjectsUpdateStatus: {
|
|
9
|
+
fetchState: 'Not-Started',
|
|
10
|
+
error: undefined,
|
|
11
|
+
},
|
|
8
12
|
capitalizationThresholdUpdateStatus: {
|
|
9
13
|
fetchState: 'Not-Started',
|
|
10
14
|
error: undefined,
|
|
11
15
|
},
|
|
16
|
+
needsQboProjectsReconnect: false,
|
|
12
17
|
companyDetails: {
|
|
13
18
|
localData: undefined,
|
|
14
19
|
updateStatus: {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { from, of } from 'rxjs';
|
|
2
2
|
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_DATE_FORMAT } from '../../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
|
|
4
|
+
import { toAbsoluteDay, toString } from '../../../../commonStateTypes/timePeriod';
|
|
4
5
|
import { updateJESchedules, updateJESchedulesDetails, } from '../../../../entity/jeSchedules/jeSchedulesReducer';
|
|
5
6
|
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
6
7
|
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
8
|
+
import { date } from '../../../../zeniDayJS';
|
|
7
9
|
import { fetchJeSchedules, fetchJeSchedulesFailure, fetchJeSchedulesSuccess, initializeJeScheduleLocalData, } from '../../reducers/jeSchedulesViewReducer';
|
|
8
10
|
export const fetchJeSchedulesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchJeSchedules.match), mergeMap((action) => {
|
|
9
11
|
const state = state$.value;
|
|
@@ -11,9 +13,20 @@ export const fetchJeSchedulesEpic = (actions$, state$, zeniAPI) => actions$.pipe
|
|
|
11
13
|
const { period, refreshViewInBackground } = action.payload;
|
|
12
14
|
const currentTenant = getCurrentTenant(state);
|
|
13
15
|
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
16
|
+
const isClosePeriodTab = state.expenseAutomationJESchedulesViewState.uiState.selectedPageTab ===
|
|
17
|
+
'schedules';
|
|
18
|
+
const existingEndDate = toAbsoluteDay(date(toString(period.start))
|
|
19
|
+
.subtract(1, 'month')
|
|
20
|
+
.endOf('month')
|
|
21
|
+
.format(DEFAULT_DATE_FORMAT));
|
|
14
22
|
const queryParam = {
|
|
15
23
|
start_date: toString(period.start),
|
|
16
|
-
end_date:
|
|
24
|
+
end_date: isClosePeriodTab || existingEndDate == null
|
|
25
|
+
? toString(period.end)
|
|
26
|
+
: toString(existingEndDate),
|
|
27
|
+
...(isClosePeriodTab
|
|
28
|
+
? { close_period_start_date: toString(period.start) }
|
|
29
|
+
: {}),
|
|
17
30
|
};
|
|
18
31
|
return zeniAPI
|
|
19
32
|
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expenses_automation/je_schedules?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { fetchAccountList } from '../../../../accountList/accountListReducer';
|
|
4
|
+
import { fetchClassList } from '../../../../classList/classListReducer';
|
|
5
|
+
import { getAccountsTypesForScheduleEpics } from '../../../../scheduleView/scheduleListView/scheduleListHelper';
|
|
6
|
+
import { clearSearchTransactionsForNewSchedule, initializeNewSchedule, resetNewScheduleLocalData, } from '../../../reducers/jeSchedulesViewReducer';
|
|
7
|
+
export const initializeNewScheduleEpic = (actions$, state$) => actions$.pipe(filter(initializeNewSchedule.match), mergeMap((action) => {
|
|
8
|
+
const newScheduleActions = [];
|
|
9
|
+
const accountType = getAccountsTypesForScheduleEpics();
|
|
10
|
+
const { accountListState, classListState } = state$.value;
|
|
11
|
+
if (accountListState.byReportId[accountType.accountListKey]?.fetchState ===
|
|
12
|
+
'Not-Started') {
|
|
13
|
+
newScheduleActions.push(fetchAccountList(accountType.accountListKey, true, false, false, false, accountType.allowedAccountList));
|
|
14
|
+
}
|
|
15
|
+
if (classListState.fetchState === 'Not-Started') {
|
|
16
|
+
newScheduleActions.push(fetchClassList());
|
|
17
|
+
}
|
|
18
|
+
newScheduleActions.push(resetNewScheduleLocalData({ scheduleType: action.payload.scheduleType }));
|
|
19
|
+
newScheduleActions.push(clearSearchTransactionsForNewSchedule());
|
|
20
|
+
return from(newScheduleActions);
|
|
21
|
+
}));
|
package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { updateJESchedules, updateJESchedulesDetails, } from '../../../../../entity/jeSchedules/jeSchedulesReducer';
|
|
4
|
+
import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
|
|
5
|
+
import { getSupportedTransactionById } from '../../../../../entity/transaction/transactionSelector';
|
|
6
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
7
|
+
import { prepareNewSchedulePayload, } from '../../../helpers/newScheduleLocalDataHelper';
|
|
8
|
+
import { resetNewScheduleLocalData, saveNewSchedule, saveNewScheduleFailure, saveNewScheduleSuccess, } from '../../../reducers/jeSchedulesViewReducer';
|
|
9
|
+
const FAILURE_REASON_MESSAGES = {
|
|
10
|
+
multi_line_not_supported: 'This transaction has multiple lines and cannot be scheduled yet.',
|
|
11
|
+
missing_third_party_id: 'This transaction is missing a QuickBooks reference and cannot be scheduled.',
|
|
12
|
+
missing_vendor: 'Select a vendor before saving this schedule.',
|
|
13
|
+
};
|
|
14
|
+
export const saveNewScheduleEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveNewSchedule.match), mergeMap((action) => {
|
|
15
|
+
const { scheduleType } = action.payload;
|
|
16
|
+
const state = state$.value;
|
|
17
|
+
const localData = state.expenseAutomationJESchedulesViewState.newSchedule
|
|
18
|
+
.newScheduleState[scheduleType];
|
|
19
|
+
const transactionId = localData.selectedBaseTransactionId?.id;
|
|
20
|
+
const transaction = transactionId != null
|
|
21
|
+
? getSupportedTransactionById(state.transactionState, transactionId)
|
|
22
|
+
: undefined;
|
|
23
|
+
if (transaction == null) {
|
|
24
|
+
return from([
|
|
25
|
+
saveNewScheduleFailure({
|
|
26
|
+
status: createZeniAPIStatus('Unexpected Error', 'No base transaction selected for this schedule.'),
|
|
27
|
+
}),
|
|
28
|
+
openSnackbar({
|
|
29
|
+
messageSection: 'create_schedule',
|
|
30
|
+
messageText: 'failed',
|
|
31
|
+
type: 'error',
|
|
32
|
+
variables: [
|
|
33
|
+
{
|
|
34
|
+
variableName: '_api-error_',
|
|
35
|
+
variableValue: 'No base transaction selected.',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
const result = prepareNewSchedulePayload(transaction, localData, scheduleType);
|
|
42
|
+
if (!result.ok) {
|
|
43
|
+
const message = FAILURE_REASON_MESSAGES[result.reason];
|
|
44
|
+
return from([
|
|
45
|
+
saveNewScheduleFailure({
|
|
46
|
+
status: createZeniAPIStatus('Unexpected Error', message),
|
|
47
|
+
}),
|
|
48
|
+
openSnackbar({
|
|
49
|
+
messageSection: 'create_schedule',
|
|
50
|
+
messageText: 'failed',
|
|
51
|
+
type: 'error',
|
|
52
|
+
variables: [{ variableName: '_api-error_', variableValue: message }],
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
|
|
57
|
+
const queryParam = {
|
|
58
|
+
je_schedule_type: scheduleType,
|
|
59
|
+
};
|
|
60
|
+
const payload = { ...result.payload };
|
|
61
|
+
return zeniAPI
|
|
62
|
+
.postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules?query=${encodeURIComponent(JSON.stringify(queryParam))}`, payload)
|
|
63
|
+
.pipe(mergeMap((response) => {
|
|
64
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
65
|
+
return from([
|
|
66
|
+
updateJESchedules(response.data.je_schedules),
|
|
67
|
+
updateJESchedulesDetails(response.data.je_schedules, response.data.scheduled_journal_entries),
|
|
68
|
+
resetNewScheduleLocalData({ scheduleType }),
|
|
69
|
+
saveNewScheduleSuccess(),
|
|
70
|
+
openSnackbar({
|
|
71
|
+
messageSection: 'create_schedule',
|
|
72
|
+
messageText: 'success',
|
|
73
|
+
type: 'success',
|
|
74
|
+
variables: [
|
|
75
|
+
{ variableName: '_vendor_name_', variableValue: vendorName },
|
|
76
|
+
],
|
|
77
|
+
}),
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
return from([
|
|
81
|
+
saveNewScheduleFailure({ status: response.status }),
|
|
82
|
+
openSnackbar({
|
|
83
|
+
messageSection: 'create_schedule',
|
|
84
|
+
messageText: 'failed',
|
|
85
|
+
type: 'error',
|
|
86
|
+
variables: [
|
|
87
|
+
{
|
|
88
|
+
variableName: '_api-error_',
|
|
89
|
+
variableValue: response.status.message,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}),
|
|
93
|
+
]);
|
|
94
|
+
}), catchError((error) => from([
|
|
95
|
+
openSnackbar({
|
|
96
|
+
messageSection: 'create_schedule',
|
|
97
|
+
messageText: 'failed',
|
|
98
|
+
type: 'error',
|
|
99
|
+
variables: [
|
|
100
|
+
{
|
|
101
|
+
variableName: '_api-error_',
|
|
102
|
+
variableValue: JSON.stringify(error),
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
saveNewScheduleFailure({
|
|
107
|
+
status: createZeniAPIStatus('Unexpected Error', `Save New Schedule REST API call errored out ${JSON.stringify(error)}`),
|
|
108
|
+
}),
|
|
109
|
+
])));
|
|
110
|
+
}));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EMPTY, from, merge, of } from 'rxjs';
|
|
2
|
+
import { catchError, debounceTime, filter, mergeMap, switchMap, } from 'rxjs/operators';
|
|
3
|
+
import { updateTransactions } from '../../../../../entity/transaction/transactionReducer';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
5
|
+
import { searchTransactionsForNewSchedule, searchTransactionsForNewScheduleFailure, searchTransactionsForNewScheduleSuccess, } from '../../../reducers/jeSchedulesViewReducer';
|
|
6
|
+
import { MIN_NEW_SCHEDULE_SEARCH_LENGTH } from '../../../types/jeSchedulesViewState';
|
|
7
|
+
/** Dropdown-sized result set — no pagination for Base Transaction search. */
|
|
8
|
+
const NEW_SCHEDULE_SEARCH_PAGE_SIZE = 10;
|
|
9
|
+
export const searchTransactionsForNewScheduleEpic = (actions$, _state$, zeniAPI) => {
|
|
10
|
+
const searchActions$ = actions$.pipe(filter(searchTransactionsForNewSchedule.match));
|
|
11
|
+
/** No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP. */
|
|
12
|
+
const newSearchTooShortOrClear$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length < MIN_NEW_SCHEDULE_SEARCH_LENGTH));
|
|
13
|
+
const newSearchDebounced$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length >= MIN_NEW_SCHEDULE_SEARCH_LENGTH), debounceTime(300));
|
|
14
|
+
return merge(newSearchTooShortOrClear$, newSearchDebounced$).pipe(switchMap((action) => {
|
|
15
|
+
const query = action.payload.query.trim();
|
|
16
|
+
if (query.length < MIN_NEW_SCHEDULE_SEARCH_LENGTH) {
|
|
17
|
+
return EMPTY;
|
|
18
|
+
}
|
|
19
|
+
const queryParam = {
|
|
20
|
+
page_size: NEW_SCHEDULE_SEARCH_PAGE_SIZE,
|
|
21
|
+
search_text: query,
|
|
22
|
+
};
|
|
23
|
+
return zeniAPI
|
|
24
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/schedules/base_transaction_search?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
25
|
+
.pipe(mergeMap((response) => {
|
|
26
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
27
|
+
const { transactions } = response.data;
|
|
28
|
+
const actionsOut = [
|
|
29
|
+
updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
|
|
30
|
+
searchTransactionsForNewScheduleSuccess({
|
|
31
|
+
searchResults: transactions.map((transaction) => transaction.transaction_id),
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
return from(actionsOut);
|
|
35
|
+
}
|
|
36
|
+
return of(searchTransactionsForNewScheduleFailure({
|
|
37
|
+
status: response.status,
|
|
38
|
+
}));
|
|
39
|
+
}), catchError((error) => of(searchTransactionsForNewScheduleFailure({
|
|
40
|
+
status: createZeniAPIStatus('Unexpected Error', 'Search transactions for new schedule errored: ' +
|
|
41
|
+
JSON.stringify(error)),
|
|
42
|
+
}))));
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EMPTY, of } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
|
|
5
|
+
import { fetchJeSchedulesPage, updateJESchedulesUIState, } from '../../reducers/jeSchedulesViewReducer';
|
|
6
|
+
export const switchJESchedulesTabEpic = (actions$, state$) => actions$.pipe(filter(updateJESchedulesUIState.match), filter((action) => action.payload.selectedPageTab != null), mergeMap(() => {
|
|
7
|
+
const state = state$.value;
|
|
8
|
+
const { fetchState, refreshStatus } = state.expenseAutomationJESchedulesViewState;
|
|
9
|
+
if (fetchState === 'In-Progress' ||
|
|
10
|
+
refreshStatus.fetchState === 'In-Progress') {
|
|
11
|
+
return EMPTY;
|
|
12
|
+
}
|
|
13
|
+
const currentTenant = getCurrentTenant(state);
|
|
14
|
+
const selectedPeriod = state.expenseAutomationViewState.selectedPeriodByTenantId[currentTenant.tenantId];
|
|
15
|
+
const period = convertToPeriod(selectedPeriod);
|
|
16
|
+
const timePeriodStart = toAbsoluteDay(period.start);
|
|
17
|
+
const timePeriodEnd = toAbsoluteDay(period.end);
|
|
18
|
+
if (timePeriodStart == null || timePeriodEnd == null) {
|
|
19
|
+
return EMPTY;
|
|
20
|
+
}
|
|
21
|
+
return of(fetchJeSchedulesPage({ start: timePeriodStart, end: timePeriodEnd }, true));
|
|
22
|
+
}));
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { toAmount } from '../../../commonStateTypes/amount';
|
|
2
|
+
import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
|
|
3
|
+
import { MONTH_YEAR_FORMAT } from '../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY';
|
|
4
|
+
import { LAST_SCHEDULE_DAY_OF_MONTH } from '../../../commonStateTypes/timePeriod';
|
|
5
|
+
import { mapSupportedTransactionLineToScheduleTransaction } from '../../../entity/transaction/scheduleTransactionHelper';
|
|
6
|
+
import { getPostingDateAndStatusForIndex } from '../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper';
|
|
7
|
+
import { mapScheduleTransactionToBaseScheduleTransactionPayload, } from '../../scheduleView/scheduleDetailView/scheduleDetailPayload';
|
|
8
|
+
const getNewScheduleMemo = (vendorName, schedulePostingDate, currentPeriod, totalPeriod, assetId) => {
|
|
9
|
+
const addAsset = assetId != null && assetId !== '' ? ` - ${assetId}` : '';
|
|
10
|
+
return `${vendorName} - ${schedulePostingDate.format(MONTH_YEAR_FORMAT)} (${currentPeriod} of ${totalPeriod})${addAsset}`;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Computes the month-by-month JE schedule breakdown for a brand-new schedule
|
|
14
|
+
* (no linked transaction yet) — replicates createNewSchedulesHelper's math
|
|
15
|
+
* (scheduleDetailLocalDataHelper.ts) exactly: lump-sum total split evenly
|
|
16
|
+
* across months with the rounding remainder absorbed by the last month, and a
|
|
17
|
+
* running balance that decrements each month and is forced to exactly 0 on
|
|
18
|
+
* the last row.
|
|
19
|
+
*/
|
|
20
|
+
export const computeNewScheduleJeDetails = (localData, totalAmount, vendorName) => {
|
|
21
|
+
const period = localData.selectedMonths;
|
|
22
|
+
const startingMonth = localData.selectedDate;
|
|
23
|
+
if (startingMonth == null || period == null) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const assetId = 'assetId' in localData ? localData.assetId : undefined;
|
|
27
|
+
const averageAmount = Math.abs(Math.round((totalAmount.amount / period) * 100) / 100);
|
|
28
|
+
const lastMonthAmount = Math.abs(Math.round((Math.abs(totalAmount.amount) - averageAmount * (period - 1)) * 100) / 100);
|
|
29
|
+
let runningBalance = Math.abs(totalAmount.amount);
|
|
30
|
+
const negativeNumbers = totalAmount.amount < 0 || runningBalance < 0;
|
|
31
|
+
const newJeDetails = [];
|
|
32
|
+
for (let index = 0; index < period; index++) {
|
|
33
|
+
if (runningBalance > averageAmount) {
|
|
34
|
+
runningBalance = Math.round((runningBalance - averageAmount) * 100) / 100;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
runningBalance = 0;
|
|
38
|
+
}
|
|
39
|
+
const amount = index === period - 1 ? lastMonthAmount : averageAmount;
|
|
40
|
+
runningBalance = index === period - 1 ? 0 : runningBalance;
|
|
41
|
+
const schedulePostingDate = startingMonth.add(index, 'month');
|
|
42
|
+
const { postingDate, postingStatus } = getPostingDateAndStatusForIndex(schedulePostingDate.month(), schedulePostingDate.year(), localData.lastDayOfMonth === true
|
|
43
|
+
? undefined
|
|
44
|
+
: localData.selectedDayOfMonth);
|
|
45
|
+
newJeDetails.push({
|
|
46
|
+
postingDate,
|
|
47
|
+
amount: toAmount(negativeNumbers ? -amount : amount, totalAmount.currencyCode, totalAmount.currencySymbol),
|
|
48
|
+
runningBalance: toAmount(negativeNumbers ? -runningBalance : runningBalance, totalAmount.currencyCode, totalAmount.currencySymbol),
|
|
49
|
+
postingStatus,
|
|
50
|
+
memo: getNewScheduleMemo(vendorName, schedulePostingDate, index + 1, period, assetId),
|
|
51
|
+
jeLink: { type: 'unknown' },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return newJeDetails;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Whether a Base Transaction search result can be selected for a new
|
|
58
|
+
* schedule this round — restricted to single-line transactions since the
|
|
59
|
+
* search/list endpoint's `lines` may not reflect the transaction's full line
|
|
60
|
+
* set, and there is no line-picker UI yet.
|
|
61
|
+
*/
|
|
62
|
+
export const isSupportedTransactionSelectableForNewSchedule = (transaction) => transaction.totalLinesCount === 1 && transaction.lines?.length === 1;
|
|
63
|
+
const mapNewJeDetailsToScheduledJournalEntryPayload = (jeScheduleDetails) => jeScheduleDetails.map((journalEntry) => ({
|
|
64
|
+
status: {
|
|
65
|
+
code: journalEntry.postingStatus,
|
|
66
|
+
label: journalEntry.postingStatus,
|
|
67
|
+
},
|
|
68
|
+
transaction_memo: journalEntry.memo,
|
|
69
|
+
third_party_id: journalEntry.jeLink.thirdPartyTransactionId ?? null,
|
|
70
|
+
expected_post_date: journalEntry.postingDate.format(DEFAULT_DATE_FORMAT),
|
|
71
|
+
amount: journalEntry.amount.amount,
|
|
72
|
+
balance: journalEntry.runningBalance.amount,
|
|
73
|
+
// Brand-new schedule — there is no prior scheduled-journal-entry history
|
|
74
|
+
// to cross-reference (unlike the legacy edit flow's equivalent mapper).
|
|
75
|
+
scheduled_journal_entry_id: null,
|
|
76
|
+
actual_post_date: null,
|
|
77
|
+
is_platform_generated: null,
|
|
78
|
+
je_schedule_id: null,
|
|
79
|
+
update_time: null,
|
|
80
|
+
create_time: null,
|
|
81
|
+
}));
|
|
82
|
+
/**
|
|
83
|
+
* Builds a savable schedule payload directly from a Base Transaction search
|
|
84
|
+
* result and the New Schedule form's local data — bypassing the legacy
|
|
85
|
+
* getJEScheduledTransactionByJEScheduleTransactionKey selector entirely,
|
|
86
|
+
* since that selector throws unless the entity has already round-tripped
|
|
87
|
+
* through a real GET /1.0/schedules/:id. A brand-new schedule has no such
|
|
88
|
+
* history, so this reads only from data already in hand (the selected
|
|
89
|
+
* transaction/line plus what the user filled into the form).
|
|
90
|
+
*/
|
|
91
|
+
export const prepareNewSchedulePayload = (transaction, localData, scheduleType) => {
|
|
92
|
+
const [firstLine] = transaction.lines ?? [];
|
|
93
|
+
if (!isSupportedTransactionSelectableForNewSchedule(transaction) ||
|
|
94
|
+
firstLine == null) {
|
|
95
|
+
return { ok: false, reason: 'multi_line_not_supported' };
|
|
96
|
+
}
|
|
97
|
+
const scheduleTransaction = mapSupportedTransactionLineToScheduleTransaction(transaction, firstLine.id);
|
|
98
|
+
if (scheduleTransaction == null) {
|
|
99
|
+
return { ok: false, reason: 'missing_third_party_id' };
|
|
100
|
+
}
|
|
101
|
+
const vendorId = localData.selectedVendor?.id ?? transaction.vendorId ?? '';
|
|
102
|
+
const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
|
|
103
|
+
if (vendorId === '' || vendorName === '') {
|
|
104
|
+
return { ok: false, reason: 'missing_vendor' };
|
|
105
|
+
}
|
|
106
|
+
const vendor = {
|
|
107
|
+
vendor_id: vendorId,
|
|
108
|
+
vendor_name: vendorName,
|
|
109
|
+
};
|
|
110
|
+
const jeScheduleDetails = computeNewScheduleJeDetails(localData, scheduleTransaction.amount, vendorName);
|
|
111
|
+
const postingDate = localData.selectedDayOfMonth ??
|
|
112
|
+
(localData.lastDayOfMonth === true ? LAST_SCHEDULE_DAY_OF_MONTH : null);
|
|
113
|
+
const firstJEScheduleDate = jeScheduleDetails.length > 0
|
|
114
|
+
? jeScheduleDetails[0].postingDate.format(DEFAULT_DATE_FORMAT)
|
|
115
|
+
: null;
|
|
116
|
+
const lastJEScheduleDate = jeScheduleDetails.length > 0
|
|
117
|
+
? jeScheduleDetails[jeScheduleDetails.length - 1].postingDate.format(DEFAULT_DATE_FORMAT)
|
|
118
|
+
: null;
|
|
119
|
+
const isFixedAssets = scheduleType === 'fixed_assets';
|
|
120
|
+
const assetId = 'assetId' in localData ? localData.assetId : undefined;
|
|
121
|
+
const selectedAccumulatedDepreciationCategory = 'selectedAccumulatedDepreciationCategory' in localData
|
|
122
|
+
? localData.selectedAccumulatedDepreciationCategory
|
|
123
|
+
: undefined;
|
|
124
|
+
const status = { code: 'new', label: 'New' };
|
|
125
|
+
const jeSchedulePayload = {
|
|
126
|
+
status,
|
|
127
|
+
vendor,
|
|
128
|
+
currency_code: scheduleTransaction.currency.currencyCode,
|
|
129
|
+
currency_symbol: scheduleTransaction.currency.currencySymbol,
|
|
130
|
+
period: localData.selectedMonths ?? null,
|
|
131
|
+
je_schedule_type: scheduleType,
|
|
132
|
+
posting_date: postingDate,
|
|
133
|
+
balance: scheduleTransaction.amount.amount,
|
|
134
|
+
start_date: firstJEScheduleDate,
|
|
135
|
+
end_date: lastJEScheduleDate,
|
|
136
|
+
je_credit_accounting_class_id: scheduleTransaction.classBase?.classId ?? null,
|
|
137
|
+
je_credit_account_id: isFixedAssets
|
|
138
|
+
? (selectedAccumulatedDepreciationCategory ?? null)
|
|
139
|
+
: scheduleTransaction.account.accountId,
|
|
140
|
+
je_debit_account_id: localData.selectedAccount ?? null,
|
|
141
|
+
je_debit_accounting_class_id: localData.selectedClass ?? null,
|
|
142
|
+
other_attributes: assetId != null ? { asset_id: assetId } : {},
|
|
143
|
+
base_transaction: mapScheduleTransactionToBaseScheduleTransactionPayload(scheduleTransaction),
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
payload: {
|
|
148
|
+
je_schedules: [jeSchedulePayload],
|
|
149
|
+
scheduled_journal_entries: mapNewJeDetailsToScheduledJournalEntryPayload(jeScheduleDetails),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|