Browse Source

chore(order.service): support "DRIP" dividends

pull/1963/head
raskanskyz 2 years ago
parent
commit
b5c299ad92
  1. 5
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 10
      apps/api/src/app/portfolio/portfolio.service.ts

5
apps/api/src/app/portfolio/portfolio-calculator.ts

@ -92,7 +92,7 @@ export class PortfolioCalculator {
let investment = new Big(0);
if (newQuantity.gt(0)) {
if (order.type === 'BUY') {
if (order.type === 'BUY' || order.type === 'DRIP') {
investment = oldAccumulatedSymbol.investment.plus(
order.quantity.mul(unitPrice)
);
@ -901,6 +901,7 @@ export class PortfolioCalculator {
switch (type) {
case 'BUY':
case 'DRIP':
factor = 1;
break;
case 'SELL':
@ -1126,7 +1127,7 @@ export class PortfolioCalculator {
}
const transactionInvestment =
order.type === 'BUY'
order.type === 'BUY' || order.type === 'DRIP'
? order.quantity.mul(order.unitPrice).mul(this.getFactor(order.type))
: totalUnits.gt(0)
? totalInvestment

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

@ -223,7 +223,7 @@ export class PortfolioService {
const activities = await this.orderService.getOrders({
filters,
userId,
types: ['DIVIDEND'],
types: ['DIVIDEND', 'DRIP'],
userCurrency: this.request.user.Settings.settings.baseCurrency
});
@ -710,7 +710,9 @@ export class PortfolioService {
.filter((order) => {
tags = tags.concat(order.tags);
return order.type === 'BUY' || order.type === 'SELL';
return (
order.type === 'BUY' || order.type === 'SELL' || order.type === 'DRIP'
);
})
.map((order) => ({
currency: order.SymbolProfile.currency,
@ -1623,7 +1625,7 @@ export class PortfolioService {
committedFunds: committedFunds.toNumber(),
emergencyFund: emergencyFund.toNumber(),
ordersCount: activities.filter(({ type }) => {
return type === 'BUY' || type === 'SELL';
return type === 'BUY' || type === 'SELL' || type === 'DRIP';
}).length
};
}
@ -1652,7 +1654,7 @@ export class PortfolioService {
userCurrency,
userId,
withExcludedAccounts,
types: ['BUY', 'SELL']
types: ['BUY', 'SELL', 'DRIP']
});
if (orders.length <= 0) {

Loading…
Cancel
Save