Search in sources :

Example 21 with Errors

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

the class LoanBusinessServiceTest method shouldComputeExtraInterestAsOfDateLaterThanLastPaymentDateAndNoLastPayment.

@Test
public void shouldComputeExtraInterestAsOfDateLaterThanLastPaymentDateAndNoLastPayment() {
    Date asOfDate = TestUtils.getDate(10, 9, 2010);
    when(loanBO.findMostRecentNonzeroPaymentByPaymentDate()).thenReturn(null);
    when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(true);
    Errors errors = loanBusinessService.computeExtraInterest(loanBO, asOfDate);
    assertThat(errors, is(not(nullValue())));
    assertThat(errors.hasErrors(), is(false));
    verify(scheduleCalculatorAdaptor).computeExtraInterest(loanBO, asOfDate);
}
Also used : Errors(org.mifos.platform.validations.Errors) Date(java.util.Date) Test(org.junit.Test)

Example 22 with Errors

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

the class LoanBusinessServiceTest method shouldComputeExtraInterestAsOfDateEarlierThanLastPaymentDate.

@Test
public void shouldComputeExtraInterestAsOfDateEarlierThanLastPaymentDate() {
    Date asOfDate = TestUtils.getDate(1, 9, 2010);
    Date lastPaymentDate = TestUtils.getDate(10, 9, 2010);
    when(accountPaymentEntity.getPaymentDate()).thenReturn(lastPaymentDate);
    when(loanBO.findMostRecentNonzeroPaymentByPaymentDate()).thenReturn(accountPaymentEntity);
    when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(true);
    Errors errors = loanBusinessService.computeExtraInterest(loanBO, asOfDate);
    assertThat(errors, is(not(nullValue())));
    assertThat(errors.hasErrors(), is(true));
    List<ErrorEntry> errorEntries = errors.getErrorEntries();
    assertThat(errorEntries, is(not(nullValue())));
    assertThat(errorEntries.size(), is(1));
    assertThat(errorEntries.get(0).getErrorCode(), is(LoanConstants.CANNOT_VIEW_REPAYMENT_SCHEDULE));
    verify(scheduleCalculatorAdaptor, never()).computeExtraInterest(loanBO, asOfDate);
}
Also used : Errors(org.mifos.platform.validations.Errors) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date) Test(org.junit.Test)

Example 23 with Errors

use of org.mifos.platform.validations.Errors 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)

Example 24 with Errors

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

the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.

@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    try {
        personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
    if (errors.hasErrors()) {
        throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
    }
    List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
    for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
        LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
        Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
        List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
        for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
            feeDtos.add(convertToDto(feeEntity));
        }
        loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
    }
    return loanSchedule;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) UserContext(org.mifos.security.util.UserContext) LoanRepaymentScheduleItemDto(org.mifos.dto.domain.LoanRepaymentScheduleItemDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountFeeScheduleDto(org.mifos.dto.domain.AccountFeeScheduleDto) Errors(org.mifos.platform.validations.Errors) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 25 with Errors

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

the class LoanAccountAction method getGroupLoanRepaymentSchedule.

@TransactionDemarcate(joinToken = true)
public ActionForward getGroupLoanRepaymentSchedule(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    UserContext userContext = getUserContext(request);
    Integer grouploanId = Integer.valueOf(request.getParameter(ACCOUNT_ID));
    Locale locale = userContext.getPreferredLocale();
    Date viewDate = loanAccountActionForm.getScheduleViewDateValue(locale);
    LoanBO groupLoan = getLoan(grouploanId);
    LoanAccountAction.setSessionAtributeForGLIM(request, groupLoan);
    groupLoan.updateDetails(userContext);
    Errors errors = loanBusinessService.computeExtraInterest(groupLoan, viewDate);
    if (errors.hasErrors()) {
        loanAccountActionForm.resetScheduleViewDate();
    }
    List<LoanBO> membersAccount = this.loanDao.findIndividualLoans(grouploanId);
    List<Integer> membersAccountIds = getMembersAccountId(membersAccount);
    OriginalScheduleInfoDto generatedSchedule = OriginalScheduleInfoHelper.sumRepaymentSchedule(getMembersSchedule(membersAccountIds));
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, groupLoan, request);
    SessionUtils.setAttribute(Constants.VIEW_DATE, viewDate, request);
    SessionUtils.setAttribute(Constants.ORIGINAL_SCHEDULE_AVAILABLE, generatedSchedule.hasOriginalInstallments(), request);
    SessionUtils.setAttribute("isNewGropLoan", Boolean.TRUE, request);
    String forward = errors.hasErrors() ? ActionForwards.getLoanRepaymentScheduleFailure.toString() : ActionForwards.getLoanRepaymentSchedule.toString();
    addErrors(request, getActionErrors(errors));
    return mapping.findForward(forward);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) ActionErrors(org.apache.struts.action.ActionErrors) Errors(org.mifos.platform.validations.Errors) UserContext(org.mifos.security.util.UserContext) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

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