Merge branch 'FINERACT-267' into develop

This commit is contained in:
Nazeer Hussain Shaik
2016-12-13 17:02:37 +05:30
@@ -6285,10 +6285,14 @@ public class Loan extends AbstractPersistableCustom<Long> {
final MonetaryCurrency currency = getCurrency(); final MonetaryCurrency currency = getCurrency();
Money totalPrincipal = Money.zero(currency); Money totalPrincipal = Money.zero(currency);
Money [] balances = retriveIncomeForOverlappingPeriod(transactionDate); Money [] balances = retriveIncomeForOverlappingPeriod(transactionDate);
boolean isInterestComponent = true;
for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) { for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
if (!installment.getDueDate().isBefore(transactionDate)) { if (!installment.getDueDate().isBefore(transactionDate)) {
totalPrincipal = totalPrincipal.plus(installment.getPrincipal(currency)); totalPrincipal = totalPrincipal.plus(installment.getPrincipal(currency));
newInstallments.remove(installment); newInstallments.remove(installment);
if (installment.getDueDate().isEqual(transactionDate)) {
isInterestComponent = false;
}
} }
} }
@@ -6303,12 +6307,18 @@ public class Loan extends AbstractPersistableCustom<Long> {
if (newInstallments.size() > 0) { if (newInstallments.size() > 0) {
installmentStartDate = newInstallments.get((newInstallments.size() - 1)).getDueDate(); installmentStartDate = newInstallments.get((newInstallments.size() - 1)).getDueDate();
} }
int installmentNumber = newInstallments.size();
if (!isInterestComponent) {
installmentNumber++;
}
LoanRepaymentScheduleInstallment newInstallment = new LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1, LoanRepaymentScheduleInstallment newInstallment = new LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1,
installmentStartDate, transactionDate, totalPrincipal.getAmount(), installmentStartDate, transactionDate, totalPrincipal.getAmount(),
balances[0].getAmount(), balances[1].getAmount(), balances[2].getAmount(), true, null); balances[0].getAmount(), balances[1].getAmount(), balances[2].getAmount(), isInterestComponent, null);
newInstallment.updateInstallmentNumber(newInstallments.size() + 1); newInstallment.updateInstallmentNumber(newInstallments.size() + 1);
newInstallments.add(newInstallment); newInstallments.add(newInstallment);
updateLoanScheduleOnForeclosure(newInstallments); updateLoanScheduleOnForeclosure(newInstallments);
@@ -6321,8 +6331,26 @@ public class Loan extends AbstractPersistableCustom<Long> {
loanCharge.setActive(false); loanCharge.setActive(false);
} else if (loanCharge.getDueLocalDate() == null) { } else if (loanCharge.getDueLocalDate() == null) {
recalculateLoanCharge(loanCharge, penaltyWaitPeriod); recalculateLoanCharge(loanCharge, penaltyWaitPeriod);
loanCharge.updateWaivedAmount(currency);
} }
} }
for (LoanTransaction loanTransaction : getLoanTransactions()) {
if (loanTransaction.isChargesWaiver()) {
for (LoanChargePaidBy chargePaidBy : loanTransaction
.getLoanChargesPaid()) {
if ((chargePaidBy.getLoanCharge().isDueDateCharge() && chargePaidBy
.getLoanCharge().getDueLocalDate()
.isAfter(transactionDate))
|| (chargePaidBy.getLoanCharge().isInstalmentFee() && (chargePaidBy
.getInstallmentNumber() != null && chargePaidBy
.getInstallmentNumber() > installmentNumber))) {
loanTransaction.reverse();
}
}
}
}
} }
public void updateLoanScheduleOnForeclosure(final Collection<LoanRepaymentScheduleInstallment> installments) { public void updateLoanScheduleOnForeclosure(final Collection<LoanRepaymentScheduleInstallment> installments) {