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


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -845,10 +904,51 @@ private BigDecimal 
calculateRateFactorPerPeriodBasedOnRepaymentFrequency(final B
         };
     }
 
+    private void 
calculateEMIOnActualModelWithFlatInterestMethod(List<RepaymentPeriod> 
repaymentPeriods,
+            ProgressiveLoanInterestScheduleModel scheduleModel) {
+
+        final MathContext mc = scheduleModel.mc();
+        final CurrencyData currency = 
scheduleModel.loanProductRelatedDetail().getCurrencyData();
+        RepaymentPeriod first = repaymentPeriods.getFirst();
+        RepaymentPeriod last = repaymentPeriods.getLast();
+        Money sumOfInterest = Money.zero(currency);
+        for (RepaymentPeriod rp : repaymentPeriods) {
+            Money interest = rp.calculateCalculatedDueInterest();
+            sumOfInterest = sumOfInterest.add(interest);
+            rp.setEmi(interest);
+        }
+
+        // already repaid principals should be subtracted from total disbursed 
amount to calculate correct EMI.
+        BigDecimal alreadyRepaidPrincipals = first.getPrevious()
+                .map(rp -> 
rp.calculateTotalDisbursedAmountTillGivenPeriod(null).subtract(rp.getOutstandingLoanBalance().getAmount()))
+                .orElse(BigDecimal.ZERO);
+        Money total = Money.of(currency, 
first.calculateTotalDisbursedAmountTillGivenPeriod(first.getLastInterestPeriod()))
+                .plus(sumOfInterest).minus(alreadyRepaidPrincipals);
+
+        Money periodEmi = total.dividedBy(repaymentPeriods.size(), mc);
+        Money remainder = 
total.minus(periodEmi.multipliedBy(repaymentPeriods.size(), mc));
+
+        repaymentPeriods.forEach(rp -> {
+            Money emi = rp.equals(last) ? periodEmi.add(remainder) : periodEmi;
+            rp.setEmi(emi);

Review Comment:
   Dont we need to add Chargeback Principal and Chargeback interest to the emi?



-- 
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: commits-unsubscr...@fineract.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to