Merge branch 'compoundingissue' into develop

This commit is contained in:
Nazeer Hussain Shaik
2016-06-22 11:30:37 +05:30
2 changed files with 30 additions and 12 deletions
@@ -549,6 +549,12 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
.getPrincipal().minus(scheduleParams.getTotalCumulativePrincipal())); .getPrincipal().minus(scheduleParams.getTotalCumulativePrincipal()));
} }
scheduleParams.getCompoundingDateVariations().put(periodStartDateApplicableForInterest,
new TreeMap<>(scheduleParams.getCompoundingMap()));
scheduleParams.getCompoundingMap().clear();
populateCompoundingDatesInPeriod(periodStartDateApplicableForInterest, calculateTill, loanApplicationTerms, holidayDetailDTO,
scheduleParams, loanCharges, totalInterestChargedForFullLoanTerm.getCurrency());
// this is to make sure we are recalculating using correct interest rate // this is to make sure we are recalculating using correct interest rate
// once calculation is done system will set the actual interest rate // once calculation is done system will set the actual interest rate
BigDecimal currentInterestRate = loanApplicationTerms.getAnnualNominalInterestRate(); BigDecimal currentInterestRate = loanApplicationTerms.getAnnualNominalInterestRate();
@@ -577,7 +583,9 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
Money penaltyDiff = currentPeriodParams.getPenaltyChargesForInstallment().minus(tempPeriod.getPenaltyChargesForInstallment()); Money penaltyDiff = currentPeriodParams.getPenaltyChargesForInstallment().minus(tempPeriod.getPenaltyChargesForInstallment());
Money diff = interestDiff.plus(chargeDiff).plus(penaltyDiff); Money diff = interestDiff.plus(chargeDiff).plus(penaltyDiff);
if (!scheduleParams.getOutstandingBalance().minus(diff).isGreaterThanZero()) { if (scheduleParams.getOutstandingBalance().minus(diff).isGreaterThanZero()) {
updateCompoundingDetails(scheduleParams, periodStartDateApplicableForInterest);
} else {
scheduleParams.reduceOutstandingBalance(diff); scheduleParams.reduceOutstandingBalance(diff);
currentPeriodParams.minusInterestForThisPeriod(interestDiff); currentPeriodParams.minusInterestForThisPeriod(interestDiff);
currentPeriodParams.minusFeeChargesForInstallment(chargeDiff); currentPeriodParams.minusFeeChargesForInstallment(chargeDiff);
@@ -593,7 +601,6 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
currentPeriodParams.fetchTotalAmountForPeriod(), false); currentPeriodParams.fetchTotalAmountForPeriod(), false);
scheduleParams.setTotalOutstandingInterestPaymentDueToGrace(interestTillDate.interestPaymentDueToGrace()); scheduleParams.setTotalOutstandingInterestPaymentDueToGrace(interestTillDate.interestPaymentDueToGrace());
} }
} }
return modifiedInstallment; return modifiedInstallment;
} }
@@ -637,8 +644,9 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
private void updateCompoundingDetails(LoanScheduleParams scheduleParams, LocalDate periodStartDateApplicableForInterest) { private void updateCompoundingDetails(LoanScheduleParams scheduleParams, LocalDate periodStartDateApplicableForInterest) {
if (scheduleParams.getCompoundingDateVariations().containsKey(periodStartDateApplicableForInterest)) { if (scheduleParams.getCompoundingDateVariations().containsKey(periodStartDateApplicableForInterest)) {
scheduleParams.getCompoundingMap().clear(); scheduleParams.getCompoundingMap().clear();
scheduleParams.getCompoundingMap().putAll( scheduleParams.getCompoundingMap()
scheduleParams.getCompoundingDateVariations().get(periodStartDateApplicableForInterest)); .putAll(scheduleParams.getCompoundingDateVariations().get(periodStartDateApplicableForInterest));
scheduleParams.getCompoundingDateVariations().remove(periodStartDateApplicableForInterest);
} }
} }
@@ -822,6 +830,8 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
&& !loanApplicationTerms.getPreClosureInterestCalculationStrategy() && !loanApplicationTerms.getPreClosureInterestCalculationStrategy()
.calculateTillRestFrequencyEnabled()) { .calculateTillRestFrequencyEnabled()) {
scheduleParams.getCompoundingDateVariations().put(periodStartDateApplicableForInterest,
new TreeMap<>(scheduleParams.getCompoundingMap()));
LocalDate calculateTill = transactionDate; LocalDate calculateTill = transactionDate;
PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod( PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
this.paymentPeriodsInOneYearCalculator, this.paymentPeriodsInOneYearCalculator,
@@ -1177,7 +1187,8 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
int periodNumberTemp = 1; int periodNumberTemp = 1;
LocalDate lastRestDate = getNextRestScheduleDate(currentDate.minusDays(1), loanApplicationTerms, holidayDetailDTO); LocalDate lastRestDate = getNextRestScheduleDate(currentDate.minusDays(1), loanApplicationTerms, holidayDetailDTO);
Collection<LoanTermVariationsData> applicableVariations = loanApplicationTerms.getLoanTermVariations().getInterestRateChanges(); Collection<LoanTermVariationsData> applicableVariations = loanApplicationTerms.getLoanTermVariations().getInterestRateChanges();
Money uncompoundedFromLastInstallment = params.getUnCompoundedAmount();
LocalDate additionalPeriodsStartDate = params.getPeriodStartDate();
do { do {
params.setActualRepaymentDate(this.scheduledDateGenerator.generateNextRepaymentDate(params.getActualRepaymentDate(), params.setActualRepaymentDate(this.scheduledDateGenerator.generateNextRepaymentDate(params.getActualRepaymentDate(),
@@ -1220,9 +1231,10 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
updateCompoundingMap(loanApplicationTerms, holidayDetailDTO, params, lastRestDate, transactionDate); updateCompoundingMap(loanApplicationTerms, holidayDetailDTO, params, lastRestDate, transactionDate);
populateCompoundingDatesInPeriod(installment.periodDueDate(), params.getActualRepaymentDate(), loanApplicationTerms, populateCompoundingDatesInPeriod(installment.periodDueDate(), params.getActualRepaymentDate(), loanApplicationTerms,
holidayDetailDTO, params, loanCharges, currency); holidayDetailDTO, params, loanCharges, currency);
params.setCompoundedInLastInstallment(params.getUnCompoundedAmount()); uncompoundedFromLastInstallment = params.getUnCompoundedAmount();
params.setPeriodStartDate(transactionDate); params.setPeriodStartDate(transactionDate);
startDate = transactionDate; startDate = transactionDate;
additionalPeriodsStartDate = startDate;
} }
loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(currentTransactions, currency, params.getInstallments()); loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(currentTransactions, currency, params.getInstallments());
updateLatePaidAmountsToPrincipalMap(detail.getTransaction(), loanApplicationTerms, currency, holidayDetailDTO, updateLatePaidAmountsToPrincipalMap(detail.getTransaction(), loanApplicationTerms, currency, holidayDetailDTO,
@@ -1256,6 +1268,10 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
compounded = compounded.plus(mapEntry.getValue()); compounded = compounded.plus(mapEntry.getValue());
} }
} }
if (compounded.isGreaterThanZero() && startDate.isEqual(additionalPeriodsStartDate)) {
params.setCompoundedInLastInstallment(uncompoundedFromLastInstallment);// uncompounded in last installment
additionalPeriodsStartDate = additionalPeriodsStartDate.plusDays(1);
}
Money compoundedForThisPeriod = compounded.minus(uncompounded); Money compoundedForThisPeriod = compounded.minus(uncompounded);
Money uncompoundedForThisPeriod = interest.minus(compoundedForThisPeriod); Money uncompoundedForThisPeriod = interest.minus(compoundedForThisPeriod);
params.setUnCompoundedAmount(uncompoundedForThisPeriod); params.setUnCompoundedAmount(uncompoundedForThisPeriod);
@@ -1506,7 +1522,11 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
final LocalDate restDate = getNextRestScheduleDate(scheduledDueDate.minusDays(1), loanApplicationTerms, final LocalDate restDate = getNextRestScheduleDate(scheduledDueDate.minusDays(1), loanApplicationTerms,
holidayDetailDTO); holidayDetailDTO);
if (!compoundingEffectiveDate.isAfter(loanRepaymentScheduleInstallment.getDueDate())) { if (!compoundingEffectiveDate.isAfter(loanRepaymentScheduleInstallment.getDueDate())) {
totalCompoundedAmount = totalCompoundedAmount.minus(params.getUnCompoundedAmount()); Money amountCompoundedFromLastPeriod = params.getCompoundedInLastInstallment();
if (amountCompoundedFromLastPeriod.isZero()) {
amountCompoundedFromLastPeriod = params.getUnCompoundedAmount();
}
totalCompoundedAmount = totalCompoundedAmount.minus(amountCompoundedFromLastPeriod);
periodHasCompoundingDate = true; periodHasCompoundingDate = true;
} }
while (!compoundingEffectiveDate.isAfter(loanRepaymentScheduleInstallment.getDueDate())) { while (!compoundingEffectiveDate.isAfter(loanRepaymentScheduleInstallment.getDueDate())) {
@@ -1544,13 +1564,11 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
for (Map.Entry<LocalDate, Money> mapEntry : params.getCompoundingMap().entrySet()) { for (Map.Entry<LocalDate, Money> mapEntry : params.getCompoundingMap().entrySet()) {
if (!mapEntry.getKey().isAfter(loanRepaymentScheduleInstallment.getDueDate())) { if (!mapEntry.getKey().isAfter(loanRepaymentScheduleInstallment.getDueDate())) {
updateMapWithAmount(params.getPrincipalPortionMap(), mapEntry.getValue().negated(), mapEntry.getKey()); updateMapWithAmount(params.getPrincipalPortionMap(), mapEntry.getValue().negated(), mapEntry.getKey());
}else if(params.getUnCompoundedAmount().isEqualTo( mapEntry.getValue())){
totalCompoundedAmount = totalCompoundedAmount.plus(params.getUnCompoundedAmount());
} }
} }
params.minusUnCompoundedAmount(params.getUnCompoundedAmount()); params.minusUnCompoundedAmount(params.getUnCompoundedAmount());
params.getCompoundingMap().clear(); params.getCompoundingMap().clear();
params.addUnCompoundedAmount(amountCharged.minus(totalCompoundedAmount.minus(params.getCompoundedInLastInstallment()))); params.addUnCompoundedAmount(amountCharged.minus(totalCompoundedAmount));
} else { } else {
params.getCompoundingMap().clear(); params.getCompoundingMap().clear();
params.getCompoundingDateVariations().put(loanRepaymentScheduleInstallment.getFromDate(), params.getCompoundingDateVariations().put(loanRepaymentScheduleInstallment.getFromDate(),
@@ -1433,7 +1433,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.loanTransactionRepository.save(applyLoanChargeTransaction); this.loanTransactionRepository.save(applyLoanChargeTransaction);
} }
boolean isAppliedOnBackDate = false; boolean isAppliedOnBackDate = false;
if (loanCharge.getDueLocalDate() == null || LocalDate.now().isAfter(loanCharge.getDueLocalDate())) { if (loanCharge.getDueLocalDate() == null || DateUtils.getLocalDateOfTenant().isAfter(loanCharge.getDueLocalDate())) {
isAppliedOnBackDate = true; isAppliedOnBackDate = true;
} }
return isAppliedOnBackDate; return isAppliedOnBackDate;