Search in sources :

Example 1 with PenaltyFrequency

use of org.mifos.accounts.penalties.util.helpers.PenaltyFrequency in project head by mifos.

the class WebTierPenaltyServiceFacade method createPenalty.

@Override
public void createPenalty(PenaltyFormDto dto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        PenaltyCategory penaltyCategory = dto.getCategoryType() != null ? PenaltyCategory.getPenaltyCategory(dto.getCategoryType()) : null;
        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;
        PenaltyCategoryEntity penaltyCategoryEntity = this.penaltyDao.findPenaltyCategoryEntityByType(penaltyCategory);
        PenaltyPeriodEntity penaltyPeriodEntity = this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod);
        PenaltyFrequencyEntity penaltyFrequencyEntity = this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency);
        GLCodeEntity glCodeEntity = this.generalLedgerDao.findGlCodeById(dto.getGlCode());
        PenaltyBO penaltyBO = null;
        String penaltyName = dto.getPenaltyName();
        Integer periodDuration = dto.getDuration();
        Double min = dto.getMin();
        Double max = dto.getMax();
        if (dto.isRatePenalty()) {
            Double rate = dto.getRate();
            PenaltyFormulaEntity formula = this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula);
            penaltyBO = new RatePenaltyBO(userContext, penaltyName, penaltyCategoryEntity, penaltyPeriodEntity, periodDuration, min, max, penaltyFrequencyEntity, glCodeEntity, formula, rate);
        } else {
            Money amount = new Money(getCurrency(dto.getCurrencyId()), dto.getAmount());
            penaltyBO = new AmountPenaltyBO(userContext, penaltyName, penaltyCategoryEntity, penaltyPeriodEntity, periodDuration, min, max, penaltyFrequencyEntity, glCodeEntity, amount);
        }
        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 : PenaltyCategory(org.mifos.accounts.penalties.util.helpers.PenaltyCategory) 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) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) PenaltyPeriodEntity(org.mifos.accounts.penalties.business.PenaltyPeriodEntity) 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) PenaltyCategoryEntity(org.mifos.accounts.penalties.business.PenaltyCategoryEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PenaltyFrequency(org.mifos.accounts.penalties.util.helpers.PenaltyFrequency) PenaltyFrequencyEntity(org.mifos.accounts.penalties.business.PenaltyFrequencyEntity) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) PenaltyFormula(org.mifos.accounts.penalties.util.helpers.PenaltyFormula) PenaltyFormulaEntity(org.mifos.accounts.penalties.business.PenaltyFormulaEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with PenaltyFrequency

use of org.mifos.accounts.penalties.util.helpers.PenaltyFrequency 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)

Aggregations

FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)2 AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)2 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)2 RatePenaltyBO (org.mifos.accounts.penalties.business.RatePenaltyBO)2 PenaltyFormula (org.mifos.accounts.penalties.util.helpers.PenaltyFormula)2 PenaltyFrequency (org.mifos.accounts.penalties.util.helpers.PenaltyFrequency)2 PenaltyPeriod (org.mifos.accounts.penalties.util.helpers.PenaltyPeriod)2 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 Money (org.mifos.framework.util.helpers.Money)2 MifosUser (org.mifos.security.MifosUser)2 UserContext (org.mifos.security.util.UserContext)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)1 PenaltyCategoryEntity (org.mifos.accounts.penalties.business.PenaltyCategoryEntity)1 PenaltyFormulaEntity (org.mifos.accounts.penalties.business.PenaltyFormulaEntity)1 PenaltyFrequencyEntity (org.mifos.accounts.penalties.business.PenaltyFrequencyEntity)1 PenaltyPeriodEntity (org.mifos.accounts.penalties.business.PenaltyPeriodEntity)1 PenaltyCategory (org.mifos.accounts.penalties.util.helpers.PenaltyCategory)1