diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 6a2351a49..db4786527 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -332,6 +332,7 @@ export class PortfolioController { 'currentValue', 'dividend', 'fees', + 'items', 'netWorth', 'totalBuy', 'totalSell' diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.ts index 4fbbeaff0..04803d14b 100644 --- a/apps/api/src/app/portfolio/portfolio.service-new.ts +++ b/apps/api/src/app/portfolio/portfolio.service-new.ts @@ -891,6 +891,7 @@ export class PortfolioServiceNew { const dividend = this.getDividend(orders).toNumber(); const fees = this.getFees(orders).toNumber(); const firstOrderDate = orders[0]?.date; + const items = this.getItems(orders).toNumber(); const totalBuy = this.getTotalByType(orders, userCurrency, 'BUY'); const totalSell = this.getTotalByType(orders, userCurrency, 'SELL'); @@ -899,6 +900,7 @@ export class PortfolioServiceNew { const netWorth = new Big(balance) .plus(performanceInformation.performance.currentValue) + .plus(items) .toNumber(); const daysInMarket = differenceInDays(new Date(), firstOrderDate); @@ -922,6 +924,7 @@ export class PortfolioServiceNew { dividend, fees, firstOrderDate, + items, netWorth, totalBuy, totalSell, @@ -1043,6 +1046,28 @@ export class PortfolioServiceNew { ); } + private getItems(orders: OrderWithAccount[], date = new Date(0)) { + return orders + .filter((order) => { + // Filter out all orders before given date and type item + return ( + isBefore(date, new Date(order.date)) && + order.type === TypeOfOrder.ITEM + ); + }) + .map((order) => { + return this.exchangeRateDataService.toCurrency( + new Big(order.quantity).mul(order.unitPrice).toNumber(), + order.currency, + this.request.user.Settings.currency + ); + }) + .reduce( + (previous, current) => new Big(previous).plus(current), + new Big(0) + ); + } + private getStartDate(aDateRange: DateRange, portfolioStart: Date) { switch (aDateRange) { case '1d': diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 84ac4c846..4b02e4d0a 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -869,6 +869,7 @@ export class PortfolioService { const dividend = this.getDividend(orders).toNumber(); const fees = this.getFees(orders).toNumber(); const firstOrderDate = orders[0]?.date; + const items = this.getItems(orders).toNumber(); const totalBuy = this.getTotalByType(orders, userCurrency, 'BUY'); const totalSell = this.getTotalByType(orders, userCurrency, 'SELL'); @@ -877,6 +878,7 @@ export class PortfolioService { const netWorth = new Big(balance) .plus(performanceInformation.performance.currentValue) + .plus(items) .toNumber(); return { @@ -884,6 +886,7 @@ export class PortfolioService { dividend, fees, firstOrderDate, + items, netWorth, totalBuy, totalSell, @@ -1007,6 +1010,28 @@ export class PortfolioService { ); } + private getItems(orders: OrderWithAccount[], date = new Date(0)) { + return orders + .filter((order) => { + // Filter out all orders before given date and type item + return ( + isBefore(date, new Date(order.date)) && + order.type === TypeOfOrder.ITEM + ); + }) + .map((order) => { + return this.exchangeRateDataService.toCurrency( + new Big(order.quantity).mul(order.unitPrice).toNumber(), + order.currency, + this.request.user.Settings.currency + ); + }) + .reduce( + (previous, current) => new Big(previous).plus(current), + new Big(0) + ); + } + private getStartDate(aDateRange: DateRange, portfolioStart: Date) { switch (aDateRange) { case '1d': diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html index c9c34cd03..dd2847c37 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html @@ -142,6 +142,17 @@ > +