Search in sources :

Example 16 with PenaltyBO

use of org.mifos.accounts.penalties.business.PenaltyBO 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 17 with PenaltyBO

use of org.mifos.accounts.penalties.business.PenaltyBO in project head by mifos.

the class LoanBO method removePenalty.

public void removePenalty(Short penaltyId, Short personnelId) throws AccountException {
    List<Short> installmentIds = getApplicableInstallmentIdsForRemovePenalties();
    Money totalPenaltyAmount = Money.zero();
    if (isPenaltyActive(penaltyId)) {
        PenaltyBO penalty = getAccountPenaltyObject(penaltyId);
        if (!installmentIds.isEmpty()) {
            totalPenaltyAmount = totalPenaltyAmount.add(removePenaltyFromLoanScheduleEntity(installmentIds, penaltyId));
            updateTotalPenaltyAmount(totalPenaltyAmount);
        }
        updateAccountPenaltiesEntity(penaltyId);
        String description = penalty.getPenaltyName() + " " + AccountConstants.PENALTIES_REMOVED;
        updateAccountActivity(null, null, totalPenaltyAmount, null, personnelId, description);
        try {
            ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AccountException(org.mifos.accounts.exceptions.AccountException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 18 with PenaltyBO

use of org.mifos.accounts.penalties.business.PenaltyBO in project head by mifos.

the class LoanBO method applyPenalty.

public void applyPenalty(final Money charge, final int scheduleEntityId, final AccountPenaltiesEntity penaltiesEntity, final Date current) {
    LoanScheduleEntity loanScheduleEntity = new ArrayList<LoanScheduleEntity>(getLoanScheduleEntities()).get(scheduleEntityId - 1);
    PenaltyBO penalty = penaltiesEntity.getPenalty();
    LoanPenaltyScheduleEntity entity = loanScheduleEntity.getPenaltyScheduleEntity(penalty.getPenaltyId());
    Money money = new Money(getCurrency());
    loanScheduleEntity.setPenalty(loanScheduleEntity.getPenalty().add(charge));
    getLoanSummary().updateOriginalPenalty(charge);
    addLoanActivity(new LoanActivityEntity(this, personnel, money, money, money, charge, getLoanSummary(), penalty.getPenaltyName() + " applied"));
    if (entity == null) {
        loanScheduleEntity.addLoanPenaltySchedule(new LoanPenaltyScheduleEntity(loanScheduleEntity, penalty, penaltiesEntity, charge, current));
    } else {
        entity.setPenaltyAmount(entity.getPenaltyAmount().add(charge));
        entity.setLastApplied(current);
    }
    penaltiesEntity.setLastAppliedDate(new DateTimeService().getCurrentJavaDateTime());
}
Also used : Money(org.mifos.framework.util.helpers.Money) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 19 with PenaltyBO

use of org.mifos.accounts.penalties.business.PenaltyBO in project head by mifos.

the class LoanProductAssembler method fromDto.

public LoanOfferingBO fromDto(MifosUser user, LoanProductRequest loanProductRequest) {
    try {
        Integer userId = user.getUserId();
        ProductDetailsDto productDetails = loanProductRequest.getProductDetails();
        String name = productDetails.getName();
        String shortName = productDetails.getShortName();
        String description = productDetails.getDescription();
        Integer category = productDetails.getCategory();
        boolean loanCycleCounter = loanProductRequest.isIncludeInLoanCycleCounter();
        boolean waiverInterest = loanProductRequest.isWaiverInterest();
        PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_ACTIVE);
        PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.LOAN_INACTIVE);
        PrdStatusEntity selectedStatus = activeStatus;
        if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
            selectedStatus = inActiveStatus;
        }
        MifosCurrency currency = Money.getDefaultCurrency();
        if (AccountingRules.isMultiCurrencyEnabled()) {
            currency = AccountingRules.getCurrencyByCurrencyId(loanProductRequest.getCurrencyId().shortValue());
        }
        ProductCategoryBO productCategory = this.loanProductDao.findActiveProductCategoryById(category);
        DateTime startDate = productDetails.getStartDate();
        DateTime endDate = productDetails.getEndDate();
        ApplicableTo applicableTo = ApplicableTo.fromInt(productDetails.getApplicableFor());
        PrdApplicableMasterEntity applicableToEntity = this.loanProductDao.findApplicableProductType(applicableTo);
        LoanAmountCalculation loanAmountCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanAmountCalculationFromDto(loanProductRequest.getLoanAmountDetails());
        InterestType interestType = InterestType.fromInt(loanProductRequest.getInterestRateType());
        Double minRate = loanProductRequest.getInterestRateRange().getMin().doubleValue();
        Double maxRate = loanProductRequest.getInterestRateRange().getMax().doubleValue();
        Double defaultRate = loanProductRequest.getInterestRateRange().getTheDefault().doubleValue();
        InterestTypesEntity interestTypeEntity = this.loanProductDao.findInterestType(interestType);
        RecurrenceType recurrence = RecurrenceType.fromInt(loanProductRequest.getRepaymentDetails().getFrequencyType().shortValue());
        Integer recurEvery = loanProductRequest.getRepaymentDetails().getRecurs();
        LoanInstallmentCalculation loanInstallmentCalculation = this.loanProductCaluclationTypeAssembler.assembleLoanInstallmentCalculationFromDto(loanProductRequest.getRepaymentDetails().getInstallmentCalculationDetails());
        GraceType gracePeriodType = GraceType.fromInt(loanProductRequest.getRepaymentDetails().getGracePeriodType());
        GracePeriodTypeEntity gracePeriodTypeEntity = this.loanProductDao.findGracePeriodType(gracePeriodType);
        Integer gracePeriodDuration = loanProductRequest.getRepaymentDetails().getGracePeriodDuration();
        List<FeeBO> applicableFees = new ArrayList<FeeBO>();
        List<Integer> applicableFeeIds = loanProductRequest.getApplicableFees();
        for (Integer feeId : applicableFeeIds) {
            FeeBO fee = ApplicationContextProvider.getBean(FeeDao.class).findById(feeId.shortValue());
            applicableFees.add(fee);
        }
        List<FundBO> applicableFunds = new ArrayList<FundBO>();
        List<Integer> applicableFundIds = loanProductRequest.getAccountDetails().getApplicableFunds();
        for (Integer fundId : applicableFundIds) {
            FundBO fund = this.fundDao.findById(fundId.shortValue());
            applicableFunds.add(fund);
        }
        List<PenaltyBO> applicablePenalties = new ArrayList<PenaltyBO>();
        List<Integer> applicablePenaltyIds = loanProductRequest.getApplicablePenalties();
        for (Integer penaltyId : applicablePenaltyIds) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(penaltyId);
            applicablePenalties.add(penalty);
        }
        GLCodeEntity interestGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getInterestGlCodeId().shortValue());
        GLCodeEntity principalGlCode = this.generalLedgerDao.findGlCodeById(loanProductRequest.getAccountDetails().getPrincipalClCodeId().shortValue());
        String globalProductId = generateProductGlobalNum(user);
        LoanOfferingBO loanProduct = LoanOfferingBO.createNew(userId, globalProductId, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, interestTypeEntity, minRate, maxRate, defaultRate, recurrence, recurEvery, interestGlCode, principalGlCode, activeStatus, inActiveStatus, gracePeriodTypeEntity, gracePeriodDuration, waiverInterest, loanCycleCounter, loanAmountCalculation, loanInstallmentCalculation, applicableFees, applicableFunds, applicablePenalties);
        loanProduct.updateStatus(selectedStatus);
        return loanProduct;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) LoanInstallmentCalculation(org.mifos.accounts.productdefinition.LoanInstallmentCalculation) ArrayList(java.util.ArrayList) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) DateTime(org.joda.time.DateTime) GraceType(org.mifos.accounts.productdefinition.util.helpers.GraceType) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) FundBO(org.mifos.accounts.fund.business.FundBO) RecurrenceType(org.mifos.application.meeting.util.helpers.RecurrenceType) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) LoanAmountCalculation(org.mifos.accounts.productdefinition.LoanAmountCalculation) ApplicableTo(org.mifos.accounts.productdefinition.util.helpers.ApplicableTo) InterestType(org.mifos.accounts.productdefinition.util.helpers.InterestType) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) FeeDao(org.mifos.accounts.fees.persistence.FeeDao) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 20 with PenaltyBO

