@zeniai/client-epic-state 5.1.35-betaRD2 → 5.1.35-betaRR0

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 (33) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +0 -1
  2. package/lib/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  3. package/lib/entity/jeSchedules/jeSchedulesSelector.d.ts +0 -1
  4. package/lib/entity/jeSchedules/jeSchedulesSelector.js +1 -2
  5. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +0 -1
  6. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +0 -1
  7. package/lib/esm/entity/jeSchedules/jeSchedulesSelector.js +1 -2
  8. package/lib/esm/index.js +6 -6
  9. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +5 -31
  10. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +3 -18
  11. package/lib/esm/view/expenseAutomationView/types/jeSchedulesViewState.js +6 -2
  12. package/lib/esm/view/transactionDetail/epics/saveTransactionHelper.js +19 -0
  13. package/lib/esm/view/transactionDetail/epics/updateTransactionDetailEpic.js +69 -2
  14. package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +58 -0
  15. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +66 -1
  16. package/lib/index.d.ts +8 -8
  17. package/lib/index.js +34 -35
  18. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -6
  19. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +6 -32
  20. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +0 -8
  21. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +3 -18
  22. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +3 -6
  23. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.js +8 -4
  24. package/lib/view/transactionDetail/epics/saveTransactionHelper.js +19 -0
  25. package/lib/view/transactionDetail/epics/updateTransactionDetailEpic.d.ts +5 -1
  26. package/lib/view/transactionDetail/epics/updateTransactionDetailEpic.js +71 -3
  27. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +27 -0
  28. package/lib/view/transactionDetail/journalEntryLinesViewModel.js +61 -1
  29. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +11 -2
  30. package/lib/view/transactionDetail/transactionDetailReducer.js +67 -2
  31. package/lib/view/transactionDetail/transactionDetailState.d.ts +8 -1
  32. package/lib/view/transactionDetail/transactionDetailTypes.d.ts +2 -0
  33. package/package.json +6 -7
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.updateRecommendationForAccountSettingsFailure = exports.updateRecommendationForAccountSettings = exports.updateJeScheduleTransactionKeys = exports.updateJeScheduleLocalDataById = exports.updateJESchedulesUIState = exports.updateJEScheduleTypeFilter = exports.updateJEHighLevelTab = exports.updateAccountSettingsListForAccountTypesFailure = exports.updateAccountSettingsListForAccountTypes = exports.toggleJERecordedGroupCollapsed = exports.toggleJEPendingGroupCollapsed = exports.saveAccountSettingsSuccess = exports.saveAccountSettingsLocalData = exports.saveAccountSettingsFailure = exports.saveAccountSettings = exports.retryJeScheduleSuccess = exports.retryJeScheduleFailure = exports.retryJeSchedule = exports.removeJeScheduleTransactionKey = exports.removeJeScheduleLocalDataById = exports.removeFailedJeScheduleTransactionKey = exports.initializeJeScheduleLocalData = exports.initializeAccountSettingsView = exports.ignoreRecommendedJeScheduleSuccess = exports.ignoreRecommendedJeScheduleFailure = exports.ignoreRecommendedJeSchedule = exports.fetchRecommendationForAccountSettings = exports.fetchJeSchedulesSuccess = exports.fetchJeSchedulesPage = exports.fetchJeSchedulesFailure = exports.fetchJeSchedules = exports.fetchAccountSettingsListForAccountTypes = exports.clearJeScheduleLocalData = exports.clearJeAccountSettingsLocalData = exports.clearExpenseAutomationJESchedulesView = exports.initialState = exports.accountSettingsInitialState = void 0;
4
+ exports.updateRecommendationForAccountSettingsFailure = exports.updateRecommendationForAccountSettings = exports.updateJeScheduleTransactionKeys = exports.updateJeScheduleLocalDataById = exports.updateJESchedulesUIState = exports.updateAccountSettingsListForAccountTypesFailure = exports.updateAccountSettingsListForAccountTypes = exports.saveAccountSettingsSuccess = exports.saveAccountSettingsLocalData = exports.saveAccountSettingsFailure = exports.saveAccountSettings = exports.retryJeScheduleSuccess = exports.retryJeScheduleFailure = exports.retryJeSchedule = exports.removeJeScheduleTransactionKey = exports.removeJeScheduleLocalDataById = exports.removeFailedJeScheduleTransactionKey = exports.initializeJeScheduleLocalData = exports.initializeAccountSettingsView = exports.ignoreRecommendedJeScheduleSuccess = exports.ignoreRecommendedJeScheduleFailure = exports.ignoreRecommendedJeSchedule = exports.fetchRecommendationForAccountSettings = exports.fetchJeSchedulesSuccess = exports.fetchJeSchedulesPage = exports.fetchJeSchedulesFailure = exports.fetchJeSchedules = exports.fetchAccountSettingsListForAccountTypes = exports.clearJeScheduleLocalData = exports.clearJeAccountSettingsLocalData = exports.clearExpenseAutomationJESchedulesView = exports.initialState = exports.accountSettingsInitialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const getNestedAccountIDHierarchyForReport_1 = require("../../../commonStateTypes/accountView/getNestedAccountIDHierarchyForReport");
7
7
  const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
