Search in sources :

Example 6 with PenaltyDto

use of org.mifos.dto.domain.PenaltyDto in project head by mifos.

the class LoanControllerHelper method populateFormBeanFromDto.

public void populateFormBeanFromDto(int customerId, int productId, LoanAccountFormBean formBean, BackdatedPaymentable loanScheduleFormBean, LocalDate disbursementDate, LoanScheduleDto loanSchedule, boolean resetActualPaymentDatesAndAmountsForRedoLoan) {
    List<DateTime> installments = new ArrayList<DateTime>();
    List<DateTime> actualPaymentDates = new ArrayList<DateTime>();
    List<Number> installmentAmounts = new ArrayList<Number>();
    List<Number> actualPaymentAmounts = new ArrayList<Number>();
    List<Short> actualPaymentTypes = new ArrayList<Short>();
    BigDecimal totalLoanInterest = BigDecimal.ZERO;
    BigDecimal totalLoanFees = BigDecimal.ZERO;
    for (LoanCreationInstallmentDto installment : loanSchedule.getInstallments()) {
        totalLoanInterest = totalLoanInterest.add(BigDecimal.valueOf(installment.getInterest()));
        totalLoanFees = totalLoanFees.add(BigDecimal.valueOf(installment.getFees()));
        installments.add(new DateTime(installment.getDueDate()));
        actualPaymentDates.add(new DateTime(installment.getDueDate()));
        installmentAmounts.add(installment.getTotal());
        if (new LocalDate(installment.getDueDate()).isBefore(new LocalDate().plusDays(1))) {
            actualPaymentAmounts.add(installment.getTotal());
        } else {
            actualPaymentAmounts.add(Double.valueOf("0.0"));
        }
        actualPaymentTypes.add(null);
    }
    loanScheduleFormBean.setInstallments(installments);
    loanScheduleFormBean.setVariableInstallments(loanSchedule.getInstallments());
    loanScheduleFormBean.setInstallmentAmounts(installmentAmounts);
    if (resetActualPaymentDatesAndAmountsForRedoLoan) {
        loanScheduleFormBean.setActualPaymentDates(actualPaymentDates);
        loanScheduleFormBean.setActualPaymentAmounts(actualPaymentAmounts);
        loanScheduleFormBean.setActualPaymentTypes(actualPaymentTypes);
    }
    loanScheduleFormBean.setLoanPrincipal(BigDecimal.valueOf(formBean.getAmount().doubleValue()));
    loanScheduleFormBean.setTotalLoanInterest(totalLoanInterest);
    loanScheduleFormBean.setTotalLoanFees(totalLoanFees);
    loanScheduleFormBean.setRepaymentInstallments(loanSchedule.getInstallments());
    if (disbursementDate != null) {
        loanScheduleFormBean.setDisbursementDate(disbursementDate.toDateMidnight().toDate());
    }
    // variable installments related
    loanScheduleFormBean.setVariableInstallmentsAllowed(formBean.isVariableInstallmentsAllowed());
    if (loanScheduleFormBean.isVariableInstallmentsAllowed()) {
        loanScheduleFormBean.setMinGapInDays(formBean.getMinGapInDays());
        loanScheduleFormBean.setMaxGapInDays(formBean.getMaxGapInDays());
        loanScheduleFormBean.setMinInstallmentAmount(formBean.getMinInstallmentAmount());
        loanScheduleFormBean.setCustomerId(formBean.getCustomerId());
        loanScheduleFormBean.setLoanAccountFormBean(formBean);
    }
    List<FeeDto> applicableFees = new ArrayList<FeeDto>();
    LoanCreationLoanDetailsDto dto = this.loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(customerId, Integer.valueOf(productId).shortValue(), formBean.isRedoLoanAccount());
    int feeIndex = 0;
    for (Boolean defaultFeeSelectedForRemoval : formBean.getDefaultFeeSelected()) {
        if (defaultFeeSelectedForRemoval == null || !defaultFeeSelectedForRemoval) {
            Integer feeId = formBean.getDefaultFeeId()[feeIndex].intValue();
            BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getDefaultFeeAmountOrRate()[feeIndex].doubleValue());
            applicableFees.add(findFeeById(dto.getDefaultFees(), feeId, amountOrRate));
        }
        feeIndex++;
    }
    List<PenaltyDto> applicablePenalties = new ArrayList<PenaltyDto>();
    int penaltyIndex = 0;
    for (Boolean defaultPenaltySelectedForRemoval : formBean.getDefaultPenaltySelected()) {
        if (defaultPenaltySelectedForRemoval == null || !defaultPenaltySelectedForRemoval) {
            Integer penaltyId = formBean.getDefaultPenaltyId()[penaltyIndex].intValue();
            BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getDefaultPenaltyAmountOrRate()[penaltyIndex].doubleValue());
            applicablePenalties.add(findPenaltyById(dto.getDefaultPenalties(), penaltyId, amountOrRate));
        }
        penaltyIndex++;
    }
    feeIndex = 0;
    Number[] additionalFeesSelected = formBean.getSelectedFeeId();
    if (additionalFeesSelected != null) {
        for (Number additionalFee : additionalFeesSelected) {
            if (additionalFee != null) {
                BigDecimal amountOrRate = BigDecimal.valueOf(formBean.getSelectedFeeAmount()[feeIndex].doubleValue());
                applicableFees.add(findFeeById(dto.getAdditionalFees(), additionalFee.intValue(), amountOrRate));
            }
            feeIndex++;
        }
    }
    loanScheduleFormBean.setApplicableFees(applicableFees);
    loanScheduleFormBean.setApplicablePenalties(applicablePenalties);
}
Also used : PenaltyDto(org.mifos.dto.domain.PenaltyDto) ArrayList(java.util.ArrayList) FeeDto(org.mifos.dto.domain.FeeDto) LoanCreationInstallmentDto(org.mifos.dto.domain.LoanCreationInstallmentDto) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) LoanCreationLoanDetailsDto(org.mifos.dto.screen.LoanCreationLoanDetailsDto)

