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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/LoanSchedulePeriodData.java:
##########
@@ -402,6 +403,49 @@ private BigDecimal defaultToZeroIfNull(final BigDecimal 
possibleNullValue) {
         return value;
     }
 
+    public BigDecimal getRatePerDay() {
+        return 
getInterestOriginalDue().divide(BigDecimal.valueOf(getDaysInPeriod()), 
MoneyHelper.getMathContext());
+    }
+
+    public BigDecimal getInterestDueUntilDate(final LocalDate businessDate) {
+        if (getComplete()) {
+            return BigDecimal.ZERO;
+        } else {
+            if (businessDate.compareTo(getDueDate()) >= 0) { // Period is 
matured
+                return getInterestOriginalDue();
+            }
+            if (businessDate.compareTo(getFromDate()) >= 0) { // If It is the 
current period
+                return 
getRatePerDay().multiply(BigDecimal.valueOf(DateUtils.getDifferenceInDays(getPeriodStartDate(),
 businessDate)),

Review Comment:
   Rate per day is not correct. Due to rounding, the daily interest amount can 
be vary. You need to calculate it recursively for each day till hit the actual 
current date:
   - calculate the daily interest rate for 1st day -> total interest charged 
divided by number of remaining days in period  (period is 1 month length and 
its August, then 31) -> round it accordingly the rounding mode and use the 
number of digits after decimal from currency
   - calculate the daily interest rate for 2nd day -> (total interest charged - 
calculated, rounded daily interest rate for 1st day ) divided by number of 
remaining days in period (30) -> round it accordingly the rounding mode and use 
the number of digits after decimal from currency
   - and so on till last day
   
   Example:
   - Interest charged for period 32
   - Number of days for period 31
   - 1st day interest: 1.03 after rounding and the next 14 day interest is 
1.03, but on the 16th day, it will be 1.04 hence the accumulating rounding 
remainders.



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