Search in sources :

Example 1 with PenaltyPeriodEntity

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

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

the class WebTierPenaltyServiceFacade method getPenaltyParameters.

@Override
public PenaltyParametersDto getPenaltyParameters() {
    try {
        List<GLCodeEntity> glCodes = generalLedgerDao.retreiveGlCodesBy(FinancialActionConstants.PENALTYPOSTING, FinancialConstants.CREDIT);
        List<PenaltyCategoryEntity> categories = this.penaltyDao.getPenaltiesCategories();
        List<PenaltyPeriodEntity> periods = this.penaltyDao.getPenaltiesPeriods();
        List<PenaltyFormulaEntity> formulas = this.penaltyDao.getPenaltiesFormulas();
        List<PenaltyFrequencyEntity> frequencies = this.penaltyDao.getPenaltiesFrequencies();
        List<PenaltyStatusEntity> statuses = this.penaltyDao.getPenaltiesStatuses();
        return new PenaltyParametersDto(listToMap(categories), listToMap(statuses), listToMap(periods), listToMap(formulas), listToMap(frequencies), glCodesToMap(glCodes));
    } catch (FinancialException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : PenaltyStatusEntity(org.mifos.accounts.penalties.business.PenaltyStatusEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) PenaltyPeriodEntity(org.mifos.accounts.penalties.business.PenaltyPeriodEntity) PenaltyCategoryEntity(org.mifos.accounts.penalties.business.PenaltyCategoryEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) PenaltyFrequencyEntity(org.mifos.accounts.penalties.business.PenaltyFrequencyEntity) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) PenaltyParametersDto(org.mifos.dto.screen.PenaltyParametersDto) PenaltyFormulaEntity(org.mifos.accounts.penalties.business.PenaltyFormulaEntity)

Example 3 with PenaltyPeriodEntity

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

the class PenaltyDaoHibernateIntegrationTest method cleanDatabaseTables.

@Before
public void cleanDatabaseTables() throws Exception {
    databaseCleaner.clean();
    periodEntity = new PenaltyPeriodEntity(PenaltyPeriod.INSTALLMENTS);
    statusEntity = new PenaltyStatusEntity(PenaltyStatus.ACTIVE);
    categoryEntity = new PenaltyCategoryEntity(PenaltyCategory.LOAN);
    frequencyEntity = new PenaltyFrequencyEntity(PenaltyFrequency.NONE);
    formulaEntity = new PenaltyFormulaEntity(PenaltyFormula.OUTSTANDING_LOAN_AMOUNT);
    glCodeEntity = new GLCodeEntity((short) 42, "31102");
    amountPenalty = new AmountPenaltyBO(TestUtils.makeUser(), "Amount Penalty Test", new PenaltyCategoryEntity(PenaltyCategory.SAVING), periodEntity, 6, 1.0, 14.0, frequencyEntity, glCodeEntity, TestUtils.createMoney(158.5));
    ratePenalty = new RatePenaltyBO(TestUtils.makeUser(), "Rate Penalty Test", categoryEntity, periodEntity, 6, 1.0, 10.0, frequencyEntity, glCodeEntity, formulaEntity, 10.5);
    IntegrationTestObjectMother.createPenalty(amountPenalty);
    IntegrationTestObjectMother.createPenalty(ratePenalty);
}
Also used : RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) PenaltyCategoryEntity(org.mifos.accounts.penalties.business.PenaltyCategoryEntity) PenaltyFrequencyEntity(org.mifos.accounts.penalties.business.PenaltyFrequencyEntity) PenaltyStatusEntity(org.mifos.accounts.penalties.business.PenaltyStatusEntity) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) PenaltyPeriodEntity(org.mifos.accounts.penalties.business.PenaltyPeriodEntity) PenaltyFormulaEntity(org.mifos.accounts.penalties.business.PenaltyFormulaEntity) Before(org.junit.Before)

Example 4 with PenaltyPeriodEntity

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

the class PenaltyDaoHibernateIntegrationTest method shouldFindPenaltyPeriodEntityByType.

@Test
public void shouldFindPenaltyPeriodEntityByType() throws Exception {
    PenaltyPeriodEntity found = penaltyDao.findPenaltyPeriodEntityByType(periodEntity.getPenaltyPeriod());
    assertThat(found.getId(), is(periodEntity.getId()));
}
Also used : PenaltyPeriodEntity(org.mifos.accounts.penalties.business.PenaltyPeriodEntity) Test(org.junit.Test)

Aggregations

PenaltyPeriodEntity (org.mifos.accounts.penalties.business.PenaltyPeriodEntity)4 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)3 PenaltyCategoryEntity (org.mifos.accounts.penalties.business.PenaltyCategoryEntity)3 PenaltyFormulaEntity (org.mifos.accounts.penalties.business.PenaltyFormulaEntity)3 PenaltyFrequencyEntity (org.mifos.accounts.penalties.business.PenaltyFrequencyEntity)3 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)2 AmountPenaltyBO (org.mifos.accounts.penalties.business.AmountPenaltyBO)2 PenaltyStatusEntity (org.mifos.accounts.penalties.business.PenaltyStatusEntity)2 RatePenaltyBO (org.mifos.accounts.penalties.business.RatePenaltyBO)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 Before (org.junit.Before)1 Test (org.junit.Test)1 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)1 PenaltyCategory (org.mifos.accounts.penalties.util.helpers.PenaltyCategory)1 PenaltyFormula (org.mifos.accounts.penalties.util.helpers.PenaltyFormula)1 PenaltyFrequency (org.mifos.accounts.penalties.util.helpers.PenaltyFrequency)1 PenaltyPeriod (org.mifos.accounts.penalties.util.helpers.PenaltyPeriod)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PenaltyParametersDto (org.mifos.dto.screen.PenaltyParametersDto)1