@zeniai/client-epic-state 5.2.95 → 5.2.97-beta0KB

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,5 @@
1
1
  import { ID } from '../../commonStateTypes/common';
2
+ import { Entity } from './entity';
2
3
  import { EntityState } from './entityState';
3
- export declare function getEntityByEntityIDs(entityState: EntityState, entityIds: ID[]): import("./entity").Entity[];
4
+ export declare function getEntityByEntityIDs(entityState: EntityState, entityIds: ID[]): Entity[];
5
+ export declare function getEntityByEntityId(entityState: EntityState, entityId: ID): Entity | undefined;
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getEntityByEntityIDs = getEntityByEntityIDs;
7
+ exports.getEntityByEntityId = getEntityByEntityId;
8
+ const get_1 = __importDefault(require("lodash/get"));
4
9
  function getEntityByEntityIDs(entityState, entityIds) {
5
10
  return entityIds.map((entityId) => {
6
11
  return entityState.entityById[entityId];
7
12
  });
8
13
  }
14
+ function getEntityByEntityId(entityState, entityId) {
15
+ return (0, get_1.default)(entityState.entityById, entityId, undefined);
16
+ }
@@ -1,5 +1,9 @@
1
+ import recordGet from 'lodash/get';
1
2
  export function getEntityByEntityIDs(entityState, entityIds) {
2
3
  return entityIds.map((entityId) => {
3
4
  return entityState.entityById[entityId];
4
5
  });
5
6
  }
7
+ export function getEntityByEntityId(entityState, entityId) {
8
+ return recordGet(entityState.entityById, entityId, undefined);
9
+ }
@@ -28,6 +28,8 @@ export const initialState = {
28
28
  reimbursementAccountList: initialAccountList,
29
29
  schedulesAccountList: initialAccountList,
30
30
  billPayAccountList: initialAccountList,
31
+ createTransactionLineAccountList: initialAccountList,
32
+ createTransactionPaymentAccountList: initialAccountList,
31
33
  },
32
34
  };
