Search in sources :

Example 21 with ProductCategoryBO

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

the class LoanPrdAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("start create method of Loan Product Action");
    LoanPrdActionForm loanPrdActionForm = (LoanPrdActionForm) form;
    UserContext userContext = getUserContext(request);
    Locale locale = getLocale(userContext);
    LoanOfferingBO loanOffering = new LoanOfferingBO(userContext, loanPrdActionForm.getPrdOfferingName(), loanPrdActionForm.getPrdOfferingShortName(), getProductCategory(((List<ProductCategoryBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRODUCTCATEGORYLIST, request)), loanPrdActionForm.getPrdCategoryValue()), (PrdApplicableMasterEntity) findMasterEntity(request, ProductDefinitionConstants.LOANAPPLFORLIST, loanPrdActionForm.getPrdApplicableMasterEnum().getValue()), loanPrdActionForm.getStartDateValue(locale), loanPrdActionForm.getEndDateValue(locale), loanPrdActionForm.getDescription(), (GracePeriodTypeEntity) findMasterEntity(request, ProductDefinitionConstants.LOANGRACEPERIODTYPELIST, loanPrdActionForm.getGracePeriodTypeValue()), loanPrdActionForm.getGracePeriodDurationValue(), (InterestTypesEntity) findMasterEntity(request, ProductDefinitionConstants.INTERESTTYPESLIST, loanPrdActionForm.getInterestTypesValue()), loanPrdActionForm.getMaxInterestRateValue(), loanPrdActionForm.getMinInterestRateValue(), loanPrdActionForm.getDefInterestRateValue(), loanPrdActionForm.isLoanCounterValue(), loanPrdActionForm.isIntDedAtDisbValue(), loanPrdActionForm.isPrinDueLastInstValue(), getFundsFromList((List<FundBO>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCFUNDSLIST, request), loanPrdActionForm.getLoanOfferingFunds()), getFeeList((List<FeeBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDFEE, request), loanPrdActionForm.getPrdOfferinFees()), getPenaltyList((List<PenaltyBO>) SessionUtils.getAttribute(ProductDefinitionConstants.LOANPRDPENALTY, request), loanPrdActionForm.getPrdOfferinPenalties()), new MeetingBO(RecurrenceType.fromInt(loanPrdActionForm.getFreqOfInstallmentsValue()), loanPrdActionForm.getRecurAfterValue(), loanPrdActionForm.getStartDateValue(locale), MeetingType.LOAN_INSTALLMENT), findGLCodeEntity(request, ProductDefinitionConstants.LOANPRICIPALGLCODELIST, loanPrdActionForm.getPrincipalGLCode()), findGLCodeEntity(request, ProductDefinitionConstants.LOANINTERESTGLCODELIST, loanPrdActionForm.getInterestGLCode()), loanPrdActionForm, loanPrdActionForm.shouldWaiverInterest());
    loanOffering.setQuestionGroups(getQuestionGroups(request));
    loanOffering.setCurrency(getCurrency(loanPrdActionForm.getCurrencyId()));
    loanOffering.setRoundingDifferenceInFirstPayment(loanPrdActionForm.isRoundingDifferenceInFirstPayment());
    mapCashFlowDetail(loanPrdActionForm, loanOffering);
    mapVariableInstallmentDetails(loanOffering, loanPrdActionForm);
    loanOffering.setFixedRepaymentSchedule(loanPrdActionForm.isFixedRepaymentSchedule());
    loanOffering.save();
    request.setAttribute(ProductDefinitionConstants.LOANPRODUCTID, loanOffering.getPrdOfferingId());
    request.setAttribute(ProductDefinitionConstants.LOANPRDGLOBALOFFERINGNUM, loanOffering.getGlobalPrdOfferingNum());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : Locale(java.util.Locale) LoanPrdActionForm(org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionForm) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) List(java.util.List) ArrayList(java.util.ArrayList) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 22 with ProductCategoryBO

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

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

