Search in sources :

Example 11 with PrdStatusEntity

use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.

the class TestObjectFactory method createSavingsProduct.

public static SavingsOfferingBO createSavingsProduct(final String name, final String shortName, final ApplicableTo applicableTo, final Date startDate, final PrdStatus status, final Double recommendedAmount, final RecommendedAmountUnit recommendedAmountUnit, final Double intRate, final Double maxAmtWithdrawl, final Double minAmtForInt, final SavingsType savingsType, final InterestCalcType interestCalculationType, final MeetingBO intCalcMeeting, final MeetingBO intPostMeeting, final Short depGLCode, final Short withGLCode) {
    GLCodeEntity depglCodeEntity = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, depGLCode);
    GLCodeEntity intglCodeEntity = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, withGLCode);
    ProductCategoryBO productCategory = (ProductCategoryBO) TestObjectFactory.getObject(ProductCategoryBO.class, SAMPLE_CATEGORY);
    PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(applicableTo);
    SavingsTypeEntity savingsTypeEntity = new SavingsTypeEntity(savingsType);
    InterestCalcTypeEntity intCalType = new InterestCalcTypeEntity(interestCalculationType);
    RecommendedAmntUnitEntity amountUnit = new RecommendedAmntUnitEntity(recommendedAmountUnit);
    SavingsOfferingBO product;
    try {
        product = new SavingsOfferingBO(TestUtils.makeUserWithLocales(), name, shortName, productCategory, prdApplicableMaster, startDate, null, null, amountUnit, savingsTypeEntity, intCalType, intCalcMeeting, intPostMeeting, TestUtils.createMoney(recommendedAmount), TestUtils.createMoney(maxAmtWithdrawl), TestUtils.createMoney(minAmtForInt), intRate, depglCodeEntity, intglCodeEntity);
    } catch (ProductDefinitionException e) {
        throw new RuntimeException(e);
    } catch (SystemException e) {
        throw new RuntimeException(e);
    }
    PrdStatusEntity prdStatus = testObjectPersistence.retrievePrdStatus(status);
    product.setPrdStatus(prdStatus);
    return (SavingsOfferingBO) testObjectPersistence.persist(product);
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) SystemException(org.mifos.framework.exceptions.SystemException) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) InterestCalcTypeEntity(org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)

Example 12 with PrdStatusEntity

use of org.mifos.accounts.productdefinition.business.PrdStatusEntity 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 13 with PrdStatusEntity

use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.

the class PrdOfferingPersistence method getApplicablePrdStatus.

@SuppressWarnings("cast")
public List<PrdStatusEntity> getApplicablePrdStatus(ProductType productType, Short localeId) throws PersistenceException {
    logger.debug("getting the applicable product Status");
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put(ProductDefinitionConstants.PRODUCTTYPEID, productType.getValue());
    List<PrdStatusEntity> prdStatusList = (List<PrdStatusEntity>) executeNamedQuery(NamedQueryConstants.PRODUCT_STATUS, queryParameters);
    for (PrdStatusEntity prdStatus : prdStatusList) {
        Hibernate.initialize(prdStatus);
        Hibernate.initialize(prdStatus.getPrdState());
    }
    logger.debug("getting the applicable product Status Done and : " + prdStatusList);
    return prdStatusList;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity)

Example 14 with PrdStatusEntity

use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.

the class LoanPrdBusinessServiceIntegrationTest method testGetApplicablePrdStatus.

@Test
public void testGetApplicablePrdStatus() throws ServiceException {
    List<PrdStatusEntity> prdStatusList = new LoanPrdBusinessService().getApplicablePrdStatus((short) 1);
    StaticHibernateUtil.flushSession();
    Assert.assertEquals(2, prdStatusList.size());
    for (PrdStatusEntity prdStatus : prdStatusList) {
        if (prdStatus.getPrdState().equals("1")) {
            Assert.assertEquals("Active", prdStatus.getPrdState().getName());
        }
        if (prdStatus.getPrdState().equals("2")) {
            Assert.assertEquals("InActive", prdStatus.getPrdState().getName());
        }
    }
}
Also used : PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) Test(org.junit.Test)

Example 15 with PrdStatusEntity

use of org.mifos.accounts.productdefinition.business.PrdStatusEntity in project head by mifos.

the class SavingsPrdBusinessServiceIntegrationTest method testGetApplicablePrdStatus.

@Test
public void testGetApplicablePrdStatus() throws ServiceException {
    List<PrdStatusEntity> prdStatusList = new SavingsPrdBusinessService().getApplicablePrdStatus((short) 1);
    StaticHibernateUtil.flushSession();
    Assert.assertEquals(2, prdStatusList.size());
    for (PrdStatusEntity prdStatus : prdStatusList) {
        if (prdStatus.getPrdState().equals("1")) {
            Assert.assertEquals("Active", prdStatus.getPrdState().getName());
        }
        if (prdStatus.getPrdState().equals("2")) {
            Assert.assertEquals("InActive", prdStatus.getPrdState().getName());
        }
    }
}
Also used : PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) Test(org.junit.Test)

Aggregations

PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)15 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)9 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)9 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 GracePeriodTypeEntity (org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity)5 InterestTypesEntity (org.mifos.application.master.business.InterestTypesEntity)5 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)4 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)4 PersistenceException (org.mifos.framework.exceptions.PersistenceException)4 FeeBO (org.mifos.accounts.fees.business.FeeBO)3 FundBO (org.mifos.accounts.fund.business.FundBO)3 InterestCalcTypeEntity (org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity)3 RecommendedAmntUnitEntity (org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity)3 SavingsTypeEntity (org.mifos.accounts.productdefinition.business.SavingsTypeEntity)3 MifosCurrency (org.mifos.application.master.business.MifosCurrency)3 List (java.util.List)2 DateTime (org.joda.time.DateTime)2