@zeniai/client-epic-state 5.1.57-betaRD3 → 5.1.57

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 (50) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +0 -2
  2. package/lib/entity/jeSchedules/jeSchedulesPayload.js +0 -2
  3. package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +0 -4
  4. package/lib/entity/jeSchedules/jeSchedulesSelector.js +1 -11
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +0 -2
  6. package/lib/epic.d.ts +1 -5
  7. package/lib/epic.js +1 -5
  8. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -2
  9. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +1 -11
  10. package/lib/esm/epic.js +1 -5
  11. package/lib/esm/index.js +4 -7
  12. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +2 -15
  13. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +6 -126
  14. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +11 -65
  15. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +6 -3
  16. package/lib/index.d.ts +7 -10
  17. package/lib/index.js +41 -59
  18. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +1 -14
  19. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +0 -1
  20. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +8 -36
  21. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +7 -128
  22. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +4 -29
  23. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +11 -65
  24. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +6 -53
  25. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +8 -5
  26. package/package.json +1 -1
  27. package/lib/entity/transaction/scheduleTransactionHelper.d.ts +0 -15
  28. package/lib/entity/transaction/scheduleTransactionHelper.js +0 -43
  29. package/lib/esm/entity/transaction/scheduleTransactionHelper.js +0 -39
  30. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -21
  31. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -110
  32. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -57
  33. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -22
  34. package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -152
  35. package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -1
  36. package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -71
  37. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +0 -8
  38. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -25
  39. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +0 -45
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -114
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +0 -8
  42. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -61
  43. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +0 -6
  44. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -26
  45. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +0 -43
  46. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -158
  47. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +0 -25
  48. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -2
  49. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +0 -10
  50. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -76
