adamsaghy commented on code in PR #4837:
URL: https://github.com/apache/fineract/pull/4837#discussion_r2213081017


##########
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,
                         MoneyHelper.getRoundingMode());
             }
+        } else {
+            if 
(realBalanceForInterestCalculation.compareTo(minOverdraftForInterestCalculation.negate())
 < 0) {
+                final BigDecimal balanceConvertPositive = 
realBalanceForInterestCalculation.abs();
+                final BigDecimal porcentaje = 
overdraftInterestRateAsFraction.divide(BigDecimal.valueOf(100));
+                final BigDecimal forDaysInYear = 
porcentaje.divide(BigDecimal.valueOf(daysInYear), MathContext.DECIMAL64);
+                final BigDecimal fordays = 
forDaysInYear.multiply(BigDecimal.valueOf(this.numberOfDays == 0 ? 1 : 
this.numberOfDays));

Review Comment:
   typo



-- 
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]

Reply via email to