@zeniai/client-epic-state 4.19.91-beta1ND → 4.19.91-beta3ND

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.
@@ -43,8 +43,10 @@ export const getProfitAndLossClassesHorizontalView = (filter, accountState, clas
43
43
  profitAndLossClassesViewState.fetchState.year,
44
44
  ]);
45
45
  const reportId = 'profit_and_loss_by_classes';
46
- // Build class columns from the class hierarchy (top-level only)
47
- const classColumns = buildClassColumns(profitAndLossClassesViewState.classHierarchy, profitAndLossClassesViewState.uiState.classesToFilterOut);
46
+ // Build class columns from the class hierarchy (top-level only).
47
+ // Use `filter.classesToFilterOut` so PDF/Excel downloads (fresh store, empty UI state)
48
+ // respect `classes_to_filter_out` from the request; in-app `classFilter` mirrors uiState.
49
+ const classColumns = buildClassColumns(profitAndLossClassesViewState.classHierarchy, filter.classesToFilterOut);
48
50
  const sections = {};
49
51
  const calculatedSections = {};
50
52
  let reportCurrency = FALLBACK_REPORT_CURRENCY;
@@ -120,7 +122,8 @@ function buildClassColumns(classHierarchy, classesToFilterOut) {
120
122
  className: c.className,
121
123
  nestedClassId: c.classId,
122
124
  qboId: c.qboId,
123
- }));
125
+ }))
126
+ .sort((a, b) => a.className.localeCompare(b.className, undefined, { sensitivity: 'base' }));
124
127
  }
125
128
  /**
126
129
  * Pivot a section from class→account→balances to account→class→balance (single period).
@@ -155,10 +158,19 @@ function pivotSectionToHorizontal(section, classColumns, title, currency) {
155
158
  accounts.push({
156
159
  accountId,
157
160
  accountName: accountData.accountName,
161
+ depth: accountData.depth,
158
162
  classBalances,
159
163
  rowTotal: toAmountWC(rowTotal, currency),
160
164
  });
161
165
  });
166
+ accounts.sort((a, b) => {
167
+ if (a.depth !== b.depth) {
168
+ return a.depth - b.depth;
169
+ }
170
+ return a.accountName.localeCompare(b.accountName, undefined, {
171
+ sensitivity: 'base',
172
+ });
173
+ });
162
174
  // Build class totals
163
175
  const classTotals = classColumns.map((col) => ({
164
176
  classId: col.classId,
@@ -176,21 +188,22 @@ function pivotSectionToHorizontal(section, classColumns, title, currency) {
176
188
  * Recursively collect account balances from a NestedClassReportV2 into accountMap.
177
189
  */
178
190
  function collectAccountsFromClass(classReport, classId, accountMap) {
179
- // Process accounts directly on this class
191
+ // Process accounts directly on this class (depth 2 matches vertical `AccountsSection` first level)
180
192
  classReport.class.accounts.forEach((nestedAccount) => {
181
- collectAccountsFromNestedAccount(nestedAccount, classId, accountMap);
193
+ collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, 2);
182
194
  });
183
195
  }
184
196
  /**
185
197
  * Recursively collect accounts from NestedAccountReport (handles sub-accounts).
186
198
  */
187
- function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap) {
199
+ function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, depth) {
188
200
  const accountId = nestedAccount.account.accountId;
189
201
  const accountName = nestedAccount.account.accountName;
190
202
  const balance = sumBalancesInSlice(nestedAccount.account.balancesInTimeframe.balances);
191
203
  if (!accountMap.has(accountId)) {
192
204
  accountMap.set(accountId, {
193
205
  accountName,
206
+ depth,
194
207
  classBalances: new Map(),
195
208
  });
196
209
  }
@@ -198,11 +211,12 @@ function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap) {
198
211
  if (accountData == null) {
199
212
  return;
200
213
  }
214
+ accountData.depth = Math.max(accountData.depth, depth);
201
215
  const existing = accountData.classBalances.get(classId) ?? 0;
202
216
  accountData.classBalances.set(classId, existing + balance);
203
217
  // Process sub-accounts
204
218
  nestedAccount.children.forEach((child) => {
205
- collectAccountsFromNestedAccount(child, classId, accountMap);
219
+ collectAccountsFromNestedAccount(child, classId, accountMap, depth + 1);
206
220
  });
207
221
  }
208
222
  /**
@@ -2,15 +2,19 @@ import { of } from 'rxjs';
2
2
  import { filter, switchMap } from 'rxjs/operators';
3
3
  import { updateCashInCashOutCOABalancesRange } from '../cashInCashOut/cashInCashOutReducer';
4
4
  import { updateCashPositionCOABalancesRange } from '../cashPosition/cashPositionReducer';
5
- import { initialFinanceStatementState, updateCOABalancesRange, } from '../financeStatement/financeStatementReducer';
5
+ import { updateCOABalancesRange } from '../financeStatement/financeStatementReducer';
6
6
  import { updateNetBurnOrIncomeCOABalancesRange } from '../netBurnOrIncome/netBurnOrIncomeReducer';
7
7
  import { updateOpExCOABalancesRange } from '../opEx/opExReducer';
8
8
  import { updateRevenueCOABalancesRange } from '../revenue/revenueReducer';
9
9
  import { updateReportUIOptionCOABalancesRange } from './reportUIOptionsReducer';
10
10
  export const updateReportUIOptionCOABalancesRangeEpic = (actions$, state$) => actions$.pipe(filter(updateReportUIOptionCOABalancesRange.match), switchMap((action) => {
11
- const thisPeriod = action.payload.selectedCOABalancesRange.thisPeriod;
12
- const orderBy = action.payload.selectedCOABalancesRange.orderBy;
13
- const highlightedNoOfPeriods = state$.value.reportUIOptionsState.isCompareModeOn === true ? 4 : 1;
11
+ const selectedRange = action.payload.selectedCOABalancesRange;
12
+ const thisPeriod = selectedRange.thisPeriod;
13
+ const orderBy = selectedRange.orderBy;
14
+ const numberOfPeriodsFromSelection = selectedRange.numberOfPeriods;
15
+ const highlightedNoOfPeriods = state$.value.reportUIOptionsState.isCompareModeOn === true
16
+ ? numberOfPeriodsFromSelection
17
+ : 1;
14
18
  const highlightedCOABalancesRange = action.payload.highlightedCOABalancesRange == null && thisPeriod != null
15
19
  ? {
16
20
  numberOfPeriods: highlightedNoOfPeriods,
@@ -62,9 +66,7 @@ export const updateReportUIOptionCOABalancesRangeEpic = (actions$, state$) => ac
62
66
  thisPeriod: action.payload.highlightedCOABalancesRange != null
63
67
  ? action.payload.highlightedCOABalancesRange.thisPeriod
64
68
  : thisPeriod,
65
- numberOfPeriods: state$.value.reportUIOptionsState.isCompareModeOn === true
66
- ? 4
67
- : initialFinanceStatementState.maxNumOfPeriodsToHighlight,
69
+ numberOfPeriods: numberOfPeriodsFromSelection,
68
70
  orderBy,
69
71
  }));
70
72
  }));