Search in sources :

Example 6 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanBusinessService method adjustInstallmentGapsPostDisbursal.

public void adjustInstallmentGapsPostDisbursal(List<RepaymentScheduleInstallment> installments, Date oldDisbursementDate, Date newDisbursementDate, Short officeId) {
    Date oldPrevDate = oldDisbursementDate, newPrevDate = newDisbursementDate;
    for (RepaymentScheduleInstallment installment : installments) {
        Date currentDueDate = installment.getDueDateValue();
        long delta = DateUtils.getNumberOfDaysBetweenTwoDates(currentDueDate, oldPrevDate);
        Date newDueDate = DateUtils.addDays(newPrevDate, (int) delta);
        if (holidayService.isFutureRepaymentHoliday(DateUtils.getCalendar(newDueDate), officeId)) {
            installment.setDueDateValue(holidayService.getNextWorkingDay(newDueDate, officeId));
        } else {
            installment.setDueDateValue(newDueDate);
        }
        oldPrevDate = currentDueDate;
        newPrevDate = installment.getDueDateValue();
    }
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 7 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class InstallmentRulesValidatorImpl method validateForMinimumInstallmentAmount.

@Override
public List<ErrorEntry> validateForMinimumInstallmentAmount(List<RepaymentScheduleInstallment> installments, BigDecimal minInstallmentAmount) {
    List<ErrorEntry> errorEntries = new ArrayList<ErrorEntry>();
    for (RepaymentScheduleInstallment installment : installments) {
        String identifier = installment.getInstallmentNumberAsString();
        if (installment.isTotalAmountInValid()) {
            ErrorEntry entry = new ErrorEntry(AccountConstants.INSTALLMENT_AMOUNT_LESS_THAN_INTEREST_FEE, identifier);
            entry.setArgs(Arrays.asList(identifier));
            errorEntries.add(entry);
        } else if (installment.isTotalAmountLessThan(minInstallmentAmount)) {
            ErrorEntry entry = new ErrorEntry(INSTALLMENT_AMOUNT_LESS_THAN_MIN_AMOUNT, identifier);
            entry.setArgs(Arrays.asList(identifier));
            errorEntries.add(entry);
        }
    }
    return errorEntries;
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) ArrayList(java.util.ArrayList) ErrorEntry(org.mifos.platform.validations.ErrorEntry)

Example 8 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class InstallmentRulesValidatorImpl method validateDueDatesForVariableInstallments.

@Override
public List<ErrorEntry> validateDueDatesForVariableInstallments(List<RepaymentScheduleInstallment> installments, VariableInstallmentDetailsBO variableInstallmentDetailsBO, Date disbursementDate) {
    List<ErrorEntry> errorEntries = new ArrayList<ErrorEntry>();
    if (CollectionUtils.isNotEmpty(installments)) {
        for (int i = 0, installmentsSize = installments.size(); i < installmentsSize; i++) {
            Date previousDueDate = getPreviousDueDate(installments, i, disbursementDate);
            RepaymentScheduleInstallment installment = installments.get(i);
            validateForDifferenceInDays(installment, previousDueDate, variableInstallmentDetailsBO, errorEntries);
        }
    }
    return errorEntries;
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) ArrayList(java.util.ArrayList) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date)

Example 9 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanBusinessServiceTest method shouldMaintainInstallmentGapsPostDisbursal.

