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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations