Search in sources :

Example 6 with PrdOfferingPersistence

use of org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence in project head by mifos.

the class AdminServiceFacadeWebTier method createOrUpdateProductMix.

@Override
public void createOrUpdateProductMix(Integer productId, List<Integer> notAllowedProductIds) {
    try {
        PrdOfferingBO product = new PrdOfferingPersistence().getPrdOfferingByID(productId.shortValue());
        StaticHibernateUtil.startTransaction();
        product.setPrdMixFlag(YesNoFlag.YES.getValue());
        applicationConfigurationDao.save(product);
        StaticHibernateUtil.flushSession();
        List<PrdOfferingBO> newNotAllowedProducts = new ArrayList<PrdOfferingBO>();
        for (Integer notAllowedProductId : notAllowedProductIds) {
            PrdOfferingBO notAllowedProduct = new PrdOfferingPersistence().getPrdOfferingByID(notAllowedProductId.shortValue());
            newNotAllowedProducts.add(notAllowedProduct);
        }
        for (ProductMixBO oldNotAllowedProduct : product.getCollectionProductMix()) {
            ProductMixBO productMix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID(productId.shortValue(), oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId());
            if (null != productMix) {
                applicationConfigurationDao.delete(productMix);
                StaticHibernateUtil.flushSession();
            }
            ProductMixBO alternateproductmix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID(oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId(), productId.shortValue());
            if (null != alternateproductmix) {
                applicationConfigurationDao.delete(alternateproductmix);
                StaticHibernateUtil.flushSession();
            }
        }
        for (PrdOfferingBO notAllowedProduct : newNotAllowedProducts) {
            ProductMixBO productMix = new ProductMixBO(product, notAllowedProduct);
            productMix.setUpdatedDate(new DateTime().toDate());
            productMix.setUpdatedBy(Short.valueOf("1"));
            applicationConfigurationDao.save(productMix);
            StaticHibernateUtil.flushSession();
        }
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PrdOfferingBO(org.mifos.accounts.productdefinition.business.PrdOfferingBO) ArrayList(java.util.ArrayList) ProductMixBO(org.mifos.accounts.productsmix.business.ProductMixBO) DateTime(org.joda.time.DateTime) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with PrdOfferingPersistence

use of org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence in project head by mifos.

the class SavingsProductAssembler method generateProductGlobalNum.

private String generateProductGlobalNum(MifosUser user) {
    StringBuilder globalPrdOfferingNum = new StringBuilder();
    globalPrdOfferingNum.append(user.getBranchId());
    globalPrdOfferingNum.append("-");
    try {
        Short maxPrdID = new PrdOfferingPersistence().getMaxPrdOffering();
        globalPrdOfferingNum.append(StringUtils.leftPad(String.valueOf(maxPrdID != null ? maxPrdID + 1 : ProductDefinitionConstants.DEFAULTMAX + 1), 3, '0'));
        return globalPrdOfferingNum.toString();
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with PrdOfferingPersistence

use of org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence 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 9 with PrdOfferingPersistence

use of org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence in project head by mifos.

the class LoanProductAssembler method generateProductGlobalNum.

private String generateProductGlobalNum(MifosUser user) {
    StringBuilder globalPrdOfferingNum = new StringBuilder();
    globalPrdOfferingNum.append(user.getBranchId());
    globalPrdOfferingNum.append("-");
    try {
        Short maxPrdID = new PrdOfferingPersistence().getMaxPrdOffering();
        globalPrdOfferingNum.append(StringUtils.leftPad(String.valueOf(maxPrdID != null ? maxPrdID + 1 : ProductDefinitionConstants.DEFAULTMAX + 1), 3, '0'));
        return globalPrdOfferingNum.toString();
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with PrdOfferingPersistence

use of org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence in project head by mifos.

the class PrdOfferingBO method update.

public void update(final Short userId, final String prdOfferingName, final String prdOfferingShortName, final ProductCategoryBO prdCategory, final PrdApplicableMasterEntity prdApplicableMaster, final Date startDate, final Date endDate, final String description, final PrdStatus status) throws ProductDefinitionException {
    vaildate(prdOfferingName, prdOfferingShortName, prdCategory, prdApplicableMaster, startDate);
    validateStartDateForUpdate(startDate);
    validateEndDateAgainstCurrentDate(startDate, endDate);
    if (!prdOfferingName.equals(this.prdOfferingName)) {
        validateDuplicateProductOfferingName(prdOfferingName);
    }
    if (!prdOfferingShortName.equals(this.prdOfferingShortName)) {
        validateDuplicateProductOfferingShortName(prdOfferingShortName);
    }
    this.prdOfferingName = prdOfferingName;
    this.prdOfferingShortName = prdOfferingShortName;
    this.prdCategory = prdCategory;
    this.prdApplicableMaster = prdApplicableMaster;
    this.startDate = startDate;
    this.endDate = endDate;
    this.description = description;
    try {
        this.prdStatus = new PrdOfferingPersistence().getPrdStatus(status);
    } catch (PersistenceException pe) {
        throw new ProductDefinitionException(pe);
    }
    logger.debug("creating product offering done");
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Aggregations

PrdOfferingPersistence (org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence)13 PersistenceException (org.mifos.framework.exceptions.PersistenceException)11 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 ArrayList (java.util.ArrayList)4 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)4 DateTime (org.joda.time.DateTime)3 PrdOfferingBO (org.mifos.accounts.productdefinition.business.PrdOfferingBO)3 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)2 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)2 PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)2 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)2 ApplicableTo (org.mifos.accounts.productdefinition.util.helpers.ApplicableTo)2 MifosCurrency (org.mifos.application.master.business.MifosCurrency)2 MeetingBO (org.mifos.application.meeting.business.MeetingBO)2 RecurrenceType (org.mifos.application.meeting.util.helpers.RecurrenceType)2 PrdOfferingDto (org.mifos.dto.domain.PrdOfferingDto)2 ProductDetailsDto (org.mifos.dto.domain.ProductDetailsDto)2 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 Date (java.util.Date)1