Search in sources :

Example 31 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class QuestionGroupController method addQuestion.

public String addQuestion(QuestionGroupForm questionGroupForm, RequestContext requestContext) {
    MessageContext context = requestContext.getMessageContext();
    boolean result = validateQuestion(questionGroupForm, context);
    if (result) {
        questionGroupForm.addCurrentSection();
    }
    return result ? "success" : "failure";
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Example 32 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class QuestionController method addQuestion.

public String addQuestion(QuestionForm questionForm, RequestContext requestContext, boolean createMode) {
    MessageContext context = requestContext.getMessageContext();
    boolean result = validateQuestion(questionForm, context, createMode);
    if (result) {
        questionForm.addCurrentQuestion();
    }
    return result ? "success" : "failure";
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Example 33 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class LoanAccountFormBean method validateEnterAccountDetailsStep.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "SIC_INNER_SHOULD_BE_STATIC_ANON" }, justification = "")
public void validateEnterAccountDetailsStep(ValidationContext context) {
    MessageContext messageContext = context.getMessageContext();
    Errors errors = validator.checkConstraints(this);
    // handle data binding errors that may of occurred
    if (messageContext.hasErrorMessages()) {
        Message[] errorMessages = messageContext.getMessagesByCriteria(new MessageCriteria() {

            @Override
            public boolean test(@SuppressWarnings("unused") Message message) {
                return true;
            }
        });
        messageContext.clearMessages();
        for (Message message : errorMessages) {
            handleDataMappingError(errors, message);
        }
    }
    if (this.glimApplicable || this.groupLoanWithMembersEnabled) {
        int index = 0;
        int selectedCount = 0;
        for (Boolean clientSelected : this.clientSelectForGroup) {
            if (clientSelected != null && clientSelected.booleanValue()) {
                Number clientAmount = this.clientAmount[index];
                if (clientAmount == null || exceedsMinOrMax(clientAmount, Integer.valueOf(1), this.maxAllowedAmount)) {
                    String defaultErrorMessage = "Please specify valid Amount.";
                    rejectGlimClientAmountField(index + 1, errors, defaultErrorMessage);
                }
                if (clientAmount != null) {
                    BigDecimal amountAsDecimal = new BigDecimal(clientAmount.toString()).stripTrailingZeros();
                    int places = amountAsDecimal.scale();
                    if (places > this.digitsAfterDecimalForMonetaryAmounts) {
                        String defaultErrorMessage = "The number of digits after the decimal separator exceeds the allowed number.";
                        rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.client.amount.digitsAfterDecimal.invalid", new Object[] { index + 1, this.digitsAfterDecimalForMonetaryAmounts });
                    }
                    int digitsBefore = amountAsDecimal.toBigInteger().toString().length();
                    if (digitsBefore > this.digitsBeforeDecimalForMonetaryAmounts) {
                        String defaultErrorMessage = "The number of digits before the decimal separator exceeds the allowed number.";
                        rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.client.amount.digitsBeforeDecimal.invalid", new Object[] { index + 1, this.digitsBeforeDecimalForMonetaryAmounts });
                    }
                }
                // check error message of loan purpose for each client when its mandatory..
                Integer clientLoanPurposeId = this.clientLoanPurposeId[index];
                if (this.purposeOfLoanMandatory && isInvalidSelection(clientLoanPurposeId)) {
                    errors.rejectValue("clientLoanPurposeId", "loanAccountFormBean.glim.purposeOfLoan.invalid", new Object[] { index + 1 }, "Please specify loan purpose.");
                    this.clientLoanPurposeId[index] = 0;
                } else {
                    // needed so attempt in freemarker(ftl) to display loan purpose doesnt fall over.
                    if (clientLoanPurposeId == null) {
                        this.clientLoanPurposeId[index] = 0;
                    }
                }
                selectedCount++;
            } else {
                Number clientAmount = this.clientAmount[index];
                Integer clientLoanPurposeId = this.clientLoanPurposeId[index];
                if (clientAmount != null || clientLoanPurposeId != null) {
                    String defaultErrorMessage = "You have entered details for a member you have not selected. Select the checkbox in front of the member's name in order to include him or her in the loan.";
                    rejectUnselectedGlimClientAmountField(index + 1, errors, defaultErrorMessage);
                }
            }
            index++;
        }
        if (selectedCount < 2) {
            String defaultErrorMessage = "Not enough clients for group loan.";
            rejectGroupLoanWithTooFewClients(errors, defaultErrorMessage);
        }
    }
    if (this.amount == null || exceedsMinOrMax(this.amount, this.minAllowedAmount, this.maxAllowedAmount)) {
        String defaultErrorMessage = "Please specify valid Amount.";
        if (glimApplicable) {
            defaultErrorMessage = "The sum of the amounts specified for each member is outside the allowable total amount for this loan product.";
            rejectGlimTotalAmountField(errors, defaultErrorMessage);
        } else {
            rejectAmountField(errors, defaultErrorMessage);
        }
    }
    if (this.amount != null) {
        BigDecimal amountAsDecimal = new BigDecimal(this.amount.toString()).stripTrailingZeros();
        int places = amountAsDecimal.scale();
        if (places > this.digitsAfterDecimalForMonetaryAmounts) {
            String defaultErrorMessage = "The number of digits after the decimal separator exceeds the allowed number.";
            rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.amount.digitsAfterDecimal.invalid", new Object[] { this.digitsAfterDecimalForMonetaryAmounts });
        }
        int digitsBefore = amountAsDecimal.toBigInteger().toString().length();
        if (digitsBefore > this.digitsBeforeDecimalForMonetaryAmounts) {
            String defaultErrorMessage = "The number of digits before the decimal separator exceeds the allowed number.";
            rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.amount.digitsBeforeDecimal.invalid", new Object[] { this.digitsBeforeDecimalForMonetaryAmounts });
        }
    }
    if (this.interestRate == null || exceedsMinOrMax(this.interestRate, this.minAllowedInterestRate, this.maxAllowedInterestRate)) {
        String defaultErrorMessage = "Please specify valid Interest rate.";
        rejectInterestRateField(errors, defaultErrorMessage);
    }
    if (this.interestRate != null) {
        BigDecimal interestRateAsDecimal = new BigDecimal(this.interestRate.toString()).stripTrailingZeros();
        int places = interestRateAsDecimal.scale();
        if (places > this.digitsAfterDecimalForInterest) {
            String defaultErrorMessage = "The number of digits after the decimal separator exceeds the allowed number.";
            rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.digitsAfterDecimalForInterest.invalid", new Object[] { this.digitsAfterDecimalForInterest });
        }
        int digitsBefore = interestRateAsDecimal.toBigInteger().toString().length();
        if (digitsBefore > this.digitsBeforeDecimalForInterest) {
            String defaultErrorMessage = "The number of digits before the decimal separator exceeds the allowed number.";
            rejectInterestRateFieldValue(errors, defaultErrorMessage, "loanAccountFormBean.digitsBeforeDecimalForInterest.invalid", new Object[] { this.digitsBeforeDecimalForInterest });
        }
    }
    if (this.numberOfInstallments == null || exceedsMinOrMax(this.numberOfInstallments, this.minNumberOfInstallments, this.maxNumberOfInstallments)) {
        String defaultErrorMessage = "Please specify valid number of installments.";
        rejectNumberOfInstallmentsField(errors, defaultErrorMessage);
    }
    if (this.graceDuration == null || this.graceDuration.intValue() < 0) {
        if (!errors.hasFieldErrors("graceDuration")) {
            String defaultErrorMessage = "Please specify valid Grace period for repayments. Grace period should be a value less than " + numberOfInstallments.intValue() + ".";
            rejectGraceDurationField(errors, defaultErrorMessage);
        }
    } else {
        if (this.graceDuration.intValue() > this.maxGraceDuration.intValue()) {
            String defaultErrorMessage = "The Grace period cannot be greater than in loan product definition.";
            errors.rejectValue("graceDuration", "loanAccountFormBean.gracePeriodDuration.invalid", defaultErrorMessage);
        }
        if (this.numberOfInstallments != null && (this.graceDuration.intValue() >= this.numberOfInstallments.intValue())) {
            String defaultErrorMessage = "Grace period for repayments must be less than number of loan installments.";
            errors.rejectValue("graceDuration", "loanAccountFormBean.gracePeriodDurationInRelationToInstallments.invalid", defaultErrorMessage);
        }
    }
    if (dateValidator == null) {
        dateValidator = new DateValidator();
    }
    if (!dateValidator.formsValidDate(this.disbursementDateDD, this.disbursementDateMM, this.disbursementDateYY)) {
        String defaultErrorMessage = "Please specify valid disbursal date.";
        rejectDisbursementDateField(errors, defaultErrorMessage, "disbursementDateDD", "loanAccountFormBean.DisbursalDate.invalid", "");
    } else {
        LocalDate validDate = new DateTime().withDate(disbursementDateYY.intValue(), disbursementDateMM.intValue(), disbursementDateDD.intValue()).toLocalDate();
        org.mifos.platform.validations.Errors disbursementDateErrors = new org.mifos.platform.validations.Errors();
        if (this.redoLoanAccount) {
            disbursementDateErrors = loanDisbursementDateValidationServiceFacade.validateLoanWithBackdatedPaymentsDisbursementDate(validDate, customerId, productId);
        } else {
            disbursementDateErrors = loanDisbursementDateValidationServiceFacade.validateLoanDisbursementDate(validDate, customerId, productId);
        }
        for (ErrorEntry entry : disbursementDateErrors.getErrorEntries()) {
            String defaultErrorMessage = "The disbursal date is invalid.";
            rejectDisbursementDateField(errors, defaultErrorMessage, "disbursementDateDD", entry.getErrorCode(), entry.getArgs().get(0));
        }
    }
    if (this.sourceOfFundsMandatory && isInvalidSelection(this.fundId)) {
        errors.rejectValue("fundId", "loanAccountFormBean.SourceOfFunds.invalid", "Please specify source of funds.");
    }
    if (this.externalIdMandatory && StringUtils.isBlank(this.externalId)) {
        errors.rejectValue("externalId", "loanAccountFormBean.externalid.invalid", "Please specify required external id.");
    }
    if (!this.glimApplicable && this.purposeOfLoanMandatory && isInvalidSelection(this.loanPurposeId)) {
        errors.rejectValue("loanPurposeId", "loanAccountFormBean.PurposeOfLoan.invalid", "Please specify loan purpose.");
    }
    validateAdministrativeAndAdditionalFees(errors);
    if (this.repaymentScheduleIndependentOfCustomerMeeting) {
        if (isInvalidRecurringFrequency(this.repaymentRecursEvery)) {
            errors.rejectValue("repaymentRecursEvery", "loanAccountFormBean.repaymentDay.recursEvery.invalid", "Please specify a valid recurring frequency for repayment day.");
        }
        if (this.weekly) {
            if (isInvalidDayOfWeekSelection()) {
                errors.rejectValue("repaymentDayOfWeek", "loanAccountFormBean.repaymentDay.weekly.dayOfWeek.invalid", "Please select a day of the week for repayment day.");
            }
        } else if (this.monthly) {
            if (this.monthlyDayOfMonthOptionSelected) {
                if (isInvalidDayOfMonthEntered()) {
                    errors.rejectValue("repaymentDayOfMonth", "loanAccountFormBean.repaymentDay.monthly.dayOfMonth.invalid", "Please select a day of the month for repayment day.");
                }
            } else if (this.monthlyWeekOfMonthOptionSelected) {
                if (isInvalidWeekOfMonthSelection()) {
                    errors.rejectValue("repaymentWeekOfMonth", "loanAccountFormBean.repaymentDay.monthly.weekOfMonth.invalid", "Please select a week of the month for repayment day.");
                }
                if (isInvalidDayOfWeekSelection()) {
                    errors.rejectValue("repaymentDayOfWeek", "loanAccountFormBean.repaymentDay.monthly.dayOfWeek.invalid", "Please select a day of the week for repayment day.");
                }
            }
        }
        if (this.variableInstallmentsAllowed) {
            if (this.selectedFeeId != null) {
                for (Number feeId : this.selectedFeeId) {
                    if (feeId != null) {
                        VariableInstallmentWithFeeValidationResult result = variableInstallmentsFeeValidationServiceFacade.validateFeeCanBeAppliedToVariableInstallmentLoan(feeId.longValue());
                        if (!result.isFeeCanBeAppliedToVariableInstallmentLoan()) {
                            errors.rejectValue("selectedFeeId", "loanAccountFormBean.additionalfees.variableinstallments.invalid", new String[] { result.getFeeName() }, "This type of fee cannot be applied to loan with variable installments.");
                        }
                    }
                }
            }
            int defaultFeeIndex = 0;
            if (this.defaultFeeId != null) {
                for (Number feeId : this.defaultFeeId) {
                    if (feeId != null) {
                        Boolean feeSelectedForRemoval = this.defaultFeeSelected[defaultFeeIndex];
                        if (feeSelectedForRemoval == null || !feeSelectedForRemoval) {
                            VariableInstallmentWithFeeValidationResult result = variableInstallmentsFeeValidationServiceFacade.validateFeeCanBeAppliedToVariableInstallmentLoan(feeId.longValue());
                            if (!result.isFeeCanBeAppliedToVariableInstallmentLoan()) {
                                errors.rejectValue("selectedFeeId", "loanAccountFormBean.defaultfees.variableinstallments.invalid", new String[] { result.getFeeName() }, "This type of fee cannot be applied to loan with variable installments.");
                            }
                        }
                    }
                    defaultFeeIndex++;
                }
            }
        }
    }
    if (errors.hasErrors()) {
        for (FieldError fieldError : errors.getFieldErrors()) {
            MessageBuilder builder = new MessageBuilder().error().source(fieldError.getField()).codes(fieldError.getCodes()).defaultText(fieldError.getDefaultMessage()).args(fieldError.getArguments());
            messageContext.addMessage(builder.build());
        }
    }
}
Also used : Message(org.springframework.binding.message.Message) VariableInstallmentWithFeeValidationResult(org.mifos.clientportfolio.newloan.applicationservice.VariableInstallmentWithFeeValidationResult) FieldError(org.springframework.validation.FieldError) LocalDate(org.joda.time.LocalDate) ErrorEntry(org.mifos.platform.validations.ErrorEntry) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) Errors(org.springframework.validation.Errors) MessageBuilder(org.springframework.binding.message.MessageBuilder) MessageCriteria(org.springframework.binding.message.MessageCriteria) MessageContext(org.springframework.binding.message.MessageContext)

