Search in sources :

Example 1 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity 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 GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity 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 GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class LegacyAccountDao method updateLedgerAccount.

public void updateLedgerAccount(COABO coaBo, String accountName, String glCode, String parentGlCode) throws PersistenceException {
    Session session = StaticHibernateUtil.getSessionTL();
    Transaction transaction = session.beginTransaction();
    try {
        Short newParentId = getAccountIdFromGlCode(parentGlCode);
        coaBo.setAccountName(accountName);
        GLCodeEntity glCodeEntity = coaBo.getAssociatedGlcode();
        createOrUpdate(coaBo);
        glCodeEntity.setGlcode(glCode);
        createOrUpdate(glCodeEntity);
        Query query = session.getNamedQuery(NamedQueryConstants.SET_COA_PARENT);
        query.setShort("parentId", newParentId);
        query.setShort("id", coaBo.getAccountId());
        query.executeUpdate();
        transaction.commit();
    } catch (HibernateException ex) {
        transaction.rollback();
        throw new PersistenceException(ex);
    }
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) Session(org.hibernate.Session)

Example 4 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class SavingsProductAssembler method fromDto.

public SavingsOfferingBO fromDto(MifosUser user, SavingsProductDto savingsProductRequest) {
    try {
        // FIXME - keithw - this is general assembler common to both savings and loans i.e. all products. so
        // ProductDao and ProductAssembler
        ProductDetailsDto productDetails = savingsProductRequest.getProductDetails();
        String name = productDetails.getName();
        String shortName = productDetails.getShortName();
        String description = productDetails.getDescription();
        Integer category = productDetails.getCategory();
        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);
        PrdStatusEntity activeStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_ACTIVE);
        PrdStatusEntity inActiveStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_INACTIVE);
        PrdStatusEntity selectedStatus = activeStatus;
        if (productDetails.getStatus() != null && inActiveStatus.getOfferingStatusId().equals(productDetails.getStatus().shortValue())) {
            selectedStatus = inActiveStatus;
        }
        String globalNum = generateProductGlobalNum(user);
        // savings specific
        SavingsType savingsType = SavingsType.fromInt(savingsProductRequest.getDepositType());
        SavingsTypeEntity savingsTypeEntity = this.loanProductDao.retrieveSavingsType(savingsType);
        RecommendedAmntUnitEntity recommendedAmntUnitEntity = null;
        if (savingsProductRequest.getGroupMandatorySavingsType() != null) {
            RecommendedAmountUnit recommendedAmountType = RecommendedAmountUnit.fromInt(savingsProductRequest.getGroupMandatorySavingsType());
            recommendedAmntUnitEntity = this.loanProductDao.retrieveRecommendedAmountType(recommendedAmountType);
        }
        Money amountForDeposit = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getAmountForDeposit()));
        Money maxWithdrawal = new Money(Money.getDefaultCurrency(), BigDecimal.valueOf(savingsProductRequest.getMaxWithdrawal()));
        // interest specific
        BigDecimal interestRate = savingsProductRequest.getInterestRate();
        InterestCalcType interestCalcType = InterestCalcType.fromInt(savingsProductRequest.getInterestCalculationType());
        InterestCalcTypeEntity interestCalcTypeEntity = this.savingsProductDao.retrieveInterestCalcType(interestCalcType);
        RecurrenceType recurrence = RecurrenceType.fromInt(savingsProductRequest.getInterestCalculationFrequencyPeriod().shortValue());
        Integer every = savingsProductRequest.getInterestCalculationFrequency();
        MeetingBO interestCalculationMeeting = new MeetingBO(recurrence, every.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_CALCULATION_TIME_PERIOD);
        Integer interestPostingEveryMonthFreq = savingsProductRequest.getInterestPostingFrequency();
        RecurrenceType interestPostingRecurrenceType = null;
        if (savingsProductRequest.isDailyPosting()) {
            interestPostingRecurrenceType = RecurrenceType.DAILY;
        } else {
            interestPostingRecurrenceType = RecurrenceType.MONTHLY;
        }
        MeetingBO interestPostingMeeting = new MeetingBO(interestPostingRecurrenceType, interestPostingEveryMonthFreq.shortValue(), new Date(), MeetingType.SAVINGS_INTEREST_POSTING);
        Money minAmountForCalculation = new Money(Money.getDefaultCurrency(), savingsProductRequest.getMinBalanceForInterestCalculation());
        GLCodeEntity depositGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getDepositGlCode().shortValue());
        GLCodeEntity interestGlEntity = this.generalLedgerDao.findGlCodeById(savingsProductRequest.getInterestGlCode().shortValue());
        MifosCurrency currency = Money.getDefaultCurrency();
        return SavingsOfferingBO.createNew(user.getUserId(), globalNum, name, shortName, description, productCategory, startDate, endDate, applicableToEntity, currency, selectedStatus, savingsTypeEntity, recommendedAmntUnitEntity, amountForDeposit, maxWithdrawal, interestRate, interestCalcTypeEntity, interestCalculationMeeting, interestPostingMeeting, minAmountForCalculation, depositGlEntity, interestGlEntity);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (MeetingException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) MifosCurrency(org.mifos.application.master.business.MifosCurrency) RecommendedAmountUnit(org.mifos.accounts.productdefinition.util.helpers.RecommendedAmountUnit) InterestCalcType(org.mifos.accounts.productdefinition.util.helpers.InterestCalcType) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) InterestCalcTypeEntity(org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity) RecurrenceType(org.mifos.application.meeting.util.helpers.RecurrenceType) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ApplicableTo(org.mifos.accounts.productdefinition.util.helpers.ApplicableTo) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) SavingsType(org.mifos.accounts.productdefinition.util.helpers.SavingsType) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with GLCodeEntity

