Search in sources :

Example 16 with Errors

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

the class XlsLoansAccountImporter method validateDisbursalDate.

private void validateDisbursalDate(Date disbursalDate, CustomerBO customerBO, LoanOfferingBO loanOfferingBO, int currentCell, HSSFRow currentRow, String statusName) throws XlsParsingException {
    if (disbursalDate == null) {
        throw new XlsParsingException(getCellError(XlsMessageConstants.MISSING_DISBURSAL_DATE, currentRow, currentCell, null));
    }
    LocalDate localDisbursalDate = new LocalDate(disbursalDate.getTime());
    Errors errors = loanAccountServiceFacade.validateLoanDisbursementDate(localDisbursalDate, customerBO.getCustomerId(), loanOfferingBO.getPrdOfferingId().intValue());
    if (localDisbursalDate.isAfter(new LocalDate()) && (statusName.equals("Active in good standing") || statusName.equals("Active in bad standing"))) {
        String[] args = { "" };
        errors.addError("import.loan.account.disbursal.date", args);
    }
    if (errors.hasErrors()) {
        XlsParsingException xlEx = new XlsParsingException(true);
        List<Object> tmp = new ArrayList<Object>();
        tmp.add(localDisbursalDate);
        xlEx.getMessages().add(getCellError(XlsMessageConstants.INVALID_DATE, currentRow, currentCell, tmp));
        for (ErrorEntry entry : errors.getErrorEntries()) {
            xlEx.getMessages().add(getNestedMessage(entry.getErrorCode(), entry.getArgs()));
        }
        throw xlEx;
    }
}
Also used : Errors(org.mifos.platform.validations.Errors) ArrayList(java.util.ArrayList) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) LocalDate(org.joda.time.LocalDate) ErrorEntry(org.mifos.platform.validations.ErrorEntry)

Example 17 with Errors

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

the class LoanAccountActionTest method getLoanRepaymentScheduleShouldCalculateExtraInterest.

@Test
public void getLoanRepaymentScheduleShouldCalculateExtraInterest() throws Exception {
    when(loanBusinessService.computeExtraInterest(eq(loanBO), Matchers.<Date>any())).thenReturn(new Errors());
    when(request.getParameter("accountId")).thenReturn("1");
    when(loanServiceFacade.retrieveOriginalLoanSchedule(Matchers.<Integer>any())).thenReturn(new OriginalScheduleInfoDto("100", new Date(), Collections.<RepaymentScheduleInstallment>emptyList()));
    loanAccountAction.getLoanRepaymentSchedule(mapping, form, request, response);
    verify(loanBusinessService, times(1)).computeExtraInterest(Matchers.<LoanBO>any(), Matchers.<Date>any());
}
Also used : Errors(org.mifos.platform.validations.Errors) ActionErrors(org.apache.struts.action.ActionErrors) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Errors

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

the class LoanAccountServiceFacadeWebTier method validateLoanWithBackdatedPaymentsDisbursementDate.

