@zeniai/client-epic-state 5.2.62-beta1MM → 5.2.62-beta2KB
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/fetchActualMatchingMatchEpic.js +2 -4
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +13 -26
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +23 -2
- package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +38 -89
- package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -61
- package/lib/esm/view/expenseAutomationView/types/actualMatchingViewState.js +0 -15
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +133 -0
- package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +132 -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 +60 -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/fetchActualMatchingMatchEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/fetchActualMatchingMatchEpic.js +1 -3
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +11 -24
- 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 -19
- package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +39 -90
- 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 -64
- package/lib/view/expenseAutomationView/types/actualMatchingViewState.d.ts +4 -20
- package/lib/view/expenseAutomationView/types/actualMatchingViewState.js +1 -18
- 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 +85 -0
- package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +136 -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 +64 -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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import orderBy from 'lodash/orderBy';
|
|
2
|
-
import { createSelector } from '@reduxjs/toolkit';
|
|
3
2
|
import { toMonthYearPeriodId, } from '../../../commonStateTypes/timePeriod';
|
|
4
3
|
import { getActualMatchingMatchById } from '../../../entity/actualMatching/actualMatchingSelector';
|
|
5
4
|
import { generateJEOneTimeAccrualKey } from '../../../entity/jeSchedules/jeScheduleHelper';
|
|
6
5
|
import { getJEOneTimeAccrualByKey, } from '../../../entity/jeSchedules/jeSchedulesSelector';
|
|
7
6
|
import { getCurrentTenant } from '../../../entity/tenant/tenantSelector';
|
|
8
7
|
import { date } from '../../../zeniDayJS';
|
|
8
|
+
import { actualMatchingTransactionLineKey, } from '../types/actualMatchingViewState';
|
|
9
9
|
export function getSelectedMonthYearForCurrentTenant(state) {
|
|
10
10
|
const tenantId = getCurrentTenant(state)?.tenantId;
|
|
11
11
|
if (tenantId == null) {
|
|
@@ -34,6 +34,27 @@ function toMatchModalAccrual(member) {
|
|
|
34
34
|
jeOneTimeAccrualKey: generateJEOneTimeAccrualKey(member.accrualId),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
function uniqueMatchModalAccruals(pinned, searched) {
|
|
38
|
+
const byId = new Map();
|
|
39
|
+
pinned.forEach((row) => byId.set(row.accrualId, row));
|
|
40
|
+
searched.forEach((row) => {
|
|
41
|
+
if (!byId.has(row.accrualId)) {
|
|
42
|
+
byId.set(row.accrualId, row);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return Array.from(byId.values());
|
|
46
|
+
}
|
|
47
|
+
function uniqueTransactionSearchResults(pinned, searched) {
|
|
48
|
+
const byKey = new Map();
|
|
49
|
+
pinned.forEach((row) => byKey.set(actualMatchingTransactionLineKey(row.transactionType, row.transactionIntegrationId, row.lineId), row));
|
|
50
|
+
searched.forEach((row) => {
|
|
51
|
+
const key = actualMatchingTransactionLineKey(row.transactionType, row.transactionIntegrationId, row.lineId);
|
|
52
|
+
if (!byKey.has(key)) {
|
|
53
|
+
byKey.set(key, row);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return Array.from(byKey.values());
|
|
57
|
+
}
|
|
37
58
|
export function parseActualMatchingMatchId(matchId) {
|
|
38
59
|
const separator = matchId.indexOf(':');
|
|
39
60
|
if (separator <= 0 || separator === matchId.length - 1) {
|
|
@@ -206,7 +227,6 @@ function emptyKpiSummary() {
|
|
|
206
227
|
actualsReceived: { count: 0, expectedCount: 0, vendorsPending: 0 },
|
|
207
228
|
autoReversed: { count: 0, percent: 0, clearedAmount: 0 },
|
|
208
229
|
pendingReview: { count: 0, amount: 0, estimatedMinutesToClear: 0 },
|
|
209
|
-
reversed: { count: 0 },
|
|
210
230
|
variance: { percent: 0, averagePercentPerMatch: 0, netAmount: 0 },
|
|
211
231
|
};
|
|
212
232
|
}
|
|
@@ -262,7 +282,6 @@ export function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
|
|
|
262
282
|
}
|
|
263
283
|
const autoReversed = kpiRows.filter((row) => row.kind === 'auto_reversed');
|
|
264
284
|
const pendingReview = kpiRows.filter((row) => row.kind === 'pending_review');
|
|
265
|
-
const reversed = kpiRows.filter((row) => isReversedMatchKind(row.kind));
|
|
266
285
|
const receivedCount = kpiRows.length;
|
|
267
286
|
const rowsWithActual = kpiRows.filter((row) => row.actualAmount?.amount != null);
|
|
268
287
|
const accruedTotal = rowsWithActual.reduce((sum, row) => sum + (row.accruedAmount?.amount ?? row.estimatedAmount.amount), 0);
|
|
@@ -288,9 +307,6 @@ export function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
|
|
|
288
307
|
amount: sumRowAmounts(pendingReview, displayCurrencyCode),
|
|
289
308
|
estimatedMinutesToClear: pendingReview.length * ESTIMATED_MINUTES_PER_PENDING_MATCH,
|
|
290
309
|
},
|
|
291
|
-
reversed: {
|
|
292
|
-
count: reversed.length,
|
|
293
|
-
},
|
|
294
310
|
variance: {
|
|
295
311
|
percent: accruedTotal === 0
|
|
296
312
|
? 0
|
|
@@ -303,56 +319,23 @@ export function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
|
|
|
303
319
|
},
|
|
304
320
|
};
|
|
305
321
|
}
|
|
306
|
-
function
|
|
322
|
+
export function getExpenseAutomationActualMatchingMatchView(state, matchId) {
|
|
323
|
+
const view = state.expenseAutomationActualMatchingViewState;
|
|
307
324
|
return {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
325
|
+
match: getActualMatchingMatchById(state.actualMatchingState, matchId),
|
|
326
|
+
detailFetchState: view.detailFetchStateByMatchId[matchId] ?? NOT_STARTED,
|
|
327
|
+
refreshStatus: view.detailRefreshStatusByMatchId[matchId] ?? NOT_STARTED,
|
|
328
|
+
undoReversalStatus: view.undoReversalStatusByMatchId[matchId] ?? NOT_STARTED,
|
|
329
|
+
lastMatchResults: view.lastMatchResultsByMatchId?.[matchId],
|
|
330
|
+
lastUndoResults: view.lastUndoResultsByMatchId?.[matchId],
|
|
313
331
|
};
|
|
314
332
|
}
|
|
315
|
-
const EMPTY_ACTUAL_MATCHING_ROWS = [];
|
|
316
|
-
const matchViewSelectorById = new Map();
|
|
317
|
-
export function getExpenseAutomationActualMatchingMatchView(state, matchId) {
|
|
318
|
-
let selector = matchViewSelectorById.get(matchId);
|
|
319
|
-
if (selector == null) {
|
|
320
|
-
selector = createSelector([
|
|
321
|
-
(root) => root.expenseAutomationActualMatchingViewState,
|
|
322
|
-
(root) => getActualMatchingMatchById(root.actualMatchingState, matchId),
|
|
323
|
-
], (view, match) => ({
|
|
324
|
-
detailFetchState: view.detailFetchStateByMatchId[matchId] ?? NOT_STARTED,
|
|
325
|
-
ignoreStatus: view.ignoreStatusByMatchId[matchId] ?? NOT_STARTED,
|
|
326
|
-
lastMatchResults: view.lastMatchResultsByMatchId?.[matchId],
|
|
327
|
-
lastUndoResults: view.lastUndoResultsByMatchId?.[matchId],
|
|
328
|
-
match: match == null ? undefined : toActualMatchingMatchView(match),
|
|
329
|
-
refreshStatus: view.detailRefreshStatusByMatchId[matchId] ?? NOT_STARTED,
|
|
330
|
-
undoReversalStatus: view.undoReversalStatusByMatchId[matchId] ?? NOT_STARTED,
|
|
331
|
-
}));
|
|
332
|
-
matchViewSelectorById.set(matchId, selector);
|
|
333
|
-
}
|
|
334
|
-
return selector(state);
|
|
335
|
-
}
|
|
336
333
|
export function getCloseMatchAfterUndo(state) {
|
|
337
|
-
return state.expenseAutomationActualMatchingViewState
|
|
338
|
-
.closeMatchAfterUndoMatchIds[0];
|
|
339
|
-
}
|
|
340
|
-
export function getCloseMatchAfterUndoMatchId(state) {
|
|
341
|
-
return getCloseMatchAfterUndo(state);
|
|
342
|
-
}
|
|
343
|
-
export function getCloseMatchAfterIgnoreMatchId(state) {
|
|
344
|
-
return state.expenseAutomationActualMatchingViewState
|
|
345
|
-
.closeMatchAfterIgnoreMatchIds[0];
|
|
346
|
-
}
|
|
347
|
-
export function getActualMatchingMatchModalConfirmStatus(state, matchId) {
|
|
348
|
-
if (matchId != null && matchId !== '') {
|
|
349
|
-
return (state.expenseAutomationActualMatchingViewState.confirmStatusByMatchId[matchId] ?? NOT_STARTED);
|
|
350
|
-
}
|
|
351
|
-
return state.expenseAutomationActualMatchingViewState.matchModal.confirmStatus;
|
|
334
|
+
return state.expenseAutomationActualMatchingViewState.closeMatchAfterUndo;
|
|
352
335
|
}
|
|
353
336
|
export function getExpenseAutomationActualMatchingView(state) {
|
|
354
337
|
const { expenseAutomationActualMatchingViewState } = state;
|
|
355
|
-
const { matchIdsByPeriod, fetchState, error, refreshStatus, uiState, matchModal,
|
|
338
|
+
const { matchIdsByPeriod, fetchState, error, refreshStatus, uiState, matchModal, } = expenseAutomationActualMatchingViewState;
|
|
356
339
|
const selectedPeriod = getSelectedMonthYearForCurrentTenant(state);
|
|
357
340
|
const monthYearPeriodId = selectedPeriod != null ? toMonthYearPeriodId(selectedPeriod) : undefined;
|
|
358
341
|
const matchIds = monthYearPeriodId != null ? matchIdsByPeriod[monthYearPeriodId] : undefined;
|
|
@@ -362,18 +345,38 @@ export function getExpenseAutomationActualMatchingView(state) {
|
|
|
362
345
|
.filter((match) => match.members.length > 0)
|
|
363
346
|
.map(toActualMatchingRow);
|
|
364
347
|
const rows = allRows.filter((row) => matchesSearch(row, uiState.searchString));
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
const reversed = includeReversed
|
|
368
|
-
? sortActualMatchingRows(rows.filter((row) => isReversedMatchKind(row.kind)), uiState)
|
|
369
|
-
: EMPTY_ACTUAL_MATCHING_ROWS;
|
|
370
|
-
const pendingReview = includePendingReview
|
|
371
|
-
? sortActualMatchingRows(rows.filter((row) => row.kind === 'pending_review'), uiState)
|
|
372
|
-
: EMPTY_ACTUAL_MATCHING_ROWS;
|
|
348
|
+
const reversed = sortActualMatchingRows(rows.filter((row) => isReversedMatchKind(row.kind)), uiState);
|
|
349
|
+
const pendingReview = sortActualMatchingRows(rows.filter((row) => row.kind === 'pending_review'), uiState);
|
|
373
350
|
const kpiSummary = buildActualMatchingKpiSummary(allRows, getTenantDisplayCurrency(state)?.currencyCode);
|
|
374
351
|
const searchedAccruals = matchModal.accrualSearch.results
|
|
375
352
|
.map((key) => getJEOneTimeAccrualByKey(key, state.jeSchedulesState))
|
|
376
353
|
.filter((accrual) => accrual != null);
|
|
354
|
+
const openedMatch = matchModal.openedFromMatchId != null
|
|
355
|
+
? getActualMatchingMatchById(state.actualMatchingState, matchModal.openedFromMatchId)
|
|
356
|
+
: undefined;
|
|
357
|
+
const pinnedAccruals = [
|
|
358
|
+
...(openedMatch?.members ?? []),
|
|
359
|
+
...(openedMatch?.leftovers ?? []),
|
|
360
|
+
].map(toMatchModalAccrual);
|
|
361
|
+
const firstMember = openedMatch?.members[0];
|
|
362
|
+
const cleared = firstMember?.cleared;
|
|
363
|
+
const suggestion = firstMember?.matchSuggestion;
|
|
364
|
+
const stamp = cleared ?? suggestion;
|
|
365
|
+
const consumedLineIds = cleared?.consumedLineIds;
|
|
366
|
+
const prefill = openedMatch == null
|
|
367
|
+
? undefined
|
|
368
|
+
: {
|
|
369
|
+
selectedAccrualIds: [
|
|
370
|
+
...openedMatch.members.map((member) => member.accrualId),
|
|
371
|
+
...(openedMatch.leftovers ?? []).map((leftover) => leftover.accrualId),
|
|
372
|
+
],
|
|
373
|
+
actualAmount: openedMatch.actualAmount.amount,
|
|
374
|
+
matchedTransactionId: stamp?.matchedTransactionId,
|
|
375
|
+
matchedLineId: cleared == null ? suggestion?.matchedLineId : undefined,
|
|
376
|
+
...(consumedLineIds != null && consumedLineIds.length > 0
|
|
377
|
+
? { consumedLineIds }
|
|
378
|
+
: {}),
|
|
379
|
+
};
|
|
377
380
|
// `fetchState` is a flat slice field that survives a period switch. Until this
|
|
378
381
|
// month's ids land, leftover Completed/Error is the previous month. Report
|
|
379
382
|
// Not-Started so chrome matches Review's "cache slot missing" skeleton, not
|
|
@@ -391,16 +394,16 @@ export function getExpenseAutomationActualMatchingView(state) {
|
|
|
391
394
|
kpiSummary,
|
|
392
395
|
uiState,
|
|
393
396
|
refreshStatus,
|
|
394
|
-
ignoreStatusByMatchId,
|
|
395
|
-
undoReversalStatusByMatchId,
|
|
396
397
|
hasLoadedForSelectedPeriod: matchIds != null,
|
|
397
398
|
matchModal: {
|
|
398
399
|
isOpen: matchModal.isOpen,
|
|
400
|
+
openedFromMatchId: matchModal.openedFromMatchId,
|
|
401
|
+
prefill,
|
|
399
402
|
confirmStatus: matchModal.confirmStatus,
|
|
400
403
|
lastBatchResults: matchModal.lastBatchResults,
|
|
401
404
|
transactionSearch: {
|
|
402
405
|
query: matchModal.transactionSearch.query,
|
|
403
|
-
results: matchModal.transactionSearch.results,
|
|
406
|
+
results: uniqueTransactionSearchResults(matchModal.pinnedTransactionResults, matchModal.transactionSearch.results),
|
|
404
407
|
fetchState: {
|
|
405
408
|
fetchState: matchModal.transactionSearch.fetchState,
|
|
406
409
|
error: matchModal.transactionSearch.error,
|
|
@@ -410,7 +413,7 @@ export function getExpenseAutomationActualMatchingView(state) {
|
|
|
410
413
|
},
|
|
411
414
|
accrualSearch: {
|
|
412
415
|
query: matchModal.accrualSearch.query,
|
|
413
|
-
results: searchedAccruals,
|
|
416
|
+
results: uniqueMatchModalAccruals(pinnedAccruals, searchedAccruals),
|
|
414
417
|
fetchState: {
|
|
415
418
|
fetchState: matchModal.accrualSearch.fetchState,
|
|
416
419
|
error: matchModal.accrualSearch.error,
|
|
@@ -13,12 +13,6 @@ const ACTUAL_MATCHING_SORT_KEYS = [
|
|
|
13
13
|
'variance',
|
|
14
14
|
];
|
|
15
15
|
export const toActualMatchingSortKey = (v) => stringToUnion(v, ACTUAL_MATCHING_SORT_KEYS);
|
|
16
|
-
const ACTUAL_MATCHING_STATUS_FILTERS = [
|
|
17
|
-
'all',
|
|
18
|
-
'pending_review',
|
|
19
|
-
'reversed',
|
|
20
|
-
];
|
|
21
|
-
export const toActualMatchingStatusFilter = (v) => stringToUnion(v, ACTUAL_MATCHING_STATUS_FILTERS);
|
|
22
16
|
export const MATCH_TRANSACTION_SEARCH_PAGE_SIZE = 50;
|
|
23
17
|
export const MATCH_ACCRUAL_SEARCH_LIMIT = 50;
|
|
24
18
|
export const MATCH_SEARCH_DEBOUNCE_MS = 300;
|
|
@@ -39,15 +33,6 @@ const UNDO_REVERSAL_RESULT_STATUSES = [
|
|
|
39
33
|
'error',
|
|
40
34
|
];
|
|
41
35
|
export const toUndoReversalResultStatus = (v) => stringToUnion(v, UNDO_REVERSAL_RESULT_STATUSES);
|
|
42
|
-
const ACTUAL_MATCHING_IGNORE_REASONS = [
|
|
43
|
-
'wrong_bill',
|
|
44
|
-
'wrong_period',
|
|
45
|
-
'amount_off',
|
|
46
|
-
'already_handled',
|
|
47
|
-
'other_ignore',
|
|
48
|
-
];
|
|
49
|
-
export const toActualMatchingIgnoreReasonType = (v) => stringToUnion(v, ACTUAL_MATCHING_IGNORE_REASONS);
|
|
50
|
-
export const ALL_ACTUAL_MATCHING_IGNORE_REASONS = ACTUAL_MATCHING_IGNORE_REASONS;
|
|
51
36
|
export function actualMatchingTransactionLineKey(transactionType, transactionIntegrationId, lineId) {
|
|
52
37
|
return `${transactionType}:${transactionIntegrationId}:${lineId}`;
|
|
53
38
|
}
|
|
@@ -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,132 @@
|
|
|
1
|
+
import { DEFAULT_DATE_FORMAT } from '../../../commonStateTypes/timePeriod';
|
|
2
|
+
import { getAccountBase } from '../../../entity/account/accountSelector';
|
|
3
|
+
import { getClassById } from '../../../entity/class/classSelector';
|
|
4
|
+
import { toProjectBasePayload, } from '../../../entity/project/projectPayload';
|
|
5
|
+
import { getProjectById } from '../../../entity/project/projectSelector';
|
|
6
|
+
import { getVendorByVendorId } from '../../../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 = (state, 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
|
+
const classQboId = toQboClassId(state, line.classId);
|
|
30
|
+
lineDetail.class = classQboId != null ? { qbo_id: classQboId } : {};
|
|
31
|
+
if (line.projectId != null) {
|
|
32
|
+
lineDetail.project = toProjectBasePayload(getProjectById(state.projectState, line.projectId) ?? {
|
|
33
|
+
projectId: line.projectId,
|
|
34
|
+
projectName: '',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (transactionType === 'journal_entry') {
|
|
38
|
+
lineDetail.posting_type = line.postingType;
|
|
39
|
+
if (line.vendorQboId != null) {
|
|
40
|
+
lineDetail.vendor = { qbo_id: line.vendorQboId };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
// The backend rejects a bool here, so this is always coerced to a number.
|
|
45
|
+
amount: line.amount?.amount ?? 0,
|
|
46
|
+
line_description: line.lineDescription,
|
|
47
|
+
line_detail_type: transactionType === 'journal_entry'
|
|
48
|
+
? 'journal_entry_line_detail'
|
|
49
|
+
: 'account_based_expense_line_detail',
|
|
50
|
+
line_detail: lineDetail,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/** Resolves a Zeni account id to the QBO id the endpoint expects. */
|
|
54
|
+
const toQboAccountId = (state, accountId) => {
|
|
55
|
+
if (accountId == null) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return (getAccountBase(state.accountState, accountId, 'account_list')?.qboId ??
|
|
59
|
+
accountId);
|
|
60
|
+
};
|
|
61
|
+
/** Resolves a Zeni class id (`class_<uuid>`) to the QBO id `line_detail.class.qbo_id` expects. */
|
|
62
|
+
const toQboClassId = (state, classId) => {
|
|
63
|
+
if (classId == null) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return (getClassById(state.classState, { classId, reportId: 'class_list' })?.qboId ??
|
|
67
|
+
classId);
|
|
68
|
+
};
|
|
69
|
+
/** Resolves a Zeni vendor id to its QBO id -- `vendor_id` on the wire is a QBO id. */
|
|
70
|
+
const toQboVendorId = (state, vendorId) => {
|
|
71
|
+
if (vendorId == null) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return getVendorByVendorId(state.vendorState, vendorId)?.qboId ?? vendorId;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Builds the request body for one transaction type. One branch per type rather than a shared
|
|
78
|
+
* body with optional keys, because the types genuinely diverge -- transfer carries no lines at
|
|
79
|
+
* all, and journal_entry carries no header account.
|
|
80
|
+
*/
|
|
81
|
+
export const prepareCreateTransactionPayload = (state, localData) => {
|
|
82
|
+
const { transactionType } = localData;
|
|
83
|
+
const base = {
|
|
84
|
+
transaction_type: transactionType,
|
|
85
|
+
transaction_date: localData.transactionDate?.format(DEFAULT_DATE_FORMAT) ?? '',
|
|
86
|
+
transaction_memo: localData.transactionMemo,
|
|
87
|
+
};
|
|
88
|
+
if (transactionType === 'transfer') {
|
|
89
|
+
return {
|
|
90
|
+
...base,
|
|
91
|
+
from_account_id: toQboAccountId(state, localData.fromAccountId),
|
|
92
|
+
to_account_id: toQboAccountId(state, localData.toAccountId),
|
|
93
|
+
total_amount: localData.totalAmount?.amount ?? 0,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const lines = localData.lines.map((line) => toLinePayload(state, line, transactionType));
|
|
97
|
+
if (transactionType === 'journal_entry') {
|
|
98
|
+
return {
|
|
99
|
+
...base,
|
|
100
|
+
document_id: localData.documentId,
|
|
101
|
+
lines,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const purchaseBase = {
|
|
105
|
+
...base,
|
|
106
|
+
payment_type: localData.paymentType,
|
|
107
|
+
qbo_account_id: toQboAccountId(state, localData.qboAccountId),
|
|
108
|
+
vendor_id: toQboVendorId(state, localData.vendorId),
|
|
109
|
+
lines,
|
|
110
|
+
};
|
|
111
|
+
if (transactionType === 'check') {
|
|
112
|
+
return {
|
|
113
|
+
...purchaseBase,
|
|
114
|
+
document_number: localData.documentNumber,
|
|
115
|
+
print_status: localData.printStatus,
|
|
116
|
+
remit_to_address: toRemitToAddressPayload(localData.remitToAddress),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (transactionType === 'credit_card_credit') {
|
|
120
|
+
// credit_card_credit is not in the backend's SUPPORTED_TRANSACTION_WRITE_TYPES. QBO models
|
|
121
|
+
// it as a Purchase with Credit: true and qbo_purchase.py already honours is_credit for
|
|
122
|
+
// card payment types, so this sends `expense` + is_credit rather than a type the validator
|
|
123
|
+
// rejects outright. Confirm with backend before enabling the menu item.
|
|
124
|
+
return {
|
|
125
|
+
...purchaseBase,
|
|
126
|
+
transaction_type: 'expense',
|
|
127
|
+
is_credit: true,
|
|
128
|
+
document_number: localData.documentNumber,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return purchaseBase;
|
|
132
|
+
};
|
|
@@ -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,60 @@
|
|
|
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, } 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
|
+
// No reset here: it would clear createdTransactionId in the same tick, before the
|
|
50
|
+
// screen renders it to upload pending attachments and navigate. The screen resets
|
|
51
|
+
// the working copy on unmount instead.
|
|
52
|
+
createTransactionSuccessOrFailure('Completed', newTransactionId),
|
|
53
|
+
openSnackbar({
|
|
54
|
+
messageSection: 'create_transaction',
|
|
55
|
+
messageText: 'success',
|
|
56
|
+
type: 'success',
|
|
57
|
+
}),
|
|
58
|
+
]);
|
|
59
|
+
}), catchError((error) => from(failureActions(JSON.stringify(error), createZeniAPIStatus('Unexpected Error', `Create Transaction REST API call errored out ${JSON.stringify(error)}`)))));
|
|
60
|
+
}));
|