Search in sources :

Example 6 with AmountPenaltyBO

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

the class PenaltyDaoHibernateIntegrationTest method shouldFindPenaltyById.

@Test
public void shouldFindPenaltyById() throws Exception {
    PenaltyBO found = penaltyDao.findPenaltyById(amountPenalty.getPenaltyId());
    assertThat((AmountPenaltyBO) found, is(amountPenalty));
    found = penaltyDao.findPenaltyById(ratePenalty.getPenaltyId());
    assertThat((RatePenaltyBO) found, is(ratePenalty));
}
Also used : PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) Test(org.junit.Test)

Example 7 with AmountPenaltyBO

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

the class WebTierPenaltyServiceFacade method updatePenalty.

@Override
public void updatePenalty(PenaltyFormDto dto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(dto.getId());
    penaltyBO.updateDetails(userContext);
    try {
        PenaltyFrequency penaltyFrequency = dto.getPenaltyFrequency() != null ? PenaltyFrequency.getPenaltyFrequencyType(dto.getPenaltyFrequency()) : null;
        PenaltyPeriod penaltyPeriod = dto.getPenaltyPeriod() != null ? PenaltyPeriod.getPenaltyPeriod(dto.getPenaltyPeriod()) : null;
        PenaltyFormula penaltyFormula = dto.getPenaltyFormula() != null ? PenaltyFormula.getPenaltyFormula(dto.getPenaltyFormula()) : null;
        PenaltyStatus penaltyStatus = dto.getPenaltyStatus() != null ? PenaltyStatus.getPenaltyStatus(dto.getPenaltyStatus()) : null;
        penaltyBO.setPeriodType(this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod));
        penaltyBO.setPenaltyFrequency(this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency));
        penaltyBO.setPenaltyName(dto.getPenaltyName());
        penaltyBO.setPeriodDuration(dto.getDuration());
        penaltyBO.setMinimumLimit(dto.getMin());
        penaltyBO.setMaximumLimit(dto.getMax());
        penaltyBO.setStatus(this.penaltyDao.findPenaltyStatusEntityByType(penaltyStatus));
        penaltyBO.setGlCode(this.generalLedgerDao.findGlCodeById(dto.getGlCode()));
        if (dto.isRatePenalty()) {
            RatePenaltyBO ratePenaltyBO = (RatePenaltyBO) penaltyBO;
            ratePenaltyBO.setRate(dto.getRate());
            ratePenaltyBO.setFormula(this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula));
        } else {
            AmountPenaltyBO amountPenaltyBO = (AmountPenaltyBO) penaltyBO;
            amountPenaltyBO.setAmount(new Money(getCurrency(dto.getCurrencyId()), dto.getAmount()));
        }
        try {
            StaticHibernateUtil.startTransaction();
            this.penaltyDao.save(penaltyBO);
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            throw new MifosRuntimeException(e);
        } finally {
            StaticHibernateUtil.closeSession();
        }
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) PenaltyPeriod(org.mifos.accounts.penalties.util.helpers.PenaltyPeriod) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) BusinessRuleException(org.mifos.service.BusinessRuleException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PenaltyFrequency(org.mifos.accounts.penalties.util.helpers.PenaltyFrequency) PenaltyStatus(org.mifos.accounts.penalties.util.helpers.PenaltyStatus) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) PenaltyFormula(org.mifos.accounts.penalties.util.helpers.PenaltyFormula) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with AmountPenaltyBO

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

the class LoanBusinessService method populaleApplicableCharge.

private void populaleApplicableCharge(List<ApplicableCharge> applicableChargeList, List<PenaltyBO> penaltyList, UserContext userContext) {
    for (PenaltyBO penalty : penaltyList) {
        ApplicableCharge applicableCharge = new ApplicableCharge();
        applicableCharge.setFeeId(penalty.getPenaltyId().toString());
        applicableCharge.setFeeName(penalty.getPenaltyName());
        applicableCharge.setIsPenaltyType(true);
        if (penalty instanceof RatePenaltyBO) {
            applicableCharge.setAmountOrRate(new LocalizationConverter().getDoubleStringForInterest(((RatePenaltyBO) penalty).getRate()));
            applicableCharge.setFormula(((RatePenaltyBO) penalty).getFormula().getFormulaStringThatHasName());
            applicableCharge.setIsRateType(true);
        } else {
            applicableCharge.setAmountOrRate(((AmountPenaltyBO) penalty).getAmount().toString());
            applicableCharge.setIsRateType(false);
        }
        if (!penalty.isOneTime()) {
            applicableCharge.setPeriodicity("true");
            applicableCharge.setFormula(penalty.getPenaltyFrequency().getName());
        }
        applicableChargeList.add(applicableCharge);
    }
}
Also used : RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO)

Example 9 with AmountPenaltyBO

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

the class ApplyPenaltyToLoanAccountsHelper method addAmountPenalty.

private void addAmountPenalty(final AccountPenaltiesEntity penaltyEntity, final LoanBO loanAccount, final LoanScheduleEntity loanScheduleEntity) {
    AmountPenaltyBO penalty = (AmountPenaltyBO) penaltyEntity.getPenalty();
    Money accountPenaltyAmount = penaltyEntity.getAccountPenaltyAmount();
    Money charge = verifyLimits(loanAccount.getTotalPenalty(accountPenaltyAmount.getCurrency(), penalty.getPenaltyId()), accountPenaltyAmount, penalty.getMinimumLimit() / loanAccount.calcFactorOfEntireLoan().doubleValue(), penalty.getMaximumLimit() / loanAccount.calcFactorOfEntireLoan().doubleValue());
    if (charge != null && charge.isGreaterThanZero()) {
        loanAccount.applyPenalty(charge, loanScheduleEntity.getInstallmentId(), penaltyEntity, currentDate);
    }
    try {
        StaticHibernateUtil.startTransaction();
        StaticHibernateUtil.getSessionTL().update(loanAccount);
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        getLogger().error(e.getMessage());
        StaticHibernateUtil.rollbackTransaction();
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException)

Aggregations

AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)9 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)7 Money (org.mifos.framework.util.helpers.Money)6 RatePenaltyBO (org.mifos.accounts.penalties.business.RatePenaltyBO)5 MifosUser (org.mifos.security.MifosUser)5 UserContext (org.mifos.security.util.UserContext)5 BusinessRuleException (org.mifos.service.BusinessRuleException)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 DateTime (org.joda.time.DateTime)3 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)3 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 MaxMinLoanAmount (org.mifos.accounts.loan.business.MaxMinLoanAmount)3 MaxMinNoOfInstall (org.mifos.accounts.loan.business.MaxMinNoOfInstall)3 AmountRange (org.mifos.accounts.productdefinition.business.AmountRange)3 InstallmentRange (org.mifos.accounts.productdefinition.business.InstallmentRange)3 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2