@zeniai/client-epic-state 5.2.60 → 5.2.62-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 (45) hide show
  1. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  2. package/lib/entity/snackbar/snackbarTypes.js +2 -0
  3. package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
  4. package/lib/entity/transaction/stateTypes/paymentType.js +9 -1
  5. package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
  6. package/lib/entity/transaction/stateTypes/printStatus.js +15 -0
  7. package/lib/epic.d.ts +4 -1
  8. package/lib/epic.js +6 -0
  9. package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
  10. package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
  11. package/lib/esm/entity/transaction/stateTypes/printStatus.js +11 -0
  12. package/lib/esm/epic.js +6 -0
  13. package/lib/esm/index.js +5 -2
  14. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
  15. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +133 -0
  16. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +114 -0
  17. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +41 -0
  18. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
  19. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +58 -0
  20. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +55 -0
  21. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
  22. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +174 -1
  23. package/lib/index.d.ts +6 -2
  24. package/lib/index.js +57 -36
  25. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  26. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -1
  27. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
  28. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +51 -0
  29. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +148 -0
  30. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +82 -0
  31. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +118 -0
  32. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +40 -0
  33. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +48 -0
  34. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +81 -0
  35. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
  36. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
  37. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +62 -0
  38. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
  39. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +59 -0
  40. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
  41. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +18 -0
  42. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +37 -1
  43. package/lib/view/transactionDetail/transactionDetailReducer.js +176 -2
  44. package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
  45. package/package.json +1 -1
@@ -640,7 +640,7 @@ const getDueDate = (billStageCode, dueDate, invoiceDate, bookCloseDate) => {
640
640
  };
641
641
  exports.getDueDate = getDueDate;
642
642
  const getWithdrawFrom = (state, fromAccountId, fromAccountType, companyId, lastSelectedFromAccount) => {
643
- const { paymentAccountState, depositAccountState, depositAccountListState, paymentAccountListState, } = state;
643
+ const { paymentAccountState, depositAccountState, paymentAccountListState } = state;
644
644
  if (fromAccountId != null) {
645
645
  const withdrawFromAsDepositAcc = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, fromAccountId);
646
646
  const withdrawFromAsPaymentAcc = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, fromAccountId);
@@ -654,42 +654,16 @@ const getWithdrawFrom = (state, fromAccountId, fromAccountType, companyId, lastS
654
654
  }
655
655
  }
656
656
  else {
657
- return (0, exports.getDefaultWithdrawFromAccount)(state, depositAccountListState.accountIds, companyId ?? '', lastSelectedFromAccount);
657
+ return (0, exports.getDefaultWithdrawFromAccount)(state, companyId ?? '', lastSelectedFromAccount);
658
658
  }
659
659
  return undefined;
660
660
  };
661
661
  exports.getWithdrawFrom = getWithdrawFrom;
