Search in sources :

Example 1 with AccountState

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

the class LoanAccountServiceFacadeWebTier method assembleLoanAccountDetail.

private LoanAccountDetail assembleLoanAccountDetail(CreateLoanAccount loanAccountInfo) {
    CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getCustomerId());
    LoanOfferingBO loanProduct = this.loanProductDao.findById(loanAccountInfo.getProductId());
    Money loanAmount = new Money(loanProduct.getCurrency(), loanAccountInfo.getLoanAmount());
    AccountState accountStateType = AccountState.fromShort(loanAccountInfo.getAccountState().shortValue());
    FundBO fund = null;
    if (loanAccountInfo.getSourceOfFundId() != null) {
        fund = this.fundDao.findById(loanAccountInfo.getSourceOfFundId().shortValue());
    }
    return new LoanAccountDetail(customer, loanProduct, loanAmount, accountStateType, fund);
}
Also used : Money(org.mifos.framework.util.helpers.Money) FundBO(org.mifos.accounts.fund.business.FundBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LoanAccountDetail(org.mifos.clientportfolio.newloan.domain.LoanAccountDetail) AccountState(org.mifos.accounts.util.helpers.AccountState)

Example 2 with AccountState

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

the class AccountBusinessService method filterDisbursementFee.

private void filterDisbursementFee(List<FeeBO> feeList, AccountBO account) {
    for (Iterator<FeeBO> iter = feeList.iterator(); iter.hasNext(); ) {
        FeeBO fee = iter.next();
        FeePaymentEntity feePaymentEntity = fee.getFeeFrequency().getFeePayment();
        if (feePaymentEntity != null) {
            Short paymentType = feePaymentEntity.getId();
            if (paymentType.equals(FeePayment.TIME_OF_DISBURSEMENT.getValue())) {
                AccountState accountState = account.getState();
                if (accountState == AccountState.LOAN_PARTIAL_APPLICATION || accountState == AccountState.LOAN_PENDING_APPROVAL || accountState == AccountState.LOAN_APPROVED || accountState == AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) {
                    continue;
                } else {
                    iter.remove();
                }
            }
        }
    }
}
Also used : FeePaymentEntity(org.mifos.accounts.fees.business.FeePaymentEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountState(org.mifos.accounts.util.helpers.AccountState)

Example 3 with AccountState

use of org.mifos.accounts.util.helpers.AccountState 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 4 with AccountState

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

the class SavingsServiceFacadeWebTier method updateSavingsAccountStatus.

@Override
public void updateSavingsAccountStatus(AccountUpdateStatus updateStatus) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    SavingsBO savingsAccount = this.savingsDao.findById(updateStatus.getSavingsId());
    savingsAccount.updateDetails(userContext);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        AccountState newStatus = AccountState.fromShort(updateStatus.getNewStatusId());
        // FIXME - keithw - refactor savings specific logic out of changeStatus and create savings statue machine
        // wrapper.
        savingsAccount.changeStatus(newStatus, updateStatus.getFlagId(), updateStatus.getComment(), loggedInUser);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } 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 : BusinessRuleException(org.mifos.service.BusinessRuleException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountState(org.mifos.accounts.util.helpers.AccountState) 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) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with AccountState

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

Aggregations

AccountState (org.mifos.accounts.util.helpers.AccountState)14 AccountException (org.mifos.accounts.exceptions.AccountException)5 CustomerBO (org.mifos.customers.business.CustomerBO)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 Money (org.mifos.framework.util.helpers.Money)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)4 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)4 ServiceException (org.mifos.framework.exceptions.ServiceException)4 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)4 MifosUser (org.mifos.security.MifosUser)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)3 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)3 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)3 UserContext (org.mifos.security.util.UserContext)3 LocalDate (org.joda.time.LocalDate)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2