@zeniai/client-epic-state 4.19.91-beta2ND → 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;
@@ -156,10 +158,19 @@ function pivotSectionToHorizontal(section, classColumns, title, currency) {
156
158
  accounts.push({
157
159
  accountId,
158
160
  accountName: accountData.accountName,
161
+ depth: accountData.depth,
159
162
  classBalances,
160
163
  rowTotal: toAmountWC(rowTotal, currency),
161
164
  });
162
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
+ });
163
174
  // Build class totals
164
175
  const classTotals = classColumns.map((col) => ({
165
176
  classId: col.classId,
@@ -177,21 +188,22 @@ function pivotSectionToHorizontal(section, classColumns, title, currency) {
177
188
  * Recursively collect account balances from a NestedClassReportV2 into accountMap.
178
189
  */
179
190
  function collectAccountsFromClass(classReport, classId, accountMap) {
180
- // Process accounts directly on this class
191
+ // Process accounts directly on this class (depth 2 matches vertical `AccountsSection` first level)
181
192
  classReport.class.accounts.forEach((nestedAccount) => {
182
- collectAccountsFromNestedAccount(nestedAccount, classId, accountMap);
193
+ collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, 2);
183
194
  });
184
195
  }
185
196
  /**
186
197
  * Recursively collect accounts from NestedAccountReport (handles sub-accounts).
187
198
  */
188
- function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap) {
199
+ function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap, depth) {
189
200
  const accountId = nestedAccount.account.accountId;
190
201
  const accountName = nestedAccount.account.accountName;
191
202
  const balance = sumBalancesInSlice(nestedAccount.account.balancesInTimeframe.balances);
192
203
  if (!accountMap.has(accountId)) {
193
204
  accountMap.set(accountId, {
194
205
  accountName,
206
+ depth,
195
207
  classBalances: new Map(),
196
208
  });
197
209
  }
@@ -199,11 +211,12 @@ function collectAccountsFromNestedAccount(nestedAccount, classId, accountMap) {
199
211
  if (accountData == null) {
200
212
  return;
201
213
  }
214
+ accountData.depth = Math.max(accountData.depth, depth);
202
215
  const existing = accountData.classBalances.get(classId) ?? 0;
203
216
  accountData.classBalances.set(classId, existing + balance);
204
217
  // Process sub-accounts
205
218
  nestedAccount.children.forEach((child) => {
206
- collectAccountsFromNestedAccount(child, classId, accountMap);
219
+ collectAccountsFromNestedAccount(child, classId, accountMap, depth + 1);
207
220
  });
208
221
  }
209
222
  /**