@zeniai/client-epic-state 5.2.62-beta0MM → 5.2.62-beta1KB

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 (70) hide show
  1. package/lib/entity/actualMatching/actualMatchingReducer.d.ts +1 -3
  2. package/lib/entity/actualMatching/actualMatchingReducer.js +2 -11
  3. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +0 -1
  4. package/lib/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +0 -1
  6. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  7. package/lib/entity/snackbar/snackbarTypes.js +1 -1
  8. package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
  9. package/lib/entity/transaction/stateTypes/paymentType.js +9 -1
  10. package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
  11. package/lib/entity/transaction/stateTypes/printStatus.js +15 -0
  12. package/lib/epic.d.ts +4 -2
  13. package/lib/epic.js +6 -2
  14. package/lib/esm/entity/actualMatching/actualMatchingReducer.js +1 -9
  15. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  16. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -1
  17. package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
  18. package/lib/esm/entity/transaction/stateTypes/printStatus.js +11 -0
  19. package/lib/esm/epic.js +6 -2
  20. package/lib/esm/index.js +10 -7
  21. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +3 -7
  22. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +23 -2
  23. package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +35 -66
  24. package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -60
  25. package/lib/esm/view/expenseAutomationView/types/actualMatchingViewState.js +0 -15
  26. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
  27. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +133 -0
  28. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +124 -0
  29. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +41 -0
  30. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
  31. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +58 -0
  32. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +55 -0
  33. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
  34. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +174 -1
  35. package/lib/index.d.ts +12 -8
  36. package/lib/index.js +70 -57
  37. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +3 -7
  38. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +22 -1
  39. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  40. package/lib/view/expenseAutomationView/payload/actualMatchingPayload.d.ts +1 -12
  41. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.d.ts +8 -16
  42. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +36 -67
  43. package/lib/view/expenseAutomationView/selectorTypes/actualMatchingViewSelectorTypes.d.ts +8 -20
  44. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +4 -7
  45. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -63
  46. package/lib/view/expenseAutomationView/types/actualMatchingViewState.d.ts +4 -20
  47. package/lib/view/expenseAutomationView/types/actualMatchingViewState.js +1 -18
  48. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -1
  49. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
  50. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +51 -0
  51. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +148 -0
  52. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +82 -0
  53. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +128 -0
  54. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +40 -0
  55. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +48 -0
  56. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +81 -0
  57. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
  58. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
  59. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +62 -0
  60. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
  61. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +59 -0
  62. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
  63. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +18 -0
  64. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +37 -1
  65. package/lib/view/transactionDetail/transactionDetailReducer.js +176 -2
  66. package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
  67. package/package.json +1 -1
  68. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -50
  69. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.d.ts +0 -10
  70. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -54
