Search in sources :

Example 11 with SavingsOfferingBO

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

the class InterestPostingAccountingEntry method applySpecificAccountActionEntry.

@Override
protected void applySpecificAccountActionEntry() throws FinancialException {
    SavingsTrxnDetailEntity savingsTrxn = (SavingsTrxnDetailEntity) financialActivity.getAccountTrxn();
    FinancialActionTypeEntity finIntPostingAction = getFinancialAction(FinancialActionConstants.SAVINGS_INTERESTPOSTING);
    SavingsOfferingBO savingsOffering = ((SavingsBO) savingsTrxn.getAccount()).getSavingsOffering();
    addAccountEntryDetails(savingsTrxn.getInterestAmount(), finIntPostingAction, savingsOffering.getInterestGLCode(), FinancialConstants.DEBIT);
    addAccountEntryDetails(savingsTrxn.getInterestAmount(), finIntPostingAction, savingsOffering.getDepositGLCode(), FinancialConstants.CREDIT);
}
Also used : FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity)

Example 12 with SavingsOfferingBO

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

the class SavingsServiceFacadeWebTier method retrieveSavingsProductReferenceData.

@Override
public SavingsProductReferenceDto retrieveSavingsProductReferenceData(Integer productId) {
    SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(productId);
    List<ListElement> interestCalcTypeOptions = new ArrayList<ListElement>();
    List<InterestCalcTypeEntity> interestCalculationTypes = this.savingsProductDao.retrieveInterestCalculationTypes();
    for (InterestCalcTypeEntity entity : interestCalculationTypes) {
        interestCalcTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
    }
    boolean savingsPendingApprovalEnabled = ProcessFlowRules.isSavingsPendingApprovalStateEnabled();
    return new SavingsProductReferenceDto(interestCalcTypeOptions, savingsProduct.toFullDto(), savingsPendingApprovalEnabled);
}
Also used : InterestCalcTypeEntity(org.mifos.accounts.productdefinition.business.InterestCalcTypeEntity) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) ArrayList(java.util.ArrayList) ListElement(org.mifos.dto.screen.ListElement) SavingsProductReferenceDto(org.mifos.dto.screen.SavingsProductReferenceDto)

Example 13 with SavingsOfferingBO

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

the class SavingsServiceFacadeWebTier method createSavingsAccount.

