@zeniai/client-epic-state 5.0.9 → 5.0.10

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.
@@ -1,3 +1,4 @@
1
+ import { NestedAccountIDHierarchy } from '../../commonStateTypes/accountView/nestedAccountID';
1
2
  import { COABalanceGroupedByPeriod } from '../../commonStateTypes/coaBalance/coaBalance';
2
3
  import { ID } from '../../commonStateTypes/common';
3
4
  import { ReportID } from '../../commonStateTypes/viewAndReport/viewAndReport';
@@ -6,6 +7,7 @@ export interface SectionProjectView {
6
7
  projectId: ID;
7
8
  sectionId: ID;
8
9
  balancesByPeriod?: COABalanceGroupedByPeriod;
10
+ nestedAccountIds?: NestedAccountIDHierarchy[];
9
11
  }
10
12
  export declare function getSectionProjectViewKey(sectionId: ID, projectId: ID, reportId: ReportID): `${string}-${string}-cash_balance` | `${string}-${string}-card_balance` | `${string}-${string}-expense_automation_card` | `${string}-${string}-operating_expenses` | `${string}-${string}-operating_expenses_by_classes` | `${string}-${string}-revenue` | `${string}-${string}-revenue_by_classes` | `${string}-${string}-net_burn_or_income` | `${string}-${string}-net_burn_or_income_story_card` | `${string}-${string}-net_burn_or_income_by_classes` | `${string}-${string}-cash_position` | `${string}-${string}-top_expenses` | `${string}-${string}-profit_and_loss` | `${string}-${string}-profit_and_loss_by_classes` | `${string}-${string}-profit_and_loss_by_projects` | `${string}-${string}-balance_sheet` | `${string}-${string}-cash_flow` | `${string}-${string}-dashboard` | `${string}-${string}-finance_statement` | `${string}-${string}-transaction_list_of_account` | `${string}-${string}-transaction_list_missing_receipt` | `${string}-${string}-transaction_list_of_account_by_class` | `${string}-${string}-transaction_detail` | `${string}-${string}-cash_in_cash_out` | `${string}-${string}-insights_dashboard` | `${string}-${string}-company_details` | `${string}-${string}-class_list` | `${string}-${string}-account_list` | `${string}-${string}-account_list_by_type` | `${string}-${string}-vendor` | `${string}-${string}-task_card` | `${string}-${string}-bill_pay` | `${string}-${string}-reimbursement` | `${string}-${string}-bill_pay_card` | `${string}-${string}-reimbursement_card` | `${string}-${string}-bill_pay_promo_card` | `${string}-${string}-zeni_accounts` | `${string}-${string}-zeni_accounts_promo_card` | `${string}-${string}-zeni_treasury` | `${string}-${string}-charge_cards` | `${string}-${string}-other_connection` | `${string}-${string}-reimbursement_promo_card` | `${string}-${string}-onboarding` | `${string}-${string}-operating_expenses_by_vendor` | `${string}-${string}-operating_expenses_by_vendor_summary` | `${string}-${string}-vendors_tab` | `${string}-${string}-accounts_payable_aging` | `${string}-${string}-accounts_receivable_aging` | `${string}-${string}-vendor_global_review` | `${string}-${string}-prepaid_expenses` | `${string}-${string}-fixed_assets` | `${string}-${string}-notification` | `${string}-${string}-rewards_card` | `${string}-${string}-billing` | `${string}-${string}-flux_analysis_operating_expense` | `${string}-${string}-account_reconciliation` | `${string}-${string}-zeni_credit_promo_card` | `${string}-${string}-treasury_promo_card` | `${string}-${string}-excluded_account_reconciliation`;
11
13
  export type SectionProjectKey = ReturnType<typeof getSectionProjectViewKey>;
@@ -1,5 +1,6 @@
1
1
  import { COABalanceGroupedByPeriodPayloadV2 } from '../../commonPayloadTypes/v2/coaBalancePayload';
2
2
  import { CurrencyPayload } from '../../commonPayloadTypes/v2/viewAndReportPayloadv2';
3
+ import { NestedAccountIDHierarchy } from '../../commonStateTypes/accountView/nestedAccountID';
3
4
  import { ID } from '../../commonStateTypes/common';
4
5
  import { ReportID } from '../../commonStateTypes/viewAndReport/viewAndReport';