use of org.mifos.accounts.penalties.business.PenaltyBO in project head by mifos.

the class LoanOfferingBO method createNew.

public static LoanOfferingBO createNew(Integer userId, String globalProductId, String name, String shortName, String description, ProductCategoryBO productCategory, DateTime startDate, DateTime endDate, PrdApplicableMasterEntity applicableToEntity, MifosCurrency currency, InterestTypesEntity interestTypeEntity, Double minRate, Double maxRate, Double defaultRate, RecurrenceType recurrence, Integer recurEvery, GLCodeEntity interestGlCode, GLCodeEntity principalGlCode, PrdStatusEntity activeStatus, PrdStatusEntity inActiveStatus, GracePeriodTypeEntity gracePeriodTypeEntity, Integer gracePeriodDuration, boolean waiverInterest, boolean loanCycleCounter, LoanAmountCalculation loanAmountCalculation, LoanInstallmentCalculation loanInstallmentCalculation, List<FeeBO> applicableFees, List<FundBO> applicableFunds, List<PenaltyBO> applicablePenalties) {
    PrdStatusEntity status = inActiveStatus;
    if (new LocalDate(startDate).isEqual(new LocalDate())) {
        status = activeStatus;
    }
    try {
        MeetingBO meeting = new MeetingBO(recurrence, recurEvery.shortValue(), startDate.toDate(), MeetingType.LOAN_INSTALLMENT);
        PrdOfferingMeetingEntity meetingEntity = new PrdOfferingMeetingEntity(meeting, null, MeetingType.LOAN_INSTALLMENT);
        LoanOfferingBO loanProduct = new LoanOfferingBO(userId, globalProductId, name, shortName, productCategory, status, applicableToEntity, startDate, currency, interestTypeEntity, minRate, maxRate, defaultRate, interestGlCode, principalGlCode, gracePeriodTypeEntity, gracePeriodDuration, loanCycleCounter, meetingEntity, waiverInterest);
        loanProduct.setDescription(description);
        if (endDate != null) {
            loanProduct.setEndDate(endDate.toDate());
        }
        for (FundBO fund : applicableFunds) {
            loanProduct.addLoanOfferingFund(new LoanOfferingFundEntity(fund, loanProduct));
        }
        for (FeeBO fee : applicableFees) {
            loanProduct.addPrdOfferingFee(new LoanOfferingFeesEntity(loanProduct, fee));
        }
        for (PenaltyBO penalty : applicablePenalties) {
            loanProduct.addPrdOfferingPenalty(new PrdOfferingPenaltiesEntity(loanProduct, penalty));
        }
        loanProduct.setLoanAmountSameForAllLoan(loanAmountCalculation.getSameForAll());
        for (LoanAmountFromLastLoanAmountBO loanAmountFromLastLoanAmount : loanAmountCalculation.getFromLastLoan()) {
            loanProduct.addLoanAmountFromLastLoanAmount(loanAmountFromLastLoanAmount);
        }
        for (LoanAmountFromLoanCycleBO loanAmountFromLoanCycle : loanAmountCalculation.getFromLoanCycle()) {
            loanProduct.addLoanAmountFromLoanCycle(loanAmountFromLoanCycle);
        }
        loanProduct.setNoOfInstallSameForAllLoan(loanInstallmentCalculation.getSameForAll());
        for (NoOfInstallFromLastLoanAmountBO noOfInstallFromLastLoanAmount : loanInstallmentCalculation.getFromLastLoan()) {
            loanProduct.addNoOfInstallFromLastLoanAmount(noOfInstallFromLastLoanAmount);
        }
        for (NoOfInstallFromLoanCycleBO noOfInstallFromLoanCycle : loanInstallmentCalculation.getFromLoanCycle()) {
            loanProduct.addNoOfInstallFromLoanCycle(noOfInstallFromLoanCycle);
        }
        return loanProduct;
    } catch (MeetingException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) FundBO(org.mifos.accounts.fund.business.FundBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) FeeBO(org.mifos.accounts.fees.business.FeeBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)22 ArrayList (java.util.ArrayList)12 AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)10 MifosRuntimeException (org.mifos.core.MifosRuntimeException)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 FeeBO (org.mifos.accounts.fees.business.FeeBO)8 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)7 Money (org.mifos.framework.util.helpers.Money)7 MifosUser (org.mifos.security.MifosUser)7 UserContext (org.mifos.security.util.UserContext)7 RatePenaltyBO (org.mifos.accounts.penalties.business.RatePenaltyBO)6 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)6 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 BigDecimal (java.math.BigDecimal)5 LoanBO (org.mifos.accounts.loan.business.LoanBO)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 LocalDate (org.joda.time.LocalDate)4 AccountException (org.mifos.accounts.exceptions.AccountException)4 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)4