use of org.mifos.platform.validations.ErrorEntry in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveGetProductDetailsForLoanAccountCreation.
@Override
public LoanCreationProductDetailsDto retrieveGetProductDetailsForLoanAccountCreation(final Integer customerId) {
final CustomerBO customer = this.customerDao.findCustomerById(customerId);
final CustomerDetailDto customerDetailDto = customer.toCustomerDetailDto();
// FIXME - keithw - below code is not needed when jsp/struts is removed as this is worked out for enter loan account details step.
final Date nextMeetingDate = customer.getCustomerAccount().getNextMeetingDate();
final String recurMonth = customer.getCustomerMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString();
final boolean isGroup = customer.isGroup();
final boolean isGlimEnabled = configurationPersistence.isGlimEnabled();
final boolean isLsimEnabled = configurationPersistence.isRepaymentIndepOfMeetingEnabled();
final boolean isGroupLoanWithMembersEnabled = AccountingRules.isGroupLoanWithMembers();
List<PrdOfferingDto> loanProductDtos = retrieveActiveLoanProductsApplicableForCustomer(customer, isLsimEnabled);
LoanCreationGlimDto loanCreationGlimDto = null;
List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
Errors errors = new Errors();
List<ErrorEntry> errorEntry = new ArrayList<ErrorEntry>();
if (isGroup && isGlimEnabled && isGroupLoanWithMembersEnabled) {
String defaultMessage = "New Group Loan option is enabled in configuration file and also GLIM option is enabled in the database. Loan for Group will be created using new Group Loan approach. Please turn off GLIM option in database. If you want to create Loan for Group using old approach, then please disable AccountingRules.GroupLoanWithMembers option in configuration file and restart Mifos.";
errorEntry.add(new ErrorEntry("createLoanAccount.glim.and.new.glim.are.enabled", "activeClients2", defaultMessage));
errors.addErrors(errorEntry);
}
if (isGroup && (isGlimEnabled || isGroupLoanWithMembersEnabled)) {
final List<ValueListElement> loanPurposes = loanProductDao.findAllLoanPurposes();
final List<ClientBO> activeClientsOfGroup = customerDao.findActiveClientsUnderGroup(customer);
loanCreationGlimDto = new LoanCreationGlimDto(loanPurposes);
if (activeClientsOfGroup == null || activeClientsOfGroup.size() < 2) {
errorEntry.clear();
String defaultMessage = "Group loan is not allowed as there must be at least two active clients within the group when Group loan with individual monitoring (GLIM) is enabled";
errorEntry.add(new ErrorEntry("createLoanAccount.glim.invalid.less.than.two.active.clients.in.group", "activeClients", defaultMessage));
errors.addErrors(errorEntry);
loanProductDtos = new ArrayList<PrdOfferingDto>();
} else {
for (ClientBO client : activeClientsOfGroup) {
LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
clientDetail.setClientId(client.getCustomerId().toString());
clientDetail.setClientName(client.getDisplayName());
clientDetails.add(clientDetail);
}
}
}
return new LoanCreationProductDetailsDto(loanProductDtos, customerDetailDto, nextMeetingDate, recurMonth, isGroup, isGlimEnabled, loanCreationGlimDto, clientDetails, errors);
}
use of org.mifos.platform.validations.ErrorEntry in project head by mifos.
the class BranchReportParameterValidatorTest method testValidatorAddsErrorIfServiceSaysNoDataFound.
public void testValidatorAddsErrorIfServiceSaysNoDataFound() throws Exception {
expect(branchReportServiceMock.isReportDataPresentForRundateAndBranchId(BRANCH_ID, VALID_RUN_DATE)).andReturn(Boolean.FALSE);
replay(branchReportServiceMock);
validator.validate(validForm, errors);
verify(branchReportServiceMock);
Assert.assertTrue(errors.hasErrors());
ErrorEntry fieldError = errors.getFieldError(ReportValidationConstants.RUN_DATE_PARAM);
Assert.assertNotNull(fieldError);
Assert.assertEquals(ReportValidationConstants.BRANCH_REPORT_NO_DATA_FOUND_MSG, fieldError.getErrorCode());
}
use of org.mifos.platform.validations.ErrorEntry in project head by mifos.
the class CashFlowSummaryFormBean method prevalidateTotalIsNonNull.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "DLS_DEAD_LOCAL_STORE" }, justification = "")
private void prevalidateTotalIsNonNull(MessageContext messageContext) {
Integer installmentIndex = 1;
for (Number totalAmount : this.installmentAmounts) {
if (totalAmount == null) {
String defaultMessage = "The total amount field for installment {0} was blank and has been defaulted to zero.";
ErrorEntry fieldError = new ErrorEntry("installment.total.amount.blank.and.invalid", "installmentAmounts", defaultMessage);
fieldError.setArgs(Arrays.asList(installmentIndex.toString()));
this.installmentAmounts.set(installmentIndex - 1, Integer.valueOf(0));
addErrorMessageToContext(messageContext, fieldError);
}
installmentIndex++;
}
}
use of org.mifos.platform.validations.ErrorEntry in project head by mifos.
the class CashFlowSummaryFormBean method validateSummaryOfCashflow.
/**
* validateXXXX is invoked on transition from state
*/
public void validateSummaryOfCashflow(ValidationContext context) {
MessageContext messageContext = context.getMessageContext();
if (this.variableInstallmentsAllowed) {
prevalidateDueDateIsNonNull(messageContext);
prevalidateActualPaymentDateIsNonNull(messageContext);
prevalidateTotalIsNonNull(messageContext);
prevalidateAmountPaidIsNonNull(messageContext);
if (!messageContext.hasErrorMessages()) {
LoanScheduleDto recalculatedLoanSchedule = this.loanAccountController.retrieveLoanSchedule(customerId, productId, loanAccountFormBean, this, false);
// set values on fields
this.variableInstallments = recalculatedLoanSchedule.getInstallments();
int installIndex = 0;
for (LoanCreationInstallmentDto installment : this.variableInstallments) {
this.installmentAmounts.set(installIndex, installment.getTotal());
installIndex++;
}
}
Errors inputInstallmentsErrors = loanAccountServiceFacade.validateInputInstallments(disbursementDate, minGapInDays, maxGapInDays, minInstallmentAmount, variableInstallments, customerId);
Errors scheduleErrors = loanAccountServiceFacade.validateInstallmentSchedule(variableInstallments, minInstallmentAmount);
if (inputInstallmentsErrors.hasErrors()) {
for (ErrorEntry fieldError : inputInstallmentsErrors.getErrorEntries()) {
addErrorMessageToContext(messageContext, fieldError);
}
}
if (scheduleErrors.hasErrors()) {
for (ErrorEntry fieldError : scheduleErrors.getErrorEntries()) {
addErrorMessageToContext(messageContext, fieldError);
}
}
} else {
prevalidateTotalIsNonNull(messageContext);
for (int index = 0; index < this.installmentAmounts.size(); index++) {
Double newTotal = Double.valueOf("0.0");
Number newTotalEntry = this.installmentAmounts.get(index);
if (newTotalEntry != null) {
newTotal = newTotalEntry.doubleValue();
} else {
this.installmentAmounts.set(index, newTotal);
}
}
}
if (!messageContext.hasErrorMessages()) {
DateTime firstInstallmentDueDate = installments.get(0);
DateTime lastInstallmentDueDate = installments.get(installments.size() - 1);
this.loanInstallmentsDto = new LoanInstallmentsDto(this.loanInstallmentsDto.getLoanAmount(), this.loanInstallmentsDto.getTotalInstallmentAmount(), firstInstallmentDueDate.toDate(), lastInstallmentDueDate.toDate());
Errors warnings = loanAccountServiceFacade.validateCashFlowForInstallmentsForWarnings(cashFlowDataDtos, productId);
Errors errors = loanAccountServiceFacade.validateCashFlowForInstallments(loanInstallmentsDto, monthlyCashFlows, repaymentCapacity, cashFlowTotalBalance);
if (warnings.hasErrors()) {
for (ErrorEntry fieldError : warnings.getErrorEntries()) {
addErrorMessageToContext(messageContext, fieldError);
}
}
if (errors.hasErrors()) {
for (ErrorEntry fieldError : errors.getErrorEntries()) {
addErrorMessageToContext(messageContext, fieldError);
}
}
}
List<LoanRepaymentTransaction> loanRepaymentTransaction = new ArrayList<LoanRepaymentTransaction>();
this.loanRepaymentPaidInstallmentsWithRunningBalance = new ArrayList<LoanRepaymentRunningBalance>();
this.loanRepaymentFutureInstallments = new ArrayList<LoanRepaymentFutureInstallments>();
// if any actual payment data exists, calculate
validatePaymentsAndAmounts(messageContext, this.actualPaymentDates, this.actualPaymentAmounts);
List<LoanInstallmentPostPayment> installmentsPostPayment = new ArrayList<LoanInstallmentPostPayment>();
int paymentIndex = 0;
if (!messageContext.hasErrorMessages()) {
for (Number actualPayment : this.actualPaymentAmounts) {
BigDecimal remainingPayment = BigDecimal.valueOf(actualPayment.doubleValue());
LocalDate paymentDate = new LocalDate(this.actualPaymentDates.get(paymentIndex));
loanRepaymentTransaction.add(new LoanRepaymentTransaction(paymentDate, remainingPayment));
int installmentIndex = 0;
while (remainingPayment.doubleValue() > BigDecimal.ZERO.doubleValue() && installmentIndex < this.actualPaymentAmounts.size()) {
LoanCreationInstallmentDto installmentDetails = this.repaymentInstallments.get(installmentIndex);
Double installmentTotalAmount = this.installmentAmounts.get(installmentIndex).doubleValue();
LocalDate dueDate = new LocalDate(this.installments.get(installmentIndex));
if (installmentsPostPayment.isEmpty() || installmentsPostPayment.size() <= installmentIndex) {
BigDecimal feesPaid = BigDecimal.valueOf(installmentDetails.getFees());
if (remainingPayment.doubleValue() >= installmentDetails.getFees()) {
remainingPayment = remainingPayment.subtract(feesPaid);
} else {
feesPaid = remainingPayment;
remainingPayment = remainingPayment.subtract(feesPaid);
}
BigDecimal interestPaid = BigDecimal.valueOf(installmentDetails.getInterest());
if (remainingPayment.doubleValue() >= installmentDetails.getInterest()) {
remainingPayment = remainingPayment.subtract(interestPaid);
} else {
interestPaid = remainingPayment;
remainingPayment = remainingPayment.subtract(interestPaid);
}
BigDecimal principalPaid = BigDecimal.valueOf(installmentDetails.getPrincipal());
if (remainingPayment.doubleValue() >= installmentDetails.getPrincipal()) {
remainingPayment = remainingPayment.subtract(principalPaid);
} else {
principalPaid = remainingPayment;
remainingPayment = remainingPayment.subtract(principalPaid);
}
BigDecimal totalInstallmentPaid = feesPaid.add(interestPaid).add(principalPaid);
LoanInstallmentPostPayment loanInstallmentPostPayment = new LoanInstallmentPostPayment(installmentDetails.getInstallmentNumber(), dueDate, paymentDate, feesPaid, interestPaid, principalPaid, totalInstallmentPaid, installmentTotalAmount);
installmentsPostPayment.add(loanInstallmentPostPayment);
} else {
LoanInstallmentPostPayment paidInstallment = installmentsPostPayment.get(installmentIndex);
if (paidInstallment.isNotFullyPaid()) {
BigDecimal feesToBePaid = BigDecimal.valueOf(installmentDetails.getFees()).subtract(paidInstallment.getFeesPaid());
if (remainingPayment.doubleValue() >= feesToBePaid.doubleValue()) {
remainingPayment = remainingPayment.subtract(feesToBePaid);
} else {
feesToBePaid = remainingPayment;
remainingPayment = remainingPayment.subtract(feesToBePaid);
}
BigDecimal interestToBePaid = BigDecimal.valueOf(installmentDetails.getInterest()).subtract(paidInstallment.getInterestPaid());
if (remainingPayment.doubleValue() >= interestToBePaid.doubleValue()) {
remainingPayment = remainingPayment.subtract(interestToBePaid);
} else {
interestToBePaid = remainingPayment;
remainingPayment = remainingPayment.subtract(interestToBePaid);
}
BigDecimal principalToBePaid = BigDecimal.valueOf(installmentDetails.getPrincipal()).subtract(paidInstallment.getPrincipalPaid());
if (remainingPayment.doubleValue() >= principalToBePaid.doubleValue()) {
remainingPayment = remainingPayment.subtract(principalToBePaid);
} else {
principalToBePaid = remainingPayment;
remainingPayment = remainingPayment.subtract(principalToBePaid);
}
BigDecimal totalInstallmentPaid = feesToBePaid.add(interestToBePaid).add(principalToBePaid);
paidInstallment.setLastPaymentDate(paymentDate);
paidInstallment.setFeesPaid(paidInstallment.getFeesPaid().add(feesToBePaid));
paidInstallment.setInterestPaid(paidInstallment.getInterestPaid().add(interestToBePaid));
paidInstallment.setPrincipalPaid(paidInstallment.getPrincipalPaid().add(principalToBePaid));
paidInstallment.setTotalInstallmentPaid(paidInstallment.getTotalInstallmentPaid().add(totalInstallmentPaid));
}
}
installmentIndex++;
}
paymentIndex++;
}
}
// remaining running balance
BigDecimal cumulativeFeesPaid = BigDecimal.ZERO;
BigDecimal cumulativeInterestPaid = BigDecimal.ZERO;
BigDecimal cumulativePrincipalPaid = BigDecimal.ZERO;
BigDecimal cumulativeTotalInstallmentPaid = BigDecimal.ZERO;
for (LoanInstallmentPostPayment installment : installmentsPostPayment) {
cumulativeFeesPaid = cumulativeFeesPaid.add(installment.getFeesPaid());
cumulativeInterestPaid = cumulativeInterestPaid.add(installment.getInterestPaid());
cumulativePrincipalPaid = cumulativePrincipalPaid.add(installment.getPrincipalPaid());
cumulativeTotalInstallmentPaid = cumulativeTotalInstallmentPaid.add(installment.getTotalInstallmentPaid());
if (installment.isNotFullyPaid()) {
BigDecimal remainingFees = this.totalLoanFees.subtract(cumulativeFeesPaid);
BigDecimal remainingInterest = this.totalLoanInterest.subtract(cumulativeInterestPaid);
BigDecimal remainingTotalInstallment = this.loanPrincipal.add(this.totalLoanFees).add(this.totalLoanInterest).subtract(cumulativeTotalInstallmentPaid);
BigDecimal remainingPrincipal = remainingTotalInstallment.subtract(remainingInterest).subtract(remainingFees);
LoanCreationInstallmentDto installmentDetails = this.repaymentInstallments.get(installment.getInstallmentNumber() - 1);
LoanCreationInstallmentDto installmentPaidDetails = new LoanCreationInstallmentDto(installment.getInstallmentNumber(), new LocalDate(installmentDetails.getDueDate()), installment.getPrincipalPaid().doubleValue(), installment.getInterestPaid().doubleValue(), installment.getFeesPaid().doubleValue(), BigDecimal.ZERO.doubleValue(), installment.getTotalInstallmentPaid().doubleValue());
this.loanRepaymentPaidInstallmentsWithRunningBalance.add(new LoanRepaymentRunningBalance(installmentPaidDetails, installment.getTotalInstallmentPaid(), remainingPrincipal, remainingInterest, remainingFees, remainingTotalInstallment, installment.getLastPaymentDate(), this.actualPaymentTypes.get(installment.getInstallmentNumber() - 1)));
BigDecimal outstandingInstallmentPrincipal = BigDecimal.valueOf(installmentDetails.getPrincipal()).subtract(installment.getPrincipalPaid());
BigDecimal outstandingInstallmentInterest = BigDecimal.valueOf(installmentDetails.getInterest()).subtract(installment.getInterestPaid());
BigDecimal outstandingInstallmentFees = BigDecimal.valueOf(installmentDetails.getFees()).subtract(installment.getFeesPaid());
this.loanRepaymentFutureInstallments.add(new LoanRepaymentFutureInstallments(installmentDetails.getInstallmentNumber(), installmentDetails.getDueDate(), outstandingInstallmentPrincipal, outstandingInstallmentInterest, outstandingInstallmentFees, outstandingInstallmentPrincipal.add(outstandingInstallmentInterest).add(outstandingInstallmentFees)));
} else {
BigDecimal remainingFees = this.totalLoanFees.subtract(cumulativeFeesPaid);
BigDecimal remainingInterest = this.totalLoanInterest.subtract(cumulativeInterestPaid);
BigDecimal remainingTotalInstallment = this.loanPrincipal.add(this.totalLoanFees).add(this.totalLoanInterest).subtract(cumulativeTotalInstallmentPaid);
BigDecimal remainingPrincipal = remainingTotalInstallment.subtract(remainingInterest).subtract(remainingFees);
LoanCreationInstallmentDto installmentDetails = this.repaymentInstallments.get(installment.getInstallmentNumber() - 1);
this.loanRepaymentPaidInstallmentsWithRunningBalance.add(new LoanRepaymentRunningBalance(installmentDetails, installment.getTotalInstallmentPaid(), remainingPrincipal, remainingInterest, remainingFees, remainingTotalInstallment, installment.getLastPaymentDate(), this.actualPaymentTypes.get(installment.getInstallmentNumber() - 1)));
}
}
int lastHandledFutureInstallmentNumber = loanRepaymentPaidInstallmentsWithRunningBalance.size();
if (!this.loanRepaymentFutureInstallments.isEmpty()) {
lastHandledFutureInstallmentNumber = this.loanRepaymentFutureInstallments.get(this.loanRepaymentFutureInstallments.size() - 1).getInstallmentNumber();
}
for (LoanCreationInstallmentDto installmentDto : this.repaymentInstallments) {
if (installmentDto.getInstallmentNumber() > lastHandledFutureInstallmentNumber) {
this.loanRepaymentFutureInstallments.add(new LoanRepaymentFutureInstallments(installmentDto.getInstallmentNumber(), installmentDto.getDueDate(), BigDecimal.valueOf(installmentDto.getPrincipal()), BigDecimal.valueOf(installmentDto.getInterest()), BigDecimal.valueOf(installmentDto.getFees()), BigDecimal.valueOf(installmentDto.getTotal())));
}
}
}
use of org.mifos.platform.validations.ErrorEntry in project head by mifos.
the class CashFlowSummaryFormBean method validatePaymentsAndAmounts.
private void validatePaymentsAndAmounts(MessageContext messageContext, List<DateTime> actualPaymentDates, List<Number> actualPaymentAmounts) {
int index = 0;
LocalDate lastPaymentDate = null;
BigDecimal totalPayment = BigDecimal.ZERO;
for (Number actualPayment : actualPaymentAmounts) {
String installment = Integer.valueOf(index + 1).toString();
LocalDate paymentDate = new LocalDate(actualPaymentDates.get(index));
if (paymentDate.isBefore(new LocalDate(this.disbursementDate))) {
String defaultMessage = "The payment date cannot be before disbursement date";
ErrorEntry fieldError = new ErrorEntry("paymentDate.before.disbursementDate.invalid", "disbursementDate", defaultMessage);
fieldError.setArgs(Arrays.asList(installment));
addErrorMessageToContext(messageContext, fieldError);
}
if (paymentDate.isAfter(new LocalDate()) && actualPayment.doubleValue() > 0) {
String defaultMessage = "The payment date cannot be in the future.";
ErrorEntry fieldError = new ErrorEntry("paymentDate.is.future.date.invalid", "disbursementDate", defaultMessage);
fieldError.setArgs(Arrays.asList(installment));
addErrorMessageToContext(messageContext, fieldError);
}
if (lastPaymentDate != null) {
if (!paymentDate.isEqual(lastPaymentDate) && !paymentDate.isAfter(lastPaymentDate)) {
String defaultMessage = "The payment date cannot be before the previous payment date";
ErrorEntry fieldError = new ErrorEntry("paymentDate.before.lastPaymentDate.invalid", "disbursementDate", defaultMessage);
fieldError.setArgs(Arrays.asList(installment));
addErrorMessageToContext(messageContext, fieldError);
}
}
BigDecimal payment = BigDecimal.valueOf(actualPayment.doubleValue());
if (payment.doubleValue() > BigDecimal.ZERO.doubleValue()) {
totalPayment = totalPayment.add(payment);
}
index++;
lastPaymentDate = paymentDate;
}
BigDecimal totalAllowedPayments = this.loanPrincipal.add(this.totalLoanFees).add(this.totalLoanInterest);
if (totalPayment.doubleValue() > totalAllowedPayments.doubleValue()) {
String defaultMessage = "Exceeds total payments allowed for loan.";
ErrorEntry fieldError = new ErrorEntry("totalPayments.exceeded.invalid", "disbursementDate", defaultMessage);
addErrorMessageToContext(messageContext, fieldError);
}
}
Aggregations