5
6
  import { SectionProjectView } from './sectionProjectView';
@@ -7,4 +8,4 @@ export declare const mapProjectCOABalanceGroupedPayloadToSectionProjectView: (ti
7
8
  projectId: ID;
8
9
  reportId: ReportID;
9
10
  sectionId: ID;
10
- }) => SectionProjectView;
11
+ }, nestedAccountIds: NestedAccountIDHierarchy[]) => SectionProjectView;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapProjectCOABalanceGroupedPayloadToSectionProjectView = void 0;
4
4
  const coaBalancePayload_1 = require("../../commonPayloadTypes/v2/coaBalancePayload");
5
5
  const sectionProjectView_1 = require("./sectionProjectView");
6
- const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id) => {
6
+ const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id, nestedAccountIds) => {
7
7
  return {
8
8
  key: (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, id.projectId, id.reportId),
9
9
  projectId: id.projectId,
10
10
  sectionId: id.sectionId,
11
11
  balancesByPeriod: (0, coaBalancePayload_1.mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod)(projectBalancesPayload, currencyPayload, timeframe),
12
+ nestedAccountIds,
12
13
  };
13
14
  };
14
15
  exports.mapProjectCOABalanceGroupedPayloadToSectionProjectView = mapProjectCOABalanceGroupedPayloadToSectionProjectView;
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.clearAllSectionsProjectView = exports.updateSectionProjectView = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const coaBalancePayload_1 = require("../../commonPayloadTypes/v2/coaBalancePayload");
7
+ const accountPayload_1 = require("../account/accountPayload");
8
+ const getNestedAccountIDHierarchyForSection_1 = require("../sectionAccountsView/getNestedAccountIDHierarchyForSection");
7
9
  const sectionProjectView_1 = require("./sectionProjectView");
8
10
  const sectionProjectViewHelper_1 = require("./sectionProjectViewHelper");
9
11
  exports.initialState = {
@@ -27,11 +29,16 @@ const sectionProjectView = (0, toolkit_1.createSlice)({
27
29
  };
28
30
  },
29
31
  reducer(draft, action) {
30
- const { timeframe, sectionPayload, sectionId, reportId, currencyPayload } = action.payload;
32
+ const { timeframe, sectionPayload, sectionId, reportId, currencyPayload, accountsMetadataPayload, } = action.payload;
31
33
  if (sectionPayload.projects != null) {
34
+ const accountsMetadata = accountsMetadataPayload.map((eachAccount) => (0, accountPayload_1.mapAccountMetadataPayloadToAccountMetadata)(eachAccount));
32
35
  Object.keys(sectionPayload.projects).forEach((projectId) => {
33
36
  const projectPayload = sectionPayload.projects[projectId];
34
- updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload);
37
+ const projectAccountIds = projectPayload.accounts != null
38
+ ? Object.keys(projectPayload.accounts)
39
+ : [];
40
+ const nestedAccountIds = (0, getNestedAccountIDHierarchyForSection_1.getNestedAccountIDHierarchyForAccounts)(projectAccountIds, accountsMetadata);
41
+ updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds);
35
42
  });
36
43
  }
37
44
  },
@@ -43,14 +50,15 @@ const sectionProjectView = (0, toolkit_1.createSlice)({
43
50
  });
44
51
  _a = sectionProjectView.actions, exports.updateSectionProjectView = _a.updateSectionProjectView, exports.clearAllSectionsProjectView = _a.clearAllSectionsProjectView;
45
52
  exports.default = sectionProjectView.reducer;
46
- const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload) => {
53
+ const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds) => {
47
54
  const sectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(sectionId, projectId, reportId);
48
55
  const section = draft.sectionsByKey[sectionKey];
49
56
  if (section != null) {
50
57
  draft.sectionsByKey[sectionKey].balancesByPeriod = Object.assign({}, draft.sectionsByKey[sectionKey].balancesByPeriod, (0, coaBalancePayload_1.mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod)(projectPayload, currencyPayload, timeframe));
58
+ draft.sectionsByKey[sectionKey].nestedAccountIds = nestedAccountIds;
51
59
  }
52
60
  else {
53
61
  draft.sectionsByKey[sectionKey] =
54
- (0, sectionProjectViewHelper_1.mapProjectCOABalanceGroupedPayloadToSectionProjectView)(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId });
62
+ (0, sectionProjectViewHelper_1.mapProjectCOABalanceGroupedPayloadToSectionProjectView)(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId }, nestedAccountIds);
55
63
  }
