adamsaghy commented on code in PR #4207:
URL: https://github.com/apache/fineract/pull/4207#discussion_r1875965860
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -3902,4 +3952,56 @@ public void closeAsMarkedForReschedule(final Loan loan,
final JsonCommand comman
loanTransactionValidator.validateLoanRescheduleDate(loan);
}
+
+ private void calculatePartialPeriodInterest(final Loan loan, final
LocalDate chargeOffDate) {
+ loan.getRepaymentScheduleInstallments().stream()
+ .filter(installment ->
!installment.getFromDate().isAfter(chargeOffDate) &&
installment.getDueDate().isAfter(chargeOffDate))
+ .forEach(installment -> {
+ final BigDecimal totalInterest =
installment.getInterestOutstanding(loan.getCurrency()).getAmount();
+ final long totalDaysInPeriod =
ChronoUnit.DAYS.between(installment.getFromDate(), installment.getDueDate());
+ final long daysTillChargeOff =
ChronoUnit.DAYS.between(installment.getFromDate(), chargeOffDate);
+
+ final BigDecimal interestTillChargeOff = totalInterest
+ .divide(BigDecimal.valueOf(totalDaysInPeriod), 10,
RoundingMode.HALF_UP)
+ .multiply(BigDecimal.valueOf(daysTillChargeOff));
+
+ final BigDecimal interestRemoved =
totalInterest.subtract(interestTillChargeOff);
+
installment.updatePrincipal(defaultToZeroIfNull(installment.getPrincipal()).add(interestRemoved));
+ installment.updateInterestCharged(interestTillChargeOff);
+ });
+ }
+
+ private BigDecimal defaultToZeroIfNull(final BigDecimal possibleNullValue)
{
+ return possibleNullValue != null ? possibleNullValue : BigDecimal.ZERO;
+ }
+
+ private void updateLastInstallmentPrincipal(final Loan loan,
Review Comment:
This looks a little overcomplicated...we have the loan entity on hand, so
fetching repayment schedule from database might not be the recommended way to
handle this.
--
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]