@Test
public void shouldMaintainInstallmentGapsPostDisbursal() {
    RepaymentScheduleInstallment installment1 = getRepaymentScheduleInstallment("01-Sep-2010", 1, "94.4", "4.6", "1", "75", "0", "0");
    RepaymentScheduleInstallment installment2 = getRepaymentScheduleInstallment("08-Sep-2010", 2, "94.8", "4.2", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment3 = getRepaymentScheduleInstallment("15-Sep-2010", 3, "95.3", "3.7", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment4 = getRepaymentScheduleInstallment("15-Oct-2010", 4, "84.9", "14.1", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment5 = getRepaymentScheduleInstallment("25-Oct-2010", 5, "94.9", "4.2", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment6 = getRepaymentScheduleInstallment("01-Nov-2010", 6, "96.5", "2.5", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment7 = getRepaymentScheduleInstallment("18-Nov-2010", 7, "439.2", "4.9", "1", "445.1", "0", "0");
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3, installment4, installment5, installment6, installment7);
    Date initialDisbursementDate = TestUtils.getDate(25, 8, 2010);
    Date disbursementDate = TestUtils.getDate(30, 8, 2010);
    when(holidayService.isFutureRepaymentHoliday(Matchers.<Calendar>any(), eq(officeId))).thenReturn(true);
    when(holidayService.getNextWorkingDay(Matchers.<Date>any(), eq(officeId))).thenReturn(TestUtils.getDate(6, 9, 2010), TestUtils.getDate(13, 9, 2010), TestUtils.getDate(20, 9, 2010), TestUtils.getDate(20, 10, 2010), TestUtils.getDate(30, 10, 2010), TestUtils.getDate(6, 11, 2010), TestUtils.getDate(23, 11, 2010));
    loanBusinessService.adjustInstallmentGapsPostDisbursal(installments, initialDisbursementDate, disbursementDate, officeId);
    assertInstallmentDueDate(installment1, "06-Sep-2010");
    assertInstallmentDueDate(installment2, "13-Sep-2010");
    assertInstallmentDueDate(installment3, "20-Sep-2010");
    assertInstallmentDueDate(installment4, "20-Oct-2010");
    assertInstallmentDueDate(installment5, "30-Oct-2010");
    assertInstallmentDueDate(installment6, "06-Nov-2010");
    assertInstallmentDueDate(installment7, "23-Nov-2010");
    verify(holidayService, times(7)).isFutureRepaymentHoliday(Matchers.<Calendar>any(), eq(officeId));
    verify(holidayService, times(7)).getNextWorkingDay(Matchers.<Date>any(), eq(officeId));
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) Date(java.util.Date) Test(org.junit.Test)

Example 10 with RepaymentScheduleInstallment

use of org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment in project head by mifos.

the class LoanBusinessServiceTest method shouldGenerateMonthlyInstallmentScheduleFromRepaymentScheduleUsingDailyInterest.

@Test
public void shouldGenerateMonthlyInstallmentScheduleFromRepaymentScheduleUsingDailyInterest() {
    MifosCurrency rupee = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    RepaymentScheduleInstallment installment1 = getRepaymentScheduleInstallment("25-Sep-2010", 1, "78.6", "20.4", "1", "100", "0", "0");
    RepaymentScheduleInstallment installment2 = getRepaymentScheduleInstallment("25-Oct-2010", 2, "182.8", "16.2", "1", "200", "0", "0");
    RepaymentScheduleInstallment installment3 = getRepaymentScheduleInstallment("25-Nov-2010", 3, "186.0", "13.0", "1", "200", "0", "0");
    RepaymentScheduleInstallment installment4 = getRepaymentScheduleInstallment("25-Dec-2010", 4, "452.6", "8.9", "1", "462.5", "0", "0");
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3, installment4);
    Date disbursementDate = TestUtils.getDate(25, 8, 2010);
    final Money loanAmount = new Money(rupee, "1000");
    loanBusinessService.applyDailyInterestRates(new LoanScheduleGenerationDto(disbursementDate, loanAmount, 24d, installments), false);
    assertInstallment(installment1, "78.6", "20.4");
    assertInstallment(installment2, "180.8", "18.2");
    assertInstallment(installment3, "183.9", "15.1");
    assertInstallment(installment4, "556.7", "11.0");
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)66 Test (org.junit.Test)44 Money (org.mifos.framework.util.helpers.Money)34 Date (java.util.Date)27 ArrayList (java.util.ArrayList)19 ErrorEntry (org.mifos.platform.validations.ErrorEntry)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 VariableInstallmentDetailsBO (org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO)7 OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)6 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)6 Errors (org.mifos.platform.validations.Errors)6 MifosCurrency (org.mifos.application.master.business.MifosCurrency)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 BigDecimal (java.math.BigDecimal)4 ActionErrors (org.apache.struts.action.ActionErrors)4 Ignore (org.junit.Ignore)4 HashSet (java.util.HashSet)3 LocalDate (org.joda.time.LocalDate)3 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)3 MessageLookup (org.mifos.application.master.MessageLookup)3