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));
}
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());
}
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);
}
}
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());
}
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;
}
Aggregations