Example 34 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class LoanScheduleFormBean method validateCalculateAndReviewLoanSchedule.

/**
     * validateXXXX is invoked on transition from state
     */
public void validateCalculateAndReviewLoanSchedule(ValidationContext context) {
    MessageContext messageContext = context.getMessageContext();
    if (this.variableInstallmentsAllowed) {
        prevalidateDueDateIsNonNull(messageContext);
        prevalidateActualPaymentDateIsNonNull(messageContext);
        prevalidateTotalIsNonNull(messageContext);
        prevalidateAmountPaidIsNonNull(messageContext);
        if (!messageContext.hasErrorMessages()) {
            boolean resetRedoLoanAccountDetails = false;
            LoanScheduleDto recalculatedLoanSchedule = this.loanAccountController.retrieveLoanSchedule(customerId, loanAccountFormBean.getProductId(), loanAccountFormBean, this, resetRedoLoanAccountDetails);
            // 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);
        handleErrors(messageContext, inputInstallmentsErrors, scheduleErrors);
    } else {
        prevalidateAmountPaidIsNonNull(messageContext);
        for (int index = 0; index < this.actualPaymentAmounts.size(); index++) {
            Double newTotal = Double.valueOf("0.0");
            Number newTotalEntry = this.actualPaymentAmounts.get(index);
            if (newTotalEntry != null) {
                newTotal = newTotalEntry.doubleValue();
            } else {
                this.actualPaymentAmounts.set(index, newTotal);
            }
        }
    }
    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())));
        }
    }
}
Also used : LoanScheduleDto(org.mifos.dto.screen.LoanScheduleDto) ArrayList(java.util.ArrayList) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Errors(org.mifos.platform.validations.Errors) MessageContext(org.springframework.binding.message.MessageContext)

Example 35 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class CustomerSearchFormBean method validateSelectCustomerStep.

public void validateSelectCustomerStep(ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    validator.validate(this, messages);
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Aggregations

MessageContext (org.springframework.binding.message.MessageContext)51 Test (org.junit.Test)18 Message (org.springframework.binding.message.Message)16 MessageBuilder (org.springframework.binding.message.MessageBuilder)9 ArrayList (java.util.ArrayList)5 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)4 UnsatisfiedAuthenticationPolicyException (org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException)4 LocalDate (org.joda.time.LocalDate)4 BigDecimal (java.math.BigDecimal)3 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 DateTime (org.joda.time.DateTime)3 LoanCreationInstallmentDto (org.mifos.dto.domain.LoanCreationInstallmentDto)2 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2