Browse Source

Refactoring

pull/2184/head
Thomas 2 years ago
parent
commit
324e21e70c
  1. 13
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 13
      libs/ui/src/lib/activities-table/activities-table.component.ts

13
apps/api/src/app/portfolio/portfolio.service.ts

@ -1875,13 +1875,14 @@ export class PortfolioService {
return accountId === account.id; return accountId === account.id;
}); });
const ordersOfTypeItemByAccount = ordersOfTypeItemOrLiability.filter( const ordersOfTypeItemOrLiabilityByAccount =
({ accountId }) => { ordersOfTypeItemOrLiability.filter(({ accountId }) => {
return accountId === account.id; return accountId === account.id;
} });
);
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount); ordersByAccount = ordersByAccount.concat(
ordersOfTypeItemOrLiabilityByAccount
);
accounts[account.id] = { accounts[account.id] = {
balance: account.balance, balance: account.balance,
@ -1921,7 +1922,7 @@ export class PortfolioService {
order.unitPrice ?? order.unitPrice ??
0); 0);
if (order.type === 'SELL' || order.type === 'LIABILITY') { if (order.type === 'LIABILITY' || order.type === 'SELL') {
currentValueOfSymbolInBaseCurrency *= -1; currentValueOfSymbolInBaseCurrency *= -1;
} }

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

@ -383,13 +383,14 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy, OnInit {
} }
private getTotalValue() { private getTotalValue() {
let totalValue = new Big(0);
const paginatedData = this.getPaginatedData(); const paginatedData = this.getPaginatedData();
for (const activity of paginatedData) { let totalValue = new Big(0);
if (isNumber(activity.valueInBaseCurrency)) {
if (activity.type === 'BUY' || activity.type === 'ITEM') { for (const { type, valueInBaseCurrency } of paginatedData) {
totalValue = totalValue.plus(activity.valueInBaseCurrency); if (isNumber(valueInBaseCurrency)) {
} else if (activity.type === 'SELL' || activity.type === 'LIABILITY') { if (type === 'BUY' || type === 'ITEM') {
totalValue = totalValue.plus(valueInBaseCurrency);
} else if (type === 'LIABILITY' || type === 'SELL') {
return null; return null;
} }
} else { } else {

Loading…
Cancel
Save