@Override
public Errors validateLoanWithBackdatedPaymentsDisbursementDate(LocalDate loanDisbursementDate, Integer customerId, Integer productId) {
    Errors errors = new Errors();
    if (!loanDisbursementDate.isBefore(new LocalDate())) {
        String[] args = { "" };
        errors.addError("dibursementdate.before.todays.date", args);
    }
    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    LocalDate customerActivationDate = new LocalDate(customer.getCustomerActivationDate());
    if (loanDisbursementDate.isBefore(customerActivationDate)) {
        String[] args = { customerActivationDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.customer.activation.date", args);
    }
    LoanOfferingBO loanProduct = this.loanProductDao.findById(productId);
    LocalDate productStartDate = new LocalDate(loanProduct.getStartDate());
    if (loanDisbursementDate.isBefore(productStartDate)) {
        String[] args = { productStartDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.product.startDate", args);
    }
    try {
        this.holidayServiceFacade.validateDisbursementDateForNewLoan(customer.getOfficeId(), loanDisbursementDate.toDateMidnight().toDateTime());
    } catch (BusinessRuleException e) {
        String[] args = { "" };
        errors.addError("dibursementdate.falls.on.holiday", args);
    }
    return errors;
}
Also used : Errors(org.mifos.platform.validations.Errors) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate)

Example 19 with Errors

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

the class LoanAccountServiceFacadeWebTier method validateCashFlowForInstallments.

@Override
public Errors validateCashFlowForInstallments(LoanInstallmentsDto loanInstallmentsDto, List<MonthlyCashFlowDto> monthlyCashFlows, Double repaymentCapacity, BigDecimal cashFlowTotalBalance) {
    Errors errors = new Errors();
    if (CollectionUtils.isNotEmpty(monthlyCashFlows)) {
        boolean lowerBound = DateUtils.firstLessOrEqualSecond(monthlyCashFlows.get(0).getMonthDate().toDate(), loanInstallmentsDto.getFirstInstallmentDueDate());
        boolean upperBound = DateUtils.firstLessOrEqualSecond(loanInstallmentsDto.getLastInstallmentDueDate(), monthlyCashFlows.get(monthlyCashFlows.size() - 1).getMonthDate().toDate());
        SimpleDateFormat df = new SimpleDateFormat("MMMM yyyy", Locale.UK);
        if (!lowerBound) {
            errors.addError(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE, new String[] { df.format(loanInstallmentsDto.getFirstInstallmentDueDate()) });
        }
        if (!upperBound) {
            errors.addError(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE, new String[] { df.format(loanInstallmentsDto.getLastInstallmentDueDate()) });
        }
    }
    validateForRepaymentCapacity(loanInstallmentsDto.getTotalInstallmentAmount(), loanInstallmentsDto.getLoanAmount(), repaymentCapacity, errors, cashFlowTotalBalance);
    return errors;
}
Also used : Errors(org.mifos.platform.validations.Errors) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with Errors

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

the class InstallmentsValidatorTest method validateShouldCallFormatListOfAndRulesValidators.

@Test
public void validateShouldCallFormatListOfAndRulesValidators() throws Exception {
    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();
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3);
    Errors errors = installmentsValidator.validateInputInstallments(installments, getValidationContext(null));
    for (RepaymentScheduleInstallment installment : installments) {
        verify(installmentFormatValidator).validateDueDateFormat(installment);
        verify(installmentFormatValidator).validateTotalAmountFormat(installment);
    }
    verify(listOfInstallmentsValidator).validateDuplicateDueDates(installments);
    verify(listOfInstallmentsValidator).validateOrderingOfDueDates(installments);
    verify(installmentRulesValidator).validateForDisbursementDate(eq(installments), any(Date.class));
    verify(installmentRulesValidator).validateDueDatesForVariableInstallments(eq(installments), any(VariableInstallmentDetailsBO.class), any(Date.class));
    verify(installmentRulesValidator).validateForHolidays(eq(installments), any(HolidayServiceFacade.class), eq(officeId));
    assertThat(errors.hasErrors(), is(false));
}
Also used : Errors(org.mifos.platform.validations.Errors) HolidayServiceFacade(org.mifos.application.admin.servicefacade.HolidayServiceFacade) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) VariableInstallmentDetailsBO(org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Errors (org.mifos.platform.validations.Errors)31 Date (java.util.Date)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 LocalDate (org.joda.time.LocalDate)7 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)7 BigDecimal (java.math.BigDecimal)6 ActionErrors (org.apache.struts.action.ActionErrors)4 OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)4 LoanCreationInstallmentDto (org.mifos.dto.domain.LoanCreationInstallmentDto)4 ErrorEntry (org.mifos.platform.validations.ErrorEntry)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)3 CustomerBO (org.mifos.customers.business.CustomerBO)3 Locale (java.util.Locale)2 DateTime (org.joda.time.DateTime)2 Ignore (org.junit.Ignore)2 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)2 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)2 Money (org.mifos.framework.util.helpers.Money)2