From 61dd2270e97d452ab9331a1cbd42a9ec368623b7 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 27 Jul 2025 16:48:17 +0200 Subject: [PATCH] Add allocation percentage to accounts table --- .../src/app/portfolio/portfolio.service.ts | 69 ++++--------------- .../accounts-table.component.ts | 6 +- .../holding-detail-dialog.html | 1 + 3 files changed, 18 insertions(+), 58 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 623bfa6ea..77c73f09b 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -72,7 +72,6 @@ import { Order, Platform, Prisma, - SymbolProfile, Tag } from '@prisma/client'; import { Big } from 'big.js'; @@ -161,11 +160,7 @@ export class PortfolioService { this.accountService.accounts({ where, include: { - activities: { - include: { - SymbolProfile: true - } - }, + activities: true, platform: true }, orderBy: { name: 'asc' } @@ -180,71 +175,39 @@ export class PortfolioService { const userCurrency = this.request.user.settings.settings.baseCurrency; - const accountsWithValue = accounts.map((account) => { + return accounts.map((account) => { let transactionCount = 0; - let valueInBaseCurrency = - details.accounts[account.id]?.valueInBaseCurrency ?? 0; - if (filterByDataSource && filterBySymbol) { - const holding = details.holdings[filterBySymbol]; - - const activities = ( - account.activities as (Order & { - SymbolProfile: SymbolProfile; - })[] - ).filter((activity) => { - return ( - activity.SymbolProfile.dataSource === filterByDataSource && - activity.SymbolProfile.symbol === filterBySymbol - ); - }); - - let quantity = new Big(0); - for (const activity of activities) { - quantity = quantity.plus( - new Big(getFactor(activity.type)).mul(activity.quantity) - ); - } - - valueInBaseCurrency = quantity.mul(holding.marketPrice ?? 0).toNumber(); - transactionCount = activities.length; - } else { - for (const { isDraft } of account.activities) { - if (!isDraft) { - transactionCount += 1; - } + for (const { isDraft } of account.activities) { + if (!isDraft) { + transactionCount += 1; } } + const valueInBaseCurrency = + details.accounts[account.id]?.valueInBaseCurrency ?? 0; + const result = { ...account, - allocationInPercentage: 0, + transactionCount, + valueInBaseCurrency, + allocationInPercentage: undefined, // TODO balanceInBaseCurrency: this.exchangeRateDataService.toCurrency( account.balance, account.currency, userCurrency ), - transactionCount, value: this.exchangeRateDataService.toCurrency( valueInBaseCurrency, userCurrency, account.currency - ), - valueInBaseCurrency + ) }; delete result.activities; return result; }); - - if (filterByDataSource && filterBySymbol) { - return accountsWithValue.filter((account) => { - return account.transactionCount > 0; - }); - } - - return accountsWithValue; } public async getAccountsWithAggregations({ @@ -275,14 +238,6 @@ export class PortfolioService { transactionCount += account.transactionCount; } - for (const account of accounts) { - account.allocationInPercentage = totalValueInBaseCurrency.gt(0) - ? new Big(account.valueInBaseCurrency) - .div(totalValueInBaseCurrency) - .toNumber() - : 0; - } - return { accounts, transactionCount, diff --git a/apps/client/src/app/components/accounts-table/accounts-table.component.ts b/apps/client/src/app/components/accounts-table/accounts-table.component.ts index 44846b944..ba638e543 100644 --- a/apps/client/src/app/components/accounts-table/accounts-table.component.ts +++ b/apps/client/src/app/components/accounts-table/accounts-table.component.ts @@ -60,6 +60,7 @@ export class GfAccountsTableComponent implements OnChanges, OnDestroy { @Input() hasPermissionToOpenDetails = true; @Input() locale = getLocale(); @Input() showActions: boolean; + @Input() showAllocationInPercentage = false; @Input() showBalance = true; @Input() showFooter = true; @Input() showTransactions = true; @@ -117,7 +118,10 @@ export class GfAccountsTableComponent implements OnChanges, OnDestroy { this.displayedColumns.push('valueInBaseCurrency'); } - this.displayedColumns.push('allocation'); + if (this.showAllocationInPercentage) { + this.displayedColumns.push('allocation'); + } + this.displayedColumns.push('comment'); if (this.showActions) { diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html index 4427cfcbb..e0673a1f5 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html @@ -375,6 +375,7 @@ [deviceType]="data.deviceType" [hasPermissionToOpenDetails]="false" [locale]="user?.settings?.locale" + [showAllocationInPercentage]="user?.settings?.isExperimentalFeatures" [showBalance]="false" [showFooter]="false" [showTransactions]="false"