Search in sources :

Example 1 with InterestCalcType

use of org.mifos.accounts.productdefinition.util.helpers.InterestCalcType in project head by mifos.

the class SavingsServiceFacadeWebTier method determinePostingPeriodResult.

private InterestPostingPeriodResult determinePostingPeriodResult(CalendarPeriod postingPeriod, SavingsBO savingsAccount, List<EndOfDayDetail> allEndOfDayDetailsForAccount) {
    List<SavingsProductHistoricalInterestDetail> historicalInterestDetails = savingsAccount.getHistoricalInterestDetailsForPeriod(postingPeriod);
    MifosCurrency currencyInUse = savingsAccount.getCurrency();
    Money startingBalanceForPeriod = calculateAccountBalanceOn(postingPeriod.getStartDate(), allEndOfDayDetailsForAccount, currencyInUse);
    InterestCalcType interestCalcType = savingsAccount.getInterestCalcType();
    int accountingNumberOfInterestDaysInYear = AccountingRules.getNumberOfInterestDays();
    SavingsInterestDetail interestDetail = new SavingsInterestDetail(interestCalcType, savingsAccount.getInterestRate(), accountingNumberOfInterestDaysInYear, savingsAccount.getMinAmntForInt());
    InterestScheduledEvent interestCalculationEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(savingsAccount.getInterestCalculationMeeting());
    return doCalculateInterestForPostingPeriod(postingPeriod, startingBalanceForPeriod, historicalInterestDetails, allEndOfDayDetailsForAccount, interestDetail, interestCalculationEvent);
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) Money(org.mifos.framework.util.helpers.Money) InterestCalcType(org.mifos.accounts.productdefinition.util.helpers.InterestCalcType) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) SavingsInterestDetail(org.mifos.accounts.savings.interest.SavingsInterestDetail) SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 2 with InterestCalcType

use of org.mifos.accounts.productdefinition.util.helpers.InterestCalcType 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)

Aggregations

InterestCalcType (org.mifos.accounts.productdefinition.util.helpers.InterestCalcType)2 MifosCurrency (org.mifos.application.master.business.MifosCurrency)2 Money (org.mifos.framework.util.helpers.Money)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)1 InterestCalcTypeEntity (org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity)1 PrdApplicableMasterEntity (org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity)1 PrdStatusEntity (org.mifos.accounts.productdefinition.business.PrdStatusEntity)1 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)1 RecommendedAmntUnitEntity (org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity)1 SavingsTypeEntity (org.mifos.accounts.productdefinition.business.SavingsTypeEntity)1 PrdOfferingPersistence (org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence)1 ApplicableTo (org.mifos.accounts.productdefinition.util.helpers.ApplicableTo)1 RecommendedAmountUnit (org.mifos.accounts.productdefinition.util.helpers.RecommendedAmountUnit)1 SavingsType (org.mifos.accounts.productdefinition.util.helpers.SavingsType)1 SavingsInterestDetail (org.mifos.accounts.savings.interest.SavingsInterestDetail)1 SavingsProductHistoricalInterestDetail (org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)1 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)1