@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.
- package/lib/entity/actualMatching/actualMatchingReducer.d.ts +1 -3
- package/lib/entity/actualMatching/actualMatchingReducer.js +2 -11
- package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +0 -1
- package/lib/entity/jeSchedules/jeSchedulesPayload.js +0 -1
- package/lib/entity/jeSchedules/jeSchedulesState.d.ts +0 -1
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +1 -1
- package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
- package/lib/entity/transaction/stateTypes/paymentType.js +9 -1
- package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
- package/lib/entity/transaction/stateTypes/printStatus.js +15 -0
- package/lib/epic.d.ts +4 -2
- package/lib/epic.js +6 -2
- package/lib/esm/entity/actualMatching/actualMatchingReducer.js +1 -9
- package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -1
- package/lib/esm/entity/snackbar/snackbarTypes.js +1 -1
- package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
- package/lib/esm/entity/transaction/stateTypes/printStatus.js +11 -0
- package/lib/esm/epic.js +6 -2
- package/lib/esm/index.js +10 -7
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +3 -7
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +23 -2
- package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +35 -66
- package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -60
- package/lib/esm/view/expenseAutomationView/types/actualMatchingViewState.js +0 -15
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +133 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +124 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +41 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +58 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +55 -0
- package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
- package/lib/esm/view/transactionDetail/transactionDetailReducer.js +174 -1
- package/lib/index.d.ts +12 -8
- package/lib/index.js +70 -57
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +3 -7
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +22 -1
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/actualMatchingPayload.d.ts +1 -12
- package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.d.ts +8 -16
- package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +36 -67
- package/lib/view/expenseAutomationView/selectorTypes/actualMatchingViewSelectorTypes.d.ts +8 -20
- package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +4 -7
- package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -63
- package/lib/view/expenseAutomationView/types/actualMatchingViewState.d.ts +4 -20
- package/lib/view/expenseAutomationView/types/actualMatchingViewState.js +1 -18
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -1
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -30
- package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +51 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +148 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +82 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +128 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +40 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +48 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +81 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
- package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +62 -0
- package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
- package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +59 -0
- package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
- package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +18 -0
- package/lib/view/transactionDetail/transactionDetailReducer.d.ts +37 -1
- package/lib/view/transactionDetail/transactionDetailReducer.js +176 -2
- package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
- package/package.json +1 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -50
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.d.ts +0 -10
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -54
|
@@ -625,7 +625,7 @@ export const getDueDate = (billStageCode, dueDate, invoiceDate, bookCloseDate) =
|
|
|
625
625
|
}
|
|
626
626
|
};
|
|
627
627
|
export const getWithdrawFrom = (state, fromAccountId, fromAccountType, companyId, lastSelectedFromAccount) => {
|
|
628
|
-
const { paymentAccountState, depositAccountState,
|
|
628
|
+
const { paymentAccountState, depositAccountState, paymentAccountListState } = state;
|
|
629
629
|
if (fromAccountId != null) {
|
|
630
630
|
const withdrawFromAsDepositAcc = getDepositAccountByDepositAccountId(depositAccountState, fromAccountId);
|
|
631
631
|
const withdrawFromAsPaymentAcc = getPaymentAccountByPaymentAccountId(paymentAccountState, fromAccountId);
|
|
@@ -639,41 +639,15 @@ export const getWithdrawFrom = (state, fromAccountId, fromAccountType, companyId
|
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
else {
|
|
642
|
-
return getDefaultWithdrawFromAccount(state,
|
|
642
|
+
return getDefaultWithdrawFromAccount(state, companyId ?? '', lastSelectedFromAccount);
|
|
643
643
|
}
|
|
644
644
|
return undefined;
|
|
645
645
|
};
|
|
646
|
-
export const getDefaultWithdrawFromAccount = (state,
|
|
646
|
+
export const getDefaultWithdrawFromAccount = (state, companyId, lastSelectedFromAccount) => {
|
|
647
647
|
const { depositAccountState, paymentAccountState, paymentAccountListState } = state;
|
|
648
648
|
const companyView = getCompanyView(state, companyId, []);
|
|
649
649
|
const primaryAccount = companyView?.company.company.companyBillPayInfo.primaryFundingAccount;
|
|
650
|
-
|
|
651
|
-
// User paying bill for first time or previously paid with external account
|
|
652
|
-
if (lastSelectedFromAccount == null ||
|
|
653
|
-
lastSelectedFromAccount?.accountType === 'paymentAccount') {
|
|
654
|
-
if (depositAccounts.length === 0) {
|
|
655
|
-
defaultAccount = primaryAccount;
|
|
656
|
-
}
|
|
657
|
-
else {
|
|
658
|
-
if (primaryAccount?.accountType === 'depositAccount') {
|
|
659
|
-
defaultAccount = primaryAccount;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
else {
|
|
664
|
-
// User paid with Zeni account previously
|
|
665
|
-
if (depositAccounts.length === 1) {
|
|
666
|
-
defaultAccount = lastSelectedFromAccount;
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
if (primaryAccount?.accountType === 'depositAccount') {
|
|
670
|
-
defaultAccount = primaryAccount;
|
|
671
|
-
}
|
|
672
|
-
else {
|
|
673
|
-
defaultAccount = lastSelectedFromAccount;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
650
|
+
const defaultAccount = primaryAccount ?? lastSelectedFromAccount;
|
|
677
651
|
if (defaultAccount != null) {
|
|
678
652
|
const defaultAccAsDepositAcc = getDepositAccountByDepositAccountId(depositAccountState, defaultAccount?.accountId);
|
|
679
653
|
const defaultAccAsPaymentAcc = getPaymentAccountByPaymentAccountId(paymentAccountState, defaultAccount?.accountId);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { dateNow } from '../../../zeniDayJS';
|
|
2
|
+
import { ALL_CREATABLE_TRANSACTION_TYPES, } from './createTransactionState';
|
|
3
|
+
/**
|
|
4
|
+
* Monotonic counter for line row keys. These never leave the client -- the payload builder
|
|
5
|
+
* drops them -- so a counter is enough, and it keeps reducer tests deterministic in a way
|
|
6
|
+
* randomUUID would not.
|
|
7
|
+
*/
|
|
8
|
+
let lineIdCounter = 0;
|
|
9
|
+
export const nextCreateTransactionLineId = () => `create-transaction-line-${lineIdCounter++}`;
|
|
10
|
+
/** Test-only: makes line ids predictable from the start of each case. */
|
|
11
|
+
export const resetCreateTransactionLineIdCounter = () => {
|
|
12
|
+
lineIdCounter = 0;
|
|
13
|
+
};
|
|
14
|
+
export const createEmptyCreateTransactionLine = (postingType) => ({
|
|
15
|
+
id: nextCreateTransactionLineId(),
|
|
16
|
+
postingType,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* The lines a freshly-opened form starts with. A journal entry is invalid with fewer than one
|
|
20
|
+
* debit and one credit, so it opens with both rather than making the user add the second row.
|
|
21
|
+
* Transfer has no lines at all.
|
|
22
|
+
*/
|
|
23
|
+
export const getDefaultCreateTransactionLines = (transactionType) => {
|
|
24
|
+
if (transactionType === 'transfer') {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (transactionType === 'journal_entry') {
|
|
28
|
+
return [
|
|
29
|
+
createEmptyCreateTransactionLine('debit'),
|
|
30
|
+
createEmptyCreateTransactionLine('credit'),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
return [createEmptyCreateTransactionLine()];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A blank working copy for one type. Note this does NOT seed the date -- the reducer's initial
|
|
37
|
+
* state has to stay a pure constant so `clearAll` restores something stable. The date is seeded
|
|
38
|
+
* by initializeCreateTransactionLocalDataEpic, which runs when the form opens.
|
|
39
|
+
*/
|
|
40
|
+
export const getEmptyCreateTransactionLocalData = (transactionType) => ({
|
|
41
|
+
lines: [],
|
|
42
|
+
transactionType,
|
|
43
|
+
});
|
|
44
|
+
export const getInitialCreateTransactionLocalDataByType = () => ALL_CREATABLE_TRANSACTION_TYPES.reduce((acc, transactionType) => {
|
|
45
|
+
acc[transactionType] =
|
|
46
|
+
getEmptyCreateTransactionLocalData(transactionType);
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
/**
|
|
50
|
+
* What the form opens with: a blank copy plus today's date, the default line set, and the one
|
|
51
|
+
* payment_type the backend insists on for a check (qbo_purchase.py raises without it).
|
|
52
|
+
*/
|
|
53
|
+
export const getSeededCreateTransactionLocalData = (transactionType) => ({
|
|
54
|
+
...getEmptyCreateTransactionLocalData(transactionType),
|
|
55
|
+
lines: getDefaultCreateTransactionLines(transactionType),
|
|
56
|
+
paymentType: transactionType === 'check' ? 'check' : undefined,
|
|
57
|
+
transactionDate: dateNow(),
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Merges a partial edit into the working copy. Lines are replaced wholesale when present --
|
|
61
|
+
* a partial line array would silently truncate the form.
|
|
62
|
+
*/
|
|
63
|
+
export const mergeCreateTransactionLocalData = (current, update) => ({
|
|
64
|
+
...current,
|
|
65
|
+
...update,
|
|
66
|
+
lines: update.lines ?? current.lines,
|
|
67
|
+
// The type is keyed by the slice, never edited through a merge.
|
|
68
|
+
transactionType: current.transactionType,
|
|
69
|
+
});
|
|
70
|
+
export const updateCreateTransactionLine = (lines, lineId, update) => lines.map((line) => line.id === lineId ? { ...line, ...update, id: line.id } : line);
|
|
71
|
+
/**
|
|
72
|
+
* Recommendation -> RecommendationWithCOT. Chain-of-thought and recommendation feedback both
|
|
73
|
+
* need an existing transaction, so cot/reasoning are empty here by design; the dropdown only
|
|
74
|
+
* needs the entities to build its "Recommended" group.
|
|
75
|
+
*/
|
|
76
|
+
export const toRecommendationsWithCOT = (recommendations) => recommendations.map((recommendation) => ({
|
|
77
|
+
account: recommendation.account != null
|
|
78
|
+
? { ...recommendation.account, cot: [], reasoning: '' }
|
|
79
|
+
: undefined,
|
|
80
|
+
class: recommendation.class != null
|
|
81
|
+
? { ...recommendation.class, cot: [], reasoning: '' }
|
|
82
|
+
: undefined,
|
|
83
|
+
vendor: recommendation.vendor != null
|
|
84
|
+
? { ...recommendation.vendor, cot: [], reasoning: '' }
|
|
85
|
+
: undefined,
|
|
86
|
+
}));
|
|
87
|
+
/**
|
|
88
|
+
* Applies a vendor's recommendations to one line: always refreshes the dropdown's "Recommended"
|
|
89
|
+
* group, but only prefills account/class when the field is still empty. Anything the user
|
|
90
|
+
* picked wins -- this follows the transaction-categorization helper, which prefills, rather
|
|
91
|
+
* than the detail-page helper, which only suggests.
|
|
92
|
+
*/
|
|
93
|
+
export const applyRecommendationsToCreateTransactionLine = (line, recommendations, isAccountingClassesEnabled) => {
|
|
94
|
+
const top = recommendations[0];
|
|
95
|
+
const updated = {
|
|
96
|
+
...line,
|
|
97
|
+
recommendationsWithCOT: toRecommendationsWithCOT(recommendations),
|
|
98
|
+
};
|
|
99
|
+
if (line.accountQboId == null && top?.account?.qboId != null) {
|
|
100
|
+
updated.accountQboId = top.account.qboId;
|
|
101
|
+
updated.accountName = top.account.accountName;
|
|
102
|
+
updated.isAccountPreFilled = true;
|
|
103
|
+
}
|
|
104
|
+
if (isAccountingClassesEnabled &&
|
|
105
|
+
line.classId == null &&
|
|
106
|
+
top?.class?.classId != null) {
|
|
107
|
+
updated.classId = top.class.classId;
|
|
108
|
+
updated.isClassPreFilled = true;
|
|
109
|
+
}
|
|
110
|
+
return updated;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Undoes a prefill when the vendor is cleared. Only the fields the prefill wrote are removed --
|
|
114
|
+
* the per-field flags are what make the user's own choices distinguishable from ours, which is
|
|
115
|
+
* why they are not a single line-level boolean: a hand-picked account alongside a prefilled
|
|
116
|
+
* class is an ordinary state, and clearing must not take the account with it.
|
|
117
|
+
*/
|
|
118
|
+
export const clearRecommendationsFromCreateTransactionLine = (line) => {
|
|
119
|
+
const cleared = {
|
|
120
|
+
...line,
|
|
121
|
+
recommendationsWithCOT: undefined,
|
|
122
|
+
};
|
|
123
|
+
if (line.isAccountPreFilled === true) {
|
|
124
|
+
cleared.accountQboId = undefined;
|
|
125
|
+
cleared.accountName = undefined;
|
|
126
|
+
cleared.isAccountPreFilled = undefined;
|
|
127
|
+
}
|
|
128
|
+
if (line.isClassPreFilled === true) {
|
|
129
|
+
cleared.classId = undefined;
|
|
130
|
+
cleared.isClassPreFilled = undefined;
|
|
131
|
+
}
|
|
132
|
+
return cleared;
|
|
133
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/timePeriod';
|
|
2
|
+
import { getAccountBase } from '../../../entity/account/accountSelector';
|
|
3
|
+
import { getClassById } from '../../../entity/class/classSelector';
|
|
4
|
+
import { getVendorByVendorId } from '../../../entity/vendor/vendorSelector';
|
|
5
|
+
const toRemitToAddressPayload = (address) => {
|
|
6
|
+
if (address == null) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
line1: address.line1,
|
|
11
|
+
city: address.city,
|
|
12
|
+
state: address.state,
|
|
13
|
+
postal_code: address.postalCode,
|
|
14
|
+
country: address.country,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const toLinePayload = (state, line, transactionType) => {
|
|
18
|
+
const lineDetail = {};
|
|
19
|
+
if (line.accountQboId != null) {
|
|
20
|
+
lineDetail.account = {
|
|
21
|
+
qbo_id: line.accountQboId,
|
|
22
|
+
account_name: line.accountName,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// An empty object is what the confirmed payloads send when no class is chosen; sending the
|
|
26
|
+
// key with a qbo_id only once one is picked.
|
|
27
|
+
const classQboId = toQboClassId(state, line.classId);
|
|
28
|
+
lineDetail.class = classQboId != null ? { qbo_id: classQboId } : {};
|
|
29
|
+
if (transactionType === 'journal_entry') {
|
|
30
|
+
lineDetail.posting_type = line.postingType;
|
|
31
|
+
if (line.vendorQboId != null) {
|
|
32
|
+
lineDetail.vendor = { qbo_id: line.vendorQboId };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
// The backend rejects a bool here, so this is always coerced to a number.
|
|
37
|
+
amount: line.amount?.amount ?? 0,
|
|
38
|
+
line_description: line.lineDescription,
|
|
39
|
+
line_detail_type: transactionType === 'journal_entry'
|
|
40
|
+
? 'journal_entry_line_detail'
|
|
41
|
+
: 'account_based_expense_line_detail',
|
|
42
|
+
line_detail: lineDetail,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** Resolves a Zeni account id to the QBO id the endpoint expects. */
|
|
46
|
+
const toQboAccountId = (state, accountId) => {
|
|
47
|
+
if (accountId == null) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return (getAccountBase(state.accountState, accountId, 'account_list')?.qboId ??
|
|
51
|
+
accountId);
|
|
52
|
+
};
|
|
53
|
+
/** Resolves a Zeni class id (`class_<uuid>`) to the QBO id `line_detail.class.qbo_id` expects. */
|
|
54
|
+
const toQboClassId = (state, classId) => {
|
|
55
|
+
if (classId == null) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return (getClassById(state.classState, { classId, reportId: 'class_list' })
|
|
59
|
+
?.qboId ?? classId);
|
|
60
|
+
};
|
|
61
|
+
/** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
|
|
62
|
+
const toQboVendorId = (state, vendorId) => {
|
|
63
|
+
if (vendorId == null) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return getVendorByVendorId(state.vendorState, vendorId)?.qboId ?? vendorId;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Builds the request body for one transaction type. One branch per type rather than a shared
|
|
70
|
+
* body with optional keys, because the types genuinely diverge -- transfer carries no lines at
|
|
71
|
+
* all, and journal_entry carries no header account.
|
|
72
|
+
*/
|
|
73
|
+
export const prepareCreateTransactionPayload = (state, localData) => {
|
|
74
|
+
const { transactionType } = localData;
|
|
75
|
+
const base = {
|
|
76
|
+
transaction_type: transactionType,
|
|
77
|
+
transaction_date: localData.transactionDate?.format(DEFAULT_DATE_FORMAT) ?? '',
|
|
78
|
+
transaction_memo: localData.transactionMemo,
|
|
79
|
+
};
|
|
80
|
+
if (transactionType === 'transfer') {
|
|
81
|
+
return {
|
|
82
|
+
...base,
|
|
83
|
+
from_account_id: toQboAccountId(state, localData.fromAccountId),
|
|
84
|
+
to_account_id: toQboAccountId(state, localData.toAccountId),
|
|
85
|
+
total_amount: localData.totalAmount?.amount ?? 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const lines = localData.lines.map((line) => toLinePayload(state, line, transactionType));
|
|
89
|
+
if (transactionType === 'journal_entry') {
|
|
90
|
+
return {
|
|
91
|
+
...base,
|
|
92
|
+
document_id: localData.documentId,
|
|
93
|
+
lines,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const purchaseBase = {
|
|
97
|
+
...base,
|
|
98
|
+
payment_type: localData.paymentType,
|
|
99
|
+
qbo_account_id: toQboAccountId(state, localData.qboAccountId),
|
|
100
|
+
vendor_id: toQboVendorId(state, localData.vendorId),
|
|
101
|
+
lines,
|
|
102
|
+
};
|
|
103
|
+
if (transactionType === 'check') {
|
|
104
|
+
return {
|
|
105
|
+
...purchaseBase,
|
|
106
|
+
document_number: localData.documentNumber,
|
|
107
|
+
print_status: localData.printStatus,
|
|
108
|
+
remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (transactionType === 'credit_card_credit') {
|
|
112
|
+
// credit_card_credit is not in the backend's SUPPORTED_TRANSACTION_WRITE_TYPES. QBO models
|
|
113
|
+
// it as a Purchase with Credit: true and qbo_purchase.py already honours is_credit for
|
|
114
|
+
// card payment types, so this sends `expense` + is_credit rather than a type the validator
|
|
115
|
+
// rejects outright. Confirm with backend before enabling the menu item.
|
|
116
|
+
return {
|
|
117
|
+
...purchaseBase,
|
|
118
|
+
transaction_type: 'expense',
|
|
119
|
+
is_credit: true,
|
|
120
|
+
document_number: localData.documentNumber,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return purchaseBase;
|
|
124
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getNestedAccountListHierarchy } from '../../accountList/accountListSelector';
|
|
2
|
+
import { getNestedClassListHierarchy } from '../../classList/classListSelector';
|
|
3
|
+
import { getResolvedTransferAccounts } from '../../createTransferEntry/createTransferEntrySelector';
|
|
4
|
+
import { getRecommendationsForEntity } from '../../recommendation/recommendationSelector';
|
|
5
|
+
export const getCreateTransactionLocalData = (state, transactionType) => state.transactionDetailState.createTransactionsState.newTransactionState[transactionType];
|
|
6
|
+
export const getCreateTransactionStatus = (state) => state.transactionDetailState.createTransactionsState.createStatus;
|
|
7
|
+
/**
|
|
8
|
+
* The vendor recommendations backing the category/class dropdowns on the create page.
|
|
9
|
+
*
|
|
10
|
+
* No new state field is needed for this: getRecommendationsForEntity already returns
|
|
11
|
+
* fetchState alongside recommendations, so composing it here is enough for the page to show a
|
|
12
|
+
* line skeleton and hold Save while a fetch is in flight.
|
|
13
|
+
*/
|
|
14
|
+
export const getCreateTransactionVendorRecommendations = (state, vendorQboId) => {
|
|
15
|
+
if (vendorQboId == null || vendorQboId === '') {
|
|
16
|
+
return { fetchState: 'Not-Started' };
|
|
17
|
+
}
|
|
18
|
+
const view = getRecommendationsForEntity(state, vendorQboId, 'vendor');
|
|
19
|
+
return {
|
|
20
|
+
fetchState: view.fetchState,
|
|
21
|
+
recommendations: view.recommendations,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const getCreateTransactionView = (state, transactionType) => {
|
|
25
|
+
const { accountListState, classListState, transactionDetailState, vendorState, } = state;
|
|
26
|
+
const { createTransactionsState } = transactionDetailState;
|
|
27
|
+
return {
|
|
28
|
+
transactionType,
|
|
29
|
+
localData: createTransactionsState.newTransactionState[transactionType],
|
|
30
|
+
createStatus: createTransactionsState.createStatus,
|
|
31
|
+
createdTransactionId: createTransactionsState.createdTransactionId,
|
|
32
|
+
vendorList: Object.values(vendorState.vendorByID),
|
|
33
|
+
accountListNestedAccountHierarchy: getNestedAccountListHierarchy(accountListState, 'accountList'),
|
|
34
|
+
classListNestedAccountHierarchy: getNestedClassListHierarchy(classListState),
|
|
35
|
+
transferAccountsList: transactionType === 'transfer'
|
|
36
|
+
? getResolvedTransferAccounts(state).transferAccountsList
|
|
37
|
+
: [],
|
|
38
|
+
fetchState: createTransactionsState.createStatus.fetchState,
|
|
39
|
+
error: createTransactionsState.createStatus.error,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction types the Create Transaction flow can originate. A narrow subset of
|
|
3
|
+
* TransactionType -- everything else is read-only and arrives via sync.
|
|
4
|
+
*/
|
|
5
|
+
export const ALL_CREATABLE_TRANSACTION_TYPES = [
|
|
6
|
+
'expense',
|
|
7
|
+
'check',
|
|
8
|
+
'credit_card_credit',
|
|
9
|
+
'transfer',
|
|
10
|
+
'journal_entry',
|
|
11
|
+
];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
|
|
4
|
+
import { toTransactionID } from '../../../../entity/transaction/payloadTypes/transactionIDPayload';
|
|
5
|
+
import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
|
|
6
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
7
|
+
import { createTransaction, createTransactionSuccessOrFailure, initializeTransactionDetailLocalData, resetCreateTransactionLocalData, } from '../../transactionDetailReducer';
|
|
8
|
+
import { getTransactionDetailKey } from '../../transactionDetailState';
|
|
9
|
+
import { prepareCreateTransactionPayload, } from '../createTransactionPayload';
|
|
10
|
+
const failureActions = (message, status) => [
|
|
11
|
+
createTransactionSuccessOrFailure('Error', undefined, status),
|
|
12
|
+
openSnackbar({
|
|
13
|
+
messageSection: 'create_transaction',
|
|
14
|
+
messageText: 'failed',
|
|
15
|
+
type: 'error',
|
|
16
|
+
// This variable is how the server's own message reaches the user. Per-type required
|
|
17
|
+
// fields live in the QBO entity classes, so a rejection comes back as a QBO error with no
|
|
18
|
+
// field name -- the message text is the only useful content we get.
|
|
19
|
+
variables: [{ variableName: '_api-error_', variableValue: message }],
|
|
20
|
+
}),
|
|
21
|
+
];
|
|
22
|
+
export const createTransactionEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(createTransaction.match), mergeMap((action) => {
|
|
23
|
+
const { transactionType } = action.payload;
|
|
24
|
+
const state = state$.value;
|
|
25
|
+
const localData = state.transactionDetailState.createTransactionsState
|
|
26
|
+
.newTransactionState[transactionType];
|
|
27
|
+
const payload = prepareCreateTransactionPayload(state, localData);
|
|
28
|
+
return zeniAPI
|
|
29
|
+
.postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/manage`, payload)
|
|
30
|
+
.pipe(mergeMap((response) => {
|
|
31
|
+
if (!isSuccessResponse(response) || response.data == null) {
|
|
32
|
+
return from(failureActions(response.status.message, response.status));
|
|
33
|
+
}
|
|
34
|
+
const created = response.data.transactions[0];
|
|
35
|
+
if (created == null) {
|
|
36
|
+
return from(failureActions('Transaction was created but returned no details.', createZeniAPIStatus('Unexpected Error', 'Create transaction returned an empty transactions array.')));
|
|
37
|
+
}
|
|
38
|
+
const newTransactionId = toTransactionID(created);
|
|
39
|
+
// The write is QBO-only: transaction_write_handler.py touches no local storage, and
|
|
40
|
+
// Zeni's mirror is populated by the delta sync that runs afterwards. Refetching here
|
|
41
|
+
// would come back without the new row, so the 200 body is inserted optimistically
|
|
42
|
+
// instead -- the same approach createTransferEntryEpic takes.
|
|
43
|
+
return from([
|
|
44
|
+
updateTransaction(getTransactionDetailKey(newTransactionId), created),
|
|
45
|
+
initializeTransactionDetailLocalData({
|
|
46
|
+
transactionId: newTransactionId,
|
|
47
|
+
vendorId: created.vendor_id ?? undefined,
|
|
48
|
+
}),
|
|
49
|
+
createTransactionSuccessOrFailure('Completed', newTransactionId),
|
|
50
|
+
resetCreateTransactionLocalData(transactionType),
|
|
51
|
+
openSnackbar({
|
|
52
|
+
messageSection: 'create_transaction',
|
|
53
|
+
messageText: 'success',
|
|
54
|
+
type: 'success',
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
}), catchError((error) => from(failureActions(JSON.stringify(error), createZeniAPIStatus('Unexpected Error', `Create Transaction REST API call errored out ${JSON.stringify(error)}`)))));
|
|
58
|
+
}));
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { concat, from, of } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap, switchMap, take } from 'rxjs/operators';
|
|
3
|
+
import { getIsAccountingClassesEnabled } from '../../../../entity/tenant/tenantSelector';
|
|
4
|
+
import { fetchRecommendationByEntityId, fetchRecommendationByEntityName, indicateReadyToInitializeRecommendation, } from '../../../recommendation/recommendationReducer';
|
|
5
|
+
import { getRecommendationsForEntity } from '../../../recommendation/recommendationSelector';
|
|
6
|
+
import { clearRecommendationsForCreateTransactionLines, fetchVendorRecommendationsForCreateTransaction, setRecommendationsForCreateTransactionLines, } from '../../transactionDetailReducer';
|
|
7
|
+
/**
|
|
8
|
+
* The entity-level recommendation fetch, keyed by whatever identifier the endpoint can resolve.
|
|
9
|
+
*
|
|
10
|
+
* A vendor that has not synced to QBO carries `qboId === name`; the id endpoint has nothing to
|
|
11
|
+
* look up in that case, so the by-name variant is used instead.
|
|
12
|
+
*/
|
|
13
|
+
const toEntityIdOrName = (entity) => entity.qboId !== '' && entity.qboId !== entity.name
|
|
14
|
+
? entity.qboId
|
|
15
|
+
: entity.name;
|
|
16
|
+
const isUnsyncedVendor = (entity) => entity.qboId === '' || entity.qboId === entity.name;
|
|
17
|
+
/**
|
|
18
|
+
* On vendor select, populates the category/class dropdowns from that vendor's recommendations.
|
|
19
|
+
*
|
|
20
|
+
* Deliberately NOT the detail page's fetchEntityRecommendationsForLineUpdate: that one sends
|
|
21
|
+
* transaction_id / line_ids and writes into transactionDetailById[key], which no-ops when the
|
|
22
|
+
* entry does not exist. A transaction being created has neither.
|
|
23
|
+
*
|
|
24
|
+
* Two differences from the reimbursement epic this is modelled on:
|
|
25
|
+
* 1. the wait filters on the matching entityIdOrName before take(1), so an unrelated
|
|
26
|
+
* recommendation landing first cannot satisfy this request, and
|
|
27
|
+
* 2. switchMap, so changing the vendor again cancels the earlier wait rather than letting a
|
|
28
|
+
* stale result overwrite the newer vendor's prefill.
|
|
29
|
+
*/
|
|
30
|
+
export const fetchVendorRecommendationsForCreateTransactionEpic = (actions$, state$) => actions$.pipe(filter(fetchVendorRecommendationsForCreateTransaction.match), switchMap((action) => {
|
|
31
|
+
const { transactionType, entity, lineIds } = action.payload;
|
|
32
|
+
if (entity == null) {
|
|
33
|
+
return of(clearRecommendationsForCreateTransactionLines(transactionType, lineIds));
|
|
34
|
+
}
|
|
35
|
+
const entityIdOrName = toEntityIdOrName(entity);
|
|
36
|
+
const state = state$.value;
|
|
37
|
+
const isAccountingClassesEnabled = getIsAccountingClassesEnabled(state);
|
|
38
|
+
const cached = getRecommendationsForEntity(state, entityIdOrName, 'vendor');
|
|
39
|
+
// Cache hit: apply straight away, no request and no wait.
|
|
40
|
+
if (cached.fetchState === 'Completed') {
|
|
41
|
+
return of(setRecommendationsForCreateTransactionLines(transactionType, lineIds, cached.recommendations ?? [], isAccountingClassesEnabled));
|
|
42
|
+
}
|
|
43
|
+
const waitThenApply = actions$.pipe(filter(indicateReadyToInitializeRecommendation.match), filter((ready) => ready.payload.entityType === 'vendor' &&
|
|
44
|
+
ready.payload.entityIdOrName === entityIdOrName), take(1), // don't listen forever! IMPORTANT!
|
|
45
|
+
mergeMap(() => from([
|
|
46
|
+
setRecommendationsForCreateTransactionLines(transactionType, lineIds, getRecommendationsForEntity(state$.value, entityIdOrName, 'vendor').recommendations ?? [], getIsAccountingClassesEnabled(state$.value)),
|
|
47
|
+
])));
|
|
48
|
+
// A fetch already in flight needs no second request, only the wait.
|
|
49
|
+
if (cached.fetchState === 'In-Progress') {
|
|
50
|
+
return waitThenApply;
|
|
51
|
+
}
|
|
52
|
+
return concat(of((isUnsyncedVendor(entity)
|
|
53
|
+
? fetchRecommendationByEntityName(entityIdOrName, 'vendor')
|
|
54
|
+
: fetchRecommendationByEntityId(entityIdOrName, 'vendor'))), waitThenApply);
|
|
55
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { filter, map } from 'rxjs/operators';
|
|
2
|
+
import { initializeCreateTransactionLocalData, updateCreateTransactionLocalData, } from '../../transactionDetailReducer';
|
|
3
|
+
import { getSeededCreateTransactionLocalData } from '../createTransactionLocalDataHelper';
|
|
4
|
+
/**
|
|
5
|
+
* Seeds the working copy when the Create form opens: today's date, the default line set for the
|
|
6
|
+
* type, and a check's mandatory payment_type.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the `else` branch of initializeScheduleDetailLocalDataEpic -- a create has no
|
|
9
|
+
* existing entity to read from, so there is nothing to merge, only defaults to apply.
|
|
10
|
+
*/
|
|
11
|
+
export const initializeCreateTransactionLocalDataEpic = (actions$) => actions$.pipe(filter(initializeCreateTransactionLocalData.match), map((action) => {
|
|
12
|
+
const { transactionType } = action.payload;
|
|
13
|
+
return updateCreateTransactionLocalData(transactionType, getSeededCreateTransactionLocalData(transactionType));
|
|
14
|
+
}));
|