Merge pull request #1044 from pramodn02/develop

MIFOSX-1421 : corrected remove installment charge and add a new installm...
This commit is contained in:
Vishwas Babu A J
2014-08-08 16:22:08 -07:00
5 changed files with 17 additions and 12 deletions
Executable
BIN
View File
Binary file not shown.
@@ -214,7 +214,7 @@ public class SchedulerJobsTestResults {
Assert.assertNotNull(specifiedDueDateChargeId); Assert.assertNotNull(specifiedDueDateChargeId);
this.loanTransactionHelper.addChargesForLoan(loanID, this.loanTransactionHelper.addChargesForLoan(loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(specifiedDueDateChargeId.toString())); LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(specifiedDueDateChargeId.toString(), "12 March 2013", "100"));
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID); ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
Assert.assertEquals(1, chargesPendingState.size()); Assert.assertEquals(1, chargesPendingState.size());
@@ -622,7 +622,7 @@ public class Loan extends AbstractPersistable<Long> {
final LocalDate lastRepaymentPeriodDueDate) { final LocalDate lastRepaymentPeriodDueDate) {
if (loanCharge.isSpecifiedDueDate() if (loanCharge.isSpecifiedDueDate()
&& !loanCharge.isDueForCollectionFromAndUpToAndIncluding(disbursementDate, lastRepaymentPeriodDueDate)) { && !loanCharge.isDueForCollectionFromAndUpToAndIncluding(disbursementDate, lastRepaymentPeriodDueDate)) {
final String defaultUserMessage = "This charge which is due at disbursement cannot be added as the loan is already disbursed."; final String defaultUserMessage = "This charge with specified due date cannot be added as the it is not in schedule range.";
throw new LoanChargeCannotBeAddedException("loanCharge", "specified.due.date.outside.range", defaultUserMessage, throw new LoanChargeCannotBeAddedException("loanCharge", "specified.due.date.outside.range", defaultUserMessage,
getDisbursementDate(), getLastRepaymentPeriodDueDate(), loanCharge.name()); getDisbursementDate(), getLastRepaymentPeriodDueDate(), loanCharge.name());
} }
@@ -478,9 +478,9 @@ public class LoanCharge extends AbstractPersistable<Long> {
} }
} }
this.loanInstallmentCharge.removeAll(remove); this.loanInstallmentCharge.removeAll(remove);
/*while (index < loanChargePerInstallmentArray.length - 1) { while (index < loanChargePerInstallmentArray.length - 1) {
chargePerInstallments.add(loanChargePerInstallmentArray[index++]); this.loanInstallmentCharge.add(loanChargePerInstallmentArray[index++]);
}*/ }
} }
} }
@@ -824,6 +824,7 @@ public class LoanCharge extends AbstractPersistable<Long> {
this.active = active; this.active = active;
if (!active) { if (!active) {
this.overdueInstallmentCharge = null; this.overdueInstallmentCharge = null;
this.clearLoanInstallmentCharges();
} }
} }
@@ -315,7 +315,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
if (diffAmt != null && !diffAmt.isEmpty() && !periodStartDate.isAfter(LocalDate.now())) { if (diffAmt != null && !diffAmt.isEmpty() && !periodStartDate.isAfter(LocalDate.now())) {
Map<LocalDate, RecalculationDetail> processDetails = new TreeMap<>(); Map<LocalDate, RecalculationDetail> processDetails = new TreeMap<>();
for (RecalculationDetail detail : diffAmt) { for (RecalculationDetail detail : diffAmt) {
if (periodStartDate.isBefore(detail.getStartDate()) && detail.isLatePayment()) { if (!periodStartDate.isAfter(detail.getStartDate()) && detail.isLatePayment()) {
if (processDetails.containsKey(detail.getToDate())) { if (processDetails.containsKey(detail.getToDate())) {
RecalculationDetail recalculationDetail = processDetails.get(detail.getToDate()); RecalculationDetail recalculationDetail = processDetails.get(detail.getToDate());
RecalculationDetail updatedDetail = new RecalculationDetail(recalculationDetail.isLatePayment(), RecalculationDetail updatedDetail = new RecalculationDetail(recalculationDetail.isLatePayment(),
@@ -604,14 +604,18 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
if (installment.getDueDate().isBefore(LocalDate.now())) { if (installment.getDueDate().isBefore(LocalDate.now())) {
LocalDate startDate = installment.getDueDate(); LocalDate startDate = installment.getDueDate();
Money totalOutstanding = installment.getTotalOutstanding(currency); Money totalOutstanding = installment.getTotalOutstanding(currency);
boolean reduceStartDate = false;
while (totalOutstanding.isGreaterThanZero() && startDate.isBefore(LocalDate.now())) { while (totalOutstanding.isGreaterThanZero() && startDate.isBefore(LocalDate.now())) {
LocalDate recalculateFrom = getNextRestScheduleDate(startDate.minusDays(1), loanApplicationTerms, isHolidayEnabled, LocalDate recalculateFrom = getNextRestScheduleDate(startDate.minusDays(1), loanApplicationTerms, isHolidayEnabled,
holidays, workingDays); holidays, workingDays);
LocalDate recalcualteTill = getNextRestScheduleDate(recalculateFrom, loanApplicationTerms, isHolidayEnabled, holidays, LocalDate recalcualteTill = getNextRestScheduleDate(recalculateFrom, loanApplicationTerms, isHolidayEnabled, holidays,
workingDays); workingDays);
if (reduceStartDate) {
startDate = startDate.minusDays(1);
}
applyRest(transactions, startDate, recalculateFrom, installment, loanRepaymentScheduleTransactionProcessor, currency, applyRest(transactions, startDate, recalculateFrom, installment, loanRepaymentScheduleTransactionProcessor, currency,
loanApplicationTerms, isHolidayEnabled, holidays, workingDays); loanApplicationTerms, isHolidayEnabled, holidays, workingDays, installments);
totalOutstanding = installment.getTotalOutstanding(currency); totalOutstanding = installment.getTotalOutstanding(currency);
if (totalOutstanding.isGreaterThanZero()) { if (totalOutstanding.isGreaterThanZero()) {
Money latepaymentoutstanding = installment.getPrincipalOutstanding(currency); Money latepaymentoutstanding = installment.getPrincipalOutstanding(currency);
@@ -636,14 +640,15 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
latepaymentoutstanding); latepaymentoutstanding);
diffAmt.add(recalculationDetail); diffAmt.add(recalculationDetail);
} }
startDate = recalcualteTill; startDate = recalculateFrom.plusDays(1);
reduceStartDate = true;
} }
} }
if (!diffAmt.isEmpty()) { if (!diffAmt.isEmpty()) {
processRecalculate = true; processRecalculate = true;
break;
} }
break;
} }
if (processRecalculate) { if (processRecalculate) {
@@ -658,7 +663,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
LoanRepaymentScheduleInstallment installment, LoanRepaymentScheduleInstallment installment,
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor, MonetaryCurrency currency, final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor, MonetaryCurrency currency,
final LoanApplicationTerms loanApplicationTerms, final boolean isHolidayEnabled, final List<Holiday> holidays, final LoanApplicationTerms loanApplicationTerms, final boolean isHolidayEnabled, final List<Holiday> holidays,
final WorkingDays workingDays) { final WorkingDays workingDays, final List<LoanRepaymentScheduleInstallment> installments) {
List<LoanTransaction> transactions = new ArrayList<>(); List<LoanTransaction> transactions = new ArrayList<>();
Map<LocalDate, LocalDate> recalculationDates = new HashMap<>(); Map<LocalDate, LocalDate> recalculationDates = new HashMap<>();
for (LoanTransaction transaction : loanTransactions) { for (LoanTransaction transaction : loanTransactions) {
@@ -671,8 +676,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
workingDays)); workingDays));
} }
} }
List<LoanRepaymentScheduleInstallment> installments = new ArrayList<>(1);
installments.add(installment);
loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(transactions, currency, installments, installment, loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(transactions, currency, installments, installment,
recalculationDates); recalculationDates);
} }