the class ProductCategoryPersistenceIntegrationTest method testFindByGlobalNum.

@Test
public void testFindByGlobalNum() throws Exception {
    ProductCategoryBO productCategoryBO = createProductCategory();
    Assert.assertNotNull(legacyProductCategoryDao.findByGlobalNum(productCategoryBO.getGlobalPrdCategoryNum()));
    deleteProductCategory(productCategoryBO);
}
Also used : ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) Test(org.junit.Test)

Example 24 with ProductCategoryBO

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

the class ProductCategoryBusinessServiceIntegrationTest method createProductCategory.

private ProductCategoryBO createProductCategory() throws Exception {
    userContext = TestUtils.makeUser();
    ProductCategoryBO productCategoryBO = new ProductCategoryBO(userContext, productCategoryBusinessService.getProductTypes().get(0), "product category", "created a category");
    productCategoryBO.save();
    StaticHibernateUtil.flushSession();
    return (ProductCategoryBO) StaticHibernateUtil.getSessionTL().createQuery("from " + ProductCategoryBO.class.getName() + " pcb order by pcb.productCategoryID").list().get(2);
}
Also used : ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO)

Example 25 with ProductCategoryBO

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

the class TestObjectFactory method createLoanOfferingFromLastLoan.

public static LoanOfferingBO createLoanOfferingFromLastLoan(final String name, final String shortName, final ApplicableTo applicableTo, final Date startDate, final PrdStatus offeringStatus, final Double defIntRate, final InterestType interestType, final boolean interestDeductedAtDisbursement, final boolean principalDueInLastInstallment, final MeetingBO meeting, final GraceType graceType, final LoanPrdActionForm loanPrdActionForm) {
    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, Short.valueOf("11"));
    GLCodeEntity glCodeInterest = (GLCodeEntity) StaticHibernateUtil.getSessionTL().get(GLCodeEntity.class, Short.valueOf("21"));
    short gracePeriodDuration = (short) 2;
    LoanOfferingBO loanOffering;
    boolean loanCounter = true;
    boolean waiverInterest = true;
    try {
        loanOffering = new LoanOfferingBO(getContext(), name, shortName, productCategory, prdApplicableMaster, startDate, null, null, gracePeriodType, gracePeriodDuration, interestTypes, defIntRate, defIntRate, defIntRate, loanCounter, interestDeductedAtDisbursement, principalDueInLastInstallment, new ArrayList<FundBO>(), new ArrayList<FeeBO>(), new ArrayList<PenaltyBO>(), meeting, glCodePrincipal, glCodeInterest, loanPrdActionForm, waiverInterest);
    } catch (ProductDefinitionException e) {
        throw new RuntimeException(e);
    }
    PrdStatusEntity prdStatus = testObjectPersistence.retrievePrdStatus(offeringStatus);
    LoanOfferingTestUtils.setStatus(loanOffering, prdStatus);
    LoanOfferingTestUtils.setGracePeriodType(loanOffering, gracePeriodType, gracePeriodDuration);
    return (LoanOfferingBO) testObjectPersistence.persist(loanOffering);
}
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

ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)26 MifosRuntimeException (org.mifos.core.MifosRuntimeException)13 ArrayList (java.util.ArrayList)11 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)11 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)9 PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)9 Test (org.junit.Test)7 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)7 GracePeriodTypeEntity (org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity)6 InterestTypesEntity (org.mifos.application.master.business.InterestTypesEntity)6 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 FeeBO (org.mifos.accounts.fees.business.FeeBO)5 FundBO (org.mifos.accounts.fund.business.FundBO)5 ServiceException (org.mifos.framework.exceptions.ServiceException)5 SystemException (org.mifos.framework.exceptions.SystemException)5 List (java.util.List)4 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 UserContext (org.mifos.security.util.UserContext)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4