@@ -48,10 +48,7 @@ exports.initialState = {
48
48
  uiState: {
49
49
  searchString: '',
50
50
  scrollPosition: { scrollTop: 0, scrollLeft: undefined },
51
- selectedJEHighLevelTab: 'je',
52
- selectedJETypeFilter: null,
53
- pendingGroupCollapsed: false,
54
- recordedGroupCollapsed: false,
51
+ selectedMainTab: 'pending_review',
55
52
  sortKey: 'transactionDate',
56
53
  sortOrder: 'descending',
57
54
  totalCount: 0,
@@ -388,39 +385,16 @@ const expenseAutomationJESchedulesView = (0, toolkit_1.createSlice)({
388
385
  if (action.payload.scrollPosition != null) {
389
386
  draft.uiState.scrollPosition = action.payload.scrollPosition;
390
387
  }
391
- },
392
- updateJEHighLevelTab: {
393
- prepare(selectedJEHighLevelTab) {
394
- return { payload: { selectedJEHighLevelTab } };
395
- },
396
- reducer(draft, action) {
397
- draft.uiState.selectedJEHighLevelTab =
398
- action.payload.selectedJEHighLevelTab;
399
- },
400
- },
401
- updateJEScheduleTypeFilter: {
402
- prepare(selectedJETypeFilter) {
403
- return { payload: { selectedJETypeFilter } };
404
- },
405
- reducer(draft, action) {
406
- draft.uiState.selectedJETypeFilter =
407
- action.payload.selectedJETypeFilter;
408
- },
409
- },
410
- toggleJEPendingGroupCollapsed(draft) {
411
- draft.uiState.pendingGroupCollapsed =
412
- !draft.uiState.pendingGroupCollapsed;
413
- },
414
- toggleJERecordedGroupCollapsed(draft) {
415
- draft.uiState.recordedGroupCollapsed =
416
- !draft.uiState.recordedGroupCollapsed;
388
+ if (action.payload.selectedMainTab != null) {
389
+ draft.uiState.selectedMainTab = action.payload.selectedMainTab;
390
+ }
417
391
  },
418
392
  clearExpenseAutomationJESchedulesView(draft) {
419
393
  Object.assign(draft, exports.initialState);
420
394
  },
421
395
  },
422
396
  });
423
- _a = expenseAutomationJESchedulesView.actions, exports.clearExpenseAutomationJESchedulesView = _a.clearExpenseAutomationJESchedulesView, exports.clearJeAccountSettingsLocalData = _a.clearJeAccountSettingsLocalData, exports.clearJeScheduleLocalData = _a.clearJeScheduleLocalData, exports.fetchAccountSettingsListForAccountTypes = _a.fetchAccountSettingsListForAccountTypes, exports.fetchJeSchedules = _a.fetchJeSchedules, exports.fetchJeSchedulesFailure = _a.fetchJeSchedulesFailure, exports.fetchJeSchedulesPage = _a.fetchJeSchedulesPage, exports.fetchJeSchedulesSuccess = _a.fetchJeSchedulesSuccess, exports.fetchRecommendationForAccountSettings = _a.fetchRecommendationForAccountSettings, exports.ignoreRecommendedJeSchedule = _a.ignoreRecommendedJeSchedule, exports.ignoreRecommendedJeScheduleFailure = _a.ignoreRecommendedJeScheduleFailure, exports.ignoreRecommendedJeScheduleSuccess = _a.ignoreRecommendedJeScheduleSuccess, exports.initializeAccountSettingsView = _a.initializeAccountSettingsView, exports.initializeJeScheduleLocalData = _a.initializeJeScheduleLocalData, exports.removeFailedJeScheduleTransactionKey = _a.removeFailedJeScheduleTransactionKey, exports.removeJeScheduleLocalDataById = _a.removeJeScheduleLocalDataById, exports.removeJeScheduleTransactionKey = _a.removeJeScheduleTransactionKey, exports.retryJeSchedule = _a.retryJeSchedule, exports.retryJeScheduleFailure = _a.retryJeScheduleFailure, exports.retryJeScheduleSuccess = _a.retryJeScheduleSuccess, exports.saveAccountSettings = _a.saveAccountSettings, exports.saveAccountSettingsFailure = _a.saveAccountSettingsFailure, exports.saveAccountSettingsLocalData = _a.saveAccountSettingsLocalData, exports.saveAccountSettingsSuccess = _a.saveAccountSettingsSuccess, exports.toggleJEPendingGroupCollapsed = _a.toggleJEPendingGroupCollapsed, exports.toggleJERecordedGroupCollapsed = _a.toggleJERecordedGroupCollapsed, exports.updateAccountSettingsListForAccountTypes = _a.updateAccountSettingsListForAccountTypes, exports.updateAccountSettingsListForAccountTypesFailure = _a.updateAccountSettingsListForAccountTypesFailure, exports.updateJEHighLevelTab = _a.updateJEHighLevelTab, exports.updateJEScheduleTypeFilter = _a.updateJEScheduleTypeFilter, exports.updateJESchedulesUIState = _a.updateJESchedulesUIState, exports.updateJeScheduleLocalDataById = _a.updateJeScheduleLocalDataById, exports.updateJeScheduleTransactionKeys = _a.updateJeScheduleTransactionKeys, exports.updateRecommendationForAccountSettings = _a.updateRecommendationForAccountSettings, exports.updateRecommendationForAccountSettingsFailure = _a.updateRecommendationForAccountSettingsFailure;
397
+ _a = expenseAutomationJESchedulesView.actions, exports.clearExpenseAutomationJESchedulesView = _a.clearExpenseAutomationJESchedulesView, exports.clearJeAccountSettingsLocalData = _a.clearJeAccountSettingsLocalData, exports.clearJeScheduleLocalData = _a.clearJeScheduleLocalData, exports.fetchAccountSettingsListForAccountTypes = _a.fetchAccountSettingsListForAccountTypes, exports.fetchJeSchedules = _a.fetchJeSchedules, exports.fetchJeSchedulesFailure = _a.fetchJeSchedulesFailure, exports.fetchJeSchedulesPage = _a.fetchJeSchedulesPage, exports.fetchJeSchedulesSuccess = _a.fetchJeSchedulesSuccess, exports.fetchRecommendationForAccountSettings = _a.fetchRecommendationForAccountSettings, exports.ignoreRecommendedJeSchedule = _a.ignoreRecommendedJeSchedule, exports.ignoreRecommendedJeScheduleFailure = _a.ignoreRecommendedJeScheduleFailure, exports.ignoreRecommendedJeScheduleSuccess = _a.ignoreRecommendedJeScheduleSuccess, exports.initializeAccountSettingsView = _a.initializeAccountSettingsView, exports.initializeJeScheduleLocalData = _a.initializeJeScheduleLocalData, exports.removeFailedJeScheduleTransactionKey = _a.removeFailedJeScheduleTransactionKey, exports.removeJeScheduleLocalDataById = _a.removeJeScheduleLocalDataById, exports.removeJeScheduleTransactionKey = _a.removeJeScheduleTransactionKey, exports.retryJeSchedule = _a.retryJeSchedule, exports.retryJeScheduleFailure = _a.retryJeScheduleFailure, exports.retryJeScheduleSuccess = _a.retryJeScheduleSuccess, exports.saveAccountSettings = _a.saveAccountSettings, exports.saveAccountSettingsFailure = _a.saveAccountSettingsFailure, exports.saveAccountSettingsLocalData = _a.saveAccountSettingsLocalData, exports.saveAccountSettingsSuccess = _a.saveAccountSettingsSuccess, exports.updateAccountSettingsListForAccountTypes = _a.updateAccountSettingsListForAccountTypes, exports.updateAccountSettingsListForAccountTypesFailure = _a.updateAccountSettingsListForAccountTypesFailure, exports.updateJESchedulesUIState = _a.updateJESchedulesUIState, exports.updateJeScheduleLocalDataById = _a.updateJeScheduleLocalDataById, exports.updateJeScheduleTransactionKeys = _a.updateJeScheduleTransactionKeys, exports.updateRecommendationForAccountSettings = _a.updateRecommendationForAccountSettings, exports.updateRecommendationForAccountSettingsFailure = _a.updateRecommendationForAccountSettingsFailure;
424
398
  exports.default = expenseAutomationJESchedulesView.reducer;
