use of org.springframework.binding.message.MessageContext in project head by mifos.
the class QuestionGroupController method addSmartChoiceTag.
public String addSmartChoiceTag(QuestionGroupForm questionGroupForm, RequestContext requestContext, int choiceIndex) {
MessageContext context = requestContext.getMessageContext();
boolean result = validateSmartChoice(questionGroupForm, context, choiceIndex);
if (result)
questionGroupForm.getCurrentQuestion().addSmartChoiceTag(choiceIndex);
return result ? "success" : "failure";
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class CashFlowValidator method validateCaptureCashFlow.
public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) {
MessageContext messageContext = context.getMessageContext();
for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) {
validateExpense(messageContext, monthlyCashFlowForm);
validateRevenue(messageContext, monthlyCashFlowForm);
validateNotes(messageContext, monthlyCashFlowForm);
}
validateCumulativeCashFlow(cashFlow, messageContext);
validateTotalCapitalAndLiability(cashFlow, messageContext);
validateIndebtednessRatio(cashFlow, messageContext);
setTotalsOnCashFlowForm(cashFlow, messageContext);
}
use of org.springframework.binding.message.MessageContext 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.springframework.binding.message.MessageContext in project head by mifos.
the class SelectProductFormBean method validateSelectLoanProductStep.
/**
* validateXXXX is invoked on transition from state
*/
public void validateSelectLoanProductStep(ValidationContext context) {
MessageContext messages = context.getMessageContext();
validator.validate(this, messages);
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class AccountDetailFormBean method validateEnterAccountDetailsStep.
public void validateEnterAccountDetailsStep(ValidationContext context) {
MessageContext messages = context.getMessageContext();
validator.validate(this, messages);
// TODO: need to get access to domain constants from controller ...
// public static final short SAVINGS_MANDATORY= 1;
// public static final short SAVINGS_VOLUNTARY= 2;
// validate recommended amount
// final Integer depositType =
// productReference.getSavingsProductDetails()
// .getDepositType();
// if (depositType == 1) { // mandatory
// result = true;
// } else if (depositType == 2) { // voluntary
// result = true;
// }
}
Aggregations