Search in sources :

Example 11 with AccountStateEntity

use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveAccountStatuses.

@Override
public AccountStatusDto retrieveAccountStatuses(Long savingsId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    try {
        List<ListElement> savingsStatesList = new ArrayList<ListElement>();
        AccountStateMachines.getInstance().initializeSavingsStates();
        List<AccountStateEntity> statusList = AccountStateMachines.getInstance().getSavingsStatusList(savingsAccount.getAccountState());
        for (AccountStateEntity accountState : statusList) {
            savingsStatesList.add(new ListElement(accountState.getId().intValue(), accountState.getName()));
        }
        return new AccountStatusDto(savingsStatesList);
    } catch (StatesInitializationException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountStatusDto(org.mifos.dto.domain.AccountStatusDto) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) ListElement(org.mifos.dto.screen.ListElement) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with AccountStateEntity

use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.

the class AccountStatusAction method getLoanOfficers.

@TransactionDemarcate(joinToken = true)
public ActionForward getLoanOfficers(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse httpservletresponse) throws Exception {
    AccountStatusActionForm accountStatusActionForm = (AccountStatusActionForm) form;
    Short officeId = Short.valueOf(accountStatusActionForm.getOfficeId());
    ChangeAccountStatusDto changeAccountStatusDto = this.loanAccountServiceFacade.retrieveLoanOfficerDetailsForBranch(officeId);
    SessionUtils.setCollectionAttribute(LoanConstants.LOAN_OFFICERS, changeAccountStatusDto.getLoanOfficers(), request);
    if (officeId != null) {
        AccountStateEntity accountStateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, changeAccountStatusDto.getAccountState());
        SessionUtils.setAttribute(LoanConstants.LOANACCOUNTSTAES, accountStateEntity, request);
    }
    return mapping.findForward(ActionForwards.changeAccountStatus_success.toString());
}
Also used : ChangeAccountStatusDto(org.mifos.dto.screen.ChangeAccountStatusDto) AccountStatusActionForm(org.mifos.accounts.loan.struts.actionforms.AccountStatusActionForm) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 13 with AccountStateEntity

use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.

the class LoanAdjustmentsIntegrationTest method testWhenARepaymentIsAdjustedItGoesBackToBadStandingIfNecessary.

@Test
public void testWhenARepaymentIsAdjustedItGoesBackToBadStandingIfNecessary() throws Exception {
    // relates to mifos-3479
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
    loan = createLoan();
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 2 installments
    makePayment(loan, "222.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 1 more installment
    makePayment(loan, "111.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // Ensure that after the adjustment the loan is calculated to be in bad standing.
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 11, 13));
    adjustLastLoanPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    assertNotNull("Account Status Change History Should Not Be Null", loan.getAccountStatusChangeHistory());
    Integer listSize = loan.getAccountStatusChangeHistory().size();
    assertFalse(listSize == 0);
    // check if the last entry has an oldstatus LOAN_ACTIVE_IN_GOOD_STANDING and a new status of
    // LOAN_ACTIVE_IN_BAD_STANDING
    AccountStateEntity oldStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getOldStatus();
    AccountStateEntity newStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getNewStatus();
    assertTrue("Old Status Should Have Been LOAN_ACTIVE_IN_GOOD_STANDING", oldStatus.isInState(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING));
    assertTrue("New Status Should Have Been LOAN_ACTIVE_IN_BAD_STANDING", newStatus.isInState(AccountState.LOAN_ACTIVE_IN_BAD_STANDING));
}
Also used : AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

Example 14 with AccountStateEntity

use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.

the class SavingsBO method goActiveDueToDepositOrWithdrawalOnAccount.

private void goActiveDueToDepositOrWithdrawalOnAccount(PersonnelBO updatedBy) {
    if (!this.isActive()) {
        AccountStateEntity oldAccountState = this.getAccountState();
        AccountStateEntity newAccountState = new AccountStateEntity(AccountState.SAVINGS_ACTIVE);
        this.setAccountState(newAccountState);
        AccountStatusChangeHistoryEntity savingsAccountToActive = new AccountStatusChangeHistoryEntity(oldAccountState, newAccountState, updatedBy, this);
        this.accountStatusChangeHistory.add(savingsAccountToActive);
    }
}
Also used : AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity)

Example 15 with AccountStateEntity

use of org.mifos.accounts.business.AccountStateEntity in project head by mifos.

the class SavingsBO method closeAccount.

public void closeAccount(final AccountPaymentEntity payment, final AccountNotesEntity notes, final CustomerBO customer, PersonnelBO loggedInUser) {
    AccountStateEntity previousAccountState = this.getAccountState();
    AccountStateEntity closedAccountState = new AccountStateEntity(AccountState.SAVINGS_CLOSED);
    AccountStatusChangeHistoryEntity statusChangeHistory = new AccountStatusChangeHistoryEntity(previousAccountState, closedAccountState, loggedInUser, this);
    this.addAccountStatusChangeHistory(statusChangeHistory);
    this.setAccountState(closedAccountState);
    Money interestOutstanding = payment.getAmount().subtract(this.savingsBalance);
    if (interestOutstanding.isGreaterThanZero()) {
        LocalDate currentPostingDate = new LocalDate(payment.getPaymentDate());
        LocalDate nextPostingDate = new LocalDate();
        doPostInterest(currentPostingDate, interestOutstanding, loggedInUser);
        updatePostingDetails(nextPostingDate);
    }
    Date transactionDate = new DateTimeService().getCurrentDateMidnight().toDate();
    if (payment.getAmount().isGreaterThanZero()) {
        SavingsTrxnDetailEntity withdrawal = SavingsTrxnDetailEntity.savingsWithdrawal(payment, customer, this.savingsBalance, payment.getAmount(), loggedInUser, transactionDate, transactionDate, transactionDate);
        payment.addAccountTrxn(withdrawal);
        this.addAccountPayment(payment);
        SavingsActivityEntity interestPostingActivity = SavingsActivityEntity.savingsWithdrawal(this, loggedInUser, this.savingsBalance, payment.getAmount(), payment.getPaymentDate());
        savingsActivityDetails.add(interestPostingActivity);
        this.savingsPerformance.setTotalWithdrawals(this.savingsPerformance.getTotalWithdrawals().add(payment.getAmount()));
        try {
            buildFinancialEntries(payment.getAccountTrxns());
        } catch (AccountException e) {
            throw new BusinessRuleException(e.getKey(), e);
        }
    }
    this.addAccountNotes(notes);
    //        this.lastIntCalcDate = transactionDate;
    this.lastIntPostDate = transactionDate;
    //        this.interIntCalcDate = null;
    this.savingsBalance = new Money(getCurrency());
    this.interestToBePosted = new Money(getCurrency());
    this.setClosedDate(new DateTimeService().getCurrentJavaDateTime());
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LocalDate(org.joda.time.LocalDate) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Aggregations

AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)49 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)11 AccountException (org.mifos.accounts.exceptions.AccountException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 Money (org.mifos.framework.util.helpers.Money)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 AdminDocAccStateMixBO (org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO)5 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)5 Date (java.util.Date)4 List (java.util.List)4 LocalDate (org.joda.time.LocalDate)4 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 AccountStateFlagEntity (org.mifos.accounts.business.AccountStateFlagEntity)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 UserContext (org.mifos.security.util.UserContext)4