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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/lib/entity/actualMatching/actualMatchingReducer.d.ts +3 -1
  2. package/lib/entity/actualMatching/actualMatchingReducer.js +11 -2
  3. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +1 -0
  4. package/lib/entity/jeSchedules/jeSchedulesPayload.js +1 -0
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +1 -0
  6. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  7. package/lib/entity/snackbar/snackbarTypes.js +1 -1
  8. package/lib/entity/transaction/stateTypes/paymentType.d.ts +2 -2
  9. package/lib/entity/transaction/stateTypes/paymentType.js +1 -9
  10. package/lib/epic.d.ts +2 -4
  11. package/lib/epic.js +2 -6
  12. package/lib/esm/entity/actualMatching/actualMatchingReducer.js +9 -1
  13. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +1 -0
  14. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -1
  15. package/lib/esm/entity/transaction/stateTypes/paymentType.js +1 -9
  16. package/lib/esm/epic.js +2 -6
  17. package/lib/esm/index.js +7 -10
  18. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +50 -0
  19. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +7 -3
  20. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +2 -23
  21. package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +66 -35
  22. package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +60 -64
  23. package/lib/esm/view/expenseAutomationView/types/actualMatchingViewState.js +15 -0
  24. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +30 -4
  25. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +1 -174
  26. package/lib/index.d.ts +8 -12
  27. package/lib/index.js +57 -70
  28. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.d.ts +10 -0
  29. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +54 -0
  30. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +7 -3
  31. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +1 -22
  32. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  33. package/lib/view/expenseAutomationView/payload/actualMatchingPayload.d.ts +12 -1
  34. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.d.ts +16 -8
  35. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +67 -36
  36. package/lib/view/expenseAutomationView/selectorTypes/actualMatchingViewSelectorTypes.d.ts +20 -8
  37. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +7 -4
  38. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +63 -64
  39. package/lib/view/expenseAutomationView/types/actualMatchingViewState.d.ts +20 -4
  40. package/lib/view/expenseAutomationView/types/actualMatchingViewState.js +18 -1
  41. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -1
  42. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +30 -4
  43. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +1 -37
  44. package/lib/view/transactionDetail/transactionDetailReducer.js +2 -176
  45. package/lib/view/transactionDetail/transactionDetailState.d.ts +0 -12
  46. package/package.json +1 -1
  47. package/lib/entity/transaction/stateTypes/printStatus.d.ts +0 -4
  48. package/lib/entity/transaction/stateTypes/printStatus.js +0 -15
  49. package/lib/esm/entity/transaction/stateTypes/printStatus.js +0 -11
  50. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +0 -133
  51. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +0 -114
  52. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +0 -41
  53. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +0 -11
  54. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +0 -58
  55. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +0 -55
  56. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +0 -14
  57. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +0 -51
  58. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +0 -148
  59. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +0 -82
  60. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +0 -118
  61. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +0 -40
  62. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +0 -48
  63. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +0 -81
  64. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +0 -14
  65. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +0 -9
  66. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +0 -62
  67. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +0 -20
  68. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +0 -59
  69. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +0 -12
  70. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +0 -18
@@ -1,58 +0,0 @@
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
- }));
@@ -1,55 +0,0 @@
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
- }));
@@ -1,14 +0,0 @@
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
- }));
@@ -1,51 +0,0 @@
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;
@@ -1,148 +0,0 @@
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;
@@ -1,82 +0,0 @@
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;
@@ -1,118 +0,0 @@
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;
@@ -1,40 +0,0 @@
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;
@@ -1,48 +0,0 @@
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;