@zeniai/client-epic-state 5.2.87 → 5.2.89-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.
Files changed (72) hide show
  1. package/lib/entity/invoicing/invoicingCommonPayload.d.ts +9 -0
  2. package/lib/entity/invoicing/invoicingCommonPayload.js +8 -1
  3. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  4. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  5. package/lib/entity/tenant/tenantPayload.d.ts +1 -0
  6. package/lib/entity/tenant/tenantReducer.js +1 -0
  7. package/lib/entity/tenant/tenantState.d.ts +1 -0
  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 +11 -0
  12. package/lib/epic.d.ts +5 -1
  13. package/lib/epic.js +8 -0
  14. package/lib/esm/entity/invoicing/invoicingCommonPayload.js +7 -0
  15. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  16. package/lib/esm/entity/tenant/tenantReducer.js +1 -0
  17. package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
  18. package/lib/esm/entity/transaction/stateTypes/printStatus.js +7 -0
  19. package/lib/esm/epic.js +8 -0
  20. package/lib/esm/index.js +5 -2
  21. package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +20 -12
  22. package/lib/esm/view/invoicing/settingsView/invoicingQboSettingsFormConfig.js +6 -1
  23. package/lib/esm/view/invoicing/settingsView/settingsViewReducer.js +19 -1
  24. package/lib/esm/view/invoicing/settingsView/settingsViewSelector.js +15 -1
  25. package/lib/esm/view/settingsView/epic/saveNotificationSettingsEpic.js +7 -0
  26. package/lib/esm/view/settingsView/settingsViewHelpers.js +1 -0
  27. package/lib/esm/view/settingsView/settingsViewReducer.js +16 -1
  28. package/lib/esm/view/settingsView/settingsViewState.js +1 -0
  29. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +157 -0
  30. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +164 -0
  31. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +47 -0
  32. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
  33. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +19 -0
  34. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +81 -0
  35. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +53 -0
  36. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +10 -0
  37. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +196 -1
  38. package/lib/index.d.ts +6 -2
  39. package/lib/index.js +58 -37
  40. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  41. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +6 -1
  42. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +20 -12
  43. package/lib/view/invoicing/settingsView/invoicingQboSettingsFormConfig.js +5 -0
  44. package/lib/view/invoicing/settingsView/settingsViewReducer.js +19 -1
  45. package/lib/view/invoicing/settingsView/settingsViewSelector.d.ts +3 -1
  46. package/lib/view/invoicing/settingsView/settingsViewSelector.js +15 -1
  47. package/lib/view/settingsView/epic/saveNotificationSettingsEpic.js +7 -0
  48. package/lib/view/settingsView/settingsViewHelpers.js +1 -0
  49. package/lib/view/settingsView/settingsViewPayload.d.ts +2 -0
  50. package/lib/view/settingsView/settingsViewReducer.js +16 -1
  51. package/lib/view/settingsView/settingsViewState.d.ts +2 -2
  52. package/lib/view/settingsView/settingsViewState.js +1 -0
  53. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +56 -0
  54. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +172 -0
  55. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +95 -0
  56. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +169 -0
  57. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +44 -0
  58. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +53 -0
  59. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +82 -0
  60. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
  61. package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.d.ts +10 -0
  62. package/lib/view/transactionDetail/createTransaction/epics/createTransactionAttachmentUploadFailureEpic.js +23 -0
  63. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
  64. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +85 -0
  65. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
  66. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +57 -0
  67. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
  68. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
  69. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +39 -1
  70. package/lib/view/transactionDetail/transactionDetailReducer.js +198 -2
  71. package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
  72. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ import { ID } from '../../../commonStateTypes/common';