@@ -1,15 +0,0 @@
1
- import { ID } from '../../commonStateTypes/common';
2
- import { ScheduleTransaction } from './stateTypes/scheduleTransaction';
3
- import { Line, TransactionWithAccountAndClassLine } from './stateTypes/transactionLine';
4
- import { SupportedTransaction } from './transactionState';
5
- export declare function hasAccountAndClassDetail(line: Line): line is TransactionWithAccountAndClassLine;
6
- /**
7
- * Builds a ScheduleTransaction directly from a Base Transaction search result
8
- * (SupportedTransaction) and the chosen line, for schedule types where the
9
- * user selects a transaction the search endpoint already returned — as
10
- * opposed to the legacy flow's ScheduleTransaction, which only ever arrives
11
- * via a GET /1.0/schedules/:id round trip. transaction.qboId stands in for
12
- * thirdPartyTransactionId since this search endpoint doesn't send a field by
13
- * that name, but qbo_id is the same identifier.
14
- */
15
- export declare function mapSupportedTransactionLineToScheduleTransaction(transaction: SupportedTransaction, lineId: ID): ScheduleTransaction | undefined;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasAccountAndClassDetail = hasAccountAndClassDetail;
4
- exports.mapSupportedTransactionLineToScheduleTransaction = mapSupportedTransactionLineToScheduleTransaction;
5
- function hasAccountAndClassDetail(line) {
6
- return 'account' in line;
7
- }
8
- /**
9
- * Builds a ScheduleTransaction directly from a Base Transaction search result
10
- * (SupportedTransaction) and the chosen line, for schedule types where the
11
- * user selects a transaction the search endpoint already returned — as
12
- * opposed to the legacy flow's ScheduleTransaction, which only ever arrives
13
- * via a GET /1.0/schedules/:id round trip. transaction.qboId stands in for
14
- * thirdPartyTransactionId since this search endpoint doesn't send a field by
15
- * that name, but qbo_id is the same identifier.
16
- */
17
- function mapSupportedTransactionLineToScheduleTransaction(transaction, lineId) {
18
- if (transaction.qboId == null || transaction.qboId === '') {
19
- return undefined;
20
- }
21
- const line = transaction.lines?.find((candidate) => candidate.id === lineId);
22
- if (line == null || !hasAccountAndClassDetail(line)) {
23
- return undefined;
24
- }
25
- return {
26
- id: transaction.id,
27
- type: transaction.type,
28
- typeOfTransaction: 'schedule',
29
- typeName: transaction.typeName,
30
- date: transaction.date,
31
- memo: transaction.memo,
32
- description: transaction.description,
33
- lineId: line.id,
34
- thirdPartyTransactionId: transaction.qboId,
35
- account: line.account,
36
- classBase: line.class,
37
- amount: line.amount,
38
- currency: {
39
- currencyCode: line.amount.currencyCode,
40
- currencySymbol: line.amount.currencySymbol,
41
- },
42
- };
43
- }
@@ -1,39 +0,0 @@
1
- export function hasAccountAndClassDetail(line) {
2
- return 'account' in line;
3
- }
4
- /**
5
- * Builds a ScheduleTransaction directly from a Base Transaction search result
6
- * (SupportedTransaction) and the chosen line, for schedule types where the
7
- * user selects a transaction the search endpoint already returned — as
8
- * opposed to the legacy flow's ScheduleTransaction, which only ever arrives
9
- * via a GET /1.0/schedules/:id round trip. transaction.qboId stands in for
10
- * thirdPartyTransactionId since this search endpoint doesn't send a field by
11
- * that name, but qbo_id is the same identifier.
12
- */
13
- export function mapSupportedTransactionLineToScheduleTransaction(transaction, lineId) {
14
- if (transaction.qboId == null || transaction.qboId === '') {
15
- return undefined;
16
- }
17
- const line = transaction.lines?.find((candidate) => candidate.id === lineId);
18
- if (line == null || !hasAccountAndClassDetail(line)) {
19
- return undefined;
20
- }
21
- return {
22
- id: transaction.id,
23
- type: transaction.type,
24
- typeOfTransaction: 'schedule',
25
- typeName: transaction.typeName,
26
- date: transaction.date,
27
- memo: transaction.memo,
28
- description: transaction.description,
29
- lineId: line.id,
30
- thirdPartyTransactionId: transaction.qboId,
31
- account: line.account,
32
- classBase: line.class,
33
- amount: line.amount,
34
- currency: {
35
- currencyCode: line.amount.currencyCode,
36
- currencySymbol: line.amount.currencySymbol,
37
- },
38
- };
39
- }
@@ -1,21 +0,0 @@
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
- }));
@@ -1,110 +0,0 @@
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
- }));
@@ -1,57 +0,0 @@
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 { DEFAULT_COMPLETED_SUB_TAB } from '../../../types/completedSubTab';
7
- import { MIN_NEW_SCHEDULE_SEARCH_LENGTH } from '../../../types/jeSchedulesViewState';
8
- import { toTransactionsSortKey } from '../../../types/transactionsViewState';
9
- /** Dropdown-sized result set — no pagination for Base Transaction search. */
10
- const NEW_SCHEDULE_SEARCH_PAGE_SIZE = 10;
11
- export const searchTransactionsForNewScheduleEpic = (actions$, _state$, zeniAPI) => {
12
- const searchActions$ = actions$.pipe(filter(searchTransactionsForNewSchedule.match));
13
- /** No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP. */
14
- const newSearchTooShortOrClear$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length < MIN_NEW_SCHEDULE_SEARCH_LENGTH));
15
- const newSearchDebounced$ = searchActions$.pipe(filter((action) => action.payload.query.trim().length >= MIN_NEW_SCHEDULE_SEARCH_LENGTH), debounceTime(300));
16
- return merge(newSearchTooShortOrClear$, newSearchDebounced$).pipe(switchMap((action) => {
17
- const query = action.payload.query.trim();
18
- if (query.length < MIN_NEW_SCHEDULE_SEARCH_LENGTH) {
19
- return EMPTY;
20
- }
21
- const queryParam = {
22
- start_date: null,
23
- end_date: null,
24
- auto_categorized: false,
25
- // A Base Transaction can be any already-recorded transaction
26
- // regardless of categorization status — unlike the categorization
27
- // list, this search isn't scoped to one status tab.
28
- search_all_statuses: true,
29
- sort_by: toTransactionsSortKey('date'),
30
- sort_order: 'desc',
31
- page_token: null,
32
- page_size: NEW_SCHEDULE_SEARCH_PAGE_SIZE,
33
- search_text: query,
34
- sub_tab: DEFAULT_COMPLETED_SUB_TAB,
35
- };
36
- return zeniAPI
37
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
38
- .pipe(mergeMap((response) => {
39
- if (isSuccessResponse(response) && response.data != null) {
40
- const { transactions } = response.data;
41
- const actionsOut = [
42
- updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
43
- searchTransactionsForNewScheduleSuccess({
44
- searchResults: transactions.map((transaction) => transaction.transaction_id),
45
- }),
46
- ];
47
- return from(actionsOut);
48
- }
49
- return of(searchTransactionsForNewScheduleFailure({
50
- status: response.status,
51
- }));
52
- }), catchError((error) => of(searchTransactionsForNewScheduleFailure({
53
- status: createZeniAPIStatus('Unexpected Error', 'Search transactions for new schedule errored: ' +
54
- JSON.stringify(error)),
55
- }))));
56
- }));
57
- };
@@ -1,22 +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
- 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
- }));
@@ -1,152 +0,0 @@
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
- };
@@ -1,71 +0,0 @@
1
- import { getAccountIdsForTypes } from '../../../entity/account/accountSelector';
2
- import { getSupportedTransactionsByIds } 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
- import { isSupportedTransactionSelectableForNewSchedule } from '../helpers/newScheduleLocalDataHelper';
9
- /**
10
- * The Base Transaction search is shared across schedule types (one search
11
- * box, not one per prepaid_expenses/fixed_assets) — split out from
12
- * getNewScheduleView so a consumer can read it without supplying an
13
- * otherwise-irrelevant scheduleType.
14
- */
15
- export const getNewScheduleSearchTransactionsView = (state) => {
16
- const { searchTransactions } = state.expenseAutomationJESchedulesViewState.newSchedule;
17
- const searchTransactionsResults = getSupportedTransactionsByIds(state.transactionState, searchTransactions.searchResults);
18
- return {
19
- searchTransactionsResults,
20
- selectableBaseTransactionIds: searchTransactionsResults
21
- .filter(isSupportedTransactionSelectableForNewSchedule)
22
- .map((transaction) => transaction.id),
23
- searchTransactionsFetchState: {
24
- fetchState: searchTransactions.fetchState,
25
- error: searchTransactions.error,
26
- },
27
- searchTransactionsString: searchTransactions.searchString,
28
- };
29
- };
30
- export const getNewScheduleView = (state, scheduleType) => {
31
- const { accountState, accountListState, classState, classListState } = state;
32
- const { newSchedule } = state.expenseAutomationJESchedulesViewState;
33
- const searchTransactionsView = getNewScheduleSearchTransactionsView(state);
34
- const accountType = getAccountsTypesForScheduleEpics();
35
- const newScheduleAccountTypes = getAccountsTypesForScheduleDetails(scheduleType);
36
- const newScheduleAccountIds = getAccountIdsForTypes(accountState, newScheduleAccountTypes);
37
- const allAccountList = getAccountList(accountState, accountListState, accountType.accountListKey);
38
- const filteredAccounts = allAccountList.accounts.filter((account) => newScheduleAccountIds.includes(account.accountId));
39
- const accountListNestedAccountHierarchy = filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), filteredAccounts.map((account) => account.accountId));
40
- const allClassList = getClassList(classState, classListState);
41
- const classListNestedAccountHierarchy = getNestedClassListHierarchy(classListState);
42
- let allDepreciationAccountList;
43
- let allDepreciationAccountListNestedAccountHierarchy;
44
- if (scheduleType === 'fixed_assets') {
45
- const depreciationCategoryIds = getAccountIdsForTypes(accountState, [
46
- 'fixed_assets',
47
- 'other_assets',
48
- ]);
49
- const accountLabel = getAccountLabelForScheduleType('fixed_assets');
50
- const fixedAssetLabelAccountIds = accountLabel != null
51
- ? getAccountIdsForLabel(accountListState, accountType.accountListKey, accountLabel)
52
- : [];
53
- allDepreciationAccountList = allAccountList.accounts.filter((account) => depreciationCategoryIds.includes(account.accountId) &&
54
- !fixedAssetLabelAccountIds.includes(account.accountId));
55
- allDepreciationAccountListNestedAccountHierarchy =
56
- filterNestedAccountHierarchyById(getNestedAccountListHierarchy(accountListState, accountType.accountListKey), allDepreciationAccountList.map((account) => account.accountId));
57
- }
58
- return {
59
- scheduleType,
60
- accountListNestedAccountHierarchy,
61
- allAccountList: filteredAccounts,
62
- allClassList: allClassList.classes,
63
- allDepreciationAccountList,
64
- allDepreciationAccountListNestedAccountHierarchy,
65
- classListNestedAccountHierarchy,
66
- newScheduleLocalData: newSchedule.newScheduleState[scheduleType],
67
- ...searchTransactionsView,
68
- fetchState: newSchedule.fetchState,
69
- error: newSchedule.error,
70
- };
71
- };
@@ -1,8 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { RootState } from '../../../../../reducer';
4
- import { fetchAccountList } from '../../../../accountList/accountListReducer';
5
- import { fetchClassList } from '../../../../classList/classListReducer';
6
- import { clearSearchTransactionsForNewSchedule, initializeNewSchedule, resetNewScheduleLocalData } from '../../../reducers/jeSchedulesViewReducer';
7
- export type ActionType = ReturnType<typeof clearSearchTransactionsForNewSchedule> | ReturnType<typeof fetchAccountList> | ReturnType<typeof fetchClassList> | ReturnType<typeof initializeNewSchedule> | ReturnType<typeof resetNewScheduleLocalData>;
8
- export declare const initializeNewScheduleEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initializeNewScheduleEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const accountListReducer_1 = require("../../../../accountList/accountListReducer");
7
- const classListReducer_1 = require("../../../../classList/classListReducer");
8
- const scheduleListHelper_1 = require("../../../../scheduleView/scheduleListView/scheduleListHelper");
9
- const jeSchedulesViewReducer_1 = require("../../../reducers/jeSchedulesViewReducer");
10
- const initializeNewScheduleEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(jeSchedulesViewReducer_1.initializeNewSchedule.match), (0, operators_1.mergeMap)((action) => {
11
- const newScheduleActions = [];
12
- const accountType = (0, scheduleListHelper_1.getAccountsTypesForScheduleEpics)();
13
- const { accountListState, classListState } = state$.value;
14
- if (accountListState.byReportId[accountType.accountListKey]?.fetchState ===
15
- 'Not-Started') {
16
- newScheduleActions.push((0, accountListReducer_1.fetchAccountList)(accountType.accountListKey, true, false, false, false, accountType.allowedAccountList));
17
- }
18
- if (classListState.fetchState === 'Not-Started') {
19
- newScheduleActions.push((0, classListReducer_1.fetchClassList)());
20
- }
21
- newScheduleActions.push((0, jeSchedulesViewReducer_1.resetNewScheduleLocalData)({ scheduleType: action.payload.scheduleType }));
22
- newScheduleActions.push((0, jeSchedulesViewReducer_1.clearSearchTransactionsForNewSchedule)());
23
- return (0, rxjs_1.from)(newScheduleActions);
24
- }));
25
- exports.initializeNewScheduleEpic = initializeNewScheduleEpic;
@@ -1,45 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { updateJESchedules, updateJESchedulesDetails } from '../../../../../entity/jeSchedules/jeSchedulesReducer';
3
- import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
4
- import { RootState } from '../../../../../reducer';
5
- import { ZeniAPI } from '../../../../../zeniAPI';
6
- import { resetNewScheduleLocalData, saveNewSchedule, saveNewScheduleFailure, saveNewScheduleSuccess } from '../../../reducers/jeSchedulesViewReducer';
7
- export type ActionType = ReturnType<typeof saveNewSchedule> | ReturnType<typeof saveNewScheduleSuccess> | ReturnType<typeof saveNewScheduleFailure> | ReturnType<typeof updateJESchedules> | ReturnType<typeof updateJESchedulesDetails> | ReturnType<typeof resetNewScheduleLocalData> | ReturnType<typeof openSnackbar>;
8
- export declare const saveNewScheduleEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
9
- payload: {
10
- messageSection: import("../../../../..").SnackbarMessageSections;
11
- messageText: import("../../../../..").SnackbarMessageSectionTexts;
12
- type: import("../../../../..").SnackbarMessageType;
13
- showStatusIcon?: boolean;
14
- variables?: {
15
- variableName: string;
16
- variableValue: string;
17
- }[];
18
- };
19
- type: "snackbar/openSnackbar";
20
- } | {
21
- payload: {
22
- jeSchedulesTransactionsPayload: import("../../../../../entity/jeSchedules/jeSchedulesPayload").JEScheduledTransactionPayload[];
23
- };
24
- type: "jeSchedules/updateJESchedules";
25
- } | {
26
- payload: {
27
- jeSchedulesPayload: import("../../../../../entity/jeSchedules/jeSchedulesPayload").JEScheduledTransactionPayload[];
28
- scheduledJEntriesPayload: import("../../../../../entity/jeSchedules/jeSchedulesPayload").ScheduledJournalEntryPayload[] | undefined;
29
- updateType: import("../../../../..").UpdateType;
30
- };
31
- type: "jeSchedules/updateJESchedulesDetails";
32
- } | {
33
- payload: {
34
- scheduleType: "prepaid_expenses" | "fixed_assets";
35
- };
36
- type: "expenseAutomationJESchedulesView/resetNewScheduleLocalData";
37
- } | {
38
- payload: undefined;
39
- type: "expenseAutomationJESchedulesView/saveNewScheduleSuccess";
40
- } | {
41
- payload: {
42
- status: import("../../../../../responsePayload").ZeniAPIStatus;
43
- };
44
- type: "expenseAutomationJESchedulesView/saveNewScheduleFailure";
45
- }>;