Search in sources :

Example 1 with PrdStatusEntity

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

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

the class LoanPrdActionStrutsTest method testManage.

@Test
public void testManage() throws Exception {
    loanOffering = createLoanOfferingBO("Loan Offering", "LOAN");
    setRequestPathInfo("/loanproductaction.do");
    addRequestParameter("method", "manage");
    addRequestParameter("prdOfferingId", loanOffering.getPrdOfferingId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    performNoErrors();
    verifyForward(ActionForwards.manage_success.toString());
    List<ProductCategoryBO> productCategories = (List<ProductCategoryBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRODUCTCATEGORYLIST, request);
    Assert.assertEquals("The size of master data for categories", 1, productCategories.size());
    for (ProductCategoryBO productCategory : productCategories) {
        Assert.assertNotNull(productCategory.getProductType());
    }
    Assert.assertEquals("The size of applicable list", 2, ((List<MasterDataEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANAPPLFORLIST, request)).size());
    Assert.assertEquals("The size of grace period types list", 3, ((List<MasterDataEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANGRACEPERIODTYPELIST, request)).size());
    Assert.assertEquals("The size of interest types list", 4, ((List<MasterDataEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.INTERESTTYPESLIST, request)).size());
    Assert.assertEquals("The size of applicable list", 10, ((List<GLCodeEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRICIPALGLCODELIST, request)).size());
    Assert.assertEquals("The size of applicable list", 3, ((List<GLCodeEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANINTERESTGLCODELIST, request)).size());
    List<FundBO> funds = (List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCFUNDSLIST, request);
    Assert.assertNotNull(funds);
    List<FeeDto> fees = (List<FeeDto>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANFEESLIST, request);
    Assert.assertNull(fees);
    List<FeeBO> productFees = (List<FeeBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDFEE, request);
    Assert.assertNotNull(productFees);
    List<FeeDto> selectedFees = (List<FeeDto>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDFEESELECTEDLIST, request);
    Assert.assertNotNull(selectedFees);
    List<FundBO> selectedFunds = (List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDFUNDSELECTEDLIST, request);
    Assert.assertNotNull(selectedFunds);
    Assert.assertEquals("The size of applicable status list", 2, ((List<PrdStatusEntity>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDSTATUSLIST, request)).size());
    LoanPrdActionForm loanPrdActionForm = (LoanPrdActionForm) request.getSession().getAttribute(ProductDefinitionConstants.LOANPRODUCTACTIONFORM);
    Assert.assertNotNull(loanPrdActionForm);
    Assert.assertEquals(loanOffering.getPrdOfferingId().toString(), loanPrdActionForm.getPrdOfferingId());
    Assert.assertEquals(loanOffering.getPrdOfferingName(), loanPrdActionForm.getPrdOfferingName());
    Assert.assertEquals(loanOffering.getPrdOfferingShortName(), loanPrdActionForm.getPrdOfferingShortName());
    Assert.assertEquals(loanOffering.getPrdCategory().getProductCategoryID().toString(), loanPrdActionForm.getPrdCategory());
    Assert.assertEquals(loanOffering.getStatus().getValue().toString(), loanPrdActionForm.getPrdStatus());
    Assert.assertEquals(loanOffering.getPrdApplicableMasterEnum(), loanPrdActionForm.getPrdApplicableMasterEnum());
    Assert.assertEquals(DateUtils.getUserLocaleDate(TestObjectFactory.getContext().getPreferredLocale(), DateUtils.toDatabaseFormat(loanOffering.getStartDate())), loanPrdActionForm.getStartDate());
    if (loanOffering.getEndDate() != null) {
        Assert.assertEquals(DateUtils.getUserLocaleDate(TestObjectFactory.getContext().getPreferredLocale(), DateUtils.toDatabaseFormat(loanOffering.getEndDate())), loanPrdActionForm.getEndDate());
    } else {
        Assert.assertNull(loanPrdActionForm.getEndDate());
    }
    Assert.assertEquals(loanOffering.getDescription(), loanPrdActionForm.getDescription());
    Assert.assertEquals(loanOffering.getGracePeriodType().getId().toString(), loanPrdActionForm.getGracePeriodType());
    Assert.assertEquals(loanOffering.getGracePeriodDuration().toString(), loanPrdActionForm.getGracePeriodDuration());
    Assert.assertEquals(loanOffering.getInterestTypes().getId().toString(), loanPrdActionForm.getInterestTypes());
    Set<LoanAmountSameForAllLoanBO> loanAmountSameForAllLoan = loanOffering.getLoanAmountSameForAllLoan();
    Assert.assertNotNull(loanAmountSameForAllLoan);
    Set<NoOfInstallSameForAllLoanBO> noOfInstallSameForAllLoan = loanOffering.getNoOfInstallSameForAllLoan();
    Assert.assertNotNull(noOfInstallSameForAllLoan);
    Assert.assertEquals(loanOffering.getMaxInterestRate().toString(), loanPrdActionForm.getMaxInterestRate());
    Assert.assertEquals(loanOffering.getMinInterestRate().toString(), loanPrdActionForm.getMinInterestRate());
    Assert.assertEquals(loanOffering.getDefInterestRate().toString(), loanPrdActionForm.getDefInterestRate());
    Assert.assertEquals(loanOffering.isIntDedDisbursement(), loanPrdActionForm.isIntDedAtDisbValue());
    Assert.assertEquals(loanOffering.isPrinDueLastInst(), loanPrdActionForm.isPrinDueLastInstValue());
    Assert.assertEquals(loanOffering.isIncludeInLoanCounter(), loanPrdActionForm.isLoanCounterValue());
    Assert.assertEquals(loanOffering.getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString(), loanPrdActionForm.getRecurAfter());
    Assert.assertEquals(loanOffering.getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceId().toString(), loanPrdActionForm.getFreqOfInstallments());
    Assert.assertEquals(loanOffering.getPrincipalGLcode().getGlcodeId().toString(), loanPrdActionForm.getPrincipalGLCode());
    Assert.assertEquals(loanOffering.getInterestGLcode().getGlcodeId().toString(), loanPrdActionForm.getInterestGLCode());
    Assert.assertEquals(loanOffering.getLoanOfferingFees().size(), (selectedFees).size());
    Assert.assertEquals(loanOffering.getLoanOfferingFunds().size(), (selectedFunds).size());
}
Also used : LoanPrdActionForm(org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionForm) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) FundBO(org.mifos.accounts.fund.business.FundBO) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) NoOfInstallSameForAllLoanBO(org.mifos.accounts.productdefinition.business.NoOfInstallSameForAllLoanBO) FeeDto(org.mifos.accounts.fees.business.FeeDto) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) List(java.util.List) FeeBO(org.mifos.accounts.fees.business.FeeBO) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) LoanAmountSameForAllLoanBO(org.mifos.accounts.productdefinition.business.LoanAmountSameForAllLoanBO) Test(org.junit.Test)