Example 7 with PenaltyDto

use of org.mifos.dto.domain.PenaltyDto in project head by mifos.

the class LoanPrdActionForm method setSelectedFeesPenaltiesAndFundsAndValidateForFrequency.

private void setSelectedFeesPenaltiesAndFundsAndValidateForFrequency(HttpServletRequest request, ActionErrors errors) {
    logger.debug("start setSelectedFeesPenaltiesAndFundsAndValidateForFrequency method " + "of Loan Product Action form method :");
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    List<FeeDto> feeDtos = new ArrayList<FeeDto>();
    try {
        if (getPrdOfferinFees() != null && getPrdOfferinFees().length > 0) {
            List<FeeBO> fees = getAllLoanPrdFee(request);
            for (String selectedFee : getPrdOfferinFees()) {
                FeeBO fee = getFeeFromList(fees, selectedFee);
                if (fee != null) {
                    isFrequencyMatchingOfferingFrequency(fee, errors);
                    if (AccountingRules.isMultiCurrencyEnabled()) {
                        isValidForCurrency(fee, errors, request);
                    }
                    feeDtos.add(getFeeDto(request, fee));
                }
            }
        }
        setSelectedFeeDtoOnSession(request, feeDtos);
    } catch (PageExpiredException e) {
    }
    List<FundBO> selectedFunds = new ArrayList<FundBO>();
    try {
        if (getLoanOfferingFunds() != null && getLoanOfferingFunds().length > 0) {
            List<FundBO> funds = (List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCFUNDSLIST, request);
            for (String selectedFund : getLoanOfferingFunds()) {
                FundBO fund = getFundFromList(funds, selectedFund);
                if (fund != null) {
                    selectedFunds.add(fund);
                }
            }
        }
        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.LOANPRDFUNDSELECTEDLIST, selectedFunds, request);
    } catch (PageExpiredException e) {
    }
    List<PenaltyDto> selectedPenalties = new ArrayList<PenaltyDto>();
    try {
        if (getPrdOfferinPenalties() != null && getPrdOfferinPenalties().length > 0) {
            List<PenaltyBO> penalties = getAllLoanPrdPenalty(request);
            for (String selectedPenalty : getPrdOfferinPenalties()) {
                PenaltyBO penalty = getPenaltyFromList(penalties, selectedPenalty);
                if (penalty != null) {
                    selectedPenalties.add(penalty.toDto());
                }
            }
        }
        setSelectedPenaltyDtoOnSession(request, selectedPenalties);
    } catch (PageExpiredException e) {
    }
    logger.debug("setSelectedFeesPenaltiesAndFundsAndValidateForFrequency method " + "of Loan Product Action form method called :");
}
Also used : PenaltyDto(org.mifos.dto.domain.PenaltyDto) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) FundBO(org.mifos.accounts.fund.business.FundBO) ArrayList(java.util.ArrayList) FeeDto(org.mifos.accounts.fees.business.FeeDto) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with PenaltyDto

use of org.mifos.dto.domain.PenaltyDto in project head by mifos.

the class LoanPrdAction method getPenaltiesSelected.

private List<PenaltyDto> getPenaltiesSelected(LoanOfferingBO loanOffering) {
    List<PenaltyDto> penaltySelected = new ArrayList<PenaltyDto>();
    for (PrdOfferingPenaltiesEntity prdOfferingPenalties : loanOffering.getLoanOfferingPenalties()) {
        PenaltyBO penalty = prdOfferingPenalties.getPenalty();
        penalty = penaltyDao.findPenaltyById(penalty.getPenaltyId());
        penaltySelected.add(penalty.toDto());
    }
    return penaltySelected;
}
Also used : PenaltyDto(org.mifos.dto.domain.PenaltyDto) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) PrdOfferingPenaltiesEntity(org.mifos.accounts.productdefinition.business.PrdOfferingPenaltiesEntity) ArrayList(java.util.ArrayList)

Example 9 with PenaltyDto

use of org.mifos.dto.domain.PenaltyDto in project head by mifos.

the class LoanControllerHelper method findPenaltyById.

public PenaltyDto findPenaltyById(final List<PenaltyDto> defaultPenalties, final Integer penaltyId, final BigDecimal amountOrRate) {
    PenaltyDto found = null;
    for (PenaltyDto penaltyDto : defaultPenalties) {
        if (Integer.valueOf(penaltyDto.getPenaltyId()).equals(penaltyId)) {
            penaltyDto.setAmount(amountOrRate.toPlainString());
            if (penaltyDto.isRateBasedPenalty()) {
                penaltyDto.setRate(amountOrRate.doubleValue());
            }
            found = penaltyDto;
        }
    }
    return found;
}
Also used : PenaltyDto(org.mifos.dto.domain.PenaltyDto)

Aggregations

PenaltyDto (org.mifos.dto.domain.PenaltyDto)9 ArrayList (java.util.ArrayList)5 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)4 LocalDate (org.joda.time.LocalDate)3 FeeDto (org.mifos.dto.domain.FeeDto)3 BigDecimal (java.math.BigDecimal)2 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 FundBO (org.mifos.accounts.fund.business.FundBO)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)2 LoanCreationLoanDetailsDto (org.mifos.dto.screen.LoanCreationLoanDetailsDto)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 FeeDto (org.mifos.accounts.fees.business.FeeDto)1 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)1 FeePaymentEntity (org.mifos.accounts.fees.business.FeePaymentEntity)1