@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.
Files changed (70) hide show
  1. package/lib/entity/actualMatching/actualMatchingReducer.d.ts +1 -3
  2. package/lib/entity/actualMatching/actualMatchingReducer.js +2 -11
  3. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +0 -1
  4. package/lib/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +0 -1
  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 +9 -1
  10. package/lib/entity/transaction/stateTypes/printStatus.d.ts +4 -0
  11. package/lib/entity/transaction/stateTypes/printStatus.js +15 -0
  12. package/lib/epic.d.ts +4 -2
  13. package/lib/epic.js +6 -2
  14. package/lib/esm/entity/actualMatching/actualMatchingReducer.js +1 -9
  15. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  16. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -1
  17. package/lib/esm/entity/transaction/stateTypes/paymentType.js +9 -1
  18. package/lib/esm/entity/transaction/stateTypes/printStatus.js +11 -0
  19. package/lib/esm/epic.js +6 -2
  20. package/lib/esm/index.js +10 -7
  21. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/fetchActualMatchingMatchEpic.js +2 -4
  22. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +13 -26
  23. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +23 -2
  24. package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +38 -89
  25. package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -61
  26. package/lib/esm/view/expenseAutomationView/types/actualMatchingViewState.js +0 -15
  27. package/lib/esm/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +133 -0
  28. package/lib/esm/view/transactionDetail/createTransaction/createTransactionPayload.js +132 -0
  29. package/lib/esm/view/transactionDetail/createTransaction/createTransactionSelector.js +41 -0
  30. package/lib/esm/view/transactionDetail/createTransaction/createTransactionState.js +11 -0
  31. package/lib/esm/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +60 -0
  32. package/lib/esm/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +55 -0
  33. package/lib/esm/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +14 -0
  34. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +174 -1
  35. package/lib/index.d.ts +12 -8
  36. package/lib/index.js +70 -57
  37. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/fetchActualMatchingMatchEpic.d.ts +2 -2
  38. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/fetchActualMatchingMatchEpic.js +1 -3
  39. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/matchAndReverseAccrualsEpic.js +11 -24
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/searchMatchTransactionsEpic.js +22 -1
  41. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  42. package/lib/view/expenseAutomationView/payload/actualMatchingPayload.d.ts +1 -12
  43. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.d.ts +8 -19
  44. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +39 -90
  45. package/lib/view/expenseAutomationView/selectorTypes/actualMatchingViewSelectorTypes.d.ts +8 -20
  46. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +4 -7
  47. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +64 -64
  48. package/lib/view/expenseAutomationView/types/actualMatchingViewState.d.ts +4 -20
  49. package/lib/view/expenseAutomationView/types/actualMatchingViewState.js +1 -18
  50. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.d.ts +51 -0
  51. package/lib/view/transactionDetail/createTransaction/createTransactionLocalDataHelper.js +148 -0
  52. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.d.ts +85 -0
  53. package/lib/view/transactionDetail/createTransaction/createTransactionPayload.js +136 -0
  54. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.d.ts +40 -0
  55. package/lib/view/transactionDetail/createTransaction/createTransactionSelector.js +48 -0
  56. package/lib/view/transactionDetail/createTransaction/createTransactionState.d.ts +81 -0
  57. package/lib/view/transactionDetail/createTransaction/createTransactionState.js +14 -0
  58. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.d.ts +9 -0
  59. package/lib/view/transactionDetail/createTransaction/epics/createTransactionEpic.js +64 -0
  60. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.d.ts +20 -0
  61. package/lib/view/transactionDetail/createTransaction/epics/fetchVendorRecommendationsForCreateTransactionEpic.js +59 -0
  62. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.d.ts +12 -0
  63. package/lib/view/transactionDetail/createTransaction/epics/initializeCreateTransactionLocalDataEpic.js +18 -0
  64. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +37 -1
  65. package/lib/view/transactionDetail/transactionDetailReducer.js +176 -2
  66. package/lib/view/transactionDetail/transactionDetailState.d.ts +12 -0
  67. package/package.json +1 -1
  68. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -50
  69. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.d.ts +0 -10
  70. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +0 -54
@@ -16,18 +16,15 @@ exports.getActualMatchingReversalDate = getActualMatchingReversalDate;
16
16
  exports.buildActualMatchingKpiSummary = buildActualMatchingKpiSummary;
17
17
  exports.getExpenseAutomationActualMatchingMatchView = getExpenseAutomationActualMatchingMatchView;
18
18
  exports.getCloseMatchAfterUndo = getCloseMatchAfterUndo;
19
- exports.getCloseMatchAfterUndoMatchId = getCloseMatchAfterUndoMatchId;
20
- exports.getCloseMatchAfterIgnoreMatchId = getCloseMatchAfterIgnoreMatchId;
21
- exports.getActualMatchingMatchModalConfirmStatus = getActualMatchingMatchModalConfirmStatus;
22
19
  exports.getExpenseAutomationActualMatchingView = getExpenseAutomationActualMatchingView;
23
20
  const orderBy_1 = __importDefault(require("lodash/orderBy"));
24
- const toolkit_1 = require("@reduxjs/toolkit");
25
21
  const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
26
22
  const actualMatchingSelector_1 = require("../../../entity/actualMatching/actualMatchingSelector");
27
23
  const jeScheduleHelper_1 = require("../../../entity/jeSchedules/jeScheduleHelper");