use of org.mifos.accounts.financial.business.GLCodeEntity in project head by mifos.

the class PenaltyBOIntegrationTest method testCreateAmountPenalty.

@Test
public void testCreateAmountPenalty() throws Exception {
    String name = "Amount Penalty Test";
    PenaltyCategoryEntity categoryEntity = new PenaltyCategoryEntity(PenaltyCategory.LOAN);
    PenaltyPeriodEntity periodEntity = new PenaltyPeriodEntity(PenaltyPeriod.DAYS);
    int duration = 10;
    double min = 1.0;
    double max = 15.0;
    PenaltyFrequencyEntity frequencyEntity = new PenaltyFrequencyEntity(PenaltyFrequency.MONTHLY);
    GLCodeEntity glCode = getGLCode("42");
    Money amount = TestUtils.createMoney(587.6);
    penalty = new AmountPenaltyBO(TestUtils.makeUser(), name, categoryEntity, periodEntity, duration, min, max, frequencyEntity, glCode, amount);
    penalty.save();
    StaticHibernateUtil.flushSession();
    penalty = (PenaltyBO) TestObjectFactory.getObject(PenaltyBO.class, penalty.getPenaltyId());
    Assert.assertEquals(name, penalty.getPenaltyName());
    Assert.assertEquals(categoryEntity.getId(), penalty.getCategoryType().getId());
    Assert.assertEquals(duration, penalty.getPeriodDuration().intValue());
    Assert.assertEquals(min, penalty.getMinimumLimit().doubleValue());
    Assert.assertEquals(max, penalty.getMaximumLimit().doubleValue());
    Assert.assertEquals(frequencyEntity.getId(), penalty.getPenaltyFrequency().getId());
    Assert.assertEquals(glCode.getGlcodeId(), penalty.getGlCode().getGlcodeId());
    Assert.assertEquals(amount.getAmount(), ((AmountPenaltyBO) penalty).getAmount().getAmount());
    StaticHibernateUtil.flushSession();
}
Also used : Money(org.mifos.framework.util.helpers.Money) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) Test(org.junit.Test)

Aggregations

GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)58 Money (org.mifos.framework.util.helpers.Money)21 MeetingBO (org.mifos.application.meeting.business.MeetingBO)18 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)17 Test (org.junit.Test)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)15 FinancialActionTypeEntity (org.mifos.accounts.financial.business.FinancialActionTypeEntity)14 Date (java.sql.Date)12 ArrayList (java.util.ArrayList)11 FeeBO (org.mifos.accounts.fees.business.FeeBO)11 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)11 COABO (org.mifos.accounts.financial.business.COABO)10 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)9 PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)9 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)7 SystemException (org.mifos.framework.exceptions.SystemException)7 CategoryTypeEntity (org.mifos.accounts.fees.business.CategoryTypeEntity)6 FeeFrequencyTypeEntity (org.mifos.accounts.fees.business.FeeFrequencyTypeEntity)6