Search in sources :

Example 1 with ErrorEntry

use of org.mifos.platform.validations.ErrorEntry in project head by mifos.

the class ListOfInstallmentsValidatorImpl method validateOrderingOfDueDates.

@Override
public List<ErrorEntry> validateOrderingOfDueDates(List<RepaymentScheduleInstallment> installments) {
    List<ErrorEntry> errorEntries = new ArrayList<ErrorEntry>();
    if (CollectionUtils.isNotEmpty(installments)) {
        List<Date> dueDates = CollectionUtils.collect(installments, getDueDateTransformer());
        int index = CollectionUtils.itemIndexOutOfAscendingOrder(dueDates);
        if (index >= 0) {
            ErrorEntry error = new ErrorEntry(INSTALLMENT_DUEDATE_INVALID_ORDER, "installmentNumber");
            error.setArgs(Arrays.asList(installments.get(index).getInstallmentNumberAsString()));
            errorEntries.add(error);
        }
    }
    return errorEntries;
}
Also used : ArrayList(java.util.ArrayList) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date)

Example 2 with ErrorEntry

use of org.mifos.platform.validations.ErrorEntry 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 3 with ErrorEntry

use of org.mifos.platform.validations.ErrorEntry 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 4 with ErrorEntry

use of org.mifos.platform.validations.ErrorEntry in project head by mifos.

the class InstallmentRulesValidatorTest method shouldNotValidateInstallmentForDueDateAfterDisburseDate.

@Test
public void shouldNotValidateInstallmentForDueDateAfterDisburseDate() {
    RepaymentScheduleInstallment installment = installmentBuilder.withInstallment(3).withDueDateValue("30-Nov-2010").withPrincipal(new Money(rupee, "499.9")).withInterest(new Money(rupee, "22.1")).withFees(new Money(rupee, "0.0")).withTotal("522.0").build();
    Date dateValue = getDate(installment, "30-Sep-2010");
    List<ErrorEntry> errorEntries = installmentRulesValidator.validateForDisbursementDate(asList(installment), dateValue);
    assertThat(errorEntries.isEmpty(), is(true));
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date) Test(org.junit.Test)

Example 5 with ErrorEntry

use of org.mifos.platform.validations.ErrorEntry in project head by mifos.

the class InstallmentRulesValidatorTest method shouldValidateMaximumGapOfFiveDaysForVariableInstallments.

@Test
public void shouldValidateMaximumGapOfFiveDaysForVariableInstallments() {
    RepaymentScheduleInstallment installment1 = installmentBuilder.reset(locale).withInstallment(1).withDueDateValue("01-Nov-2010").build();
    RepaymentScheduleInstallment installment2 = installmentBuilder.reset(locale).withInstallment(2).withDueDateValue("06-Nov-2010").build();
    RepaymentScheduleInstallment installment3 = installmentBuilder.reset(locale).withInstallment(3).withDueDateValue("08-Nov-2010").build();
    RepaymentScheduleInstallment installment4 = installmentBuilder.reset(locale).withInstallment(4).withDueDateValue("14-Nov-2010").build();
    RepaymentScheduleInstallment installment5 = installmentBuilder.reset(locale).withInstallment(5).withDueDateValue("20-Nov-2010").build();
    RepaymentScheduleInstallment installment6 = installmentBuilder.reset(locale).withInstallment(6).withDueDateValue("30-Nov-2010").build();
    RepaymentScheduleInstallment installment7 = installmentBuilder.reset(locale).withInstallment(7).withDueDateValue("01-Dec-2010").build();
    VariableInstallmentDetailsBO variableInstallmentDetails = getVariableInstallmentDetails(null, 5, 100, rupee);
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3, installment4, installment5, installment6, installment7);
    Date disbursementDate = getDate(installment1, "27-Oct-2010");
    List<ErrorEntry> errorEntries = installmentRulesValidator.validateDueDatesForVariableInstallments(installments, variableInstallmentDetails, disbursementDate);
    assertErrorEntry(errorEntries.get(0), AccountConstants.INSTALLMENT_DUEDATE_MORE_THAN_MAX_GAP, "4");
    assertErrorEntry(errorEntries.get(1), AccountConstants.INSTALLMENT_DUEDATE_MORE_THAN_MAX_GAP, "5");
    assertErrorEntry(errorEntries.get(2), AccountConstants.INSTALLMENT_DUEDATE_MORE_THAN_MAX_GAP, "6");
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) VariableInstallmentDetailsBO(org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ErrorEntry (org.mifos.platform.validations.ErrorEntry)42 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)19 Test (org.junit.Test)17 Date (java.util.Date)14 ArrayList (java.util.ArrayList)8 Money (org.mifos.framework.util.helpers.Money)8 DateTime (org.joda.time.DateTime)6 LocalDate (org.joda.time.LocalDate)6 VariableInstallmentDetailsBO (org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO)5 BigDecimal (java.math.BigDecimal)4 Errors (org.mifos.platform.validations.Errors)4 Calendar (java.util.Calendar)2 LoanCreationProductDetailsDto (org.mifos.dto.screen.LoanCreationProductDetailsDto)2 MessageBuilder (org.springframework.binding.message.MessageBuilder)2 MessageContext (org.springframework.binding.message.MessageContext)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)1 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 VariableInstallmentWithFeeValidationResult (org.mifos.clientportfolio.newloan.applicationservice.VariableInstallmentWithFeeValidationResult)1 CustomerBO (org.mifos.customers.business.CustomerBO)1