adamsaghy commented on code in PR #4837:
URL: https://github.com/apache/fineract/pull/4837#discussion_r2212814994
##########
fineract-core/src/main/java/org/apache/fineract/portfolio/savings/domain/interest/EndOfDayBalance.java:
##########
@@ -81,9 +88,40 @@ public BigDecimal calculateInterestOnBalance(final
BigDecimal interestToCompound
final BigDecimal dailyInterestRate =
overdraftInterestRateAsFraction.multiply(multiplicand, MathContext.DECIMAL64);
final BigDecimal periodicInterestRate =
dailyInterestRate.multiply(BigDecimal.valueOf(this.numberOfDays),
MathContext.DECIMAL64);
- interest =
realBalanceForInterestCalculation.multiply(periodicInterestRate,
MathContext.DECIMAL64).setScale(9,
+ interest =
realBalanceForInterestCalculation.multiply(periodicInterestRate,
MathContext.DECIMAL64).setScale(this.decimals,
+ MoneyHelper.getRoundingMode());
+ }
+ }
+ return interest;
+ }
+
+ public BigDecimal calculateInterestOnBalanceNegative(final BigDecimal
interestToCompound, final BigDecimal interestRateAsFraction,
+ final long daysInYear, final BigDecimal
minBalanceForInterestCalculation, final BigDecimal
overdraftInterestRateAsFraction,
+ final BigDecimal minOverdraftForInterestCalculation) {
+
+ BigDecimal interest = BigDecimal.ZERO.setScale(this.decimals,
MoneyHelper.getRoundingMode());
+ final BigDecimal realBalanceForInterestCalculation =
this.endOfDayBalance.getAmount().add(interestToCompound);
+ if (realBalanceForInterestCalculation.compareTo(BigDecimal.ZERO) >= 0)
{
+ if
(realBalanceForInterestCalculation.compareTo(minBalanceForInterestCalculation)
>= 0) {
+ final BigDecimal multiplicand =
BigDecimal.ONE.divide(BigDecimal.valueOf(daysInYear), MathContext.DECIMAL64);
+ final BigDecimal dailyInterestRate =
interestRateAsFraction.multiply(multiplicand, MathContext.DECIMAL64);
+ final BigDecimal periodicInterestRate =
dailyInterestRate.multiply(BigDecimal.valueOf(this.numberOfDays),
+ MathContext.DECIMAL64);
+ interest =
realBalanceForInterestCalculation.multiply(periodicInterestRate,
MathContext.DECIMAL64).setScale(this.decimals,
Review Comment:
Dont set back and forth the precision...
There should be only 2 cases:
- Using MoneyHelper precision and BigDecimal to calculate something
(example: 1.0566)
- Using Money to calculate and realize the balance (example: $1.06)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]