Search in sources :

Example 1 with LoanDisbursementDateValidator

use of org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateValidator in project head by mifos.

the class LoanAccountServiceFacadeWebTier method validateLoanDisbursementDate.

@Override
public Errors validateLoanDisbursementDate(LocalDate loanDisbursementDate, Integer customerId, Integer productId) {
    Errors errors = new Errors();
    if (loanDisbursementDate.isBefore(new LocalDate())) {
        String[] args = { "" };
        errors.addError("dibursementdate.cannot.be.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);
    }
    boolean isRepaymentIndependentOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
    LoanDisbursementDateFactory loanDisbursementDateFactory = new LoanDisbursmentDateFactoryImpl();
    LoanDisbursementDateValidator loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, isRepaymentIndependentOfMeetingEnabled, false);
    boolean isValid = loanDisbursementDateFinder.isDisbursementDateValidInRelationToSchedule(loanDisbursementDate);
    if (!isValid) {
        String[] args = { "" };
        errors.addError("dibursementdate.invalid.in.relation.to.meeting.schedule", args);
    }
    return errors;
}
Also used : Errors(org.mifos.platform.validations.Errors) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanDisbursementDateValidator(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateValidator) LoanDisbursementDateFactory(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFactory) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) LoanDisbursmentDateFactoryImpl(org.mifos.clientportfolio.newloan.domain.LoanDisbursmentDateFactoryImpl)

Aggregations

LocalDate (org.joda.time.LocalDate)1 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)1 LoanDisbursementDateFactory (org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFactory)1 LoanDisbursementDateValidator (org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateValidator)1 LoanDisbursmentDateFactoryImpl (org.mifos.clientportfolio.newloan.domain.LoanDisbursmentDateFactoryImpl)1 ConfigurationBusinessService (org.mifos.config.business.service.ConfigurationBusinessService)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 Errors (org.mifos.platform.validations.Errors)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1