Search in sources :

Example 1 with AccountStatusChangeHistoryEntity

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

the class SavingsBO method save.

/**
     * @deprecated use {@link SavingsDao#save(SavingsBO)} to persist savings account.
     */
@Deprecated
public void save() throws AccountException {
    logger.info("In SavingsBO::save(), Before Saving , accountId: " + getAccountId());
    try {
        this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), this.getAccountState(), getPersonnelPersistence().getPersonnel(userContext.getId()), this));
        getSavingsPersistence().createOrUpdate(this);
        OfficeBO branch = getSavingsPersistence().getPersistentObject(OfficeBO.class, userContext.getBranchId());
        this.globalAccountNum = generateId(branch.getGlobalOfficeNum());
        getSavingsPersistence().createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    logger.info("In SavingsBO::save(), Successfully saved , accountId: " + getAccountId());
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 2 with AccountStatusChangeHistoryEntity

use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity 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 3 with AccountStatusChangeHistoryEntity

use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity 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)

Example 4 with AccountStatusChangeHistoryEntity

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

the class SavingsServiceFacadeWebTier method retrieveStatusChangeHistory.

@Override
public List<SavingsStatusChangeHistoryDto> retrieveStatusChangeHistory(String globalAccountNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);
    savingsAccount.updateDetails(userContext);
    List<SavingsStatusChangeHistoryDto> dtoList = new ArrayList<SavingsStatusChangeHistoryDto>();
    List<AccountStatusChangeHistoryEntity> statusChangeHistory = savingsAccount.getAccountStatusChangeHistory();
    for (AccountStatusChangeHistoryEntity accountStatusChangeHistory : statusChangeHistory) {
        dtoList.add(accountStatusChangeHistory.toDto());
    }
    return dtoList;
}
Also used : SavingsStatusChangeHistoryDto(org.mifos.dto.domain.SavingsStatusChangeHistoryDto) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 5 with AccountStatusChangeHistoryEntity

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

the class ApplyAdjustmentActionStrutsTest method testApplyAdjustment.

@Ignore
@Test
public void testApplyAdjustment() throws Exception {
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(PersonnelConstants.SYSTEM_USER);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    loan = (LoanBO) getLoanAccount();
    applyPayment(loan, 212);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    applyPayment(loan, 700);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), personnel, loan);
    AccountTestUtils.addToAccountStatusChangeHistory(loan, historyEntity);
    TestObjectFactory.updateObject(loan);
    StaticHibernateUtil.flushAndClearSession();
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    loan.setUserContext(userContext);
    for (AccountStatusChangeHistoryEntity accountStatus : loan.getAccountStatusChangeHistory()) {
        Assert.assertEquals(loan.getAccountId(), accountStatus.getAccount().getAccountId());
        Assert.assertNotNull(accountStatus.getAccountStatusChangeId());
        Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue(), accountStatus.getNewStatus().getId());
        Assert.assertEquals(personnel.getPersonnelId(), accountStatus.getPersonnel().getPersonnelId());
        Assert.assertEquals(personnel.getDisplayName(), accountStatus.getPersonnel().getDisplayName());
        Assert.assertEquals("-", accountStatus.getOldStatusName());
        Assert.assertNotNull(accountStatus.getNewStatusName());
        Assert.assertNull(accountStatus.getLocale());
        Assert.assertNotNull(accountStatus.getUserPrefferedTransactionDate());
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setRequestPathInfo("/applyAdjustment");
    addRequestParameter("method", "applyAdjustment");
    addRequestParameter("adjustmentNote", "Loan adjustment testing");
    addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    setUpSecurityContext();
    getRequest().getSession().setAttribute(Constants.USERCONTEXT, TestUtils.makeUser());
    actionPerform();
    loan = (LoanBO) TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
    verifyForward("applyadj_success");
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)21 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)11 AccountException (org.mifos.accounts.exceptions.AccountException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 Money (org.mifos.framework.util.helpers.Money)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 LocalDate (org.joda.time.LocalDate)3 Test (org.junit.Test)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 AccountState (org.mifos.accounts.util.helpers.AccountState)3 AccountNotesEntity (org.mifos.accounts.business.AccountNotesEntity)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)2 SavingsStatusChangeHistoryDto (org.mifos.dto.domain.SavingsStatusChangeHistoryDto)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 UserContext (org.mifos.security.util.UserContext)2 BigDecimal (java.math.BigDecimal)1