@@ -0,0 +1,82 @@
1
+ import { ID } from '../../../commonStateTypes/common';
2
+ import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
+ import { ZeniAPIResponse } from '../../../responsePayload';
4
+ import { RootState } from '../../../rootStateTypes';
5
+ import { CreateTransactionLocalData } from './createTransactionState';
6
+ /**
7
+ * Wire types for POST /1.0/transactions/manage.
8
+ *
9
+ * Two things here are easy to get wrong and are deliberately explicit:
10
+ *
11
+ * 1. `line_detail_type` is snake_case. The PascalCase strings in the backend are Python
12
+ * constant NAMES; ZENI_LINE_DETAIL_TYPE_TO_QBO_LINE_DETAIL_TYPE_MAP converts them for the
13
+ * body the backend sends on to QuickBooks, never for ours.
14
+ * 2. The reference number uses two different keys depending on the QBO entity. check and
15
+ * expense are Purchases and take `document_number`; everything else takes `document_id`.
16
+ */
17
+ export interface CreateTransactionAccountPayload {
18
+ qbo_id: ID;
19
+ account_name?: string;
20
+ }
21
+ export interface CreateTransactionLineDetailPayload {
22
+ account?: CreateTransactionAccountPayload;
23
+ class?: Record<string, never> | {
24
+ qbo_id: ID;
25
+ };
26
+ /**
27
+ * journal_entry only, and it MUST sit inside line_detail. The write validator's docstring
28
+ * warns that a misplaced posting_type is silently dropped and then rejected by QBO.
29
+ */
30
+ posting_type?: 'credit' | 'debit';
31
+ vendor?: {
32
+ qbo_id: ID;
33
+ };
34
+ }
35
+ export interface CreateTransactionLinePayload {
36
+ amount: number;
37
+ line_detail: CreateTransactionLineDetailPayload;
38
+ line_detail_type: 'account_based_expense_line_detail' | 'item_based_expense_line_detail' | 'journal_entry_line_detail';
39
+ line_description?: string;
40
+ }
41
+ export interface CreateTransactionRemitToAddressPayload {
42
+ city?: string;
43
+ country?: string;
44
+ line1?: string;
45
+ postal_code?: string;
46
+ state?: string;
47
+ }
48
+ export interface CreateTransactionRequest extends Record<string, unknown> {
49
+ transaction_date: string;
50
+ transaction_type: string;
51
+ /** journal_entry reference number. */
52
+ document_id?: string;
53
+ /** check / credit_card_credit reference number (QBO Purchase). */
54
+ document_number?: string;
55
+ from_account_id?: ID;
56
+ /** credit_card_credit is modelled as a Purchase with Credit: true. */
57
+ is_credit?: boolean;
58
+ lines?: CreateTransactionLinePayload[];
59
+ payment_type?: string;
60
+ print_status?: string;
61
+ qbo_account_id?: ID;
62
+ remit_to_address?: CreateTransactionRemitToAddressPayload;
63
+ to_account_id?: ID;
64
+ total_amount?: number;
65
+ transaction_memo?: string;
66
+ vendor_id?: ID;
67
+ }
68
+ /**
69
+ * The create endpoint writes to QBO and returns the created entity; Zeni's own mirror is
70
+ * populated by the delta sync that runs afterwards, so this response is the only view of the
71
+ * new transaction the client gets immediately.
72
+ */
73
+ export interface CreateTransactionPayload {
74
+ transactions: TransactionPayload[];
75
+ }
76
+ export type CreateTransactionResponse = ZeniAPIResponse<CreateTransactionPayload>;
77
+ /**
78
+ * Builds the request body for one transaction type. One branch per type rather than a shared
79
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
80
+ * all, and journal_entry carries no header account.
81
+ */
82
+ export declare const prepareCreateTransactionPayload: (state: RootState, localData: CreateTransactionLocalData) => CreateTransactionRequest;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareCreateTransactionPayload = void 0;
4
+ const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
5
+ const accountSelector_1 = require("../../../entity/account/accountSelector");
6
+ const classSelector_1 = require("../../../entity/class/classSelector");
7
+ const vendorSelector_1 = require("../../../entity/vendor/vendorSelector");
8
+ const toRemitToAddressPayload = (address) => {
9
+ if (address == null) {
10
+ return undefined;
11
+ }
12
+ return {
13
+ line1: address.line1,
14
+ city: address.city,
15
+ state: address.state,
16
+ postal_code: address.postalCode,
17
+ country: address.country,
18
+ };
19
+ };
20
+ const toLinePayload = (state, line, transactionType) => {
21
+ const lineDetail = {};
22
+ if (line.accountQboId != null) {
23
+ lineDetail.account = {
24
+ qbo_id: line.accountQboId,
25
+ account_name: line.accountName,
26
+ };
27
+ }
28
+ // An empty object is what the confirmed payloads send when no class is chosen; sending the
29
+ // key with a qbo_id only once one is picked.
30
+ const classQboId = toQboClassId(state, line.classId);
31
+ lineDetail.class = classQboId != null ? { qbo_id: classQboId } : {};
32
+ if (transactionType === 'journal_entry') {
33
+ lineDetail.posting_type = line.postingType;
34
+ if (line.vendorQboId != null) {
35
+ lineDetail.vendor = { qbo_id: line.vendorQboId };
36
+ }
37
+ }
38
+ return {
39
+ // The backend rejects a bool here, so this is always coerced to a number.
40
+ amount: line.amount?.amount ?? 0,
41
+ line_description: line.lineDescription,
42
+ line_detail_type: transactionType === 'journal_entry'
43
+ ? 'journal_entry_line_detail'
44
+ : 'account_based_expense_line_detail',
45
+ line_detail: lineDetail,
46
+ };
47
+ };
48
+ /** Resolves a Zeni account id to the QBO id the endpoint expects. */
49
+ const toQboAccountId = (state, accountId) => {
50
+ if (accountId == null) {
51
+ return undefined;
52
+ }
53
+ return ((0, accountSelector_1.getAccountBase)(state.accountState, accountId, 'account_list')?.qboId ??
54
+ accountId);
55
+ };
56
+ /** Resolves a Zeni class id (`class_<uuid>`) to the QBO id `line_detail.class.qbo_id` expects. */
57
+ const toQboClassId = (state, classId) => {
58
+ if (classId == null) {
59
+ return undefined;
60
+ }
61
+ return ((0, classSelector_1.getClassById)(state.classState, { classId, reportId: 'class_list' })
62
+ ?.qboId ?? classId);
63
+ };
64
+ /** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
65
+ const toQboVendorId = (state, vendorId) => {
66
+ if (vendorId == null) {
67
+ return undefined;
68
+ }
69
+ return (0, vendorSelector_1.getVendorByVendorId)(state.vendorState, vendorId)?.qboId ?? vendorId;
70
+ };
71
+ /**
72
+ * Builds the request body for one transaction type. One branch per type rather than a shared
73
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
74
+ * all, and journal_entry carries no header account.
75
+ */
76
+ const prepareCreateTransactionPayload = (state, localData) => {
77
+ const { transactionType } = localData;
78
+ const base = {
79
+ transaction_type: transactionType,
80
+ transaction_date: localData.transactionDate?.format(timePeriod_1.DEFAULT_DATE_FORMAT) ?? '',
81
+ transaction_memo: localData.transactionMemo,
82
+ };
83
+ if (transactionType === 'transfer') {
84
+ return {
85
+ ...base,
86
+ from_account_id: toQboAccountId(state, localData.fromAccountId),
87
+ to_account_id: toQboAccountId(state, localData.toAccountId),
88
+ total_amount: localData.totalAmount?.amount ?? 0,
89
+ };
90
+ }
91
+ const lines = localData.lines.map((line) => toLinePayload(state, line, transactionType));
92
+ if (transactionType === 'journal_entry') {
93
+ return {
94
+ ...base,
95
+ document_id: localData.documentId,
96
+ lines,
97
+ };
98
+ }
99
+ const purchaseBase = {
100
+ ...base,
101
+ payment_type: localData.paymentType,
102
+ qbo_account_id: toQboAccountId(state, localData.qboAccountId),
103
+ vendor_id: toQboVendorId(state, localData.vendorId),
104
+ lines,
105
+ };
106
+ if (transactionType === 'check') {
107
+ return {
108
+ ...purchaseBase,
109
+ document_number: localData.documentNumber,
110
+ print_status: localData.printStatus,
111
+ remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
112
+ };
113
+ }
114
+ if (transactionType === 'credit_card_credit') {
115
+ // credit_card_credit is not in the backend's SUPPORTED_TRANSACTION_WRITE_TYPES. QBO models
116
+ // it as a Purchase with Credit: true and qbo_purchase.py already honours is_credit for
117
+ // card payment types, so this sends `expense` + is_credit rather than a type the validator
118
+ // rejects outright. Confirm with backend before enabling the menu item.
119
+ return {
120
+ ...purchaseBase,
121
+ transaction_type: 'expense',
122
+ is_credit: true,
123
+ document_number: localData.documentNumber,
124
+ };
125
+ }
126
+ return purchaseBase;
127
+ };
128
+ exports.prepareCreateTransactionPayload = prepareCreateTransactionPayload;
@@ -0,0 +1,40 @@
1
+ import { FetchState, FetchStateAndError } from '../../../commonStateTypes/common';
2
+ import { Recommendation } from '../../../commonStateTypes/recommendationBase';
3
+ import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
4
+ import { AccountBase } from '../../../entity/account/accountState';
5
+ import { TransactionID } from '../../../entity/transaction/stateTypes/transactionID';
6
+ import { Vendor } from '../../../entity/vendor/vendorState';
7
+ import { RootState } from '../../../rootStateTypes';
8
+ import { NestedAccountHierarchyForReport } from '../../../commonStateTypes/accountView/nestedAccountID';
9
+ import { NestedClassHierarchyForReport } from '../../../commonStateTypes/classesView/nestedClassID';
10
+ import { CreatableTransactionType, CreateTransactionLocalData } from './createTransactionState';
11
+ export interface CreateTransactionView extends SelectorView {
12
+ /**
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.
16
+ */
17
+ accountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
18
+ classListNestedAccountHierarchy: NestedClassHierarchyForReport[];
19
+ createStatus: FetchStateAndError;
20
+ localData: CreateTransactionLocalData;
21
+ transactionType: CreatableTransactionType;
22
+ /** Populated for transfer only; the COA would offer ineligible accounts. */
23
+ transferAccountsList: AccountBase[];
24
+ vendorList: Vendor[];
25
+ createdTransactionId?: TransactionID;
26
+ }
27
+ export declare const getCreateTransactionLocalData: (state: RootState, transactionType: CreatableTransactionType) => CreateTransactionLocalData;
28
+ export declare const getCreateTransactionStatus: (state: RootState) => FetchStateAndError;
29
+ /**
30
+ * The vendor recommendations backing the category/class dropdowns on the create page.
31
+ *
32
+ * No new state field is needed for this: getRecommendationsForEntity already returns
33
+ * fetchState alongside recommendations, so composing it here is enough for the page to show a
34
+ * line skeleton and hold Save while a fetch is in flight.
35
+ */
36
+ export declare const getCreateTransactionVendorRecommendations: (state: RootState, vendorQboId?: string) => {
37
+ fetchState: FetchState;
38
+ recommendations?: Recommendation[];
39
+ };
40
+ export declare const getCreateTransactionView: (state: RootState, transactionType: CreatableTransactionType) => CreateTransactionView;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCreateTransactionView = exports.getCreateTransactionVendorRecommendations = exports.getCreateTransactionStatus = exports.getCreateTransactionLocalData = void 0;
4
+ const accountListSelector_1 = require("../../accountList/accountListSelector");
5
+ const classListSelector_1 = require("../../classList/classListSelector");
6
+ const createTransferEntrySelector_1 = require("../../createTransferEntry/createTransferEntrySelector");
7
+ const recommendationSelector_1 = require("../../recommendation/recommendationSelector");
8
+ const getCreateTransactionLocalData = (state, transactionType) => state.transactionDetailState.createTransactionsState.newTransactionState[transactionType];
9
+ exports.getCreateTransactionLocalData = getCreateTransactionLocalData;
10
+ const getCreateTransactionStatus = (state) => state.transactionDetailState.createTransactionsState.createStatus;
11
+ exports.getCreateTransactionStatus = getCreateTransactionStatus;
12
+ /**
13
+ * The vendor recommendations backing the category/class dropdowns on the create page.
14
+ *
15
+ * No new state field is needed for this: getRecommendationsForEntity already returns
16
+ * fetchState alongside recommendations, so composing it here is enough for the page to show a
17
+ * line skeleton and hold Save while a fetch is in flight.
18
+ */
19
+ const getCreateTransactionVendorRecommendations = (state, vendorQboId) => {
20
+ if (vendorQboId == null || vendorQboId === '') {
21
+ return { fetchState: 'Not-Started' };
22
+ }
23
+ const view = (0, recommendationSelector_1.getRecommendationsForEntity)(state, vendorQboId, 'vendor');
24
+ return {
25
+ fetchState: view.fetchState,
26
+ recommendations: view.recommendations,
27
+ };
28
+ };
29
+ exports.getCreateTransactionVendorRecommendations = getCreateTransactionVendorRecommendations;
30
+ const getCreateTransactionView = (state, transactionType) => {
31
+ const { accountListState, classListState, transactionDetailState, vendorState, } = state;
32
+ const { createTransactionsState } = transactionDetailState;
33
+ return {
34
+ transactionType,
35
+ localData: createTransactionsState.newTransactionState[transactionType],
36
+ createStatus: createTransactionsState.createStatus,
37
+ createdTransactionId: createTransactionsState.createdTransactionId,
38
+ vendorList: Object.values(vendorState.vendorByID),
39
+ accountListNestedAccountHierarchy: (0, accountListSelector_1.getNestedAccountListHierarchy)(accountListState, 'accountList'),
40
+ classListNestedAccountHierarchy: (0, classListSelector_1.getNestedClassListHierarchy)(classListState),
41
+ transferAccountsList: transactionType === 'transfer'
42
+ ? (0, createTransferEntrySelector_1.getResolvedTransferAccounts)(state).transferAccountsList
43
+ : [],
44
+ fetchState: createTransactionsState.createStatus.fetchState,
45
+ error: createTransactionsState.createStatus.error,
46
+ };
47
+ };
48
+ exports.getCreateTransactionView = getCreateTransactionView;
@@ -0,0 +1,81 @@
1
+ import { Amount } from '../../../commonStateTypes/amount';
2
+ import { ID } from '../../../commonStateTypes/common';
3
+ import { RecommendationWithCOT } from '../../../commonStateTypes/recommendationBase';
4
+ import { PaymentType } from '../../../entity/transaction/stateTypes/paymentType';
5
+ import { PrintStatus } from '../../../entity/transaction/stateTypes/printStatus';
6
+ import { TransactionCategory, TransactionType } from '../../../entity/transaction/stateTypes/transactionType';
7
+ import { ZeniDate } from '../../../zeniDayJS';
8
+ /**
9
+ * The transaction types the Create Transaction flow can originate. A narrow subset of
10
+ * TransactionType -- everything else is read-only and arrives via sync.
11
+ */
12
+ export declare const ALL_CREATABLE_TRANSACTION_TYPES: readonly ["expense", "check", "credit_card_credit", "transfer", "journal_entry"];
13
+ export type CreatableTransactionType = (typeof ALL_CREATABLE_TRANSACTION_TYPES)[number];
14
+ /**
15
+ * The wire shape the create endpoint expects for a check's remit-to address. Deliberately not
16
+ * the CES AddressPayload, which carries `street: string[]` plus address_id/create_time/
17
+ * update_time that the create endpoint does not accept.
18
+ */
19
+ export interface RemitToAddress {
20
+ city?: string;
21
+ country?: string;
22
+ line1?: string;
23
+ postalCode?: string;
24
+ state?: string;
25
+ }
26
+ export interface CreateTransactionLineLocalData {
27
+ /** Client-side row key only -- never sent. */
28
+ id: string;
29
+ accountName?: string;
30
+ accountQboId?: ID;
31
+ amount?: Amount;
32
+ classId?: ID;
33
+ /**
34
+ * Tracked per field, not per line. A line can have a hand-picked account and a prefilled
35
+ * class at the same time, and clearing the vendor must undo only the latter.
36
+ */
37
+ isAccountPreFilled?: boolean;
38
+ isClassPreFilled?: boolean;
39
+ lineDescription?: string;
40
+ /** journal_entry only. */
41
+ postingType?: TransactionCategory;
42
+ projectId?: ID;
43
+ /**
44
+ * Backs the "Recommended" group in the category/class dropdowns. Carries the COT shape the
45
+ * line-table row already expects, with empty cot/reasoning -- chain-of-thought needs an
46
+ * existing transaction, which a create does not have.
47
+ */
48
+ recommendationsWithCOT?: RecommendationWithCOT[];
49
+ /** journal_entry only -- the per-line name. */
50
+ vendorQboId?: ID;
51
+ }
52
+ export interface CreateTransactionLocalData {
53
+ /** Empty for transfer, which has no lines at all. */
54
+ lines: CreateTransactionLineLocalData[];
55
+ transactionType: CreatableTransactionType;
56
+ /** journal_entry reference number. */
57
+ documentId?: string;
58
+ /** check / credit_card_credit reference number. */
59
+ documentNumber?: string;
60
+ /** transfer */
61
+ fromAccountId?: ID;
62
+ paymentType?: PaymentType;
63
+ /** check only. */
64
+ printStatus?: PrintStatus;
65
+ qboAccountId?: ID;
66
+ /** check only. */
67
+ remitToAddress?: RemitToAddress;
68
+ toAccountId?: ID;
69
+ /** transfer only -- every other type derives its total from the lines. */
70
+ totalAmount?: Amount;
71
+ transactionDate?: ZeniDate;
72
+ transactionMemo?: string;
73
+ vendorId?: ID;
74
+ }
75
+ export type CreateTransactionLocalDataByType = Record<CreatableTransactionType, CreateTransactionLocalData>;
76
+ /**
77
+ * Type-level guarantee that CreatableTransactionType stays a subset of TransactionType. If a
78
+ * value is ever added here that the entity layer does not know about, this line fails to
79
+ * compile rather than failing at the payload boundary.
80
+ */
81
+ export type CreatableTransactionTypeIsTransactionType = CreatableTransactionType extends TransactionType ? true : never;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_CREATABLE_TRANSACTION_TYPES = void 0;
4
+ /**
5
+ * The transaction types the Create Transaction flow can originate. A narrow subset of
6
+ * TransactionType -- everything else is read-only and arrives via sync.
7
+ */
8
+ exports.ALL_CREATABLE_TRANSACTION_TYPES = [
9
+ 'expense',
10
+ 'check',
11
+ 'credit_card_credit',
12
+ 'transfer',
13
+ 'journal_entry',
14
+ ];
@@ -0,0 +1,9 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
+ import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
5
+ import { RootState } from '../../../../rootStateTypes';
6
+ import { ZeniAPI } from '../../../../zeniAPI';
7
+ import { createTransaction, createTransactionSuccessOrFailure, initializeTransactionDetailLocalData, resetCreateTransactionLocalData } from '../../transactionDetailReducer';
8
+ export type ActionType = ReturnType<typeof createTransaction> | ReturnType<typeof createTransactionSuccessOrFailure> | ReturnType<typeof resetCreateTransactionLocalData> | ReturnType<typeof initializeTransactionDetailLocalData> | ReturnType<typeof updateTransaction> | ReturnType<typeof openSnackbar>;
9
+ export declare const createTransactionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTransactionEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
7
+ const transactionIDPayload_1 = require("../../../../entity/transaction/payloadTypes/transactionIDPayload");
8
+ const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
9
+ const responsePayload_1 = require("../../../../responsePayload");
10
+ const transactionDetailReducer_1 = require("../../transactionDetailReducer");
11
+ const transactionDetailState_1 = require("../../transactionDetailState");
12
+ const createTransactionPayload_1 = require("../createTransactionPayload");
13
+ const failureActions = (message, status) => [
14
+ (0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Error', undefined, status),
15
+ (0, snackbarReducer_1.openSnackbar)({
16
+ messageSection: 'create_transaction',
17
+ messageText: 'failed',
18
+ type: 'error',
19
+ // This variable is how the server's own message reaches the user. Per-type required
20
+ // fields live in the QBO entity classes, so a rejection comes back as a QBO error with no
21
+ // field name -- the message text is the only useful content we get.
22
+ variables: [{ variableName: '_api-error_', variableValue: message }],
23
+ }),
24
+ ];
25
+ const createTransactionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.createTransaction.match), (0, operators_1.mergeMap)((action) => {
26
+ const { transactionType } = action.payload;
27
+ const state = state$.value;
28
+ const localData = state.transactionDetailState.createTransactionsState
29
+ .newTransactionState[transactionType];
30
+ const payload = (0, createTransactionPayload_1.prepareCreateTransactionPayload)(state, localData);
31
+ return zeniAPI
32
+ .postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/manage`, payload)
33
+ .pipe((0, operators_1.mergeMap)((response) => {
34
+ if (!(0, responsePayload_1.isSuccessResponse)(response) || response.data == null) {
35
+ return (0, rxjs_1.from)(failureActions(response.status.message, response.status));
36
+ }
37
+ const created = response.data.transactions[0];
38
+ if (created == null) {
39
+ return (0, rxjs_1.from)(failureActions('Transaction was created but returned no details.', (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Create transaction returned an empty transactions array.')));
40
+ }
41
+ const newTransactionId = (0, transactionIDPayload_1.toTransactionID)(created);
42
+ // The write is QBO-only: transaction_write_handler.py touches no local storage, and
43
+ // Zeni's mirror is populated by the delta sync that runs afterwards. Refetching here
44
+ // would come back without the new row, so the 200 body is inserted optimistically
45
+ // instead -- the same approach createTransferEntryEpic takes.
46
+ return (0, rxjs_1.from)([
47
+ (0, transactionReducer_1.updateTransaction)((0, transactionDetailState_1.getTransactionDetailKey)(newTransactionId), created),
48
+ (0, transactionDetailReducer_1.initializeTransactionDetailLocalData)({
49
+ transactionId: newTransactionId,
50
+ vendorId: created.vendor_id ?? undefined,
51
+ }),
52
+ (0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Completed', newTransactionId),
53
+ (0, transactionDetailReducer_1.resetCreateTransactionLocalData)(transactionType),
54
+ (0, snackbarReducer_1.openSnackbar)({
55
+ messageSection: 'create_transaction',
56
+ messageText: 'success',
57
+ type: 'success',
58
+ }),
59
+ ]);
60
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.from)(failureActions(JSON.stringify(error), (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Create Transaction REST API call errored out ${JSON.stringify(error)}`)))));
61
+ }));
62
+ exports.createTransactionEpic = createTransactionEpic;
@@ -0,0 +1,20 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { RootState } from '../../../../rootStateTypes';
4
+ import { fetchRecommendationByEntityId, fetchRecommendationByEntityName, indicateReadyToInitializeRecommendation } from '../../../recommendation/recommendationReducer';
5
+ import { clearRecommendationsForCreateTransactionLines, fetchVendorRecommendationsForCreateTransaction, setRecommendationsForCreateTransactionLines } from '../../transactionDetailReducer';
6
+ export type ActionType = ReturnType<typeof fetchVendorRecommendationsForCreateTransaction> | ReturnType<typeof setRecommendationsForCreateTransactionLines> | ReturnType<typeof clearRecommendationsForCreateTransactionLines> | ReturnType<typeof fetchRecommendationByEntityId> | ReturnType<typeof fetchRecommendationByEntityName> | ReturnType<typeof indicateReadyToInitializeRecommendation>;
7
+ /**
8
+ * On vendor select, populates the category/class dropdowns from that vendor's recommendations.
9
+ *
10
+ * Deliberately NOT the detail page's fetchEntityRecommendationsForLineUpdate: that one sends
11
+ * transaction_id / line_ids and writes into transactionDetailById[key], which no-ops when the
12
+ * entry does not exist. A transaction being created has neither.
13
+ *
14
+ * Two differences from the reimbursement epic this is modelled on:
15
+ * 1. the wait filters on the matching entityIdOrName before take(1), so an unrelated
16
+ * recommendation landing first cannot satisfy this request, and
17
+ * 2. switchMap, so changing the vendor again cancels the earlier wait rather than letting a
18
+ * stale result overwrite the newer vendor's prefill.
19
+ */
20
+ export declare const fetchVendorRecommendationsForCreateTransactionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchVendorRecommendationsForCreateTransactionEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
7
+ const recommendationReducer_1 = require("../../../recommendation/recommendationReducer");
8
+ const recommendationSelector_1 = require("../../../recommendation/recommendationSelector");
9
+ const transactionDetailReducer_1 = require("../../transactionDetailReducer");
10
+ /**
11
+ * The entity-level recommendation fetch, keyed by whatever identifier the endpoint can resolve.
12
+ *
13
+ * A vendor that has not synced to QBO carries `qboId === name`; the id endpoint has nothing to
14
+ * look up in that case, so the by-name variant is used instead.
15
+ */
16
+ const toEntityIdOrName = (entity) => entity.qboId !== '' && entity.qboId !== entity.name
17
+ ? entity.qboId
18
+ : entity.name;
19
+ const isUnsyncedVendor = (entity) => entity.qboId === '' || entity.qboId === entity.name;
20
+ /**
21
+ * On vendor select, populates the category/class dropdowns from that vendor's recommendations.
22
+ *
23
+ * Deliberately NOT the detail page's fetchEntityRecommendationsForLineUpdate: that one sends
24
+ * transaction_id / line_ids and writes into transactionDetailById[key], which no-ops when the
25
+ * entry does not exist. A transaction being created has neither.
26
+ *
27
+ * Two differences from the reimbursement epic this is modelled on:
28
+ * 1. the wait filters on the matching entityIdOrName before take(1), so an unrelated
29
+ * recommendation landing first cannot satisfy this request, and
30
+ * 2. switchMap, so changing the vendor again cancels the earlier wait rather than letting a
31
+ * stale result overwrite the newer vendor's prefill.
32
+ */
33
+ const fetchVendorRecommendationsForCreateTransactionEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.fetchVendorRecommendationsForCreateTransaction.match), (0, operators_1.switchMap)((action) => {
34
+ const { transactionType, entity, lineIds } = action.payload;
35
+ if (entity == null) {
36
+ return (0, rxjs_1.of)((0, transactionDetailReducer_1.clearRecommendationsForCreateTransactionLines)(transactionType, lineIds));
37
+ }
38
+ const entityIdOrName = toEntityIdOrName(entity);
39
+ const state = state$.value;
40
+ const isAccountingClassesEnabled = (0, tenantSelector_1.getIsAccountingClassesEnabled)(state);
41
+ const cached = (0, recommendationSelector_1.getRecommendationsForEntity)(state, entityIdOrName, 'vendor');
42
+ // Cache hit: apply straight away, no request and no wait.
43
+ if (cached.fetchState === 'Completed') {
44
+ return (0, rxjs_1.of)((0, transactionDetailReducer_1.setRecommendationsForCreateTransactionLines)(transactionType, lineIds, cached.recommendations ?? [], isAccountingClassesEnabled));
45
+ }
46
+ const waitThenApply = actions$.pipe((0, operators_1.filter)(recommendationReducer_1.indicateReadyToInitializeRecommendation.match), (0, operators_1.filter)((ready) => ready.payload.entityType === 'vendor' &&
47
+ ready.payload.entityIdOrName === entityIdOrName), (0, operators_1.take)(1), // don't listen forever! IMPORTANT!
48
+ (0, operators_1.mergeMap)(() => (0, rxjs_1.from)([
49
+ (0, transactionDetailReducer_1.setRecommendationsForCreateTransactionLines)(transactionType, lineIds, (0, recommendationSelector_1.getRecommendationsForEntity)(state$.value, entityIdOrName, 'vendor').recommendations ?? [], (0, tenantSelector_1.getIsAccountingClassesEnabled)(state$.value)),
50
+ ])));
51
+ // A fetch already in flight needs no second request, only the wait.
52
+ if (cached.fetchState === 'In-Progress') {
53
+ return waitThenApply;
54
+ }
55
+ return (0, rxjs_1.concat)((0, rxjs_1.of)((isUnsyncedVendor(entity)
56
+ ? (0, recommendationReducer_1.fetchRecommendationByEntityName)(entityIdOrName, 'vendor')
57
+ : (0, recommendationReducer_1.fetchRecommendationByEntityId)(entityIdOrName, 'vendor'))), waitThenApply);
58
+ }));
59
+ exports.fetchVendorRecommendationsForCreateTransactionEpic = fetchVendorRecommendationsForCreateTransactionEpic;
@@ -0,0 +1,12 @@
1
+ import { ActionsObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { initializeCreateTransactionLocalData, updateCreateTransactionLocalData } from '../../transactionDetailReducer';
4
+ export type ActionType = ReturnType<typeof initializeCreateTransactionLocalData> | ReturnType<typeof updateCreateTransactionLocalData>;
5
+ /**
6
+ * Seeds the working copy when the Create form opens: today's date, the default line set for the
7
+ * type, and a check's mandatory payment_type.
8
+ *
9
+ * Mirrors the `else` branch of initializeScheduleDetailLocalDataEpic -- a create has no
10
+ * existing entity to read from, so there is nothing to merge, only defaults to apply.
11
+ */
12
+ export declare const initializeCreateTransactionLocalDataEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initializeCreateTransactionLocalDataEpic = void 0;
4
+ const operators_1 = require("rxjs/operators");
5
+ const transactionDetailReducer_1 = require("../../transactionDetailReducer");
6
+ const createTransactionLocalDataHelper_1 = require("../createTransactionLocalDataHelper");
7
+ /**
8
+ * Seeds the working copy when the Create form opens: today's date, the default line set for the
9
+ * type, and a check's mandatory payment_type.
10
+ *
11
+ * Mirrors the `else` branch of initializeScheduleDetailLocalDataEpic -- a create has no
12
+ * existing entity to read from, so there is nothing to merge, only defaults to apply.
13
+ */
14
+ const initializeCreateTransactionLocalDataEpic = (actions$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.initializeCreateTransactionLocalData.match), (0, operators_1.map)((action) => {
15
+ const { transactionType } = action.payload;
16
+ return (0, transactionDetailReducer_1.updateCreateTransactionLocalData)(transactionType, (0, createTransactionLocalDataHelper_1.getSeededCreateTransactionLocalData)(transactionType));
17
+ }));
18
+ exports.initializeCreateTransactionLocalDataEpic = initializeCreateTransactionLocalDataEpic;
@@ -9,6 +9,7 @@ import { TransactionID } from '../../entity/transaction/stateTypes/transactionID
9
9
  import { SupportedTransaction, SupportedTransactionPayload } from '../../entity/transaction/transactionState';
