FINERACT-2081: Refactor - Simplify LoanSchedulePeriodData.java class
This commit is contained in:
+3
-12
@@ -122,13 +122,7 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
|
||||
outstandingAmountsDTO.principal().getAmount(), outstandingAmountsDTO.interest().getAmount(),
|
||||
outstandingAmountsDTO.feeCharges().getAmount(), outstandingAmountsDTO.penaltyCharges().getAmount(), false, null);
|
||||
|
||||
Money totalAmount = totalPrincipal.plus(loanRepaymentScheduleInstallment.getFeeChargesOutstanding(currency))
|
||||
.plus(loanRepaymentScheduleInstallment.getPenaltyChargesOutstanding(currency));
|
||||
Money interestDue = Money.zero(currency);
|
||||
if (loanRepaymentScheduleInstallment.isInterestDue(currency)) {
|
||||
interestDue = loanRepaymentScheduleInstallment.getInterestOutstanding(currency);
|
||||
totalAmount = totalAmount.plus(interestDue);
|
||||
}
|
||||
Money interestDue = loanRepaymentScheduleInstallment.getInterestOutstanding(currency);
|
||||
boolean isNewPaymentRequired = loanRepaymentScheduleInstallment.isInterestDue(currency) || totalPrincipal.isGreaterThanZero();
|
||||
|
||||
LoanScheduleModel model = this.loanScheduleAssembler.assembleForInterestRecalculation(loanApplicationTerms, loan.getOfficeId(),
|
||||
@@ -141,14 +135,12 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
|
||||
periodData.getFromDate(), periodData.getDueDate(), totalPrincipal.getAmount(),
|
||||
periodData.getPrincipalLoanBalanceOutstanding(), interestDue.getAmount(),
|
||||
loanRepaymentScheduleInstallment.getFeeChargesCharged(currency).getAmount(),
|
||||
loanRepaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount(), totalAmount.getAmount(),
|
||||
totalPrincipal.plus(interestDue).getAmount());
|
||||
loanRepaymentScheduleInstallment.getPenaltyChargesCharged(currency).getAmount());
|
||||
futureInstallments.add(loanSchedulePeriodData);
|
||||
isNewPaymentRequired = false;
|
||||
} else if (DateUtils.isAfter(periodData.getDueDate(), today)) {
|
||||
futureInstallments.add(periodData);
|
||||
}
|
||||
|
||||
}
|
||||
loanScheduleData.updateFuturePeriods(futureInstallments);
|
||||
}
|
||||
@@ -198,8 +190,7 @@ public class LoanScheduleCalculationPlatformServiceImpl implements LoanScheduleC
|
||||
LoanSchedulePeriodData loanSchedulePeriodData = LoanSchedulePeriodData.repaymentOnlyPeriod(installment.getInstallmentNumber(),
|
||||
installment.getFromDate(), installment.getDueDate(), installment.getPrincipal(currency).getAmount(),
|
||||
outstanding.getAmount(), installment.getInterestCharged(currency).getAmount(),
|
||||
installment.getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount(),
|
||||
installment.getDue(currency).getAmount(), installment.getTotalPrincipalAndInterest(currency).getAmount());
|
||||
installment.getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount());
|
||||
installmentData.add(loanSchedulePeriodData);
|
||||
totalInterest = totalInterest.plus(installment.getInterestCharged(currency));
|
||||
totalCharge = totalCharge.plus(installment.getFeeChargesCharged(currency));
|
||||
|
||||
+1
-4
@@ -191,9 +191,6 @@ public class LoanScheduleHistoryReadPlatformServiceImpl implements LoanScheduleH
|
||||
final BigDecimal interestExpectedDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestDue");
|
||||
totalInterestCharged = totalInterestCharged.plus(interestExpectedDue);
|
||||
|
||||
final BigDecimal totalInstallmentAmount = totalPrincipalExpected.zero().plus(principalDue).plus(interestExpectedDue)
|
||||
.getAmount();
|
||||
|
||||
final BigDecimal feeChargesExpectedDue = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "feeChargesDue");
|
||||
totalFeeChargesCharged = totalFeeChargesCharged.plus(feeChargesExpectedDue);
|
||||
|
||||
@@ -218,7 +215,7 @@ public class LoanScheduleHistoryReadPlatformServiceImpl implements LoanScheduleH
|
||||
|
||||
final LoanSchedulePeriodData periodData = LoanSchedulePeriodData.repaymentOnlyPeriod(period, fromDate, dueDate,
|
||||
principalDue, outstandingPrincipalBalanceOfLoan, interestExpectedDue, feeChargesExpectedDue,
|
||||
penaltyChargesExpectedDue, totalDueForPeriod, totalInstallmentAmount);
|
||||
penaltyChargesExpectedDue);
|
||||
|
||||
periods.add(periodData);
|
||||
}
|
||||
|
||||
+2
-5
@@ -159,15 +159,12 @@ public abstract class CommonLoanSummaryDataProvider implements LoanSummaryDataPr
|
||||
|
||||
@Override
|
||||
public BigDecimal computeTotalUnpaidPayableDueInterestAmount(Collection<LoanSchedulePeriodData> periods, final LocalDate businessDate) {
|
||||
return periods.stream().filter(period -> !period.getDownPaymentPeriod() && businessDate.compareTo(period.getDueDate()) >= 0)
|
||||
return periods.stream().filter(period -> !period.isDownPaymentPeriod() && !businessDate.isBefore(period.getDueDate()))
|
||||
.map(LoanSchedulePeriodData::getInterestOutstanding).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanSummaryData withOnlyCurrencyData(CurrencyData currencyData) {
|
||||
{
|
||||
return LoanSummaryData.builder().currency(currencyData).build();
|
||||
}
|
||||
return LoanSummaryData.builder().currency(currencyData).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -46,8 +46,10 @@ public class CumulativeLoanSummaryDataProvider extends CommonLoanSummaryDataProv
|
||||
public BigDecimal computeTotalUnpaidPayableNotDueInterestAmountOnActualPeriod(final Loan loan,
|
||||
final Collection<LoanSchedulePeriodData> periods, final LocalDate businessDate, final CurrencyData currency) {
|
||||
// Find the current Period (If exists one) based on the Business date
|
||||
final Optional<LoanSchedulePeriodData> optCurrentPeriod = periods.stream()
|
||||
.filter(period -> !period.getDownPaymentPeriod() && period.isActualPeriodForNotDuePayableCalculation(businessDate))
|
||||
final Optional<LoanSchedulePeriodData> optCurrentPeriod = periods.stream().filter(period -> !period.isDownPaymentPeriod() //
|
||||
&& period.getPeriod() != null //
|
||||
&& !businessDate.isBefore(period.getFromDate()) //
|
||||
&& businessDate.isBefore(period.getDueDate())) //
|
||||
.findFirst();
|
||||
|
||||
if (optCurrentPeriod.isPresent()) {
|
||||
|
||||
+4
-7
@@ -1263,8 +1263,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
|
||||
final BigDecimal interestPaid = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestPaid");
|
||||
final BigDecimal interestWaived = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestWaived");
|
||||
final BigDecimal interestWrittenOff = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "interestWrittenOff");
|
||||
final BigDecimal totalInstallmentAmount = totalPrincipalPaid.zero().plus(principalDue).plus(interestExpectedDue)
|
||||
.getAmount();
|
||||
final BigDecimal accrualInterest = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "accrualInterest");
|
||||
|
||||
final BigDecimal interestActualDue = interestExpectedDue.subtract(interestWaived).subtract(interestWrittenOff);
|
||||
@@ -1330,14 +1328,13 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
|
||||
|
||||
LoanSchedulePeriodData periodData;
|
||||
|
||||
periodData = LoanSchedulePeriodData.periodWithPayments(loanId, period, fromDate, dueDate, obligationsMetOnDate, complete,
|
||||
periodData = LoanSchedulePeriodData.periodWithPayments(period, fromDate, dueDate, obligationsMetOnDate, complete,
|
||||
principalDue, principalPaid, principalWrittenOff, principalOutstanding, outstandingPrincipalBalanceOfLoan,
|
||||
interestExpectedDue, interestPaid, interestWaived, interestWrittenOff, interestOutstanding, feeChargesExpectedDue,
|
||||
feeChargesPaid, feeChargesWaived, feeChargesWrittenOff, feeChargesOutstanding, penaltyChargesExpectedDue,
|
||||
penaltyChargesPaid, penaltyChargesWaived, penaltyChargesWrittenOff, penaltyChargesOutstanding, totalDueForPeriod,
|
||||
totalPaidForPeriod, totalPaidInAdvanceForPeriod, totalPaidLateForPeriod, totalWaivedForPeriod,
|
||||
totalWrittenOffForPeriod, totalOutstandingForPeriod, totalActualCostOfLoanForPeriod, totalInstallmentAmount,
|
||||
credits, isDownPayment, accrualInterest);
|
||||
penaltyChargesPaid, penaltyChargesWaived, penaltyChargesWrittenOff, penaltyChargesOutstanding, totalPaidForPeriod,
|
||||
totalPaidInAdvanceForPeriod, totalPaidLateForPeriod, totalWaivedForPeriod, totalWrittenOffForPeriod, credits,
|
||||
isDownPayment, accrualInterest);
|
||||
|
||||
periods.add(periodData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user