fix gain calculation in overview page

This commit is contained in:
Anantha Kumaran 2022-08-23 19:25:44 +05:30
parent 97b407b345
commit 76c9069895
2 changed files with 5 additions and 3 deletions

View File

@ -65,13 +65,15 @@ func computeOverviewTimeline(db *gorm.DB, postings []posting.Posting) []Overview
}
}, 0)
gain := lo.Reduce(pastPostings, func(agg float64, p posting.Posting, _ int) float64 {
balance := lo.Reduce(pastPostings, func(agg float64, p posting.Posting, _ int) float64 {
if service.IsInterest(db, p) {
return p.Amount + agg
} else {
return service.GetMarketPrice(db, p, start) - p.Amount + agg
return service.GetMarketPrice(db, p, start) + agg
}
}, 0)
gain := balance + withdrawal - investment
networths = append(networths, Overview{Date: start, InvestmentAmount: investment, WithdrawalAmount: withdrawal, GainAmount: gain})
}
return networths

View File

@ -130,7 +130,7 @@ function renderBreakdowns(breakdowns: Breakdown[]) {
b.investment_amount != 0 && gain != 0 ? formatCurrency(gain) : ""
}</td>
<td class='${changeClass} has-text-right'>${
b.xirr > 0.0001 ? formatFloat(b.xirr) : ""
b.xirr > 0.0001 || b.xirr < -0.0001 ? formatFloat(b.xirr) : ""
}</td>
`;
});