2
+ import { ProjectBasePayload } from '../../../entity/project/projectPayload';
3
+ import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
4
+ import { ZeniAPIResponse } from '../../../responsePayload';
5
+ import { RootState } from '../../../rootStateTypes';
6
+ import { CreateTransactionLocalData } from './createTransactionState';
7
+ /**
8
+ * Wire types for POST /1.0/transactions/manage.
9
+ *
10
+ * Two things here are easy to get wrong and are deliberately explicit:
11
+ *
12
+ * 1. `line_detail_type` is snake_case. The PascalCase strings in the backend are Python
13
+ * constant NAMES; ZENI_LINE_DETAIL_TYPE_TO_QBO_LINE_DETAIL_TYPE_MAP converts them for the
14
+ * body the backend sends on to QuickBooks, never for ours.
15
+ * 2. The reference number uses two different keys depending on the QBO entity. check and
16
+ * expense are Purchases and take `document_number`; everything else takes `document_id`.
17
+ */
18
+ export interface CreateTransactionAccountPayload {
19
+ qbo_id: ID;
20
+ account_name?: string;
21
+ }
22
+ export interface CreateTransactionLineDetailPayload {
23
+ account?: CreateTransactionAccountPayload;
24
+ class?: Record<string, never> | {
25
+ qbo_id: ID;
26
+ };
27
+ /**
28
+ * journal_entry only, and it MUST sit inside line_detail. The write validator's docstring
29
+ * warns that a misplaced posting_type is silently dropped and then rejected by QBO.
30
+ */
31
+ posting_type?: 'credit' | 'debit';
32
+ /** Same shape the transaction update sends on a vendor line. */
33
+ project?: ProjectBasePayload;
34
+ vendor?: {
35
+ qbo_id: ID;
36
+ };
37
+ }
38
+ export interface CreateTransactionLinePayload {
39
+ amount: number;
40
+ line_detail: CreateTransactionLineDetailPayload;
41
+ line_detail_type: 'account_based_expense_line_detail' | 'item_based_expense_line_detail' | 'journal_entry_line_detail';
42
+ line_description?: string;
43
+ }
44
+ export interface CreateTransactionRemitToAddressPayload {
45
+ city?: string;
46
+ country?: string;
47
+ line1?: string;
48
+ postal_code?: string;
49
+ state?: string;
50
+ }
51
+ export interface CreateTransactionRequest extends Record<string, unknown> {
52
+ transaction_date: string;
53
+ transaction_type: string;
54
+ /** journal_entry reference number. */
55
+ document_id?: string;
56
+ /** check / credit_card_credit reference number (QBO Purchase). */
57
+ document_number?: string;
58
+ from_account_id?: ID;
59
+ /** credit_card_credit is modelled as a Purchase with Credit: true. */
60
+ is_credit?: boolean;
61
+ lines?: CreateTransactionLinePayload[];
62
+ payment_type?: string;
63
+ print_status?: string;
64
+ qbo_account_id?: ID;
65
+ remit_to_address?: CreateTransactionRemitToAddressPayload;
66
+ to_account_id?: ID;
67
+ total_amount?: number;
68
+ transaction_memo?: string;
69
+ vendor_id?: ID;
70
+ }
71
+ /**
72
+ * The create endpoint writes to QBO and returns the created entity; Zeni's own mirror is
73
+ * populated by the delta sync that runs afterwards, so this response is the only view of the
74
+ * new transaction the client gets immediately.
75
+ */
76
+ export interface CreateTransactionPayload {
77
+ transactions: TransactionPayload[];
78
+ }
79
+ export type CreateTransactionResponse = ZeniAPIResponse<CreateTransactionPayload>;
80
+ /**
81
+ * Thrown when a picked id has no QBO id to send. Sending the Zeni id instead would reach QBO as
82
+ * an unknown reference and come back as an opaque error, so the create is stopped here and the
83
+ * epic shows this message instead.
84
+ */
85
+ export declare class UnresolvedCreateTransactionIdError extends Error {
86
+ }
87
+ /**
88
+ * Builds the request body for one transaction type. One branch per type rather than a shared
89
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
90
+ * all, and journal_entry carries no header account.
91
+ *
92
+ * Throws UnresolvedCreateTransactionIdError when a picked vendor (header or journal entry line),
93
+ * class or transfer account has no QBO id.
94
+ */
95
+ export declare const prepareCreateTransactionPayload: (state: RootState, localData: CreateTransactionLocalData) => CreateTransactionRequest;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareCreateTransactionPayload = exports.UnresolvedCreateTransactionIdError = 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 projectPayload_1 = require("../../../entity/project/projectPayload");
8
+ const projectSelector_1 = require("../../../entity/project/projectSelector");
9
+ const vendorSelector_1 = require("../../../entity/vendor/vendorSelector");
10
+ const toRemitToAddressPayload = (address) => {
11
+ if (address == null) {
12
+ return undefined;
13
+ }
14
+ return {
15
+ line1: address.line1,
16
+ city: address.city,
17
+ state: address.state,
18
+ postal_code: address.postalCode,
19
+ country: address.country,
20
+ };
21
+ };
22
+ const toLinePayload = (state, line, transactionType) => {
23
+ const lineDetail = {};
24
+ if (line.accountQboId != null) {
25
+ lineDetail.account = {
26
+ qbo_id: line.accountQboId,
27
+ account_name: line.accountName,
28
+ };
29
+ }
30
+ // An empty object is what the confirmed payloads send when no class is chosen; sending the
31
+ // key with a qbo_id only once one is picked.
32
+ const classQboId = toQboClassId(state, line.classId);
33
+ lineDetail.class = classQboId != null ? { qbo_id: classQboId } : {};
34
+ if (line.projectId != null) {
35
+ lineDetail.project = (0, projectPayload_1.toProjectBasePayload)((0, projectSelector_1.getProjectById)(state.projectState, line.projectId) ?? {
36
+ projectId: line.projectId,
37
+ projectName: '',
38
+ });
39
+ }
40
+ if (transactionType === 'journal_entry') {
41
+ lineDetail.posting_type = line.postingType;
42
+ const vendorQboId = toQboLineVendorId(state, line.vendorQboId);
43
+ if (vendorQboId != null) {
44
+ lineDetail.vendor = { qbo_id: vendorQboId };
45
+ }
46
+ }
47
+ return {
48
+ // The backend rejects a bool here, so this is always coerced to a number.
49
+ amount: line.amount?.amount ?? 0,
50
+ line_description: line.lineDescription,
51
+ line_detail_type: transactionType === 'journal_entry'
52
+ ? 'journal_entry_line_detail'
53
+ : 'account_based_expense_line_detail',
54
+ line_detail: lineDetail,
55
+ };
56
+ };
57
+ /**
58
+ * Thrown when a picked id has no QBO id to send. Sending the Zeni id instead would reach QBO as
59
+ * an unknown reference and come back as an opaque error, so the create is stopped here and the
60
+ * epic shows this message instead.
61
+ */
62
+ class UnresolvedCreateTransactionIdError extends Error {
63
+ }
64
+ exports.UnresolvedCreateTransactionIdError = UnresolvedCreateTransactionIdError;
65
+ /**
66
+ * Resolves a transfer account (the Zeni account id from the transfer pools) to its QBO id. The
67
+ * header and line account dropdowns already hold the QBO id, so they are sent as-is.
68
+ */
69
+ const toQboTransferAccountId = (state, accountId) => {
70
+ if (accountId == null) {
71
+ return undefined;
72
+ }
73
+ const qboId = (0, accountSelector_1.getAccountBaseForTransferAccounts)(state.accountState, accountId)?.qboId;
74
+ if (qboId == null || qboId === '') {
75
+ throw new UnresolvedCreateTransactionIdError('The selected transfer account could not be found in QuickBooks.');
76
+ }
77
+ return qboId;
78
+ };
79
+ /** Resolves a Zeni class id (`class_<uuid>`) to the QBO id `line_detail.class.qbo_id` expects. */
80
+ const toQboClassId = (state, classId) => {
81
+ if (classId == null) {
82
+ return undefined;
83
+ }
84
+ const qboId = (0, classSelector_1.getClassById)(state.classState, {
85
+ classId,
86
+ reportId: 'class_list',
87
+ })?.qboId;
88
+ if (qboId == null || qboId === '') {
89
+ throw new UnresolvedCreateTransactionIdError('The selected class could not be found in QuickBooks.');
90
+ }
91
+ return qboId;
92
+ };
93
+ /** A vendor not yet synced to QBO carries `qboId === name`, which QBO would reject. */
94
+ const toSyncedVendorQboId = (vendor) => {
95
+ if (vendor == null || vendor.qboId === '' || vendor.qboId === vendor.name) {
96
+ throw new UnresolvedCreateTransactionIdError('The selected vendor is not synced to QuickBooks yet.');
97
+ }
98
+ return vendor.qboId;
99
+ };
100
+ /** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
101
+ const toQboVendorId = (state, vendorId) => vendorId == null
102
+ ? undefined
103
+ : toSyncedVendorQboId((0, vendorSelector_1.getVendorByVendorId)(state.vendorState, vendorId));
104
+ /** A journal entry line holds the QBO id already, so it is only checked against the store. */
105
+ const toQboLineVendorId = (state, vendorQboId) => vendorQboId == null
106
+ ? undefined
107
+ : toSyncedVendorQboId((0, vendorSelector_1.getVendorByQboId)(state.vendorState, vendorQboId));
108
+ /**
109
+ * Builds the request body for one transaction type. One branch per type rather than a shared
110
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
111
+ * all, and journal_entry carries no header account.
112
+ *
113
+ * Throws UnresolvedCreateTransactionIdError when a picked vendor (header or journal entry line),
114
+ * class or transfer account has no QBO id.
115
+ */
116
+ const prepareCreateTransactionPayload = (state, localData) => {
117
+ const { transactionType } = localData;
118
+ const base = {
119
+ transaction_type: transactionType,
120
+ transaction_date: localData.transactionDate?.format(timePeriod_1.DEFAULT_DATE_FORMAT) ?? '',
121
+ transaction_memo: localData.transactionMemo,
122
+ };
123
+ if (transactionType === 'transfer') {
124
+ return {
125
+ ...base,
126
+ from_account_id: toQboTransferAccountId(state, localData.fromAccountId),
127
+ to_account_id: toQboTransferAccountId(state, localData.toAccountId),
128
+ total_amount: localData.totalAmount?.amount ?? 0,
129
+ };
130
+ }
131
+ const lines = localData.lines.map((line) => toLinePayload(state, line, transactionType));
132
+ if (transactionType === 'journal_entry') {
133
+ return {
134
+ ...base,
135
+ document_id: localData.documentId,
136
+ lines,
137
+ };
138
+ }
139
+ const purchaseBase = {
140
+ ...base,
141
+ payment_type: localData.paymentType,
142
+ qbo_account_id: localData.qboAccountId,
143
+ vendor_id: toQboVendorId(state, localData.vendorId),
144
+ lines,
145
+ };
146
+ if (transactionType === 'check') {
147
+ return {
148
+ ...purchaseBase,
149
+ document_number: localData.documentNumber,
150
+ print_status: localData.printStatus,
151
+ remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
152
+ };
153
+ }
154
+ if (transactionType === 'credit_card_credit') {
155
+ // credit_card_credit is not in the backend's SUPPORTED_TRANSACTION_WRITE_TYPES. QBO models
156
+ // it as a Purchase with Credit: true and qbo_purchase.py already honours is_credit for
157
+ // card payment types, so this sends `expense` + is_credit rather than a type the validator
158
+ // rejects outright. Confirm with backend before enabling the menu item. The seed sets
159
+ // payment_type to credit_card, since qbo_purchase.py raises on is_credit without a card type.
160
+ return {
161
+ ...purchaseBase,
162
+ transaction_type: 'expense',
163
+ is_credit: true,
164
+ document_number: localData.documentNumber,
165
+ };
166
+ }
167
+ return purchaseBase;
168
+ };
169
+ exports.prepareCreateTransactionPayload = prepareCreateTransactionPayload;
@@ -0,0 +1,44 @@
1
+ import { NestedAccountHierarchyForReport } from '../../../commonStateTypes/accountView/nestedAccountID';
2
+ import { NestedClassHierarchyForReport } from '../../../commonStateTypes/classesView/nestedClassID';
3
+ import { FetchState, FetchStateAndError } from '../../../commonStateTypes/common';
4
+ import { Recommendation } from '../../../commonStateTypes/recommendationBase';
5
+ import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
6
+ import { AccountBase } from '../../../entity/account/accountState';
7
+ import { TransactionID } from '../../../entity/transaction/stateTypes/transactionID';
8
+ import { Vendor } from '../../../entity/vendor/vendorState';
9
+ import { RootState } from '../../../rootStateTypes';
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
+ /**
41
+ * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
42
+ * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
43
+ */
44
+ export declare const getCreateTransactionView: (state: RootState, transactionType: CreatableTransactionType) => CreateTransactionView;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCreateTransactionView = exports.getCreateTransactionVendorRecommendations = exports.getCreateTransactionStatus = exports.getCreateTransactionLocalData = void 0;
4
+ const toolkit_1 = require("@reduxjs/toolkit");
5
+ const accountListSelector_1 = require("../../accountList/accountListSelector");
6
+ const classListSelector_1 = require("../../classList/classListSelector");
7
+ const createTransferEntrySelector_1 = require("../../createTransferEntry/createTransferEntrySelector");
8
+ const recommendationSelector_1 = require("../../recommendation/recommendationSelector");
9
+ const getCreateTransactionLocalData = (state, transactionType) => state.transactionDetailState.createTransactionsState.newTransactionState[transactionType];
10
+ exports.getCreateTransactionLocalData = getCreateTransactionLocalData;
11
+ const getCreateTransactionStatus = (state) => state.transactionDetailState.createTransactionsState.createStatus;
12
+ exports.getCreateTransactionStatus = getCreateTransactionStatus;
13
+ /**
14
+ * The vendor recommendations backing the category/class dropdowns on the create page.
15
+ *
16
+ * No new state field is needed for this: getRecommendationsForEntity already returns
17
+ * fetchState alongside recommendations, so composing it here is enough for the page to show a
18
+ * line skeleton and hold Save while a fetch is in flight.
19
+ */
20
+ const getCreateTransactionVendorRecommendations = (state, vendorQboId) => {
21
+ if (vendorQboId == null || vendorQboId === '') {
22
+ return { fetchState: 'Not-Started' };
23
+ }
24
+ const view = (0, recommendationSelector_1.getRecommendationsForEntity)(state, vendorQboId, 'vendor');
25
+ return {
26
+ fetchState: view.fetchState,
27
+ recommendations: view.recommendations,
28
+ };
29
+ };
30
+ exports.getCreateTransactionVendorRecommendations = getCreateTransactionVendorRecommendations;
31
+ /**
32
+ * Memoized: app-ui reads this straight from useSelector, and the vendor list and hierarchies are
33
+ * rebuilt on every call, so an unmemoized version re-renders the page on every store action.
34
+ */
35
+ exports.getCreateTransactionView = (0, toolkit_1.createSelector)([
36
+ (state) => state.transactionDetailState.createTransactionsState,
37
+ (state) => state.vendorState.vendorByID,
38
+ (state) => state.accountListState,
39
+ (state) => state.classListState,
40
+ (state) => (0, createTransferEntrySelector_1.getResolvedTransferAccounts)(state).transferAccountsList,
41
+ (_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
+ }));
@@ -0,0 +1,82 @@
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
+ className?: string;
34
+ /**
35
+ * Tracked per field, not per line. A line can have a hand-picked account and a prefilled
36
+ * class at the same time, and clearing the vendor must undo only the latter.
37
+ */
38
+ isAccountPreFilled?: boolean;
39
+ isClassPreFilled?: boolean;
40
+ lineDescription?: string;
41
+ /** journal_entry only. */
42
+ postingType?: TransactionCategory;
43
+ projectId?: ID;
44
+ /**
45
+ * Backs the "Recommended" group in the category/class dropdowns. Carries the COT shape the
46
+ * line-table row already expects, with empty cot/reasoning -- chain-of-thought needs an
47
+ * existing transaction, which a create does not have.
48
+ */
49
+ recommendationsWithCOT?: RecommendationWithCOT[];
50
+ /** journal_entry only -- the per-line name. */
51
+ vendorQboId?: ID;
52
+ }
53
+ export interface CreateTransactionLocalData {
54
+ /** Empty for transfer, which has no lines at all. */
55
+ lines: CreateTransactionLineLocalData[];
56
+ transactionType: CreatableTransactionType;
57
+ /** journal_entry reference number. */
58
+ documentId?: string;
59
+ /** check / credit_card_credit reference number. */
60
+ documentNumber?: string;
61
+ /** transfer */
62
+ fromAccountId?: ID;
63
+ paymentType?: PaymentType;
64
+ /** check only. */
65
+ printStatus?: PrintStatus;
66
+ qboAccountId?: ID;
67
+ /** check only. */
68
+ remitToAddress?: RemitToAddress;
69
+ toAccountId?: ID;
70
+ /** transfer only -- every other type derives its total from the lines. */
71
+ totalAmount?: Amount;
72
+ transactionDate?: ZeniDate;
73
+ transactionMemo?: string;
74
+ vendorId?: ID;
75
+ }
76
+ export type CreateTransactionLocalDataByType = Record<CreatableTransactionType, CreateTransactionLocalData>;
77
+ /**
78
+ * Type-level guarantee that CreatableTransactionType stays a subset of TransactionType. If a
79
+ * value is ever added here that the entity layer does not know about, this line fails to
80
+ * compile rather than failing at the payload boundary.
81
+ */
82
+ 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,10 @@
1
+ import { ActionsObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
+ import { createTransactionAttachmentUploadFailure } from '../../transactionDetailReducer';
5
+ export type ActionType = ReturnType<typeof createTransactionAttachmentUploadFailure> | ReturnType<typeof openSnackbar>;
6
+ /**
7
+ * Attachments upload from the page after the create succeeds, so a failure is reported back here
8
+ * rather than by createTransactionEpic.
9
+ */
10
+ export declare const createTransactionAttachmentUploadFailureEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTransactionAttachmentUploadFailureEpic = void 0;
4
+ const operators_1 = require("rxjs/operators");
5
+ const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
6
+ const transactionDetailReducer_1 = require("../../transactionDetailReducer");
7
+ /**
8
+ * Attachments upload from the page after the create succeeds, so a failure is reported back here
9
+ * rather than by createTransactionEpic.
10
+ */
11
+ const createTransactionAttachmentUploadFailureEpic = (actions$) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.createTransactionAttachmentUploadFailure.match), (0, operators_1.filter)((action) => action.payload.failedAttachmentFileNames.length > 0), (0, operators_1.map)((action) => (0, snackbarReducer_1.openSnackbar)({
12
+ messageSection: 'missing_receipts_attachment',
13
+ messageText: 'failed',
14
+ type: 'error',
15
+ showStatusIcon: true,
16
+ variables: [
17
+ {
18
+ variableName: '__message__',
19
+ variableValue: ` - ${action.payload.failedAttachmentFileNames.join(', ')},`,
20
+ },
21
+ ],
22
+ })));
23
+ exports.createTransactionAttachmentUploadFailureEpic = createTransactionAttachmentUploadFailureEpic;
@@ -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 } from '../../transactionDetailReducer';
8
+ export type ActionType = ReturnType<typeof createTransaction> | ReturnType<typeof createTransactionSuccessOrFailure> | 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,85 @@
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 createTransactionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(transactionDetailReducer_1.createTransaction.match),
14
+ // exhaustMap, not mergeMap: a second submit while one is in flight is dropped here rather
15
+ // than relying only on the disabled Save button, so it cannot create a duplicate in QBO.
16
+ (0, operators_1.exhaustMap)((action) => {
17
+ const { transactionType } = action.payload;
18
+ const state = state$.value;
19
+ const localData = state.transactionDetailState.createTransactionsState
20
+ .newTransactionState[transactionType];
21
+ // Deferred so a payload that cannot be built (an id with no QBO id) lands in catchError
22
+ // below as a failure, instead of throwing out of the epic.
23
+ return (0, rxjs_1.defer)(() => zeniAPI.postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/manage`, (0, createTransactionPayload_1.prepareCreateTransactionPayload)(state, localData))).pipe((0, operators_1.mergeMap)((response) => {
24
+ const created = (0, responsePayload_1.isSuccessResponse)(response)
25
+ ? response.data?.transactions[0]
26
+ : undefined;
27
+ if (created == null) {
28
+ const status = (0, responsePayload_1.isSuccessResponse)(response)
29
+ ? (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Transaction was created but returned no details.')
30
+ : response.status;
31
+ return (0, rxjs_1.from)([
32
+ (0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Error', undefined, status),
33
+ (0, snackbarReducer_1.openSnackbar)({
34
+ messageSection: 'create_transaction',
35
+ messageText: 'failed',
36
+ type: 'error',
37
+ // This variable is how the server's own message reaches the user. Per-type
38
+ // required fields live in the QBO entity classes, so a rejection comes back as a
39
+ // QBO error with no field name -- the message text is the only useful content.
40
+ variables: [
41
+ { variableName: '_api-error_', variableValue: status.message },
42
+ ],
43
+ }),
44
+ ]);
45
+ }
46
+ const newTransactionId = (0, transactionIDPayload_1.toTransactionID)(created);
47
+ // The write is QBO-only: transaction_write_handler.py touches no local storage, and
48
+ // Zeni's mirror is populated by the delta sync that runs afterwards. Refetching here
49
+ // would come back without the new row, so the 200 body is inserted optimistically
50
+ // instead -- the same approach createTransferEntryEpic takes.
51
+ return (0, rxjs_1.from)([
52
+ (0, transactionReducer_1.updateTransaction)((0, transactionDetailState_1.getTransactionDetailKey)(newTransactionId), created),
53
+ // No reset here: it would clear createdTransactionId in the same tick, before the
54
+ // screen renders it to upload pending attachments and navigate. The screen resets
55
+ // the working copy on unmount instead.
56
+ // Before the local-data init: it seeds the detail entry that init writes into.
57
+ (0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Completed', newTransactionId),
58
+ (0, transactionDetailReducer_1.initializeTransactionDetailLocalData)({
59
+ transactionId: newTransactionId,
60
+ vendorId: created.vendor_id ?? undefined,
61
+ }),
62
+ (0, snackbarReducer_1.openSnackbar)({
63
+ messageSection: 'create_transaction',
64
+ messageText: 'success',
65
+ type: 'success',
66
+ }),
67
+ ]);
68
+ }), (0, operators_1.catchError)((error) => {
69
+ const message = error instanceof createTransactionPayload_1.UnresolvedCreateTransactionIdError
70
+ ? error.message
71
+ : JSON.stringify(error);
72
+ return (0, rxjs_1.from)([
73
+ (0, transactionDetailReducer_1.createTransactionSuccessOrFailure)('Error', undefined, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', `Create Transaction REST API call errored out ${message}`)),
74
+ (0, snackbarReducer_1.openSnackbar)({
75
+ messageSection: 'create_transaction',
76
+ messageText: 'failed',
77
+ type: 'error',
78
+ variables: [
79
+ { variableName: '_api-error_', variableValue: message },
80
+ ],
81
+ }),
82
+ ]);
83
+ }));
84
+ }));
85
+ 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>;