425
399
  const doUpdateRecommendationForAccountSettings = (draft, payload) => {
426
400
  const { prepaidExpensesRecommendations, fixedAssetsRecommendations, accruedExpensesRecommendations, } = (0, accountTypeRecommendationPayload_1.mapAccountTypeRecommendationPayloadToAccountRecommendationByType)(payload);
@@ -10,12 +10,6 @@ import { UncategorizedAccounts } from '../../accountList/accountListSelector';
10
10
  import { JEAccountSettingsView } from '../selectorTypes/jeAccountSettingsViewSelectorTypes';
11
11
  import { JEScheduledTransactionWithFailedEntries } from '../selectors/jeSchedulesViewSelector';
12
12
  import { JEScheduleLocalData, JESchedulesViewUIState } from '../types/jeSchedulesViewState';
13
- export interface JEKpiSummary {
14
- aiAccountant: number;
15
- manual: number;
16
- needsReview: number;
17
- total: number;
18
- }
19
13
  export interface ExpenseAutomationJESchedulesViewSelector extends SelectorView {
20
14
  accountListNestedAccountHierarchy: NestedAccountHierarchyForReport[];
21
15
  accountSettingsView: JEAccountSettingsView;
@@ -29,11 +23,9 @@ export interface ExpenseAutomationJESchedulesViewSelector extends SelectorView {
29
23
  draftSchedules: JEScheduledTransaction[];
30
24
  ignoreStatusById: Record<JEScheduleTransactionKey, FetchStateAndError>;
31
25
  jeScheduleLocalDataById: Record<ID, JEScheduleLocalData>;
32
- kpiSummary: JEKpiSummary;
33
26
  ongoingSchedules: JEScheduledTransaction[];
34
27
  pendingReviewSchedules: (JEScheduledTransaction | JEScheduledTransactionWithFailedEntries)[];
35
28
  postStatusById: Record<ID, FetchStateAndError>;
36
- recordedSchedules: JEScheduledTransaction[];
37
29
  refreshStatus: FetchStateAndError;
38
30
  resolveSchedules: JEScheduledTransactionWithFailedEntries[];
39
31
  uiState: JESchedulesViewUIState;
@@ -119,24 +119,11 @@ function getExpenseAutomationJESchedulesView(state) {
119
119
  const jeScheduleDetails = (0, jeSchedulesSelector_1.getJEScheduledTransactionByJEScheduleTransactionKey)(jeScheduleKey, state);
120
120
  failedJeScheduledTransaction.push(jeScheduleDetails);
121
121
  });
122
- const { sortKey, sortOrder, selectedJETypeFilter } = uiState;
123
- const matchesTypeFilter = (schedule) => selectedJETypeFilter == null ||
124
- schedule.jeScheduleType === selectedJETypeFilter;
122
+ const { sortKey, sortOrder } = uiState;
125
123
  const draftSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft'), sortKey, sortOrder);
126
124
  const ongoingSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'ongoing'), sortKey, sortOrder);
127
125
  const completedSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => schedule.status.code === 'completed' ||