10
10
  import { ZeniAPIStatus } from '../../responsePayload';
11
11
  import { UncategorizedAccounts } from '../accountList/accountListSelector';
12
+ import { CreateTransactionLineLocalData, CreateTransactionLocalData } from './createTransaction/createTransactionState';
12
13
  import { TransactionDetailState, TransactionSaveUpdates } from './transactionDetailState';
13
14
  import { TransactionDetailLineItemData, TransactionDetailLocalData, TransactionVendorUpdates } from './transactionDetailTypes';
14
15
  export declare const initialState: TransactionDetailState;
@@ -176,6 +177,41 @@ export declare const downloadAccountingProviderAttachment: import("@reduxjs/tool
176
177
  }, "transactionDetail/deleteSplitLine", never, never>, toggleSplitEditMode: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, editMode: boolean], {
177
178
  transactionId: TransactionID;
178
179
  editMode: boolean;
179
- }, "transactionDetail/toggleSplitEditMode", never, never>;
180
+ }, "transactionDetail/toggleSplitEditMode", never, never>, initializeCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
181
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
182
+ }, "transactionDetail/initializeCreateTransactionLocalData", never, never>, updateCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", localData: Partial<CreateTransactionLocalData>], {
183
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
184
+ localData: Partial<CreateTransactionLocalData>;
185
+ }, "transactionDetail/updateCreateTransactionLocalData", never, never>, updateCreateTransactionLineLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineId: string, lineUpdates: Partial<CreateTransactionLineLocalData>], {
186
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
187
+ lineId: string;
188
+ lineUpdates: Partial<CreateTransactionLineLocalData>;
189
+ }, "transactionDetail/updateCreateTransactionLineLocalData", never, never>, addCreateTransactionLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", line?: Partial<CreateTransactionLineLocalData> | undefined], {
190
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
191
+ line: Partial<CreateTransactionLineLocalData> | undefined;
192
+ }, "transactionDetail/addCreateTransactionLine", never, never>, removeCreateTransactionLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineId: string], {
193
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
194
+ lineId: string;
195
+ }, "transactionDetail/removeCreateTransactionLine", never, never>, resetCreateTransactionLocalData: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
196
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
197
+ }, "transactionDetail/resetCreateTransactionLocalData", never, never>, createTransaction: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry"], {
198
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
199
+ }, "transactionDetail/createTransaction", never, never>, createTransactionSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[fetchState: FetchState, createdTransactionId?: TransactionID | undefined, error?: ZeniAPIStatus<Record<string, unknown>> | undefined], {
200
+ fetchState: FetchState;
201
+ createdTransactionId: TransactionID | undefined;
202
+ error: ZeniAPIStatus<Record<string, unknown>> | undefined;
203
+ }, "transactionDetail/createTransactionSuccessOrFailure", never, never>, setRecommendationsForCreateTransactionLines: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[], recommendations: Recommendation[], isAccountingClassesEnabled: boolean], {
204
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
205
+ lineIds: string[];
206
+ recommendations: Recommendation[];
207
+ isAccountingClassesEnabled: boolean;
208
+ }, "transactionDetail/setRecommendationsForCreateTransactionLines", never, never>, clearRecommendationsForCreateTransactionLines: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[]], {
209
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
210
+ lineIds: string[];
211
+ }, "transactionDetail/clearRecommendationsForCreateTransactionLines", never, never>, fetchVendorRecommendationsForCreateTransaction: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry", lineIds: string[], entity?: Entity | undefined], {
212
+ transactionType: "expense" | "check" | "credit_card_credit" | "transfer" | "journal_entry";
213
+ lineIds: string[];
214
+ entity: Entity | undefined;
215
+ }, "transactionDetail/fetchVendorRecommendationsForCreateTransaction", never, never>;
180
216
  declare const _default: import("redux").Reducer<TransactionDetailState>;
181
217
  export default _default;