56
64
  };
@@ -7,41 +7,21 @@ exports.getSectionProjectViewReport = void 0;
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
8
  const coaBalance_1 = require("../../commonStateTypes/coaBalance/coaBalance");
9
9
  const getSumOfBalancesGroupedByPeriod_1 = require("../../commonStateTypes/coaBalance/classBalances/getSumOfBalancesGroupedByPeriod");
10
- const accountPayload_1 = require("../account/accountPayload");
11
- const accountState_1 = require("../account/accountState");
12
10
  const subAccountSelector_1 = require("../account/subAccountSelector");
13
11
  const projectSelector_1 = require("../project/projectSelector");
14
- const getNestedAccountIDHierarchyForSection_1 = require("../sectionAccountsView/getNestedAccountIDHierarchyForSection");
15
12
  const sectionProjectView_1 = require("./sectionProjectView");
16
13
  const getSectionProjectViewReport = (accountState, projectState, sectionState, projectIds, id, filter) => {
17
14
  const projectIdsToShow = projectIds.filter((projectId) => !filter.projectsToFilterOut.includes(projectId));
18
15
  const projectReports = [];
19
16
  const sectionBalancesTotalByPeriodArray = [];
20
- const accountsByProject = getAccountsByProject(accountState, id.sectionId, id.reportId);
21
17
  projectIdsToShow.forEach((projectId) => {
22
18
  const project = (0, projectSelector_1.getProjectById)(projectState, projectId);
23
19
  if (project == null) {
24
20
  return;
25
21
  }
26
- const projectAccountIds = accountsByProject[projectId] ?? [];
27
- const accountsMetadata = projectAccountIds
28
- .map((accountId) => {
29
- const key = (0, accountState_1.getAccountKey)(id.reportId, accountId, undefined, undefined, { projectId, sectionId: id.sectionId });
30
- const account = accountState.accountsByKey[key];
31
- if (account == null) {
32
- return undefined;
33
- }
34
- return (0, accountPayload_1.mapAccountMetadataPayloadToAccountMetadata)({
35
- account_id: account.accountId,
36
- account_name: account.accountName,
37
- account_description: account.accountDescription,
38
- labels: account.labels,
39
- is_sub_account: account.accountsViewParentId != null,
40
- parent_account_id: account.accountsViewParentId?.parentAccountId?.[0] ?? null,
41
- });
42
- })
43
- .filter((metadata) => metadata != null);
44
- const nestedAccountHierarchy = (0, getNestedAccountIDHierarchyForSection_1.getNestedAccountIDHierarchyForAccounts)(projectAccountIds, accountsMetadata);
22
+ const projectSectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, projectId, id.reportId);
23
+ const projectSectionView = (0, get_1.default)(sectionState.sectionsByKey, projectSectionKey, undefined);
24
+ const nestedAccountHierarchy = projectSectionView?.nestedAccountIds ?? [];
45
25
  const nestedAccountReports = [];
46
26
  nestedAccountHierarchy.forEach((accountIdHierarchy) => {
47
27
  const report = (0, subAccountSelector_1.getNestedAccountReportForAccount)(accountState, {
@@ -56,8 +36,6 @@ const getSectionProjectViewReport = (accountState, projectState, sectionState, p
56
36
  nestedAccountReports.push(report);
57
37
  }
58
38
  });
59
- const projectSectionKey = (0, sectionProjectView_1.getSectionProjectViewKey)(id.sectionId, projectId, id.reportId);
60
- const projectSectionView = (0, get_1.default)(sectionState.sectionsByKey, projectSectionKey, undefined);
61
39
  const projectBalancesTotalByPeriod = projectSectionView?.balancesByPeriod ?? {};
62
40
  const projectReport = {
63
41
  projectId,
@@ -77,18 +55,3 @@ const getSectionProjectViewReport = (accountState, projectState, sectionState, p
77
55
  };
78
56
  };
79
57
  exports.getSectionProjectViewReport = getSectionProjectViewReport;
80
- const getAccountsByProject = (accountState, sectionId, reportId) => {
81
- const result = {};
82
- Object.values(accountState.accountsByKey).forEach((account) => {
83
- if (account.projectsViewParentId != null &&
84
- account.projectsViewParentId.sectionId === sectionId &&
85
- account.key.endsWith(reportId)) {
86
- const projectId = account.projectsViewParentId.projectId;
87
- if (result[projectId] == null) {
88
- result[projectId] = [];
89
- }
90
- result[projectId].push(account.accountId);
91
- }
92
- });
93
- return result;
94
- };
@@ -1,10 +1,11 @@
1
1
  import { mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod, } from '../../commonPayloadTypes/v2/coaBalancePayload';
2
2
  import { getSectionProjectViewKey, } from './sectionProjectView';
3
- export const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id) => {
3
+ export const mapProjectCOABalanceGroupedPayloadToSectionProjectView = (timeframe, projectBalancesPayload, currencyPayload, id, nestedAccountIds) => {
4
4
  return {
5
5
  key: getSectionProjectViewKey(id.sectionId, id.projectId, id.reportId),
6
6
  projectId: id.projectId,
7
7
  sectionId: id.sectionId,
8
8
  balancesByPeriod: mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod(projectBalancesPayload, currencyPayload, timeframe),
9
+ nestedAccountIds,
9
10
  };
10
11
  };
@@ -1,5 +1,7 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod } from '../../commonPayloadTypes/v2/coaBalancePayload';
3
+ import { mapAccountMetadataPayloadToAccountMetadata, } from '../account/accountPayload';
4
+ import { getNestedAccountIDHierarchyForAccounts } from '../sectionAccountsView/getNestedAccountIDHierarchyForSection';
3
5
  import { getSectionProjectViewKey } from './sectionProjectView';
4
6
  import { mapProjectCOABalanceGroupedPayloadToSectionProjectView } from './sectionProjectViewHelper';
5
7
  export const initialState = {
@@ -23,11 +25,16 @@ const sectionProjectView = createSlice({
23
25
  };
24
26
  },
25
27
  reducer(draft, action) {
26
- const { timeframe, sectionPayload, sectionId, reportId, currencyPayload } = action.payload;
28
+ const { timeframe, sectionPayload, sectionId, reportId, currencyPayload, accountsMetadataPayload, } = action.payload;
27
29
  if (sectionPayload.projects != null) {
30
+ const accountsMetadata = accountsMetadataPayload.map((eachAccount) => mapAccountMetadataPayloadToAccountMetadata(eachAccount));
28
31
  Object.keys(sectionPayload.projects).forEach((projectId) => {
29
32
  const projectPayload = sectionPayload.projects[projectId];
30
- updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload);
33
+ const projectAccountIds = projectPayload.accounts != null
34
+ ? Object.keys(projectPayload.accounts)
35
+ : [];
36
+ const nestedAccountIds = getNestedAccountIDHierarchyForAccounts(projectAccountIds, accountsMetadata);
37
+ updateSectionProject(draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds);
31
38
  });
32
39
  }
33
40
  },
@@ -39,14 +46,15 @@ const sectionProjectView = createSlice({
39
46
  });
40
47
  export const { updateSectionProjectView, clearAllSectionsProjectView } = sectionProjectView.actions;
41
48
  export default sectionProjectView.reducer;
42
- const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload) => {
49
+ const updateSectionProject = (draft, timeframe, projectPayload, sectionId, projectId, reportId, currencyPayload, nestedAccountIds) => {
43
50
  const sectionKey = getSectionProjectViewKey(sectionId, projectId, reportId);
44
51
  const section = draft.sectionsByKey[sectionKey];
45
52
  if (section != null) {
46
53
  draft.sectionsByKey[sectionKey].balancesByPeriod = Object.assign({}, draft.sectionsByKey[sectionKey].balancesByPeriod, mapCOABalanceGroupedByPeriodPayloadV2ToCOABalanceGroupedByPeriod(projectPayload, currencyPayload, timeframe));
54
+ draft.sectionsByKey[sectionKey].nestedAccountIds = nestedAccountIds;
47
55
  }
48
56
  else {
49
57
  draft.sectionsByKey[sectionKey] =
50
- mapProjectCOABalanceGroupedPayloadToSectionProjectView(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId });
58
+ mapProjectCOABalanceGroupedPayloadToSectionProjectView(timeframe, projectPayload, currencyPayload, { sectionId, projectId, reportId }, nestedAccountIds);
51
59
  }
52
60
  };
@@ -1,41 +1,21 @@
1
1
  import recordGet from 'lodash/get';
2
2
  import { getCOABalances, } from '../../commonStateTypes/coaBalance/coaBalance';
3
3
  import { getSumOfBalancesByGroupedByPeriod } from '../../commonStateTypes/coaBalance/classBalances/getSumOfBalancesGroupedByPeriod';
4
- import { mapAccountMetadataPayloadToAccountMetadata } from '../account/accountPayload';
5
- import { getAccountKey } from '../account/accountState';
6
4
  import { getNestedAccountReportForAccount, } from '../account/subAccountSelector';
7
5
  import { getProjectById } from '../project/projectSelector';
8
- import { getNestedAccountIDHierarchyForAccounts } from '../sectionAccountsView/getNestedAccountIDHierarchyForSection';
9
6
  import { getSectionProjectViewKey } from './sectionProjectView';
10
7
  export const getSectionProjectViewReport = (accountState, projectState, sectionState, projectIds, id, filter) => {
11
8
  const projectIdsToShow = projectIds.filter((projectId) => !filter.projectsToFilterOut.includes(projectId));
12
9
  const projectReports = [];
13
10
  const sectionBalancesTotalByPeriodArray = [];
14
- const accountsByProject = getAccountsByProject(accountState, id.sectionId, id.reportId);
15
11
  projectIdsToShow.forEach((projectId) => {
16
12
  const project = getProjectById(projectState, projectId);
17
13
  if (project == null) {
18
14
  return;
19
15
  }
20
- const projectAccountIds = accountsByProject[projectId] ?? [];
21
- const accountsMetadata = projectAccountIds
22
- .map((accountId) => {
23
- const key = getAccountKey(id.reportId, accountId, undefined, undefined, { projectId, sectionId: id.sectionId });
24
- const account = accountState.accountsByKey[key];
25
- if (account == null) {
26
- return undefined;
27
- }
28
- return mapAccountMetadataPayloadToAccountMetadata({
29
- account_id: account.accountId,
30
- account_name: account.accountName,
31
- account_description: account.accountDescription,
32
- labels: account.labels,
33
- is_sub_account: account.accountsViewParentId != null,
34
- parent_account_id: account.accountsViewParentId?.parentAccountId?.[0] ?? null,
35
- });
36
- })
37
- .filter((metadata) => metadata != null);
38
- const nestedAccountHierarchy = getNestedAccountIDHierarchyForAccounts(projectAccountIds, accountsMetadata);
16
+ const projectSectionKey = getSectionProjectViewKey(id.sectionId, projectId, id.reportId);
17
+ const projectSectionView = recordGet(sectionState.sectionsByKey, projectSectionKey, undefined);
18
+ const nestedAccountHierarchy = projectSectionView?.nestedAccountIds ?? [];
39
19
  const nestedAccountReports = [];
40
20
  nestedAccountHierarchy.forEach((accountIdHierarchy) => {
41
21
  const report = getNestedAccountReportForAccount(accountState, {
@@ -50,8 +30,6 @@ export const getSectionProjectViewReport = (accountState, projectState, sectionS
50
30
  nestedAccountReports.push(report);
51
31
  }
52
32
  });
53
- const projectSectionKey = getSectionProjectViewKey(id.sectionId, projectId, id.reportId);
54
- const projectSectionView = recordGet(sectionState.sectionsByKey, projectSectionKey, undefined);
55
33
  const projectBalancesTotalByPeriod = projectSectionView?.balancesByPeriod ?? {};
56
34
  const projectReport = {
57
35
  projectId,
@@ -70,18 +48,3 @@ export const getSectionProjectViewReport = (accountState, projectState, sectionS
70
48
  sectionBalancesTotalByPeriod,
71
49
  };
72
50
  };
73
- const getAccountsByProject = (accountState, sectionId, reportId) => {
74
- const result = {};
75
- Object.values(accountState.accountsByKey).forEach((account) => {
76
- if (account.projectsViewParentId != null &&
77
- account.projectsViewParentId.sectionId === sectionId &&
78
- account.key.endsWith(reportId)) {
79
- const projectId = account.projectsViewParentId.projectId;
80
- if (result[projectId] == null) {
81
- result[projectId] = [];
82
- }
83
- result[projectId].push(account.accountId);
84
- }
85
- });
86
- return result;
87
- };