128
126
  schedule.status.code === 'marked_as_completed'), sortKey, sortOrder);
129
- const recordedSchedules = sortJEScheduledTransactions(jeScheduledTransaction.filter((schedule) => (schedule.status.code === 'ongoing' ||
130
- schedule.status.code === 'completed' ||
131
- schedule.status.code === 'marked_as_completed') &&
132
- matchesTypeFilter(schedule)), sortKey, sortOrder);
133
- const allDraftSchedules = jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft');
134
- const kpiSummary = {
135
- aiAccountant: jeScheduledTransaction.filter((schedule) => schedule.confidenceScore != null).length,
136
- manual: jeScheduledTransaction.filter((schedule) => schedule.confidenceScore == null).length,
137
- needsReview: allDraftSchedules.length,
138
- total: jeScheduledTransaction.length,
139
- };
140
127
  const unsortedResolveSchedules = [];
141
128
  failedJeScheduledTransaction.forEach((schedule) => {
142
129
  schedule.scheduledJournalEntry.forEach((journalEntry) => {
@@ -149,8 +136,8 @@ function getExpenseAutomationJESchedulesView(state) {
149
136
  const resolveSchedules = sortJEScheduledTransactions(unsortedResolveSchedules, sortKey, sortOrder);
150
137
  const validResolveForPending = unsortedResolveSchedules.filter((r) => jeScheduleLocalDataById[r.scheduledJournalEntry.scheduledJournalEntryID] != null);
151
138
  const pendingReviewSchedules = sortJEScheduledTransactions([
152
- ...allDraftSchedules.filter(matchesTypeFilter),
153
- ...validResolveForPending.filter((r) => matchesTypeFilter(r)),
139
+ ...jeScheduledTransaction.filter((schedule) => schedule.status.code === 'draft'),
140
+ ...validResolveForPending,
154
141
  ], sortKey, sortOrder);
155
142
  const allSteps = monthYearPeriodId != null
156
143
  ? (0, expenseAutomationViewSelectorTypes_1.getAllSteps)(monthEndCloseChecksState, monthYearPeriodId, currentTenant.tenantId)
@@ -174,10 +161,8 @@ function getExpenseAutomationJESchedulesView(state) {
174
161
  allClassList: allClasses,
175
162
  completedSchedules,
176
163
  draftSchedules,
177
- kpiSummary,
178
164
  ongoingSchedules,
179
165
  pendingReviewSchedules,
180
- recordedSchedules,
181
166
  resolveSchedules: resolveSchedules,
182
167
  accountSettingsView,
183
168
  postStatusById: postStatusById,
@@ -6,20 +6,17 @@ import { MonthYearPeriodId } from '../../../commonStateTypes/timePeriod';
6
6
  import { AccountBase } from '../../../entity/account/accountState';
7
7
  import { JEScheduleTransactionKey, ScheduleTypes } from '../../../entity/jeSchedules/jeSchedulesTypes';
8
8
  import { VendorBase } from '../../../entity/vendor/vendorState';
9
- export declare const toJEHighLevelTab: (v: string) => "je" | "ongoing_schedules";
10
- export type JEHighLevelTab = ReturnType<typeof toJEHighLevelTab>;
11
9
  export declare const toJEScheduleSortKey: (v: string) => "vendor" | "type" | "category" | "class" | "memo" | "transactionDate" | "totalAmount" | "runningBalance" | "depCategory" | "scheduleCategory" | "startMonth" | "amortizationPeriod" | "jePostingDate" | "remainingMonths";
12
10
  export type JEScheduleSortKey = ReturnType<typeof toJEScheduleSortKey>;
11
+ export declare const toJEScheduleMainTab: (v: string) => "completed" | "pending_review" | "ongoing";
12
+ export type JEScheduleMainTab = ReturnType<typeof toJEScheduleMainTab>;
13
13
  export interface JESchedulesViewUIState {
14
- pendingGroupCollapsed: boolean;
15
- recordedGroupCollapsed: boolean;
16
14
  scrollPosition: {
17
15
  scrollTop: number;
18
16
  scrollLeft?: number;
19
17
  } | undefined;
20
18
  searchString: string;
21
- selectedJEHighLevelTab: JEHighLevelTab;
22
- selectedJETypeFilter: ScheduleTypes | null;
19
+ selectedMainTab: JEScheduleMainTab;
23
20
  sortKey: JEScheduleSortKey;
24
21
  sortOrder: SortOrder;
25
22
  totalCount: number;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toJEScheduleSortKey = exports.toJEHighLevelTab = void 0;
3
+ exports.toJEScheduleMainTab = exports.toJEScheduleSortKey = void 0;
4
4
  const stringToUnion_1 = require("../../../commonStateTypes/stringToUnion");
5
- const JE_HIGH_LEVEL_TABS = ['je', 'ongoing_schedules'];
6
- const toJEHighLevelTab = (v) => (0, stringToUnion_1.stringToUnion)(v, JE_HIGH_LEVEL_TABS);
7
- exports.toJEHighLevelTab = toJEHighLevelTab;
8
5
  const JE_SCHEDULE_SORT_KEYS = [
9
6
  'vendor',
10
7
  'category',
@@ -23,3 +20,10 @@ const JE_SCHEDULE_SORT_KEYS = [
23
20
  ];
24
21
  const toJEScheduleSortKey = (v) => (0, stringToUnion_1.stringToUnion)(v, JE_SCHEDULE_SORT_KEYS);
25
22
  exports.toJEScheduleSortKey = toJEScheduleSortKey;
23
+ const JE_SCHEDULE_MAIN_TABS = [
24
+ 'pending_review',
25
+ 'ongoing',
26
+ 'completed',
27
+ ];
28
+ const toJEScheduleMainTab = (v) => (0, stringToUnion_1.stringToUnion)(v, JE_SCHEDULE_MAIN_TABS);
29
+ exports.toJEScheduleMainTab = toJEScheduleMainTab;
@@ -48,7 +48,15 @@ const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDetailLoc
48
48
  let lastUpdatedCategory;
49
49
  let lastUpdatedClass;
50
50
  // single recommendation to just pick the last recommendation in the list of lines
51
+ const deletedLineIds = new Set(transactionDetailLocalData.deletedLineIds ?? []);
52
+ const existingLineIds = new Set(transaction.lines?.map((l) => l.id) ?? []);
53
+ // Collect new lines — in lineItemById but not yet in transaction.lines.
54
+ const addedLines = Object.values(transactionDetailLocalData.lineItemById).filter((item) => !existingLineIds.has(item.id));
51
55
  transaction.lines?.forEach((line) => {
56
+ // Skip lines the user deleted in edit mode.
57
+ if (deletedLineIds.has(line.id)) {
58
+ return;
59
+ }
52
60
  const lineItem = transactionDetailLocalData.lineItemById[line.id];
53
61
  if (line.type === 'transaction_with_account_and_class_line' ||
54
62
  line.type === 'transaction_with_product_or_service_line' ||
@@ -59,6 +67,7 @@ const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDetailLoc
59
67
  const entityDetails = getEntityDetails(selectedEntity, lineItem, transactionDetailLocalData.vendorUpdates, transactionDetailLocalData.customerUpdates);
60
68
  updatesByLineId[line.id] = {
61
69
  lineDescription: lineItem.lineDescription,
70
+ amount: lineItem.amount,
62
71
  class: lineItem.class,
63
72
  account: lineItem.account,
64
73
  // Project is at the transaction level for invoice/credit_memo; omit from lines.
@@ -80,6 +89,14 @@ const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDetailLoc
80
89
  currentSelectedEntityLine.type === 'vendor'
81
90
  ? lineItem.vendor
82
91
  : undefined,
92
+ // Carry the JE debit/credit side so a split edit that flips an
93
+ // existing line's posting side persists through the line patch.
94
+ ...(line.type === 'journal_entry_transaction_line'
95
+ ? {
96
+ postingType: lineItem.postingType,
97
+ postingTypeName: lineItem.postingTypeName,
98
+ }
99
+ : {}),
83
100
  };
84
101
  }
85
102
  let hasCategoryChanged = false;
@@ -166,6 +183,8 @@ const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDetailLoc
166
183
  and all the line items are NOT uncategorized*/
167
184
  markAsMiscatUpdates: isTransactionMisCategorized,
168
185
  anyBulkUpdates: isBulkUpdate,
186
+ addedLines: addedLines.length > 0 ? addedLines : undefined,
187
+ deletedLineIds: deletedLineIds.size > 0 ? [...deletedLineIds] : undefined,
169
188
  };
170
189
  };
171
190
  exports.toTransactionUpdatesFromTransactionDetailLocalData = toTransactionUpdatesFromTransactionDetailLocalData;
@@ -1,9 +1,11 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { ID } from '../../../commonStateTypes/common';
2
3
  import { COTTransactionTracking } from '../../../commonStateTypes/recommendationBase';
3
4
  import { CustomerBase } from '../../../entity/customer/customerState';
4
5
  import { Entity } from '../../../entity/genericEntity/entity';
5
6
  import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
6
7
  import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
8
+ import { Line } from '../../../entity/transaction/stateTypes/transactionLine';
7
9
  import { updateTransaction, updateTransactions } from '../../../entity/transaction/transactionReducer';
8
10
  import { SupportedTransaction } from '../../../entity/transaction/transactionState';
9
11
  import { updateVendors } from '../../../entity/vendor/vendorReducer';
@@ -13,6 +15,8 @@ import { ZeniAPI } from '../../../zeniAPI';
13
15
  import { syncTransactionCategorizationFromDetailSave } from '../../expenseAutomationView/reducers/transactionsViewReducer';
14
16
  import { initializeTransactionDetailLocalData, markTransactionAsNotMiscategorized, updateStatusConsolidatedSaveTransactionDetail, updateTransactionDetail, updateTransactionDetailSaveStatus, updateTransactionStateIfUpdateActionNotAllowed } from '../transactionDetailReducer';
15
17
  import { TransactionUpdates } from '../transactionDetailState';
18
+ import { TransactionDetailLineItemData } from '../transactionDetailTypes';
16
19
  export type ActionType = ReturnType<typeof updateTransactionDetail> | ReturnType<typeof updateTransaction> | ReturnType<typeof updateTransactions> | ReturnType<typeof updateTransactionStateIfUpdateActionNotAllowed> | ReturnType<typeof openSnackbar> | ReturnType<typeof updateTransactionDetailSaveStatus> | ReturnType<typeof updateStatusConsolidatedSaveTransactionDetail> | ReturnType<typeof initializeTransactionDetailLocalData> | ReturnType<typeof updateVendors> | ReturnType<typeof markTransactionAsNotMiscategorized> | ReturnType<typeof syncTransactionCategorizationFromDetailSave>;
17
20
  export declare const updateTransactionDetailEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<ActionType>;
18
- export declare const toTransactionUpdatePayload: (updates: TransactionUpdates, detail: SupportedTransaction, cotTransactionTracking: COTTransactionTracking, isAccountingProjectsEnabled: boolean, vendorUpdates?: VendorBase, customerUpdates?: CustomerBase, tranSelectedEntity?: Entity) => Partial<TransactionPayload>;
21
+ export declare const toTransactionUpdatePayload: (updates: TransactionUpdates, detail: SupportedTransaction, cotTransactionTracking: COTTransactionTracking, isAccountingProjectsEnabled: boolean, vendorUpdates?: VendorBase, customerUpdates?: CustomerBase, tranSelectedEntity?: Entity, deletedLineIds?: ID[], addedLines?: TransactionDetailLineItemData[]) => Partial<TransactionPayload>;
22
+ export declare const toNewTransactionLine: (item: TransactionDetailLineItemData) => Line;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toTransactionUpdatePayload = exports.updateTransactionDetailEpic = void 0;
6
+ exports.toNewTransactionLine = exports.toTransactionUpdatePayload = exports.updateTransactionDetailEpic = void 0;
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
8
  const rxjs_1 = require("rxjs");
9
9
  const operators_1 = require("rxjs/operators");
@@ -166,7 +166,7 @@ function preparePayload(transactionState, vendorState, transactionDetailState, t
166
166
  };
167
167
  }
168
168
  if (detail != null) {
169
- const transUpdates = (0, exports.toTransactionUpdatePayload)(saveUpdates.updates, detail, cotTransactionTracking, isAccountingProjectsEnabled, vendorUpdates, customerUpdates, currentSelectedEntity);
169
+ const transUpdates = (0, exports.toTransactionUpdatePayload)(saveUpdates.updates, detail, cotTransactionTracking, isAccountingProjectsEnabled, vendorUpdates, customerUpdates, currentSelectedEntity, saveUpdates.deletedLineIds, saveUpdates.addedLines);
170
170
  const entityUpdates = toEntityUpdatePayload(saveUpdates.entityRelatedUpdates);
171
171
  return {
172
172
  entity_related_updates: entityUpdates,
@@ -176,7 +176,7 @@ function preparePayload(transactionState, vendorState, transactionDetailState, t
176
176
  }
177
177
  return undefined;
178
178
  }
179
- const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isAccountingProjectsEnabled, vendorUpdates, customerUpdates, tranSelectedEntity) => {
179
+ const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isAccountingProjectsEnabled, vendorUpdates, customerUpdates, tranSelectedEntity, deletedLineIds, addedLines) => {
180
180
  const transaction = Object.assign({}, detail);
181
181
  transaction.memo = updates.memo ?? '';
182
182
  // Unlike `memo` (always reset to '' when absent), `documentId` falls back to
@@ -185,6 +185,11 @@ const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isA
185
185
  // either the unchanged current value or undefined, and we must not send an
186
186
  // empty `document_id` that the server would treat as clearing the number.
187
187
  transaction.documentId = updates.documentId ?? transaction.documentId;
188
+ // Remove lines deleted by the user in edit mode before patching or serializing.
189
+ if (deletedLineIds != null && deletedLineIds.length > 0) {
190
+ const deletedSet = new Set(deletedLineIds);
191
+ transaction.lines = transaction.lines?.filter((line) => !deletedSet.has(line.id));
192
+ }
188
193
  const recommendationUpdates = {};
189
194
  for (const key in updates.updatesByLineId) {
190
195
  const lineUpdates = updates.updatesByLineId[key];
@@ -192,6 +197,9 @@ const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isA
192
197
  if (line.id === key) {
193
198
  const lineTobeUpdated = Object.assign({}, line);
194
199
  lineTobeUpdated.lineDescription = lineUpdates.lineDescription ?? '';
200
+ if (lineUpdates.amount != null) {
201
+ lineTobeUpdated.amount = lineUpdates.amount;
202
+ }
195
203
  if (lineUpdates.class != null) {
196
204
  lineTobeUpdated.class = lineUpdates.class;
197
205
  }
@@ -213,6 +221,16 @@ const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isA
213
221
  else {
214
222
  lineTobeUpdated.vendor = undefined;
215
223
  }
224
+ // Persist a debit↔credit flip on an existing JE line. `lineTobeUpdated`
225
+ // is typed as the account-and-class shape, but for a JE the runtime
226
+ // object is a JournalEntryTransactionLine, so cast to set the side.
227
+ if (lineUpdates.postingType != null) {
228
+ const journalEntryLine = lineTobeUpdated;
229
+ journalEntryLine.postingType = lineUpdates.postingType;
230
+ if (lineUpdates.postingTypeName != null) {
231
+ journalEntryLine.postingTypeName = lineUpdates.postingTypeName;
232
+ }
233
+ }
216
234
  if (lineUpdates.recommendation != null) {
217
235
  recommendationUpdates[line.id] = lineUpdates.recommendation;
218
236
  }
@@ -232,6 +250,12 @@ const toTransactionUpdatePayload = (updates, detail, cotTransactionTracking, isA
232
250
  });
233
251
  transaction.lines = newLineMap;
234
252
  }
253
+ // Append lines added by the user in edit mode. Sending id='' tells the
254
+ // backend to create a new QBO line rather than updating an existing one.
255
+ if (addedLines != null && addedLines.length > 0) {
256
+ const newLines = addedLines.map(exports.toNewTransactionLine);
257
+ transaction.lines = [...(transaction.lines ?? []), ...newLines];
258
+ }
235
259
  transaction.recommendations = recommendationUpdates;
236
260
  // Convert transaction to payload first
237
261
  let basePayload;
@@ -307,6 +331,50 @@ const checkIfVendorOrCustomerMissingForAnyLineItem = (transactionPayload) => {
307
331
  }
308
332
  return isAnyVendorOrCustomerMissing;
309
333
  };
334
+ // Converts a locally-created line item (from edit mode) into the wire shape
335
+ // expected by the categorize endpoint. Sending id='' signals the backend to
336
+ // create a new QBO line rather than update an existing one.
337
+ //
338
+ // Type-dispatched so each transaction family contributes its own new-line
339
+ // shape: journal entries carry debit/credit `postingType`, expenses carry
340
+ // `billable`. Phase 3 types extend this by adding a branch rather than forking
341
+ // the function.
342
+ const EMPTY_ACCOUNT = {
343
+ accountDescription: '',
344
+ accountId: '',
345
+ accountName: '',
346
+ labels: [],
347
+ };
348
+ const toNewTransactionLine = (item) => {
349
+ if (item.type === 'journal_entry_transaction_line') {
350
+ const journalEntryLine = {
351
+ ...item,
352
+ id: '',
353
+ type: 'journal_entry_transaction_line',
354
+ platformLineDetailType: item.platformLineDetailType ?? 'journal_entry_line_detail',
355
+ account: item.account ?? EMPTY_ACCOUNT,
356
+ billable: item.billable ?? 'not_billable',
357
+ isCategoryMiscategorized: false,
358
+ isClassMiscategorized: false,
359
+ lineTransactionType: item.lineTransactionType ?? 'journal_entry',
360
+ postingType: item.postingType ?? 'debit',
361
+ postingTypeName: item.postingTypeName ?? '',
362
+ };
363
+ return journalEntryLine;
364
+ }
365
+ const accountAndClassLine = {
366
+ ...item,
367
+ id: '',
368
+ type: 'transaction_with_account_and_class_line',
369
+ platformLineDetailType: item.platformLineDetailType ?? 'account_based_expense_line_detail',
370
+ account: item.account ?? EMPTY_ACCOUNT,
371
+ billable: item.billable ?? 'not_billable',
372
+ isCategoryMiscategorized: false,
373
+ isClassMiscategorized: false,
374
+ };
375
+ return accountAndClassLine;
376
+ };
377
+ exports.toNewTransactionLine = toNewTransactionLine;
310
378
  const toEntityUpdatePayload = (entityUpdates) => {
311
379
  const entityUpdatesPayload = [];
312
380
  let entityKey;
@@ -64,6 +64,33 @@ export declare const journalEntryTotalsByPostingSide: (lines: ReadonlyArray<Pick
64
64
  creditTotal?: Amount;
65
65
  debitTotal?: Amount;
66
66
  };
67
+ type PostingBearer = Pick<JournalEntryTransactionLine, 'amount' | 'postingType'>;
68
+ export interface JournalEntrySplitReconciliation {
69
+ creditTotal: number;
70
+ debitTotal: number;
71
+ /** Total debits == total credits == original transaction total. */
72
+ isBalanced: boolean;
73
+ }
74
+ /**
75
+ * Sums debit and credit sides (big.js-exact) and reports whether the split is
76
+ * balanced: total debits equal total credits AND equal the original
77
+ * transaction total. The original total of a valid JE equals its total debits,
78
+ * so it is passed in by the caller (`transaction.amount.amount`).
79
+ */
80
+ export declare const journalEntrySplitReconciliation: (lines: ReadonlyArray<PostingBearer>, originalTotal: number) => JournalEntrySplitReconciliation;
81
+ export type JournalEntrySplitErrorKey = 'lineNeedsDebitOrCredit' | 'totalsMustEqual';
82
+ export interface JournalEntrySplitValidation {
83
+ ok: boolean;
84
+ errorKey?: JournalEntrySplitErrorKey;
85
+ }
86
+ /**
87
+ * Save-time validation for a JE split (Figma `4165:33028` / `4165:45379`):
88
+ * 1. every line needs a non-zero debit or credit, and
89
+ * 2. total debits == total credits == original total.
90
+ * Returns the first failing rule's `errorKey` (maps to a strings entry). Does
91
+ * NOT require category/class to be chosen — balance is the only gate.
92
+ */
93
+ export declare const validateJournalEntrySplit: (lines: ReadonlyArray<PostingBearer>, originalTotal: number) => JournalEntrySplitValidation;
67
94
  /**
68
95
  * Drops `linked_transaction_line` entries — equivalent to legacy
69
96
  * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sortJournalEntryLines = exports.filterJournalEntryLinesExcludingLinked = exports.journalEntryTotalsByPostingSide = exports.sumJournalEntryAmounts = exports.journalEntryDefaultSortConfig = exports.toJournalEntrySortKey = exports.JOURNAL_ENTRY_SORT_KEYS = void 0;
6
+ exports.sortJournalEntryLines = exports.filterJournalEntryLinesExcludingLinked = exports.validateJournalEntrySplit = exports.journalEntrySplitReconciliation = exports.journalEntryTotalsByPostingSide = exports.sumJournalEntryAmounts = exports.journalEntryDefaultSortConfig = exports.toJournalEntrySortKey = exports.JOURNAL_ENTRY_SORT_KEYS = void 0;
7
+ const big_js_1 = __importDefault(require("big.js"));
7
8
  const orderBy_1 = __importDefault(require("lodash/orderBy"));
8
9
  const stringToUnion_1 = require("../../commonStateTypes/stringToUnion");
9
10
  const transactionLine_1 = require("../../entity/transaction/stateTypes/transactionLine");
@@ -110,6 +111,65 @@ const journalEntryTotalsByPostingSide = (lines) => {
110
111
  };
111
112
  exports.journalEntryTotalsByPostingSide = journalEntryTotalsByPostingSide;
112
113
  // ---------------------------------------------------------------------------
114
+ // Split reconciliation & validation (Phase 2 — JE split)
115
+ // ---------------------------------------------------------------------------
116
+ // Half-cent tolerance for the balance equality checks, matching the expense
117
+ // reconciliation row's epsilon. Sums use big.js so repeated decimal addition
118
+ // doesn't drift before the comparison.
119
+ const JOURNAL_ENTRY_BALANCE_EPSILON = 0.005;
120
+ /**
121
+ * Sums debit and credit sides (big.js-exact) and reports whether the split is
122
+ * balanced: total debits equal total credits AND equal the original
123
+ * transaction total. The original total of a valid JE equals its total debits,
124
+ * so it is passed in by the caller (`transaction.amount.amount`).
125
+ */
126
+ const journalEntrySplitReconciliation = (lines, originalTotal) => {
127
+ let debit = new big_js_1.default(0);
128
+ let credit = new big_js_1.default(0);
129
+ for (const line of lines) {
130
+ const amount = new big_js_1.default(line.amount?.amount ?? 0);
131
+ if (line.postingType === 'debit') {
132
+ debit = debit.plus(amount);
133
+ }
134
+ else if (line.postingType === 'credit') {
135
+ credit = credit.plus(amount);
136
+ }
137
+ }
138
+ const balancedToEachOther = debit
139
+ .minus(credit)
140
+ .abs()
141
+ .lt(JOURNAL_ENTRY_BALANCE_EPSILON);
142
+ const balancedToOriginal = debit
143
+ .minus(originalTotal)
144
+ .abs()
145
+ .lt(JOURNAL_ENTRY_BALANCE_EPSILON);
146
+ return {
147
+ debitTotal: debit.toNumber(),
148
+ creditTotal: credit.toNumber(),
149
+ isBalanced: balancedToEachOther && balancedToOriginal,
150
+ };
151
+ };
152
+ exports.journalEntrySplitReconciliation = journalEntrySplitReconciliation;
153
+ /**
154
+ * Save-time validation for a JE split (Figma `4165:33028` / `4165:45379`):
155
+ * 1. every line needs a non-zero debit or credit, and
156
+ * 2. total debits == total credits == original total.
157
+ * Returns the first failing rule's `errorKey` (maps to a strings entry). Does
158
+ * NOT require category/class to be chosen — balance is the only gate.
159
+ */
160
+ const validateJournalEntrySplit = (lines, originalTotal) => {
161
+ const everyLineHasSide = lines.every((line) => (line.postingType === 'debit' || line.postingType === 'credit') &&
162
+ Math.abs(line.amount?.amount ?? 0) > JOURNAL_ENTRY_BALANCE_EPSILON);
163
+ if (!everyLineHasSide) {
164
+ return { ok: false, errorKey: 'lineNeedsDebitOrCredit' };
165
+ }
166
+ if (!(0, exports.journalEntrySplitReconciliation)(lines, originalTotal).isBalanced) {
167
+ return { ok: false, errorKey: 'totalsMustEqual' };
168
+ }
169
+ return { ok: true };
170
+ };
171
+ exports.validateJournalEntrySplit = validateJournalEntrySplit;
172
+ // ---------------------------------------------------------------------------
113
173
  // Filter
114
174
  // ---------------------------------------------------------------------------
115
175
  /**
@@ -8,7 +8,7 @@ import { SupportedTransaction, SupportedTransactionPayload } from '../../entity/
8
8
  import { ZeniAPIStatus } from '../../responsePayload';
9
9
  import { UncategorizedAccounts } from '../accountList/accountListSelector';
10
10
  import { TransactionDetailState, TransactionSaveUpdates } from './transactionDetailState';
11
- import { TransactionDetailLocalData, TransactionVendorUpdates } from './transactionDetailTypes';
11
+ import { TransactionDetailLineItemData, TransactionDetailLocalData, TransactionVendorUpdates } from './transactionDetailTypes';
12
12
  export declare const initialState: TransactionDetailState;
13
13
  export declare const downloadAccountingProviderAttachment: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[attachmentId: string], {
14
14
  attachmentId: string;
@@ -166,6 +166,15 @@ export declare const downloadAccountingProviderAttachment: import("@reduxjs/tool
166
166
  transactionId: TransactionID;
167
167
  transaction: SupportedTransaction;
168
168
  isEnabled: boolean;
169
- }, "transactionDetail/setIsVendorUpdateAllChecked", never, never>;
169
+ }, "transactionDetail/setIsVendorUpdateAllChecked", never, never>, addSplitLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, newLine: TransactionDetailLineItemData], {
170
+ transactionId: TransactionID;
171
+ newLine: TransactionDetailLineItemData;
172
+ }, "transactionDetail/addSplitLine", never, never>, deleteSplitLine: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, lineId: string], {
173
+ transactionId: TransactionID;
174
+ lineId: string;
175
+ }, "transactionDetail/deleteSplitLine", never, never>, toggleSplitEditMode: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transactionId: TransactionID, editMode: boolean], {
176
+ transactionId: TransactionID;
177
+ editMode: boolean;
178
+ }, "transactionDetail/toggleSplitEditMode", never, never>;
170
179
  declare const _default: import("redux").Reducer<TransactionDetailState>;
171
180
  export default _default;