@Override
public String createSavingsAccount(OpeningBalanceSavingsAccount openingBalanceSavingsAccount) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LocalDate createdDate = new LocalDate();
    Integer createdById = user.getUserId();
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
    CustomerBO customer = this.customerDao.findCustomerBySystemId(openingBalanceSavingsAccount.getCustomerGlobalId());
    SavingsOfferingBO savingsProduct = this.savingsProductDao.findBySystemId(openingBalanceSavingsAccount.getProductGlobalId());
    AccountState savingsAccountState = AccountState.fromShort(openingBalanceSavingsAccount.getAccountState());
    Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getRecommendedOrMandatoryAmount());
    Money openingBalance = new Money(savingsProduct.getCurrency(), new BigDecimal(0));
    LocalDate activationDate = openingBalanceSavingsAccount.getActivationDate();
    CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    SavingsAccountActivationDetail activationDetails = SavingsBO.generateAccountActivationDetails(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, calendarEvents, activationDate);
    SavingsBO savingsAccount = SavingsBO.createOpeningBalanceIndividualSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, activationDetails, createdBy, openingBalance);
    savingsAccount.setGlobalAccountNum(openingBalanceSavingsAccount.getAccountNumber());
    savingsAccount.setSavingsBalance(openingBalance);
    DateTimeService dateTimeService = new DateTimeService();
    savingsAccount.setDateTimeService(dateTimeService);
    openingBalance = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getOpeningBalance());
    if (savingsAccountState.isActiveLoanAccountState()) {
        savingsAccount.resetRecommendedAmountOnFutureInstallments();
    }
    try {
        if (openingBalance.isGreaterThanZero()) {
            PaymentData paymentData = new PaymentData(openingBalance, createdBy, Short.valueOf("1"), activationDate.toDateMidnight().toDate());
            paymentData.setCustomer(customer);
            savingsAccount.applyPayment(paymentData);
        }
        this.transactionHelper.startTransaction();
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        // savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
        return savingsAccount.getGlobalAccountNum();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountPaymentData(org.mifos.accounts.util.helpers.AccountPaymentData) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountState(org.mifos.accounts.util.helpers.AccountState) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with SavingsOfferingBO

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

the class SavingsServiceFacadeWebTier method createSavingsAccount.

@Override
public Long createSavingsAccount(SavingsAccountCreationDto savingsAccountCreation, List<QuestionGroupDetail> questionGroups) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    LocalDate createdDate = new LocalDate();
    Integer createdById = user.getUserId();
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
    CustomerBO customer = this.customerDao.findCustomerById(savingsAccountCreation.getCustomerId());
    SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(savingsAccountCreation.getProductId());
    Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), savingsAccountCreation.getRecommendedOrMandatoryAmount());
    AccountState savingsAccountState = AccountState.fromShort(savingsAccountCreation.getAccountState());
    CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    SavingsAccountTypeInspector savingsAccountWrapper = new SavingsAccountTypeInspector(customer, savingsProduct.getRecommendedAmntUnit());
    try {
        SavingsBO savingsAccount = null;
        if (savingsAccountWrapper.isIndividualSavingsAccount()) {
            savingsAccount = SavingsBO.createIndividalSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy);
        } else if (savingsAccountWrapper.isJointSavingsAccountWithClientTracking()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(customer.getSearchId(), customer.getOfficeId(), CustomerLevel.CLIENT);
            savingsAccount = SavingsBO.createJointSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy, activeAndOnHoldClients);
        }
        try {
            personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
        } catch (AccountException e) {
            throw new MifosRuntimeException("Access denied!", e);
        }
        this.transactionHelper.startTransaction();
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        // save question groups
        if (!questionGroups.isEmpty()) {
            Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Savings");
            QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), savingsAccount.getAccountId(), eventSourceId, questionGroups);
            questionnaireServiceFacade.saveResponses(questionGroupDetails);
        }
        this.transactionHelper.commitTransaction();
        return savingsAccount.getAccountId().longValue();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) QuestionGroupDetails(org.mifos.platform.questionnaire.service.QuestionGroupDetails) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountState(org.mifos.accounts.util.helpers.AccountState) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SavingsAccountTypeInspector(org.mifos.accounts.savings.business.SavingsAccountTypeInspector) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) ArrayList(java.util.ArrayList) List(java.util.List) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 15 with SavingsOfferingBO

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

the class SavingsProductDaoHibernateIntegrationTest method testShouldFindSavingsProductById.

@Test
public void testShouldFindSavingsProductById() {
    // setup
    SavingsOfferingBO savingsProduct = new SavingsProductBuilder().appliesToCentersOnly().mandatory().withName("product1").withShortName("1234").withMandatoryAmount("25").buildForIntegrationTests();
    IntegrationTestObjectMother.saveSavingsProducts(savingsProduct);
    // exercise test
    SavingsOfferingBO result = savingsProductDao.findById(savingsProduct.getPrdOfferingId().intValue());
    Money recommendedAmount = TestUtils.createMoney("25");
    RecommendedAmntUnitEntity recommendedAmntUnit = null;
    Money maxAmntWithdrawl = TestUtils.createMoney("100");
    Double interestRate = Double.valueOf("12");
    Money minAmountRequiredForInterestToBeCalculated = TestUtils.createMoney("100");
    LocalDate updateDate = new LocalDate();
    result.updateSavingsDetails(recommendedAmount, recommendedAmntUnit, maxAmntWithdrawl, interestRate, minAmountRequiredForInterestToBeCalculated, updateDate);
    IntegrationTestObjectMother.saveSavingsProducts(result);
    // assertion
    assertNotNull(result);
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsProductBuilder(org.mifos.domain.builders.SavingsProductBuilder) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) RecommendedAmntUnitEntity(org.mifos.accounts.productdefinition.business.RecommendedAmntUnitEntity) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)63 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)20 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)17 SavingsProductBuilder (org.mifos.domain.builders.SavingsProductBuilder)14 MeetingBO (org.mifos.application.meeting.business.MeetingBO)11 LocalDate (org.joda.time.LocalDate)10 SavingsAccountBuilder (org.mifos.domain.builders.SavingsAccountBuilder)10 Date (java.util.Date)9 UserContext (org.mifos.security.util.UserContext)9 Date (java.sql.Date)8 DateTime (org.joda.time.DateTime)8 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)8 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)8 SavingsTestHelper (org.mifos.accounts.savings.util.helpers.SavingsTestHelper)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 CustomerException (org.mifos.customers.exceptions.CustomerException)7 Money (org.mifos.framework.util.helpers.Money)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)5