33
35
  const accountList = createSlice({
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/timePeriod';
2
2
  import { getAccountBaseForTransferAccounts } from '../../../entity/account/accountSelector';
3
3
  import { getClassById } from '../../../entity/class/classSelector';
4
+ import { getEntityByEntityId } from '../../../entity/genericEntity/entitySelector';
4
5
  import { toProjectBasePayload, } from '../../../entity/project/projectPayload';
5
6
  import { getProjectById } from '../../../entity/project/projectSelector';
6
7
  import { getVendorByQboId, getVendorByVendorId, } from '../../../entity/vendor/vendorSelector';
@@ -93,10 +94,14 @@ const toSyncedVendorQboId = (vendor) => {
93
94
  }
94
95
  return vendor.qboId;
95
96
  };
96
- /** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
97
+ /**
98
+ * Resolves the picked vendor to its QBO id -- `vendor_id` on the wire is a QBO id. A vendor
99
+ * found by the server-side search is only in the entity store, keyed by its entity id.
100
+ */
97
101
  const toQboVendorId = (state, vendorId) => vendorId == null
98
102
  ? undefined
99
- : toSyncedVendorQboId(getVendorByVendorId(state.vendorState, vendorId));
103
+ : toSyncedVendorQboId(getVendorByVendorId(state.vendorState, vendorId) ??
104
+ getEntityByEntityId(state.entityState, vendorId));
100
105
  /** A journal entry line holds the QBO id already, so it is only checked against the store. */
101
106
  const toQboLineVendorId = (state, vendorQboId) => vendorQboId == null
102
107
  ? undefined
@@ -142,6 +147,8 @@ export const prepareCreateTransactionPayload = (state, localData) => {
142
147
  if (transactionType === 'check') {
143
148
  return {
144
149
  ...purchaseBase,
150
+ // The form has no payment method field for a check; it is always paid by check.
151
+ payment_type: 'check',
145
152
  document_number: localData.documentNumber,
146
153
  print_status: localData.printStatus,
147
154
  remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
@@ -1,5 +1,6 @@
1
1
  import { createSelector } from '@reduxjs/toolkit';
2
- import { getNestedAccountListHierarchy } from '../../accountList/accountListSelector';
2
+ import { getAccountBase } from '../../../entity/account/accountSelector';
3
+ import { getAccountListFetchState, getNestedAccountListHierarchy, } from '../../accountList/accountListSelector';
3
4
  import { getNestedClassListHierarchy } from '../../classList/classListSelector';
4
5
  import { getResolvedTransferAccounts } from '../../createTransferEntry/createTransferEntrySelector';
5
6
  import { getRecommendationsForEntity } from '../../recommendation/recommendationSelector';
@@ -22,6 +23,9 @@ export const getCreateTransactionVendorRecommendations = (state, vendorQboId) =>
22
23
  recommendations: view.recommendations,
23
24
  };
24
25
  };
26
+ /** QBO keeps a sub-account on its parent's type, so filtering the roots is enough. */
27
+ const getBankAccountsOnly = (accountState, hierarchy) => hierarchy.filter((node) => getAccountBase(accountState, node.accountId[0], 'account_list')
28
+ ?.accountType === 'bank');
25
29
  /**
26
30
  * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
27
31
  * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
@@ -30,18 +34,28 @@ export const getCreateTransactionView = createSelector([
30
34
  (state) => state.transactionDetailState.createTransactionsState,
31
35
  (state) => state.vendorState.vendorByID,
32
36
  (state) => state.accountListState,
37
+ (state) => state.accountState,
33
38
  (state) => state.classListState,
34
39
  (state) => getResolvedTransferAccounts(state).transferAccountsList,
35
40
  (_state, transactionType) => transactionType,
36
- ], (createTransactionsState, vendorByID, accountListState, classListState, transferAccountsList, transactionType) => ({
37
- transactionType,
38
- localData: createTransactionsState.newTransactionState[transactionType],
39
- createStatus: createTransactionsState.createStatus,
40
- createdTransactionId: createTransactionsState.createdTransactionId,
41
- vendorList: Object.values(vendorByID),
42
- accountListNestedAccountHierarchy: getNestedAccountListHierarchy(accountListState, 'accountList'),
43
- classListNestedAccountHierarchy: getNestedClassListHierarchy(classListState),
44
- transferAccountsList: transactionType === 'transfer' ? transferAccountsList : [],
45
- fetchState: createTransactionsState.createStatus.fetchState,
46
- error: createTransactionsState.createStatus.error,
47
- }));
41
+ ], (createTransactionsState, vendorByID, accountListState, accountState, classListState, transferAccountsList, transactionType) => {
42
+ const paymentAccountListNestedAccountHierarchy = getNestedAccountListHierarchy(accountListState, 'createTransactionPaymentAccountList');
43
+ return {
44
+ transactionType,
45
+ localData: createTransactionsState.newTransactionState[transactionType],
46
+ createStatus: createTransactionsState.createStatus,
47
+ createdTransactionId: createTransactionsState.createdTransactionId,
48
+ vendorList: Object.values(vendorByID),
49
+ accountListFetchState: getAccountListFetchState(accountListState, 'accountList'),
50
+ lineAccountListFetchState: getAccountListFetchState(accountListState, 'createTransactionLineAccountList'),
51
+ paymentAccountListFetchState: getAccountListFetchState(accountListState, 'createTransactionPaymentAccountList'),
52
+ accountListNestedAccountHierarchy: getNestedAccountListHierarchy(accountListState, 'createTransactionLineAccountList'),
53
+ paymentAccountListNestedAccountHierarchy: transactionType === 'check'
54
+ ? getBankAccountsOnly(accountState, paymentAccountListNestedAccountHierarchy)
55
+ : paymentAccountListNestedAccountHierarchy,
56
+ classListNestedAccountHierarchy: getNestedClassListHierarchy(classListState),
57
+ transferAccountsList: transactionType === 'transfer' ? transferAccountsList : [],
58
+ fetchState: createTransactionsState.createStatus.fetchState,
59
+ error: createTransactionsState.createStatus.error,
60
+ };
61
+ });
@@ -35,6 +35,8 @@ exports.initialState = {
35
35
  reimbursementAccountList: exports.initialAccountList,
36
36
  schedulesAccountList: exports.initialAccountList,
37
37
  billPayAccountList: exports.initialAccountList,
38
+ createTransactionLineAccountList: exports.initialAccountList,
39
+ createTransactionPaymentAccountList: exports.initialAccountList,
38
40
  },
39
41
  };
40
42
  const accountList = (0, toolkit_1.createSlice)({
@@ -1,7 +1,7 @@
1
1
  import { NestedAccountHierarchyForReport } from '../../commonStateTypes/accountView/nestedAccountID';
2
2
  import { FetchedState, ID } from '../../commonStateTypes/common';
3
3
  import { AccountLabel } from '../../entity/account/accountState';
4
- export type AccountListKeyType = 'accountList' | 'reimbursementAccountList' | 'schedulesAccountList' | 'billPayAccountList';
4
+ export type AccountListKeyType = 'accountList' | 'reimbursementAccountList' | 'schedulesAccountList' | 'billPayAccountList' | 'createTransactionLineAccountList' | 'createTransactionPaymentAccountList';
5
5
  export interface AccountList extends FetchedState {
6
6
  accountIds: ID[];
7
7
  accountIdsByLabel: Record<AccountLabel, ID[]>;
@@ -4,6 +4,7 @@ exports.prepareCreateTransactionPayload = exports.UnresolvedCreateTransactionIdE
4
4
  const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
5
5
  const accountSelector_1 = require("../../../entity/account/accountSelector");
6
6
  const classSelector_1 = require("../../../entity/class/classSelector");
7
+ const entitySelector_1 = require("../../../entity/genericEntity/entitySelector");
7
8
  const projectPayload_1 = require("../../../entity/project/projectPayload");
8
9
  const projectSelector_1 = require("../../../entity/project/projectSelector");
9
10
  const vendorSelector_1 = require("../../../entity/vendor/vendorSelector");
@@ -97,10 +98,14 @@ const toSyncedVendorQboId = (vendor) => {
97
98
  }
98
99
  return vendor.qboId;
99
100
  };
100
- /** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
101
+ /**
102
+ * Resolves the picked vendor to its QBO id -- `vendor_id` on the wire is a QBO id. A vendor
103
+ * found by the server-side search is only in the entity store, keyed by its entity id.
104
+ */
101
105
  const toQboVendorId = (state, vendorId) => vendorId == null
102
106
  ? undefined
103
- : toSyncedVendorQboId((0, vendorSelector_1.getVendorByVendorId)(state.vendorState, vendorId));
107
+ : toSyncedVendorQboId((0, vendorSelector_1.getVendorByVendorId)(state.vendorState, vendorId) ??
108
+ (0, entitySelector_1.getEntityByEntityId)(state.entityState, vendorId));
104
109
  /** A journal entry line holds the QBO id already, so it is only checked against the store. */
105
110
  const toQboLineVendorId = (state, vendorQboId) => vendorQboId == null
106
111
  ? undefined
@@ -146,6 +151,8 @@ const prepareCreateTransactionPayload = (state, localData) => {
146
151
  if (transactionType === 'check') {
147
152
  return {
148
153
  ...purchaseBase,
154
+ // The form has no payment method field for a check; it is always paid by check.
155
+ payment_type: 'check',
149
156
  document_number: localData.documentNumber,
150
157
  print_status: localData.printStatus,
151
158
  remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
@@ -9,15 +9,24 @@ import { Vendor } from '../../../entity/vendor/vendorState';
9
9
  import { RootState } from '../../../rootStateTypes';
10
10
  import { CreatableTransactionType, CreateTransactionLocalData } from './createTransactionState';
11
11
  export interface CreateTransactionView extends SelectorView {
12
+ /** The shared COA; on this page it only backs the transfer From/To fallback. */
13
+ accountListFetchState: FetchState;
12
14
  /**
13
- * COA and class trees for the header account and the line dropdowns. The hierarchies rather
14
- * than flat lists, because the create page builds its grouped "Recommended" / "All" options
15
- * with the same helpers the detail page uses.
15
+ * COA and class trees for the line dropdowns. The hierarchies rather than flat lists, because
16
+ * the create page builds its grouped "Recommended" / "All" options with the same helpers the
17
+ * detail page uses.
16
18
  */
17
19
  accountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
18
20
  classListNestedAccountHierarchy: NestedClassHierarchyForReport[];
19
21
  createStatus: FetchStateAndError;
22
+ lineAccountListFetchState: FetchState;
20
23
  localData: CreateTransactionLocalData;
24
+ paymentAccountListFetchState: FetchState;
25
+ /**
26
+ * Bank, credit card and other current asset accounts for the header payment account; bank
27
+ * accounts only for a check.
28
+ */
29
+ paymentAccountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
21
30
  transactionType: CreatableTransactionType;
22
31
  /** Populated for transfer only; the COA would offer ineligible accounts. */
23
32
  transferAccountsList: AccountBase[];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCreateTransactionView = exports.getCreateTransactionVendorRecommendations = exports.getCreateTransactionStatus = exports.getCreateTransactionLocalData = void 0;
4
4
  const toolkit_1 = require("@reduxjs/toolkit");
5
+ const accountSelector_1 = require("../../../entity/account/accountSelector");
5
6
  const accountListSelector_1 = require("../../accountList/accountListSelector");
6
7
  const classListSelector_1 = require("../../classList/classListSelector");
7
8
  const createTransferEntrySelector_1 = require("../../createTransferEntry/createTransferEntrySelector");
@@ -28,6 +29,9 @@ const getCreateTransactionVendorRecommendations = (state, vendorQboId) => {
28
29
  };
29
30
  };
30
31
  exports.getCreateTransactionVendorRecommendations = getCreateTransactionVendorRecommendations;
32
+ /** QBO keeps a sub-account on its parent's type, so filtering the roots is enough. */
33
+ const getBankAccountsOnly = (accountState, hierarchy) => hierarchy.filter((node) => (0, accountSelector_1.getAccountBase)(accountState, node.accountId[0], 'account_list')
34
+ ?.accountType === 'bank');
31
35
  /**
32
36
  * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
33
37
  * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
@@ -36,18 +40,28 @@ exports.getCreateTransactionView = (0, toolkit_1.createSelector)([
36
40
  (state) => state.transactionDetailState.createTransactionsState,
37
41
  (state) => state.vendorState.vendorByID,
38
42
  (state) => state.accountListState,
43
+ (state) => state.accountState,
39
44
  (state) => state.classListState,
40
45
  (state) => (0, createTransferEntrySelector_1.getResolvedTransferAccounts)(state).transferAccountsList,
41
46
  (_state, transactionType) => transactionType,
42
- ], (createTransactionsState, vendorByID, accountListState, classListState, transferAccountsList, transactionType) => ({
43
- transactionType,
44
- localData: createTransactionsState.newTransactionState[transactionType],
45
- createStatus: createTransactionsState.createStatus,
46
- createdTransactionId: createTransactionsState.createdTransactionId,
47
- vendorList: Object.values(vendorByID),
48
- accountListNestedAccountHierarchy: (0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, 'accountList'),
49
- classListNestedAccountHierarchy: (0, classListSelector_1.getNestedClassListHierarchy)(classListState),
50
- transferAccountsList: transactionType === 'transfer' ? transferAccountsList : [],
51
- fetchState: createTransactionsState.createStatus.fetchState,
52
- error: createTransactionsState.createStatus.error,
53
- }));
47
+ ], (createTransactionsState, vendorByID, accountListState, accountState, classListState, transferAccountsList, transactionType) => {
48
+ const paymentAccountListNestedAccountHierarchy = (0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, 'createTransactionPaymentAccountList');
49
+ return {
50
+ transactionType,
51
+ localData: createTransactionsState.newTransactionState[transactionType],
52
+ createStatus: createTransactionsState.createStatus,
53
+ createdTransactionId: createTransactionsState.createdTransactionId,
54
+ vendorList: Object.values(vendorByID),
55
+ accountListFetchState: (0, accountListSelector_1.getAccountListFetchState)(accountListState, 'accountList'),
56
+ lineAccountListFetchState: (0, accountListSelector_1.getAccountListFetchState)(accountListState, 'createTransactionLineAccountList'),
57
+ paymentAccountListFetchState: (0, accountListSelector_1.getAccountListFetchState)(accountListState, 'createTransactionPaymentAccountList'),
58
+ accountListNestedAccountHierarchy: (0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, 'createTransactionLineAccountList'),
59
+ paymentAccountListNestedAccountHierarchy: transactionType === 'check'
60
+ ? getBankAccountsOnly(accountState, paymentAccountListNestedAccountHierarchy)
61
+ : paymentAccountListNestedAccountHierarchy,
62
+ classListNestedAccountHierarchy: (0, classListSelector_1.getNestedClassListHierarchy)(classListState),
63
+ transferAccountsList: transactionType === 'transfer' ? transferAccountsList : [],
64
+ fetchState: createTransactionsState.createStatus.fetchState,
65
+ error: createTransactionsState.createStatus.error,
66
+ };
67
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.2.95",
3
+ "version": "5.2.97-beta0KB",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",