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

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

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

Loading…
Cancel
Save