Search in sources :

Example 1 with SavingsAccountActivationDetail

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

use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.

the class SavingsAccountBuilder method buildForUnitTests.

public SavingsBO buildForUnitTests() {
    List<AccountActionDateEntity> listOfScheduledPayments = new ArrayList<AccountActionDateEntity>();
    if (scheduledPayments != null) {
        listOfScheduledPayments = new ArrayList<AccountActionDateEntity>(scheduledPayments);
    }
    activationDetails = new SavingsAccountActivationDetail(new LocalDate(activationDate), nextInterestPostingDate, listOfScheduledPayments);
    return buildAccount(activationDetails);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate)

Example 3 with SavingsAccountActivationDetail

use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.

the class SavingsAccountBuilder method build.

// build individual savings account
public SavingsBO build() {
    CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
    LocalDate activationDate = new LocalDate(createdDate);
    SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, activationDate);
    return buildAccount(derivedActivationDetails);
}
Also used : SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) CalendarEvent(org.mifos.calendar.CalendarEvent) LocalDate(org.joda.time.LocalDate)

Example 4 with SavingsAccountActivationDetail

use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.

the class SavingsAccountBuilder method buildAccount.

private SavingsBO buildAccount(SavingsAccountActivationDetail derivedActivationDetails) {
    List<AccountActionDateEntity> listOfScheduledPayments = new ArrayList<AccountActionDateEntity>();
    if (scheduledPayments == null) {
        listOfScheduledPayments = derivedActivationDetails.getScheduledPayments();
    } else {
        listOfScheduledPayments = new ArrayList<AccountActionDateEntity>(scheduledPayments);
    }
    activationDetails = new SavingsAccountActivationDetail(new LocalDate(activationDate), nextInterestPostingDate, listOfScheduledPayments);
    CreationDetail creationDetail = new CreationDetail(new DateTime(createdDate), createdByUserId.intValue());
    SavingsBO savingsAccount = new SavingsBO(accountState, customer, activationDetails, creationDetail, savingsProduct, recommendedAmountUnit, recommendedAmount, createdBy, savingsBalanceAmount);
    savingsAccount.setCustomerPersistence(customerDao);
    savingsAccount.setSavingsPaymentStrategy(savingsPaymentStrategy);
    savingsAccount.setSavingsTransactionActivityHelper(savingsTransactionActivityHelper);
    savingsAccount.updateDetails(TestUtils.makeUserWithLocales());
    for (AccountPaymentEntity depositPayment : deposits) {
        try {
            depositPayment.setAccount(savingsAccount);
            savingsAccount.deposit(depositPayment, customer);
        } catch (AccountException e) {
            throw new MifosRuntimeException("builder failed to apply deposits.", e);
        }
    }
    for (AccountPaymentEntity withdrawal : withdrawals) {
        try {
            withdrawal.setAccount(savingsAccount);
            savingsAccount.withdraw(withdrawal, customer);
        } catch (AccountException e) {
            throw new MifosRuntimeException("builder failed to apply withdrawals.", e);
        }
    }
    return savingsAccount;
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) AccountException(org.mifos.accounts.exceptions.AccountException) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CreationDetail(org.mifos.clientportfolio.newloan.domain.CreationDetail) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with SavingsAccountActivationDetail

use of org.mifos.accounts.savings.business.SavingsAccountActivationDetail in project head by mifos.

the class SavingsAccountBuilder method buildJointSavingsAccount.

public SavingsBO buildJointSavingsAccount() {
    CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
    SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, jointAccountMembers);
    return buildAccount(derivedActivationDetails);
}
Also used : SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) CalendarEvent(org.mifos.calendar.CalendarEvent)

Aggregations

SavingsAccountActivationDetail (org.mifos.accounts.savings.business.SavingsAccountActivationDetail)5 LocalDate (org.joda.time.LocalDate)4 CalendarEvent (org.mifos.calendar.CalendarEvent)3 ArrayList (java.util.ArrayList)2 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)2 AccountException (org.mifos.accounts.exceptions.AccountException)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 BigDecimal (java.math.BigDecimal)1 DateTime (org.joda.time.DateTime)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)1 AccountPaymentData (org.mifos.accounts.util.helpers.AccountPaymentData)1 AccountState (org.mifos.accounts.util.helpers.AccountState)1 PaymentData (org.mifos.accounts.util.helpers.PaymentData)1 SavingsPaymentData (org.mifos.accounts.util.helpers.SavingsPaymentData)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 CreationDetail (org.mifos.clientportfolio.newloan.domain.CreationDetail)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1