28
24
  const jeSchedulesSelector_1 = require("../../../entity/jeSchedules/jeSchedulesSelector");
29
25
  const tenantSelector_1 = require("../../../entity/tenant/tenantSelector");
30
26
  const zeniDayJS_1 = require("../../../zeniDayJS");
27
+ const actualMatchingViewState_1 = require("../types/actualMatchingViewState");
31
28
  function getSelectedMonthYearForCurrentTenant(state) {
32
29
  const tenantId = (0, tenantSelector_1.getCurrentTenant)(state)?.tenantId;
33
30
  if (tenantId == null) {
@@ -56,6 +53,27 @@ function toMatchModalAccrual(member) {
56
53
  jeOneTimeAccrualKey: (0, jeScheduleHelper_1.generateJEOneTimeAccrualKey)(member.accrualId),
57
54
  };
58
55
  }
56
+ function uniqueMatchModalAccruals(pinned, searched) {
57
+ const byId = new Map();
58
+ pinned.forEach((row) => byId.set(row.accrualId, row));
59
+ searched.forEach((row) => {
60
+ if (!byId.has(row.accrualId)) {
61
+ byId.set(row.accrualId, row);
62
+ }
63
+ });
64
+ return Array.from(byId.values());
65
+ }
66
+ function uniqueTransactionSearchResults(pinned, searched) {
67
+ const byKey = new Map();
68
+ pinned.forEach((row) => byKey.set((0, actualMatchingViewState_1.actualMatchingTransactionLineKey)(row.transactionType, row.transactionIntegrationId, row.lineId), row));
69
+ searched.forEach((row) => {
70
+ const key = (0, actualMatchingViewState_1.actualMatchingTransactionLineKey)(row.transactionType, row.transactionIntegrationId, row.lineId);
71
+ if (!byKey.has(key)) {
72
+ byKey.set(key, row);
73
+ }
74
+ });
75
+ return Array.from(byKey.values());
76
+ }
59
77
  function parseActualMatchingMatchId(matchId) {
60
78
  const separator = matchId.indexOf(':');
61
79
  if (separator <= 0 || separator === matchId.length - 1) {
@@ -228,7 +246,6 @@ function emptyKpiSummary() {
228
246
  actualsReceived: { count: 0, expectedCount: 0, vendorsPending: 0 },
229
247
  autoReversed: { count: 0, percent: 0, clearedAmount: 0 },
230
248
  pendingReview: { count: 0, amount: 0, estimatedMinutesToClear: 0 },
231
- reversed: { count: 0 },
232
249
  variance: { percent: 0, averagePercentPerMatch: 0, netAmount: 0 },
233
250
  };
234
251
  }
@@ -284,7 +301,6 @@ function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
284
301
  }
285
302
  const autoReversed = kpiRows.filter((row) => row.kind === 'auto_reversed');
286
303
  const pendingReview = kpiRows.filter((row) => row.kind === 'pending_review');
287
- const reversed = kpiRows.filter((row) => isReversedMatchKind(row.kind));
288
304
  const receivedCount = kpiRows.length;
289
305
  const rowsWithActual = kpiRows.filter((row) => row.actualAmount?.amount != null);
290
306
  const accruedTotal = rowsWithActual.reduce((sum, row) => sum + (row.accruedAmount?.amount ?? row.estimatedAmount.amount), 0);
@@ -310,9 +326,6 @@ function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
310
326
  amount: sumRowAmounts(pendingReview, displayCurrencyCode),
311
327
  estimatedMinutesToClear: pendingReview.length * ESTIMATED_MINUTES_PER_PENDING_MATCH,
312
328
  },
313
- reversed: {
314
- count: reversed.length,
315
- },
316
329
  variance: {
317
330
  percent: accruedTotal === 0
318
331
  ? 0
@@ -325,56 +338,23 @@ function buildActualMatchingKpiSummary(rows, displayCurrencyCode) {
325
338
  },
326
339
  };
327
340
  }
