Browse Source

Add items to summary

pull/666/head
Thomas 3 years ago
parent
commit
c5ab9eb6fd
  1. 1
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 25
      apps/api/src/app/portfolio/portfolio.service-new.ts
  3. 25
      apps/api/src/app/portfolio/portfolio.service.ts
  4. 11
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html
  5. 1
      libs/common/src/lib/interfaces/portfolio-summary.interface.ts
  6. 10
      libs/ui/src/lib/activities-table/activities-table.component.ts

1
apps/api/src/app/portfolio/portfolio.controller.ts

@ -332,6 +332,7 @@ export class PortfolioController {
'currentValue',
'dividend',
'fees',
'items',
'netWorth',
'totalBuy',
'totalSell'

25
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':

25
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':

11
apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html

@ -142,6 +142,17 @@
></gf-value>
</div>
</div>
<div class="row px-3 py-1">
<div class="d-flex flex-grow-1" i18n>Items</div>
<div class="d-flex justify-content-end">
<gf-value
class="justify-content-end"
[currency]="baseCurrency"
[locale]="locale"
[value]="isLoading ? undefined : summary?.items"
></gf-value>
</div>
</div>
<div class="row">
<div class="col"><hr /></div>
</div>

1
libs/common/src/lib/interfaces/portfolio-summary.interface.ts

@ -7,6 +7,7 @@ export interface PortfolioSummary extends PortfolioPerformance {
committedFunds: number;
fees: number;
firstOrderDate: Date;
items: number;
netWorth: number;
ordersCount: number;
totalBuy: number;

10
libs/ui/src/lib/activities-table/activities-table.component.ts

@ -276,11 +276,11 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy {
fieldValues.add(activity.Account?.name);
fieldValues.add(activity.Account?.Platform?.name);
fieldValues.add(activity.SymbolProfile.currency);
fieldValues.add(
isUUID(activity.SymbolProfile.symbol)
? activity.SymbolProfile.name
: activity.SymbolProfile.symbol
);
if (!isUUID(activity.SymbolProfile.symbol)) {
fieldValues.add(activity.SymbolProfile.symbol);
}
fieldValues.add(activity.type);
fieldValues.add(format(activity.date, 'yyyy'));

Loading…
Cancel
Save