@zeniai/client-epic-state 5.1.72-betaRD1 → 5.1.73

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 (53) 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/entity/transaction/payloadTypes/scheduleTransactionPayload.d.ts +0 -2
  7. package/lib/entity/transaction/payloadTypes/scheduleTransactionPayload.js +0 -2
  8. package/lib/entity/transaction/stateTypes/scheduleTransaction.d.ts +0 -2
  9. package/lib/epic.d.ts +1 -5
  10. package/lib/epic.js +1 -5
  11. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -2
  12. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +1 -11
  13. package/lib/esm/entity/transaction/payloadTypes/scheduleTransactionPayload.js +0 -2
  14. package/lib/esm/epic.js +1 -5
  15. package/lib/esm/index.js +4 -10
  16. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +3 -23
  17. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +8 -133
  18. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +15 -110
  19. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +6 -3
  20. package/lib/index.d.ts +7 -11
  21. package/lib/index.js +48 -70
  22. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.d.ts +2 -2
  23. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +1 -21
  24. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +1 -7
  25. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +9 -40
  26. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +8 -134
  27. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +7 -31
  28. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.d.ts +1 -4
  29. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +14 -112
  30. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +6 -53
  31. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +8 -5
  32. package/package.json +1 -1
  33. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -21
  34. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -110
  35. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -73
  36. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -22
  37. package/lib/esm/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -140
  38. package/lib/esm/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -1
  39. package/lib/esm/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -70
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.d.ts +0 -8
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/initializeNewScheduleEpic.js +0 -25
  42. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.d.ts +0 -45
  43. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/saveNewScheduleEpic.js +0 -114
  44. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.d.ts +0 -8
  45. package/lib/view/expenseAutomationView/epics/jeSchedule/newSchedule/searchTransactionsForNewScheduleEpic.js +0 -77
  46. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.d.ts +0 -6
  47. package/lib/view/expenseAutomationView/epics/jeSchedule/switchJESchedulesTabEpic.js +0 -26
  48. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.d.ts +0 -36
  49. package/lib/view/expenseAutomationView/helpers/newScheduleLocalDataHelper.js +0 -145
  50. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.d.ts +0 -25
  51. package/lib/view/expenseAutomationView/selectorTypes/jeNewScheduleViewSelectorTypes.js +0 -2
  52. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.d.ts +0 -10
  53. package/lib/view/expenseAutomationView/selectors/jeNewScheduleViewSelector.js +0 -75
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareNewSchedulePayload = exports.computeNewScheduleJeDetails = void 0;
4
- const amount_1 = require("../../../commonStateTypes/amount");
5
- const formatZeniDateFY_1 = require("../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY");
6
- const formatZeniDateFY_2 = require("../../../commonStateTypes/fiscalYearHelpers/formatZeniDateFY");
7
- const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
8
- const scheduleDetailLocalDataHelper_1 = require("../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper");
9
- const scheduleDetailPayload_1 = require("../../scheduleView/scheduleDetailView/scheduleDetailPayload");
10
- const getNewScheduleMemo = (vendorName, schedulePostingDate, currentPeriod, totalPeriod, assetId) => {
11
- const addAsset = assetId != null && assetId !== '' ? ` - ${assetId}` : '';
12
- return `${vendorName} - ${schedulePostingDate.format(formatZeniDateFY_2.MONTH_YEAR_FORMAT)} (${currentPeriod} of ${totalPeriod})${addAsset}`;
13
- };
14
- /**
15
- * Computes the month-by-month JE schedule breakdown for a brand-new schedule
16
- * (no linked transaction yet) — replicates createNewSchedulesHelper's math
17
- * (scheduleDetailLocalDataHelper.ts) exactly: lump-sum total split evenly
18
- * across months with the rounding remainder absorbed by the last month, and a
19
- * running balance that decrements each month and is forced to exactly 0 on
20
- * the last row.
21
- */
22
- const computeNewScheduleJeDetails = (localData, totalAmount, vendorName) => {
23
- const period = localData.selectedMonths;
24
- const startingMonth = localData.selectedDate;
25
- if (startingMonth == null || period == null) {
26
- return [];
27
- }
28
- const assetId = 'assetId' in localData ? localData.assetId : undefined;
29
- const averageAmount = Math.abs(Math.round((totalAmount.amount / period) * 100) / 100);
30
- const lastMonthAmount = Math.abs(Math.round((Math.abs(totalAmount.amount) - averageAmount * (period - 1)) * 100) / 100);
31
- let runningBalance = Math.abs(totalAmount.amount);
32
- const negativeNumbers = totalAmount.amount < 0 || runningBalance < 0;
33
- const newJeDetails = [];
34
- for (let index = 0; index < period; index++) {
35
- if (runningBalance > averageAmount) {
36
- runningBalance = Math.round((runningBalance - averageAmount) * 100) / 100;
37
- }
38
- else {
39
- runningBalance = 0;
40
- }
41
- const amount = index === period - 1 ? lastMonthAmount : averageAmount;
42
- runningBalance = index === period - 1 ? 0 : runningBalance;
43
- const schedulePostingDate = startingMonth.add(index, 'month');
44
- const { postingDate, postingStatus } = (0, scheduleDetailLocalDataHelper_1.getPostingDateAndStatusForIndex)(schedulePostingDate.month(), schedulePostingDate.year(), localData.lastDayOfMonth === true
45
- ? undefined
46
- : localData.selectedDayOfMonth);
47
- newJeDetails.push({
48
- postingDate,
49
- amount: (0, amount_1.toAmount)(negativeNumbers ? -amount : amount, totalAmount.currencyCode, totalAmount.currencySymbol),
50
- runningBalance: (0, amount_1.toAmount)(negativeNumbers ? -runningBalance : runningBalance, totalAmount.currencyCode, totalAmount.currencySymbol),
51
- postingStatus,
52
- memo: getNewScheduleMemo(vendorName, schedulePostingDate, index + 1, period, assetId),
53
- jeLink: { type: 'unknown' },
54
- });
55
- }
56
- return newJeDetails;
57
- };
58
- exports.computeNewScheduleJeDetails = computeNewScheduleJeDetails;
59
- const mapNewJeDetailsToScheduledJournalEntryPayload = (jeScheduleDetails) => jeScheduleDetails.map((journalEntry) => ({
60
- status: {
61
- code: journalEntry.postingStatus,
62
- label: journalEntry.postingStatus,
63
- },
64
- transaction_memo: journalEntry.memo,
65
- third_party_id: journalEntry.jeLink.thirdPartyTransactionId ?? null,
66
- expected_post_date: journalEntry.postingDate.format(formatZeniDateFY_1.DEFAULT_DATE_FORMAT),
67
- amount: journalEntry.amount.amount,
68
- balance: journalEntry.runningBalance.amount,
69
- // Brand-new schedule — there is no prior scheduled-journal-entry history
70
- // to cross-reference (unlike the legacy edit flow's equivalent mapper).
71
- scheduled_journal_entry_id: null,
72
- actual_post_date: null,
73
- is_platform_generated: null,
74
- je_schedule_id: null,
75
- update_time: null,
76
- create_time: null,
77
- }));
78
- /**
79
- * Builds a savable schedule payload directly from a Base Transaction search
80
- * result and the New Schedule form's local data — bypassing the legacy
81
- * getJEScheduledTransactionByJEScheduleTransactionKey selector entirely,
82
- * since that selector throws unless the entity has already round-tripped
83
- * through a real GET /1.0/schedules/:id. A brand-new schedule has no such
84
- * history, so this reads only from data already in hand (the selected
85
- * transaction/line plus what the user filled into the form).
86
- */
87
- const prepareNewSchedulePayload = (transaction, localData, scheduleType) => {
88
- if (transaction.thirdPartyTransactionId == null ||
89
- transaction.thirdPartyTransactionId === '') {
90
- return { ok: false, reason: 'missing_third_party_id' };
91
- }
92
- const scheduleTransaction = transaction;
93
- const vendorId = localData.selectedVendor?.id ?? transaction.vendorId ?? '';
94
- const vendorName = localData.selectedVendor?.name ?? transaction.vendorName ?? '';
95
- if (vendorId === '' || vendorName === '') {
96
- return { ok: false, reason: 'missing_vendor' };
97
- }
98
- const vendor = {
99
- vendor_id: vendorId,
100
- vendor_name: vendorName,
101
- };
102
- const jeScheduleDetails = (0, exports.computeNewScheduleJeDetails)(localData, scheduleTransaction.amount, vendorName);
103
- const postingDate = localData.selectedDayOfMonth ??
104
- (localData.lastDayOfMonth === true ? timePeriod_1.LAST_SCHEDULE_DAY_OF_MONTH : null);
105
- const firstJEScheduleDate = jeScheduleDetails.length > 0
106
- ? jeScheduleDetails[0].postingDate.format(formatZeniDateFY_1.DEFAULT_DATE_FORMAT)
107
- : null;
108
- const lastJEScheduleDate = jeScheduleDetails.length > 0
109
- ? jeScheduleDetails[jeScheduleDetails.length - 1].postingDate.format(formatZeniDateFY_1.DEFAULT_DATE_FORMAT)
110
- : null;
111
- const isFixedAssets = scheduleType === 'fixed_assets';
112
- const assetId = 'assetId' in localData ? localData.assetId : undefined;
113
- const selectedAccumulatedDepreciationCategory = 'selectedAccumulatedDepreciationCategory' in localData
114
- ? localData.selectedAccumulatedDepreciationCategory
115
- : undefined;
116
- const status = { code: 'new', label: 'New' };
117
- const jeSchedulePayload = {
118
- status,
119
- vendor,
120
- currency_code: scheduleTransaction.currency.currencyCode,
121
- currency_symbol: scheduleTransaction.currency.currencySymbol,
122
- period: localData.selectedMonths ?? null,
123
- je_schedule_type: scheduleType,
124
- posting_date: postingDate,
125
- balance: scheduleTransaction.amount.amount,
126
- start_date: firstJEScheduleDate,
127
- end_date: lastJEScheduleDate,
128
- je_credit_accounting_class_id: scheduleTransaction.classBase?.classId ?? null,
129
- je_credit_account_id: isFixedAssets
130
- ? (selectedAccumulatedDepreciationCategory ?? null)
131
- : scheduleTransaction.account.accountId,
132
- je_debit_account_id: localData.selectedAccount ?? null,
133
- je_debit_accounting_class_id: localData.selectedClass ?? null,
134
- other_attributes: assetId != null ? { asset_id: assetId } : {},
135
- base_transaction: (0, scheduleDetailPayload_1.mapScheduleTransactionToBaseScheduleTransactionPayload)(scheduleTransaction),
136
- };
137
- return {
138
- ok: true,
139
- payload: {
140
- je_schedules: [jeSchedulePayload],
141
- scheduled_journal_entries: mapNewJeDetailsToScheduledJournalEntryPayload(jeScheduleDetails),
142
- },
143
- };
144
- };
145
- exports.prepareNewSchedulePayload = prepareNewSchedulePayload;
@@ -1,25 +0,0 @@
1
- import { NestedAccountHierarchyForReport } from '../../../commonStateTypes/accountView/nestedAccountID';
2
- import { NestedClassHierarchyForReport } from '../../../commonStateTypes/classesView/nestedClassID';
3
- import { FetchStateAndError } from '../../../commonStateTypes/common';
4
- import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
5
- import { AccountBase } from '../../../entity/account/accountState';
6
- import { ClassBase } from '../../../entity/class/classState';
7
- import { ScheduleTypes } from '../../../entity/jeSchedules/jeSchedulesTypes';
8
- import { ScheduleTransaction } from '../../../entity/transaction/stateTypes/scheduleTransaction';
9
- import { NewScheduleLocalData, NewScheduleLocalDataFixedAssets } from '../types/jeSchedulesViewState';
10
- export interface NewScheduleSearchTransactionsView {
11
- searchTransactionsFetchState: FetchStateAndError;
12
- searchTransactionsResults: ScheduleTransaction[];
13
- searchTransactionsString?: string;
14
- }
15
- export interface NewScheduleView extends SelectorView, NewScheduleSearchTransactionsView {
16
- accountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
17
- allAccountList: AccountBase[];
18
- allClassList: ClassBase[];
19
- classListNestedAccountHierarchy: NestedClassHierarchyForReport[];
20
- newScheduleLocalData: NewScheduleLocalData | NewScheduleLocalDataFixedAssets;
21
- saveStatus: FetchStateAndError;
22
- scheduleType: ScheduleTypes;
23
- allDepreciationAccountList?: AccountBase[];
24
- allDepreciationAccountListNestedAccountHierarchy?: NestedAccountHierarchyForReport[];
25
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import { RootState } from '../../../reducer';
2
- import { NewScheduleSearchTransactionsView, NewScheduleView } from '../selectorTypes/jeNewScheduleViewSelectorTypes';
3
- /**
4
- * The Base Transaction search is shared across schedule types (one search
5
- * box, not one per prepaid_expenses/fixed_assets) — split out from
6
- * getNewScheduleView so a consumer can read it without supplying an
7
- * otherwise-irrelevant scheduleType.
8
- */
9
- export declare const getNewScheduleSearchTransactionsView: (state: RootState) => NewScheduleSearchTransactionsView;
10
- export declare const getNewScheduleView: (state: RootState, scheduleType: "fixed_assets" | "prepaid_expenses") => NewScheduleView;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNewScheduleView = exports.getNewScheduleSearchTransactionsView = void 0;
4
- const accountSelector_1 = require("../../../entity/account/accountSelector");
5
- const transactionSelector_1 = require("../../../entity/transaction/transactionSelector");
6
- const accountListSelector_1 = require("../../accountList/accountListSelector");
7
- const classListSelector_1 = require("../../classList/classListSelector");
8
- const scheduleDetailLocalDataHelper_1 = require("../../scheduleView/scheduleDetailView/scheduleDetailLocalDataHelper");
9
- const scheduleDetailSelector_1 = require("../../scheduleView/scheduleDetailView/scheduleDetailSelector");
10
- const scheduleListHelper_1 = require("../../scheduleView/scheduleListView/scheduleListHelper");
11
- /**
12
- * The Base Transaction search is shared across schedule types (one search
13
- * box, not one per prepaid_expenses/fixed_assets) — split out from
14
- * getNewScheduleView so a consumer can read it without supplying an
15
- * otherwise-irrelevant scheduleType.
16
- */
17
- const getNewScheduleSearchTransactionsView = (state) => {
18
- const { searchTransactions } = state.expenseAutomationJESchedulesViewState.newSchedule;
19
- const searchTransactionsResults = searchTransactions.searchResults
20
- .map((key) => (0, transactionSelector_1.getScheduleTransactionById)(state.transactionState, key))
21
- .filter((transaction) => transaction != null);
22
- return {
23
- searchTransactionsResults,
24
- searchTransactionsFetchState: {
25
- fetchState: searchTransactions.fetchState,
26
- error: searchTransactions.error,
27
- },
28
- searchTransactionsString: searchTransactions.searchString,
29
- };
30
- };
31
- exports.getNewScheduleSearchTransactionsView = getNewScheduleSearchTransactionsView;
32
- const getNewScheduleView = (state, scheduleType) => {
33
- const { accountState, accountListState, classState, classListState } = state;
34
- const { newSchedule } = state.expenseAutomationJESchedulesViewState;
35
- const searchTransactionsView = (0, exports.getNewScheduleSearchTransactionsView)(state);
36
- const accountType = (0, scheduleListHelper_1.getAccountsTypesForScheduleEpics)();
37
- const newScheduleAccountTypes = (0, scheduleDetailLocalDataHelper_1.getAccountsTypesForScheduleDetails)(scheduleType);
38
- const newScheduleAccountIds = (0, accountSelector_1.getAccountIdsForTypes)(accountState, newScheduleAccountTypes);
39
- const allAccountList = (0, accountListSelector_1.getAccountList)(accountState, accountListState, accountType.accountListKey);
40
- const filteredAccounts = allAccountList.accounts.filter((account) => newScheduleAccountIds.includes(account.accountId));
41
- const accountListNestedAccountHierarchy = (0, scheduleDetailSelector_1.filterNestedAccountHierarchyById)((0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, accountType.accountListKey), filteredAccounts.map((account) => account.accountId));
42
- const allClassList = (0, classListSelector_1.getClassList)(classState, classListState);
43
- const classListNestedAccountHierarchy = (0, classListSelector_1.getNestedClassListHierarchy)(classListState);
44
- let allDepreciationAccountList;
45
- let allDepreciationAccountListNestedAccountHierarchy;
46
- if (scheduleType === 'fixed_assets') {
47
- const depreciationCategoryIds = (0, accountSelector_1.getAccountIdsForTypes)(accountState, [
48
- 'fixed_assets',
49
- 'other_assets',
50
- ]);
51
- const accountLabel = (0, scheduleListHelper_1.getAccountLabelForScheduleType)('fixed_assets');
52
- const fixedAssetLabelAccountIds = accountLabel != null
53
- ? (0, accountListSelector_1.getAccountIdsForLabel)(accountListState, accountType.accountListKey, accountLabel)
54
- : [];
55
- allDepreciationAccountList = allAccountList.accounts.filter((account) => depreciationCategoryIds.includes(account.accountId) &&
56
- !fixedAssetLabelAccountIds.includes(account.accountId));
57
- allDepreciationAccountListNestedAccountHierarchy =
58
- (0, scheduleDetailSelector_1.filterNestedAccountHierarchyById)((0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, accountType.accountListKey), allDepreciationAccountList.map((account) => account.accountId));
59
- }
60
- return {
61
- scheduleType,
62
- accountListNestedAccountHierarchy,
63
- allAccountList: filteredAccounts,
64
- allClassList: allClassList.classes,
65
- allDepreciationAccountList,
66
- allDepreciationAccountListNestedAccountHierarchy,
67
- classListNestedAccountHierarchy,
68
- newScheduleLocalData: newSchedule.newScheduleState[scheduleType],
69
- saveStatus: newSchedule.saveStatus,
70
- ...searchTransactionsView,
71
- fetchState: newSchedule.fetchState,
72
- error: newSchedule.error,
73
- };
74
- };
75
- exports.getNewScheduleView = getNewScheduleView;