328
- function toActualMatchingMatchView(match) {
341
+ function getExpenseAutomationActualMatchingMatchView(state, matchId) {
342
+ const view = state.expenseAutomationActualMatchingViewState;
329
343
  return {
330
- ...match,
331
- members: match.members.map(toMatchModalAccrual),
332
- leftovers: match.leftovers == null
333
- ? undefined
334
- : match.leftovers.map(toMatchModalAccrual),
344
+ match: (0, actualMatchingSelector_1.getActualMatchingMatchById)(state.actualMatchingState, matchId),
345
+ detailFetchState: view.detailFetchStateByMatchId[matchId] ?? NOT_STARTED,
346
+ refreshStatus: view.detailRefreshStatusByMatchId[matchId] ?? NOT_STARTED,
347
+ undoReversalStatus: view.undoReversalStatusByMatchId[matchId] ?? NOT_STARTED,
348
+ lastMatchResults: view.lastMatchResultsByMatchId?.[matchId],
349
+ lastUndoResults: view.lastUndoResultsByMatchId?.[matchId],
335
350
  };
336
351
  }
337
- const EMPTY_ACTUAL_MATCHING_ROWS = [];
338
- const matchViewSelectorById = new Map();
339
- function getExpenseAutomationActualMatchingMatchView(state, matchId) {
340
- let selector = matchViewSelectorById.get(matchId);
341
- if (selector == null) {
342
- selector = (0, toolkit_1.createSelector)([
343
- (root) => root.expenseAutomationActualMatchingViewState,
344
- (root) => (0, actualMatchingSelector_1.getActualMatchingMatchById)(root.actualMatchingState, matchId),
345
- ], (view, match) => ({
346
- detailFetchState: view.detailFetchStateByMatchId[matchId] ?? NOT_STARTED,
347
- ignoreStatus: view.ignoreStatusByMatchId[matchId] ?? NOT_STARTED,
348
- lastMatchResults: view.lastMatchResultsByMatchId?.[matchId],
349
- lastUndoResults: view.lastUndoResultsByMatchId?.[matchId],
350
- match: match == null ? undefined : toActualMatchingMatchView(match),
351
- refreshStatus: view.detailRefreshStatusByMatchId[matchId] ?? NOT_STARTED,
352
- undoReversalStatus: view.undoReversalStatusByMatchId[matchId] ?? NOT_STARTED,
353
- }));
354
- matchViewSelectorById.set(matchId, selector);
355
- }
356
- return selector(state);
357
- }
358
352
  function getCloseMatchAfterUndo(state) {
359
- return state.expenseAutomationActualMatchingViewState
360
- .closeMatchAfterUndoMatchIds[0];
361
- }
362
- function getCloseMatchAfterUndoMatchId(state) {
363
- return getCloseMatchAfterUndo(state);
364
- }
365
- function getCloseMatchAfterIgnoreMatchId(state) {
366
- return state.expenseAutomationActualMatchingViewState
367
- .closeMatchAfterIgnoreMatchIds[0];
368
- }
369
- function getActualMatchingMatchModalConfirmStatus(state, matchId) {
370
- if (matchId != null && matchId !== '') {
371
- return (state.expenseAutomationActualMatchingViewState.confirmStatusByMatchId[matchId] ?? NOT_STARTED);
372
- }
373
- return state.expenseAutomationActualMatchingViewState.matchModal.confirmStatus;
353
+ return state.expenseAutomationActualMatchingViewState.closeMatchAfterUndo;
374
354
  }
375
355
  function getExpenseAutomationActualMatchingView(state) {
376
356
  const { expenseAutomationActualMatchingViewState } = state;
377
- const { matchIdsByPeriod, fetchState, error, refreshStatus, uiState, matchModal, ignoreStatusByMatchId, undoReversalStatusByMatchId, } = expenseAutomationActualMatchingViewState;
357
+ const { matchIdsByPeriod, fetchState, error, refreshStatus, uiState, matchModal, } = expenseAutomationActualMatchingViewState;
378
358
  const selectedPeriod = getSelectedMonthYearForCurrentTenant(state);
379
359
  const monthYearPeriodId = selectedPeriod != null ? (0, timePeriod_1.toMonthYearPeriodId)(selectedPeriod) : undefined;
380
360
  const matchIds = monthYearPeriodId != null ? matchIdsByPeriod[monthYearPeriodId] : undefined;
@@ -384,18 +364,38 @@ function getExpenseAutomationActualMatchingView(state) {
384
364
  .filter((match) => match.members.length > 0)
385
365
  .map(toActualMatchingRow);
386
366
  const rows = allRows.filter((row) => matchesSearch(row, uiState.searchString));
387
- const includePendingReview = uiState.statusFilter !== 'reversed';
388
- const includeReversed = uiState.statusFilter !== 'pending_review';
389
- const reversed = includeReversed
390
- ? sortActualMatchingRows(rows.filter((row) => isReversedMatchKind(row.kind)), uiState)
391
- : EMPTY_ACTUAL_MATCHING_ROWS;
392
- const pendingReview = includePendingReview
393
- ? sortActualMatchingRows(rows.filter((row) => row.kind === 'pending_review'), uiState)
394
- : EMPTY_ACTUAL_MATCHING_ROWS;
367
+ const reversed = sortActualMatchingRows(rows.filter((row) => isReversedMatchKind(row.kind)), uiState);
368
+ const pendingReview = sortActualMatchingRows(rows.filter((row) => row.kind === 'pending_review'), uiState);
395
369
  const kpiSummary = buildActualMatchingKpiSummary(allRows, getTenantDisplayCurrency(state)?.currencyCode);
396
370
  const searchedAccruals = matchModal.accrualSearch.results
397
371
  .map((key) => (0, jeSchedulesSelector_1.getJEOneTimeAccrualByKey)(key, state.jeSchedulesState))
398
372
  .filter((accrual) => accrual != null);
373
+ const openedMatch = matchModal.openedFromMatchId != null
374
+ ? (0, actualMatchingSelector_1.getActualMatchingMatchById)(state.actualMatchingState, matchModal.openedFromMatchId)
375
+ : undefined;
376
+ const pinnedAccruals = [
377
+ ...(openedMatch?.members ?? []),
378
+ ...(openedMatch?.leftovers ?? []),
379
+ ].map(toMatchModalAccrual);
380
+ const firstMember = openedMatch?.members[0];
381
+ const cleared = firstMember?.cleared;
382
+ const suggestion = firstMember?.matchSuggestion;
383
+ const stamp = cleared ?? suggestion;
384
+ const consumedLineIds = cleared?.consumedLineIds;
385
+ const prefill = openedMatch == null
386
+ ? undefined
387
+ : {
388
+ selectedAccrualIds: [
389
+ ...openedMatch.members.map((member) => member.accrualId),
390
+ ...(openedMatch.leftovers ?? []).map((leftover) => leftover.accrualId),
391
+ ],
392
+ actualAmount: openedMatch.actualAmount.amount,
393
+ matchedTransactionId: stamp?.matchedTransactionId,
394
+ matchedLineId: cleared == null ? suggestion?.matchedLineId : undefined,
395
+ ...(consumedLineIds != null && consumedLineIds.length > 0
396
+ ? { consumedLineIds }
397
+ : {}),
398
+ };
399
399
  // `fetchState` is a flat slice field that survives a period switch. Until this
400
400
  // month's ids land, leftover Completed/Error is the previous month. Report
401
401
  // Not-Started so chrome matches Review's "cache slot missing" skeleton, not
@@ -413,16 +413,16 @@ function getExpenseAutomationActualMatchingView(state) {
413
413
  kpiSummary,
414
414
  uiState,
415
415
  refreshStatus,
416
- ignoreStatusByMatchId,
417
- undoReversalStatusByMatchId,
418
416
  hasLoadedForSelectedPeriod: matchIds != null,
419
417
  matchModal: {
420
418
  isOpen: matchModal.isOpen,
419
+ openedFromMatchId: matchModal.openedFromMatchId,
420
+ prefill,
421
421
  confirmStatus: matchModal.confirmStatus,
422
422
  lastBatchResults: matchModal.lastBatchResults,
423
423
  transactionSearch: {
424
424
  query: matchModal.transactionSearch.query,
425
- results: matchModal.transactionSearch.results,
425
+ results: uniqueTransactionSearchResults(matchModal.pinnedTransactionResults, matchModal.transactionSearch.results),
426
426
  fetchState: {
427
427
  fetchState: matchModal.transactionSearch.fetchState,
428
428
  error: matchModal.transactionSearch.error,
@@ -432,7 +432,7 @@ function getExpenseAutomationActualMatchingView(state) {
432
432
  },
433
433
  accrualSearch: {
434
434
  query: matchModal.accrualSearch.query,
435
- results: searchedAccruals,
435
+ results: uniqueMatchModalAccruals(pinnedAccruals, searchedAccruals),
436
436
  fetchState: {
437
437
  fetchState: matchModal.accrualSearch.fetchState,
438
438
  error: matchModal.accrualSearch.error,
@@ -5,8 +5,6 @@ import { ActualMatchingMatchId } from '../../../entity/actualMatching/actualMatc
5
5
  import { JEOneTimeAccrualKey } from '../../../entity/jeSchedules/jeSchedulesTypes';
6
6
  export declare const toActualMatchingSortKey: (v: string) => "type" | "date" | "vendor" | "category" | "class" | "amount" | "variance" | "lifecycle" | "service" | "accrued" | "actual";
7
7
  export type ActualMatchingSortKey = ReturnType<typeof toActualMatchingSortKey>;
8
- export declare const toActualMatchingStatusFilter: (v: string) => "pending_review" | "reversed" | "all";
9
- export type ActualMatchingStatusFilter = ReturnType<typeof toActualMatchingStatusFilter>;
10
8
  export declare const MATCH_TRANSACTION_SEARCH_PAGE_SIZE = 50;
11
9
  export declare const MATCH_ACCRUAL_SEARCH_LIMIT = 50;
12
10
  export declare const MATCH_SEARCH_DEBOUNCE_MS = 300;
@@ -20,12 +18,6 @@ export interface ActualMatchingViewUIState {
20
18
  searchString: string;
21
19
  sortKey: ActualMatchingSortKey;
22
20
  sortOrder: SortOrder;
23
- /**
24
- * List-only filter. `all` shows both groups; `pending_review` / `reversed`
25
- * empty the other group (`reversed` includes auto and manual). KPI summary
26
- * stays on the unfiltered period.
27
- */
28
- statusFilter: ActualMatchingStatusFilter;
29
21
  }
30
22
  /**
31
23
  * Sibling of Missing Receipts `MatchCandidate`. Confirm needs `lineId` and
@@ -77,14 +69,6 @@ export interface UndoReversalAccrualsParams {
77
69
  accrualIds: ID[];
78
70
  matchId: ActualMatchingMatchId;
79
71
  }
80
- export declare const toActualMatchingIgnoreReasonType: (v: string) => "other_ignore" | "already_handled" | "amount_off" | "wrong_period" | "wrong_bill";
81
- export type ActualMatchingIgnoreReasonType = ReturnType<typeof toActualMatchingIgnoreReasonType>;
82
- export declare const ALL_ACTUAL_MATCHING_IGNORE_REASONS: readonly ActualMatchingIgnoreReasonType[];
83
- export interface IgnoreActualMatchingSuggestionParams {
84
- matchId: ActualMatchingMatchId;
85
- reason: ActualMatchingIgnoreReasonType;
86
- note?: string;
87
- }
88
72
  export interface ActualMatchingTransactionSearchState extends FetchStateAndError {
89
73
  isLoadingMore: boolean;
90
74
  nextPageToken: string | null;
@@ -100,18 +84,18 @@ export interface ActualMatchingAccrualSearchState extends FetchStateAndError {
100
84
  export interface ActualMatchingMatchModalState {
101
85
  accrualSearch: ActualMatchingAccrualSearchState;
102
86
  confirmStatus: FetchStateAndError;
87
+ didPinPrefillTransactions: boolean;
103
88
  isOpen: boolean;
89
+ pinnedTransactionResults: ActualMatchingTransactionSearchResult[];
104
90
  transactionSearch: ActualMatchingTransactionSearchState;
105
91
  lastBatchResults?: MatchAndReverseResult[];
92
+ openedFromMatchId?: ActualMatchingMatchId;
106
93
  }
107
94
  export declare function actualMatchingTransactionLineKey(transactionType: string, transactionIntegrationId: string, lineId: string): string;
108
95
  export interface ActualMatchingViewState extends FetchedState {
109
- closeMatchAfterIgnoreMatchIds: ActualMatchingMatchId[];
110
- closeMatchAfterUndoMatchIds: ActualMatchingMatchId[];
111
- confirmStatusByMatchId: Record<ActualMatchingMatchId, FetchStateAndError>;
96
+ closeMatchAfterUndo: boolean;
112
97
  detailFetchStateByMatchId: Record<ActualMatchingMatchId, FetchStateAndError>;
113
98
  detailRefreshStatusByMatchId: Record<ActualMatchingMatchId, FetchStateAndError>;
114
- ignoreStatusByMatchId: Record<ActualMatchingMatchId, FetchStateAndError>;
115
99
  lastMatchResultsByMatchId: Record<ActualMatchingMatchId, MatchAndReverseResult[]>;
116
100
  lastUndoResultsByMatchId: Record<ActualMatchingMatchId, UndoReversalResult[]>;
117
101
  matchIdsByPeriod: Record<MonthYearPeriodId, ActualMatchingMatchId[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALL_ACTUAL_MATCHING_IGNORE_REASONS = exports.toActualMatchingIgnoreReasonType = exports.toUndoReversalResultStatus = exports.toMatchAndReverseResultStatus = exports.MATCH_SEARCH_DEBOUNCE_MS = exports.MATCH_ACCRUAL_SEARCH_LIMIT = exports.MATCH_TRANSACTION_SEARCH_PAGE_SIZE = exports.toActualMatchingStatusFilter = exports.toActualMatchingSortKey = void 0;
3
+ exports.toUndoReversalResultStatus = exports.toMatchAndReverseResultStatus = exports.MATCH_SEARCH_DEBOUNCE_MS = exports.MATCH_ACCRUAL_SEARCH_LIMIT = exports.MATCH_TRANSACTION_SEARCH_PAGE_SIZE = exports.toActualMatchingSortKey = void 0;
4
4
  exports.isMatchAndReverseCompleteStatus = isMatchAndReverseCompleteStatus;
5
5
  exports.actualMatchingTransactionLineKey = actualMatchingTransactionLineKey;
6
6
  const stringToUnion_1 = require("../../../commonStateTypes/stringToUnion");
@@ -19,13 +19,6 @@ const ACTUAL_MATCHING_SORT_KEYS = [
19
19
  ];
20
20
  const toActualMatchingSortKey = (v) => (0, stringToUnion_1.stringToUnion)(v, ACTUAL_MATCHING_SORT_KEYS);
21
21
  exports.toActualMatchingSortKey = toActualMatchingSortKey;
22
- const ACTUAL_MATCHING_STATUS_FILTERS = [
23
- 'all',
24
- 'pending_review',
25
- 'reversed',
26
- ];
27
- const toActualMatchingStatusFilter = (v) => (0, stringToUnion_1.stringToUnion)(v, ACTUAL_MATCHING_STATUS_FILTERS);
28
- exports.toActualMatchingStatusFilter = toActualMatchingStatusFilter;
29
22
  exports.MATCH_TRANSACTION_SEARCH_PAGE_SIZE = 50;
30
23
  exports.MATCH_ACCRUAL_SEARCH_LIMIT = 50;
31
24
  exports.MATCH_SEARCH_DEBOUNCE_MS = 300;
@@ -48,16 +41,6 @@ const UNDO_REVERSAL_RESULT_STATUSES = [
48
41
  ];
49
42
  const toUndoReversalResultStatus = (v) => (0, stringToUnion_1.stringToUnion)(v, UNDO_REVERSAL_RESULT_STATUSES);
50
43
  exports.toUndoReversalResultStatus = toUndoReversalResultStatus;
51
- const ACTUAL_MATCHING_IGNORE_REASONS = [
52
- 'wrong_bill',
53
- 'wrong_period',
54
- 'amount_off',
55
- 'already_handled',
56
- 'other_ignore',
57
- ];
58
- const toActualMatchingIgnoreReasonType = (v) => (0, stringToUnion_1.stringToUnion)(v, ACTUAL_MATCHING_IGNORE_REASONS);
59
- exports.toActualMatchingIgnoreReasonType = toActualMatchingIgnoreReasonType;
60
- exports.ALL_ACTUAL_MATCHING_IGNORE_REASONS = ACTUAL_MATCHING_IGNORE_REASONS;
61
44
  function actualMatchingTransactionLineKey(transactionType, transactionIntegrationId, lineId) {
62
45
  return `${transactionType}:${transactionIntegrationId}:${lineId}`;
63
46
  }
@@ -0,0 +1,51 @@
1
+ import { Recommendation, RecommendationWithCOT } from '../../../commonStateTypes/recommendationBase';
2
+ import { TransactionCategory } from '../../../entity/transaction/stateTypes/transactionType';
3
+ import { CreatableTransactionType, CreateTransactionLineLocalData, CreateTransactionLocalData, CreateTransactionLocalDataByType } from './createTransactionState';
4
+ export declare const nextCreateTransactionLineId: () => string;
5
+ /** Test-only: makes line ids predictable from the start of each case. */
6
+ export declare const resetCreateTransactionLineIdCounter: () => void;
7
+ export declare const createEmptyCreateTransactionLine: (postingType?: TransactionCategory) => CreateTransactionLineLocalData;
8
+ /**
9
+ * The lines a freshly-opened form starts with. A journal entry is invalid with fewer than one
10
+ * debit and one credit, so it opens with both rather than making the user add the second row.
11
+ * Transfer has no lines at all.
12
+ */
13
+ export declare const getDefaultCreateTransactionLines: (transactionType: CreatableTransactionType) => CreateTransactionLineLocalData[];
14
+ /**
15
+ * A blank working copy for one type. Note this does NOT seed the date -- the reducer's initial
16
+ * state has to stay a pure constant so `clearAll` restores something stable. The date is seeded
17
+ * by initializeCreateTransactionLocalDataEpic, which runs when the form opens.
18
+ */
19
+ export declare const getEmptyCreateTransactionLocalData: (transactionType: CreatableTransactionType) => CreateTransactionLocalData;
20
+ export declare const getInitialCreateTransactionLocalDataByType: () => CreateTransactionLocalDataByType;
21
+ /**
22
+ * What the form opens with: a blank copy plus today's date, the default line set, and the one
23
+ * payment_type the backend insists on for a check (qbo_purchase.py raises without it).
24
+ */
25
+ export declare const getSeededCreateTransactionLocalData: (transactionType: CreatableTransactionType) => CreateTransactionLocalData;
26
+ /**
27
+ * Merges a partial edit into the working copy. Lines are replaced wholesale when present --
28
+ * a partial line array would silently truncate the form.
29
+ */
30
+ export declare const mergeCreateTransactionLocalData: (current: CreateTransactionLocalData, update: Partial<CreateTransactionLocalData>) => CreateTransactionLocalData;
31
+ export declare const updateCreateTransactionLine: (lines: CreateTransactionLineLocalData[], lineId: string, update: Partial<CreateTransactionLineLocalData>) => CreateTransactionLineLocalData[];
32
+ /**
33
+ * Recommendation -> RecommendationWithCOT. Chain-of-thought and recommendation feedback both
34
+ * need an existing transaction, so cot/reasoning are empty here by design; the dropdown only
35
+ * needs the entities to build its "Recommended" group.
36
+ */
37
+ export declare const toRecommendationsWithCOT: (recommendations: Recommendation[]) => RecommendationWithCOT[];
38
+ /**
39
+ * Applies a vendor's recommendations to one line: always refreshes the dropdown's "Recommended"
40
+ * group, but only prefills account/class when the field is still empty. Anything the user
41
+ * picked wins -- this follows the transaction-categorization helper, which prefills, rather
42
+ * than the detail-page helper, which only suggests.
43
+ */
44
+ export declare const applyRecommendationsToCreateTransactionLine: (line: CreateTransactionLineLocalData, recommendations: Recommendation[], isAccountingClassesEnabled: boolean) => CreateTransactionLineLocalData;
45
+ /**
46
+ * Undoes a prefill when the vendor is cleared. Only the fields the prefill wrote are removed --
47
+ * the per-field flags are what make the user's own choices distinguishable from ours, which is
48
+ * why they are not a single line-level boolean: a hand-picked account alongside a prefilled
49
+ * class is an ordinary state, and clearing must not take the account with it.
50
+ */
51
+ export declare const clearRecommendationsFromCreateTransactionLine: (line: CreateTransactionLineLocalData) => CreateTransactionLineLocalData;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearRecommendationsFromCreateTransactionLine = exports.applyRecommendationsToCreateTransactionLine = exports.toRecommendationsWithCOT = exports.updateCreateTransactionLine = exports.mergeCreateTransactionLocalData = exports.getSeededCreateTransactionLocalData = exports.getInitialCreateTransactionLocalDataByType = exports.getEmptyCreateTransactionLocalData = exports.getDefaultCreateTransactionLines = exports.createEmptyCreateTransactionLine = exports.resetCreateTransactionLineIdCounter = exports.nextCreateTransactionLineId = void 0;
4
+ const zeniDayJS_1 = require("../../../zeniDayJS");
5
+ const createTransactionState_1 = require("./createTransactionState");
6
+ /**
7
+ * Monotonic counter for line row keys. These never leave the client -- the payload builder
8
+ * drops them -- so a counter is enough, and it keeps reducer tests deterministic in a way
9
+ * randomUUID would not.
10
+ */
11
+ let lineIdCounter = 0;
12
+ const nextCreateTransactionLineId = () => `create-transaction-line-${lineIdCounter++}`;
13
+ exports.nextCreateTransactionLineId = nextCreateTransactionLineId;
14
+ /** Test-only: makes line ids predictable from the start of each case. */
15
+ const resetCreateTransactionLineIdCounter = () => {
16
+ lineIdCounter = 0;
17
+ };
18
+ exports.resetCreateTransactionLineIdCounter = resetCreateTransactionLineIdCounter;
19
+ const createEmptyCreateTransactionLine = (postingType) => ({
20
+ id: (0, exports.nextCreateTransactionLineId)(),
21
+ postingType,
22
+ });
23
+ exports.createEmptyCreateTransactionLine = createEmptyCreateTransactionLine;
24
+ /**
25
+ * The lines a freshly-opened form starts with. A journal entry is invalid with fewer than one
26
+ * debit and one credit, so it opens with both rather than making the user add the second row.
27
+ * Transfer has no lines at all.
28
+ */
29
+ const getDefaultCreateTransactionLines = (transactionType) => {
30
+ if (transactionType === 'transfer') {
31
+ return [];
32
+ }
33
+ if (transactionType === 'journal_entry') {
34
+ return [
35
+ (0, exports.createEmptyCreateTransactionLine)('debit'),
36
+ (0, exports.createEmptyCreateTransactionLine)('credit'),
37
+ ];
38
+ }
39
+ return [(0, exports.createEmptyCreateTransactionLine)()];
40
+ };
41
+ exports.getDefaultCreateTransactionLines = getDefaultCreateTransactionLines;
42
+ /**
43
+ * A blank working copy for one type. Note this does NOT seed the date -- the reducer's initial
44
+ * state has to stay a pure constant so `clearAll` restores something stable. The date is seeded
45
+ * by initializeCreateTransactionLocalDataEpic, which runs when the form opens.
46
+ */
47
+ const getEmptyCreateTransactionLocalData = (transactionType) => ({
48
+ lines: [],
49
+ transactionType,
50
+ });
51
+ exports.getEmptyCreateTransactionLocalData = getEmptyCreateTransactionLocalData;
52
+ const getInitialCreateTransactionLocalDataByType = () => createTransactionState_1.ALL_CREATABLE_TRANSACTION_TYPES.reduce((acc, transactionType) => {
53
+ acc[transactionType] =
54
+ (0, exports.getEmptyCreateTransactionLocalData)(transactionType);
55
+ return acc;
56
+ }, {});
57
+ exports.getInitialCreateTransactionLocalDataByType = getInitialCreateTransactionLocalDataByType;
58
+ /**
59
+ * What the form opens with: a blank copy plus today's date, the default line set, and the one
60
+ * payment_type the backend insists on for a check (qbo_purchase.py raises without it).
61
+ */
62
+ const getSeededCreateTransactionLocalData = (transactionType) => ({
63
+ ...(0, exports.getEmptyCreateTransactionLocalData)(transactionType),
64
+ lines: (0, exports.getDefaultCreateTransactionLines)(transactionType),
65
+ paymentType: transactionType === 'check' ? 'check' : undefined,
66
+ transactionDate: (0, zeniDayJS_1.dateNow)(),
67
+ });
68
+ exports.getSeededCreateTransactionLocalData = getSeededCreateTransactionLocalData;
69
+ /**
70
+ * Merges a partial edit into the working copy. Lines are replaced wholesale when present --
71
+ * a partial line array would silently truncate the form.
72
+ */
73
+ const mergeCreateTransactionLocalData = (current, update) => ({
74
+ ...current,
75
+ ...update,
76
+ lines: update.lines ?? current.lines,
77
+ // The type is keyed by the slice, never edited through a merge.
78
+ transactionType: current.transactionType,
79
+ });
80
+ exports.mergeCreateTransactionLocalData = mergeCreateTransactionLocalData;
81
+ const updateCreateTransactionLine = (lines, lineId, update) => lines.map((line) => line.id === lineId ? { ...line, ...update, id: line.id } : line);
82
+ exports.updateCreateTransactionLine = updateCreateTransactionLine;
83
+ /**
84
+ * Recommendation -> RecommendationWithCOT. Chain-of-thought and recommendation feedback both
85
+ * need an existing transaction, so cot/reasoning are empty here by design; the dropdown only
86
+ * needs the entities to build its "Recommended" group.
87
+ */
88
+ const toRecommendationsWithCOT = (recommendations) => recommendations.map((recommendation) => ({
89
+ account: recommendation.account != null
90
+ ? { ...recommendation.account, cot: [], reasoning: '' }
91
+ : undefined,
92
+ class: recommendation.class != null
93
+ ? { ...recommendation.class, cot: [], reasoning: '' }
94
+ : undefined,
95
+ vendor: recommendation.vendor != null
96
+ ? { ...recommendation.vendor, cot: [], reasoning: '' }
97
+ : undefined,
98
+ }));
99
+ exports.toRecommendationsWithCOT = toRecommendationsWithCOT;
100
+ /**
101
+ * Applies a vendor's recommendations to one line: always refreshes the dropdown's "Recommended"
102
+ * group, but only prefills account/class when the field is still empty. Anything the user
103
+ * picked wins -- this follows the transaction-categorization helper, which prefills, rather
104
+ * than the detail-page helper, which only suggests.
105
+ */
106
+ const applyRecommendationsToCreateTransactionLine = (line, recommendations, isAccountingClassesEnabled) => {
107
+ const top = recommendations[0];
108
+ const updated = {
109
+ ...line,
110
+ recommendationsWithCOT: (0, exports.toRecommendationsWithCOT)(recommendations),
111
+ };
112
+ if (line.accountQboId == null && top?.account?.qboId != null) {
113
+ updated.accountQboId = top.account.qboId;
114
+ updated.accountName = top.account.accountName;
115
+ updated.isAccountPreFilled = true;
116
+ }
117
+ if (isAccountingClassesEnabled &&
118
+ line.classId == null &&
119
+ top?.class?.classId != null) {
120
+ updated.classId = top.class.classId;
121
+ updated.isClassPreFilled = true;
122
+ }
123
+ return updated;
124
+ };
125
+ exports.applyRecommendationsToCreateTransactionLine = applyRecommendationsToCreateTransactionLine;
126
+ /**
127
+ * Undoes a prefill when the vendor is cleared. Only the fields the prefill wrote are removed --
128
+ * the per-field flags are what make the user's own choices distinguishable from ours, which is
129
+ * why they are not a single line-level boolean: a hand-picked account alongside a prefilled
130
+ * class is an ordinary state, and clearing must not take the account with it.
131
+ */
132
+ const clearRecommendationsFromCreateTransactionLine = (line) => {
133
+ const cleared = {
134
+ ...line,
135
+ recommendationsWithCOT: undefined,
136
+ };
137
+ if (line.isAccountPreFilled === true) {
138
+ cleared.accountQboId = undefined;
139
+ cleared.accountName = undefined;
140
+ cleared.isAccountPreFilled = undefined;
141
+ }
142
+ if (line.isClassPreFilled === true) {
143
+ cleared.classId = undefined;
144
+ cleared.isClassPreFilled = undefined;
145
+ }
146
+ return cleared;
147
+ };
148
+ exports.clearRecommendationsFromCreateTransactionLine = clearRecommendationsFromCreateTransactionLine;
@@ -0,0 +1,85 @@
1
+ import { ID } from '../../../commonStateTypes/common';
2
+ import { ProjectBasePayload } from '../../../entity/project/projectPayload';
3
+ import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
4
+ import { ZeniAPIResponse } from '../../../responsePayload';
5
+ import { RootState } from '../../../rootStateTypes';
6
+ import { CreateTransactionLocalData } from './createTransactionState';
7
+ /**
8
+ * Wire types for POST /1.0/transactions/manage.
9
+ *
10
+ * Two things here are easy to get wrong and are deliberately explicit:
11
+ *
12
+ * 1. `line_detail_type` is snake_case. The PascalCase strings in the backend are Python
13
+ * constant NAMES; ZENI_LINE_DETAIL_TYPE_TO_QBO_LINE_DETAIL_TYPE_MAP converts them for the
14
+ * body the backend sends on to QuickBooks, never for ours.
15
+ * 2. The reference number uses two different keys depending on the QBO entity. check and
16
+ * expense are Purchases and take `document_number`; everything else takes `document_id`.
17
+ */
18
+ export interface CreateTransactionAccountPayload {
19
+ qbo_id: ID;
20
+ account_name?: string;
21
+ }
22
+ export interface CreateTransactionLineDetailPayload {
23
+ account?: CreateTransactionAccountPayload;
24
+ class?: Record<string, never> | {
25
+ qbo_id: ID;
26
+ };
27
+ /**
28
+ * journal_entry only, and it MUST sit inside line_detail. The write validator's docstring
29
+ * warns that a misplaced posting_type is silently dropped and then rejected by QBO.
30
+ */
31
+ posting_type?: 'credit' | 'debit';
32
+ /** Same shape the transaction update sends on a vendor line. */
33
+ project?: ProjectBasePayload;
34
+ vendor?: {
35
+ qbo_id: ID;
36
+ };
37
+ }
38
+ export interface CreateTransactionLinePayload {
39
+ amount: number;
40
+ line_detail: CreateTransactionLineDetailPayload;
41
+ line_detail_type: 'account_based_expense_line_detail' | 'item_based_expense_line_detail' | 'journal_entry_line_detail';
42
+ line_description?: string;
43
+ }
44
+ export interface CreateTransactionRemitToAddressPayload {
45
+ city?: string;
46
+ country?: string;
47
+ line1?: string;
48
+ postal_code?: string;
49
+ state?: string;
50
+ }
51
+ export interface CreateTransactionRequest extends Record<string, unknown> {
52
+ transaction_date: string;
53
+ transaction_type: string;
54
+ /** journal_entry reference number. */
55
+ document_id?: string;
56
+ /** check / credit_card_credit reference number (QBO Purchase). */
57
+ document_number?: string;
58
+ from_account_id?: ID;
59
+ /** credit_card_credit is modelled as a Purchase with Credit: true. */
60
+ is_credit?: boolean;
61
+ lines?: CreateTransactionLinePayload[];
62
+ payment_type?: string;
63
+ print_status?: string;
64
+ qbo_account_id?: ID;
65
+ remit_to_address?: CreateTransactionRemitToAddressPayload;
66
+ to_account_id?: ID;
67
+ total_amount?: number;
68
+ transaction_memo?: string;
69
+ vendor_id?: ID;
70
+ }
71
+ /**
72
+ * The create endpoint writes to QBO and returns the created entity; Zeni's own mirror is
73
+ * populated by the delta sync that runs afterwards, so this response is the only view of the
74
+ * new transaction the client gets immediately.
75
+ */
76
+ export interface CreateTransactionPayload {
77
+ transactions: TransactionPayload[];
78
+ }
79
+ export type CreateTransactionResponse = ZeniAPIResponse<CreateTransactionPayload>;
80
+ /**
81
+ * Builds the request body for one transaction type. One branch per type rather than a shared
82
+ * body with optional keys, because the types genuinely diverge -- transfer carries no lines at
83
+ * all, and journal_entry carries no header account.
84
+ */
85
+ export declare const prepareCreateTransactionPayload: (state: RootState, localData: CreateTransactionLocalData) => CreateTransactionRequest;