662
- const getDefaultWithdrawFromAccount = (state, depositAccounts, companyId, lastSelectedFromAccount) => {
662
+ const getDefaultWithdrawFromAccount = (state, companyId, lastSelectedFromAccount) => {
663
663
  const { depositAccountState, paymentAccountState, paymentAccountListState } = state;
664
664
  const companyView = (0, getCompanyView_1.getCompanyView)(state, companyId, []);
665
665
  const primaryAccount = companyView?.company.company.companyBillPayInfo.primaryFundingAccount;
666
- let defaultAccount = undefined;
667
- // User paying bill for first time or previously paid with external account
668
- if (lastSelectedFromAccount == null ||
669
- lastSelectedFromAccount?.accountType === 'paymentAccount') {
670
- if (depositAccounts.length === 0) {
671
- defaultAccount = primaryAccount;
672
- }
673
- else {
674
- if (primaryAccount?.accountType === 'depositAccount') {
675
- defaultAccount = primaryAccount;
676
- }
677
- }
678
- }
679
- else {
680
- // User paid with Zeni account previously
681
- if (depositAccounts.length === 1) {
682
- defaultAccount = lastSelectedFromAccount;
683
- }
684
- else {
685
- if (primaryAccount?.accountType === 'depositAccount') {
686
- defaultAccount = primaryAccount;
687
- }
688
- else {
689
- defaultAccount = lastSelectedFromAccount;
690
- }
691
- }
692
- }
666
+ const defaultAccount = primaryAccount ?? lastSelectedFromAccount;
693
667
  if (defaultAccount != null) {
694
668
  const defaultAccAsDepositAcc = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, defaultAccount?.accountId);
695
669
  const defaultAccAsPaymentAcc = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, defaultAccount?.accountId);
@@ -0,0 +1,51 @@
1
+ import { Recommendation, RecommendationWithCOT } from '../../../commonStateTypes/recommendationBase';
2
+ import { TransactionCategory } from '../../../entity/transaction/stateTypes/transactionType';
3
+ import { CreatableTransactionType, CreateTransactionLineLocalData, CreateTransactionLocalData, CreateTransactionLocalDataByType } from './createTransactionState';
4
+ export declare const nextCreateTransactionLineId: () => string;
5
+ /** Test-only: makes line ids predictable from the start of each case. */
6
+ export declare const resetCreateTransactionLineIdCounter: () => void;
7
+ export declare const createEmptyCreateTransactionLine: (postingType?: TransactionCategory) => CreateTransactionLineLocalData;
8
+ /**
9
+ * The lines a freshly-opened form starts with. A journal entry is invalid with fewer than one
10
+ * debit and one credit, so it opens with both rather than making the user add the second row.
11
+ * Transfer has no lines at all.
12
+ */
13
+ export declare const getDefaultCreateTransactionLines: (transactionType: CreatableTransactionType) => CreateTransactionLineLocalData[];
14
+ /**
15
+ * A blank working copy for one type. Note this does NOT seed the date -- the reducer's initial
16
+ * state has to stay a pure constant so `clearAll` restores something stable. The date is seeded
17
+ * by initializeCreateTransactionLocalDataEpic, which runs when the form opens.
18
+ */
19
+ export declare const getEmptyCreateTransactionLocalData: (transactionType: CreatableTransactionType) => CreateTransactionLocalData;
20
+ export declare const getInitialCreateTransactionLocalDataByType: () => CreateTransactionLocalDataByType;
21
+ /**
22
+ * What the form opens with: a blank copy plus today's date, the default line set, and the one
23
+ * payment_type the backend insists on for a check (qbo_purchase.py raises without it).
24
+ */
25
+ export declare const getSeededCreateTransactionLocalData: (transactionType: CreatableTransactionType) => CreateTransactionLocalData;
26
+ /**
27
+ * Merges a partial edit into the working copy. Lines are replaced wholesale when present --
28
+ * a partial line array would silently truncate the form.
29
+ */
30
+ export declare const mergeCreateTransactionLocalData: (current: CreateTransactionLocalData, update: Partial<CreateTransactionLocalData>) => CreateTransactionLocalData;
31
+ export declare const updateCreateTransactionLine: (lines: CreateTransactionLineLocalData[], lineId: string, update: Partial<CreateTransactionLineLocalData>) => CreateTransactionLineLocalData[];
32
+ /**
33
+ * Recommendation -> RecommendationWithCOT. Chain-of-thought and recommendation feedback both
34
+ * need an existing transaction, so cot/reasoning are empty here by design; the dropdown only
35
+ * needs the entities to build its "Recommended" group.
36
+ */
37
+ export declare const toRecommendationsWithCOT: (recommendations: Recommendation[]) => RecommendationWithCOT[];
38
+ /**
39
+ * Applies a vendor's recommendations to one line: always refreshes the dropdown's "Recommended"
40
+ * group, but only prefills account/class when the field is still empty. Anything the user
41
+ * picked wins -- this follows the transaction-categorization helper, which prefills, rather
42
+ * than the detail-page helper, which only suggests.
43
+ */
44
+ export declare const applyRecommendationsToCreateTransactionLine: (line: CreateTransactionLineLocalData, recommendations: Recommendation[], isAccountingClassesEnabled: boolean) => CreateTransactionLineLocalData;
45
+ /**
46
+ * Undoes a prefill when the vendor is cleared. Only the fields the prefill wrote are removed --
47
+ * the per-field flags are what make the user's own choices distinguishable from ours, which is
48
+ * why they are not a single line-level boolean: a hand-picked account alongside a prefilled
49
+ * class is an ordinary state, and clearing must not take the account with it.
50
+ */
51
+ export declare const clearRecommendationsFromCreateTransactionLine: (line: CreateTransactionLineLocalData) => CreateTransactionLineLocalData;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearRecommendationsFromCreateTransactionLine = exports.applyRecommendationsToCreateTransactionLine = exports.toRecommendationsWithCOT = exports.updateCreateTransactionLine = exports.mergeCreateTransactionLocalData = exports.getSeededCreateTransactionLocalData = exports.getInitialCreateTransactionLocalDataByType = exports.getEmptyCreateTransactionLocalData = exports.getDefaultCreateTransactionLines = exports.createEmptyCreateTransactionLine = exports.resetCreateTransactionLineIdCounter = exports.nextCreateTransactionLineId = void 0;
4
+ const zeniDayJS_1 = require("../../../zeniDayJS");
5
+ const createTransactionState_1 = require("./createTransactionState");
6
+ /**
7
+ * Monotonic counter for line row keys. These never leave the client -- the payload builder
8
+ * drops them -- so a counter is enough, and it keeps reducer tests deterministic in a way
9
+ * randomUUID would not.
10
+ */
11
+ let lineIdCounter = 0;
12
+ const nextCreateTransactionLineId = () => `create-transaction-line-${lineIdCounter++}`;
13
+ exports.nextCreateTransactionLineId = nextCreateTransactionLineId;
14
+ /** Test-only: makes line ids predictable from the start of each case. */
15
+ const resetCreateTransactionLineIdCounter = () => {
16
+ lineIdCounter = 0;
17
+ };
18
+ exports.resetCreateTransactionLineIdCounter = resetCreateTransactionLineIdCounter;
19
+ const createEmptyCreateTransactionLine = (postingType) => ({
20
+ id: (0, exports.nextCreateTransactionLineId)(),
21
+ postingType,
22
+ });
23
+ exports.createEmptyCreateTransactionLine = createEmptyCreateTransactionLine;
24
+ /**
25
+ * The lines a freshly-opened form starts with. A journal entry is invalid with fewer than one
26
+ * debit and one credit, so it opens with both rather than making the user add the second row.
27
+ * Transfer has no lines at all.
28
+ */
29
+ const getDefaultCreateTransactionLines = (transactionType) => {
30
+ if (transactionType === 'transfer') {
31
+ return [];
32
+ }
33
+ if (transactionType === 'journal_entry') {
34
+ return [
35
+ (0, exports.createEmptyCreateTransactionLine)('debit'),
36
+ (0, exports.createEmptyCreateTransactionLine)('credit'),
37
+ ];
38
+ }
39
+ return [(0, exports.createEmptyCreateTransactionLine)()];
40
+ };
41
+ exports.getDefaultCreateTransactionLines = getDefaultCreateTransactionLines;
42
+ /**
43
+ * A blank working copy for one type. Note this does NOT seed the date -- the reducer's initial
44
+ * state has to stay a pure constant so `clearAll` restores something stable. The date is seeded
45
+ * by initializeCreateTransactionLocalDataEpic, which runs when the form opens.
46
+ */
47
+ const getEmptyCreateTransactionLocalData = (transactionType) => ({
48
+ lines: [],
49
+ transactionType,
50
+ });
51
+ exports.getEmptyCreateTransactionLocalData = getEmptyCreateTransactionLocalData;
52
+ const getInitialCreateTransactionLocalDataByType = () => createTransactionState_1.ALL_CREATABLE_TRANSACTION_TYPES.reduce((acc, transactionType) => {
53
+ acc[transactionType] =
54
+ (0, exports.getEmptyCreateTransactionLocalData)(transactionType);
55
+ return acc;
56
+ }, {});
57
+ exports.getInitialCreateTransactionLocalDataByType = getInitialCreateTransactionLocalDataByType;
58
+ /**
59
+ * What the form opens with: a blank copy plus today's date, the default line set, and the one
60
+ * payment_type the backend insists on for a check (qbo_purchase.py raises without it).
61
+ */
62
+ const getSeededCreateTransactionLocalData = (transactionType) => ({
63
+ ...(0, exports.getEmptyCreateTransactionLocalData)(transactionType),
64
+ lines: (0, exports.getDefaultCreateTransactionLines)(transactionType),
65
+ paymentType: transactionType === 'check' ? 'check' : undefined,
66
+ transactionDate: (0, zeniDayJS_1.dateNow)(),
67
+ });
68
+ exports.getSeededCreateTransactionLocalData = getSeededCreateTransactionLocalData;
69
+ /**
70
+ * Merges a partial edit into the working copy. Lines are replaced wholesale when present --
71
+ * a partial line array would silently truncate the form.
72
+ */
73
+ const mergeCreateTransactionLocalData = (current, update) => ({
74
+ ...current,
75
+ ...update,
76
+ lines: update.lines ?? current.lines,
77
+ // The type is keyed by the slice, never edited through a merge.
78
+ transactionType: current.transactionType,
79
+ });
80
+ exports.mergeCreateTransactionLocalData = mergeCreateTransactionLocalData;
81
+ const updateCreateTransactionLine = (lines, lineId, update) => lines.map((line) => line.id === lineId ? { ...line, ...update, id: line.id } : line);
82
+ exports.updateCreateTransactionLine = updateCreateTransactionLine;
83
+ /**
84
+ * Recommendation -> RecommendationWithCOT. Chain-of-thought and recommendation feedback both
85
+ * need an existing transaction, so cot/reasoning are empty here by design; the dropdown only
86
+ * needs the entities to build its "Recommended" group.
87
+ */
88
+ const toRecommendationsWithCOT = (recommendations) => recommendations.map((recommendation) => ({
89
+ account: recommendation.account != null
90
+ ? { ...recommendation.account, cot: [], reasoning: '' }
91
+ : undefined,
92
+ class: recommendation.class != null
93
+ ? { ...recommendation.class, cot: [], reasoning: '' }
94
+ : undefined,
95
+ vendor: recommendation.vendor != null
96
+ ? { ...recommendation.vendor, cot: [], reasoning: '' }
97
+ : undefined,
98
+ }));
99
+ exports.toRecommendationsWithCOT = toRecommendationsWithCOT;
100
+ /**
101
+ * Applies a vendor's recommendations to one line: always refreshes the dropdown's "Recommended"
102
+ * group, but only prefills account/class when the field is still empty. Anything the user
103
+ * picked wins -- this follows the transaction-categorization helper, which prefills, rather
104
+ * than the detail-page helper, which only suggests.
105
+ */
106
+ const applyRecommendationsToCreateTransactionLine = (line, recommendations, isAccountingClassesEnabled) => {
107
+ const top = recommendations[0];
108
+ const updated = {
109
+ ...line,
110
+ recommendationsWithCOT: (0, exports.toRecommendationsWithCOT)(recommendations),
111
+ };
112
+ if (line.accountQboId == null && top?.account?.qboId != null) {
113
+ updated.accountQboId = top.account.qboId;
114
+ updated.accountName = top.account.accountName;
115
+ updated.isAccountPreFilled = true;
116
+ }
117
+ if (isAccountingClassesEnabled &&
118
+ line.classId == null &&
119
+ top?.class?.classId != null) {
120
+ updated.classId = top.class.classId;
121
+ updated.isClassPreFilled = true;
122
+ }
123
+ return updated;
124
+ };
125
+ exports.applyRecommendationsToCreateTransactionLine = applyRecommendationsToCreateTransactionLine;
126
+ /**
127
+ * Undoes a prefill when the vendor is cleared. Only the fields the prefill wrote are removed --
128
+ * the per-field flags are what make the user's own choices distinguishable from ours, which is
129
+ * why they are not a single line-level boolean: a hand-picked account alongside a prefilled
130
+ * class is an ordinary state, and clearing must not take the account with it.
131
+ */
132
+ const clearRecommendationsFromCreateTransactionLine = (line) => {
133
+ const cleared = {
134
+ ...line,
135
+ recommendationsWithCOT: undefined,
136
+ };
137
+ if (line.isAccountPreFilled === true) {
138
+ cleared.accountQboId = undefined;
139
+ cleared.accountName = undefined;
140
+ cleared.isAccountPreFilled = undefined;
141
+ }
142
+ if (line.isClassPreFilled === true) {
143
+ cleared.classId = undefined;
144
+ cleared.isClassPreFilled = undefined;
145
+ }
146
+ return cleared;
147
+ };
148
+ exports.clearRecommendationsFromCreateTransactionLine = clearRecommendationsFromCreateTransactionLine;
@@ -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,118 @@
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 vendorSelector_1 = require("../../../entity/vendor/vendorSelector");
7
+ const toRemitToAddressPayload = (address) => {
8
+ if (address == null) {
9
+ return undefined;
10
+ }
11
+ return {
12
+ line1: address.line1,
13
+ city: address.city,
14
+ state: address.state,
15
+ postal_code: address.postalCode,
16
+ country: address.country,
17
+ };
18
+ };
19
+ const toLinePayload = (line, transactionType) => {
20
+ const lineDetail = {};
21
+ if (line.accountQboId != null) {
22
+ lineDetail.account = {
23
+ qbo_id: line.accountQboId,
24
+ account_name: line.accountName,
25
+ };
26
+ }
27
+ // An empty object is what the confirmed payloads send when no class is chosen; sending the
28
+ // key with a qbo_id only once one is picked.
29
+ lineDetail.class = line.classId != null ? { qbo_id: line.classId } : {};
30
+ if (transactionType === 'journal_entry') {
31
+ lineDetail.posting_type = line.postingType;
32
+ if (line.vendorQboId != null) {
33
+ lineDetail.vendor = { qbo_id: line.vendorQboId };
34
+ }
35
+ }
36
+ return {
37
+ // The backend rejects a bool here, so this is always coerced to a number.
38
+ amount: line.amount?.amount ?? 0,
39
+ line_description: line.lineDescription,
40
+ line_detail_type: transactionType === 'journal_entry'
41
+ ? 'journal_entry_line_detail'
42
+ : 'account_based_expense_line_detail',
43
+ line_detail: lineDetail,
44
+ };
45
+ };
46
+ /** Resolves a Zeni account id to the QBO id the endpoint expects. */
47
+ const toQboAccountId = (state, accountId) => {
48
+ if (accountId == null) {
49
+ return undefined;
50
+ }
51
+ return ((0, accountSelector_1.getAccountBase)(state.accountState, accountId, 'account_list')?.qboId ??
52
+ accountId);
53
+ };
54
+ /** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
55
+ const toQboVendorId = (state, vendorId) => {
56
+ if (vendorId == null) {
57
+ return undefined;
58
+ }
59
+ return (0, vendorSelector_1.getVendorByVendorId)(state.vendorState, vendorId)?.qboId ?? vendorId;
60
+ };
61
+ /**
62
+ * Builds the request body for one transaction type. One branch per type rather than a shared
63
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
64
+ * all, and journal_entry carries no header account.
65
+ */
66
+ const prepareCreateTransactionPayload = (state, localData) => {
67
+ const { transactionType } = localData;
68
+ const base = {
69
+ transaction_type: transactionType,
70
+ transaction_date: localData.transactionDate?.format(timePeriod_1.DEFAULT_DATE_FORMAT) ?? '',
71
+ transaction_memo: localData.transactionMemo,
72
+ };
73
+ if (transactionType === 'transfer') {
74
+ return {
75
+ ...base,
76
+ from_account_id: toQboAccountId(state, localData.fromAccountId),
77
+ to_account_id: toQboAccountId(state, localData.toAccountId),
78
+ total_amount: localData.totalAmount?.amount ?? 0,
79
+ };
80
+ }
81
+ const lines = localData.lines.map((line) => toLinePayload(line, transactionType));
82
+ if (transactionType === 'journal_entry') {
83
+ return {
84
+ ...base,
85
+ document_id: localData.documentId,
86
+ lines,
87
+ };
88
+ }
89
+ const purchaseBase = {
90
+ ...base,
91
+ payment_type: localData.paymentType,
92
+ qbo_account_id: toQboAccountId(state, localData.qboAccountId),
93
+ vendor_id: toQboVendorId(state, localData.vendorId),
94
+ lines,
95
+ };
96
+ if (transactionType === 'check') {
97
+ return {
98
+ ...purchaseBase,
99
+ document_number: localData.documentNumber,
100
+ print_status: localData.printStatus,
101
+ remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
102
+ };
103
+ }
104
+ if (transactionType === 'credit_card_credit') {
105
+ // credit_card_credit is not in the backend's SUPPORTED_TRANSACTION_WRITE_TYPES. QBO models
106
+ // it as a Purchase with Credit: true and qbo_purchase.py already honours is_credit for
107
+ // card payment types, so this sends `expense` + is_credit rather than a type the validator
108
+ // rejects outright. Confirm with backend before enabling the menu item.
109
+ return {
110
+ ...purchaseBase,
111
+ transaction_type: 'expense',
112
+ is_credit: true,
113
+ document_number: localData.documentNumber,
114
+ };
115
+ }
116
+ return purchaseBase;
117
+ };
118
+ 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>;