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