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


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanSummaryData.java:
##########
@@ -236,44 +223,23 @@ public static LoanSummaryData 
withOnlyCurrencyData(CurrencyData currencyData) {
         return LoanSummaryData.builder().currency(currencyData).build();
     }
 
-    private static BigDecimal 
computeTotalAccruedDueInterestAmount(Collection<LoanSchedulePeriodData> 
periods) {
-        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
-        return periods.stream().filter(period -> 
!period.getDownPaymentPeriod() && businessDate.isAfter(period.getDueDate()))
-                .map(period -> 
period.getTotalAccruedInterest()).reduce(BigDecimal.ZERO, BigDecimal::add);
-    }
-
-    private static BigDecimal 
computeTotalInterestPaidDueAmount(Collection<LoanSchedulePeriodData> periods) {
-        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+    private static BigDecimal 
computeTotalUnpaidPayableDueInterestAmount(Collection<LoanSchedulePeriodData> 
periods,
+            final LocalDate businessDate) {
         return periods.stream().filter(period -> 
!period.getDownPaymentPeriod() && businessDate.isAfter(period.getDueDate()))
-                .map(period -> 
period.getInterestPaid()).reduce(BigDecimal.ZERO, BigDecimal::add);
+                .map(period -> 
period.getInterestOutstanding()).reduce(BigDecimal.ZERO, BigDecimal::add);
     }
 
-    private static BigDecimal 
computeTotalAccruedNotDueInterestAmountOnActualPeriod(Collection<LoanSchedulePeriodData>
 periods) {
-        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
-        return periods.stream()
-                .filter(period -> !period.getDownPaymentPeriod() && 
isActualPeriod(period) && businessDate.isBefore(period.getDueDate()))
-                .map(period -> 
period.getTotalAccruedInterest()).reduce(BigDecimal.ZERO, BigDecimal::add);
-    }
-
-    private static BigDecimal 
computeTotalInterestPaidNotDueAmountOnActualPeriod(Collection<LoanSchedulePeriodData>
 periods) {
-        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
-        return periods.stream()
-                .filter(period -> !period.getDownPaymentPeriod() && 
isActualPeriod(period) && businessDate.isBefore(period.getDueDate()))
-                .map(period -> 
period.getInterestPaid()).reduce(BigDecimal.ZERO, BigDecimal::add);
-    }
-
-    private static boolean isActualPeriod(LoanSchedulePeriodData period) {
-        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
-        boolean actualPeriod = false;
-        if (period.getPeriod() != null) {
-            if (period.getPeriod() == 1) {
-                actualPeriod = ((businessDate.isEqual(period.getFromDate()) || 
businessDate.isAfter(period.getFromDate()))
-                        && businessDate.isBefore(period.getDueDate()));
-            } else {
-                actualPeriod = (businessDate.isAfter(period.getFromDate()) && 
businessDate.isBefore(period.getDueDate()));
-            }
+    private static BigDecimal 
computeTotalUnpaidPayableNotDueInterestAmountOnActualPeriod(final 
Collection<LoanSchedulePeriodData> periods,
+            final LocalDate businessDate) {
+        // Default value equal to Zero
+        BigDecimal totalAccruedNotDueInterestAmount = BigDecimal.ZERO;
+        // Find the current Period (If exists one) based in the Business date
+        final Optional<LoanSchedulePeriodData> optCurrentPeriod = 
periods.stream()
+                .filter(period -> !period.getDownPaymentPeriod() && 
period.isActualPeriod(businessDate)).findFirst();

Review Comment:
   This is not correct, we want to calculate the not yet due payable interest, 
so the due date should not be included here. The due date should be included in 
the due payable interest calculation.



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