Search in sources :

Example 11 with AccountStatusChangeHistoryEntity

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

the class SavingsCloseTest method whenClosingAccountShouldCreateStatusChangeHistoryForClosure.

@Test
public void whenClosingAccountShouldCreateStatusChangeHistoryForClosure() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(1));
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(2));
    AccountStatusChangeHistoryEntity closure = savingsAccount.getAccountStatusChangeHistory().get(1);
    assertThat(closure.getAccount(), is((AccountBO) savingsAccount));
    assertTrue(closure.getOldStatus().isInState(AccountState.SAVINGS_ACTIVE));
    assertTrue(closure.getNewStatus().isInState(AccountState.SAVINGS_CLOSED));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 12 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 13 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 14 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 15 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)

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