Example 3 with PrdStatusEntity

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

the class PrdOfferingPersistenceIntegrationTest method testGetPrdStatus.

@Test
public void testGetPrdStatus() throws PersistenceException {
    PrdStatusEntity prdStatus = new PrdOfferingPersistence().getPrdStatus(PrdStatus.SAVINGS_ACTIVE);
    Assert.assertNotNull(prdStatus);
    Assert.assertEquals(ProductType.SAVINGS.getValue(), prdStatus.getPrdType().getProductTypeID());
    Assert.assertEquals(Short.valueOf("1"), prdStatus.getPrdState().getId());
}
Also used : PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) Test(org.junit.Test)

Example 4 with PrdStatusEntity

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

the class PrdOfferingPersistenceIntegrationTest method testGetApplicablePrdStatus.

@Test
public void testGetApplicablePrdStatus() throws PersistenceException {
    List<PrdStatusEntity> prdStatusList = new PrdOfferingPersistence().getApplicablePrdStatus(ProductType.LOAN, (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 5 with PrdStatusEntity

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

the class TestObjectFactory method createLoanOffering.

public static LoanOfferingBO createLoanOffering(final String name, final String shortName, final ApplicableTo applicableTo, final Date startDate, final PrdStatus offeringStatus, final Double defLnAmnt, final Double defIntRate, final Short defInstallments, final InterestType interestType, final boolean interestDeductedAtDisbursement, final boolean principalDueInLastInstallment, final MeetingBO meeting, final GraceType graceType, final short gracePeriodDuration, final String loanAmountCalcType, final String noOfInstallCalcType, final MifosCurrency currency, VariableInstallmentDetailsBO variableInstallmentDetails) {
    PrdApplicableMasterEntity prdApplicableMaster = new PrdApplicableMasterEntity(applicableTo);
    ProductCategoryBO productCategory = TestObjectFactory.getLoanPrdCategory();
    GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(graceType);
    InterestTypesEntity interestTypes = new InterestTypesEntity(interestType);
    GLCodeEntity glCodePrincipal = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, TestGeneralLedgerCode.LOANS_TO_CLIENTS);
    GLCodeEntity glCodeInterest = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, TestGeneralLedgerCode.INTEREST_ON_LOANS);
    LoanOfferingBO loanOffering;
    boolean loanCounter = true;
    boolean waiverInterest = true;
    try {
        loanOffering = new LoanOfferingBO(getContext(), name, shortName, productCategory, prdApplicableMaster, startDate, null, null, gracePeriodType, gracePeriodDuration, interestTypes, new Money(currency, defLnAmnt.toString()), new Money(currency, defLnAmnt.toString()), new Money(currency, defLnAmnt.toString()), defIntRate, defIntRate, defIntRate, defInstallments, defInstallments, defInstallments, loanCounter, interestDeductedAtDisbursement, principalDueInLastInstallment, new ArrayList<FundBO>(), new ArrayList<FeeBO>(), new ArrayList<PenaltyBO>(), meeting, glCodePrincipal, glCodeInterest, loanAmountCalcType, noOfInstallCalcType, waiverInterest);
    } catch (ProductDefinitionException e) {
        throw new RuntimeException(e);
    }
    loanOffering.setCurrency(currency);
    PrdStatusEntity prdStatus = testObjectPersistence.retrievePrdStatus(offeringStatus);
    LoanOfferingTestUtils.setStatus(loanOffering, prdStatus);
    LoanOfferingTestUtils.setGracePeriodType(loanOffering, gracePeriodType, gracePeriodDuration);
    if (variableInstallmentDetails != null) {
        loanOffering.setVariableInstallmentsAllowed(true);
        loanOffering.setVariableInstallmentDetails(variableInstallmentDetails);
    }
    IntegrationTestObjectMother.saveLoanProducts(loanOffering);
    return IntegrationTestObjectMother.findLoanProductBySystemId(loanOffering.getGlobalPrdOfferingNum());
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)

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