use of org.mifos.accounts.business.AccountNotesEntity in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldSetClosedDate.
@Test
public void whenClosingAccountShouldSetClosedDate() {
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();
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertThat(new LocalDate(savingsAccount.getClosedDate()), is(new LocalDate()));
}
use of org.mifos.accounts.business.AccountNotesEntity in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn.
@Test
public void whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
Money withdrawalAtCloseAmount = TestUtils.createMoney("105.56");
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(withdrawalAtCloseAmount).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// pre verification
assertTrue(savingsAccount.getAccountPayments().isEmpty());
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertFalse(savingsAccount.getAccountPayments().isEmpty());
assertThat(savingsAccount.getAccountPayments().size(), is(2));
AccountPaymentEntity interestPayment = savingsAccount.getAccountPayments().get(0);
assertThat(interestPayment.getAmount(), is(TestUtils.createMoney("5.56")));
AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(1);
assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("105.56")));
}
use of org.mifos.accounts.business.AccountNotesEntity 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.AccountNotesEntity in project head by mifos.
the class LoanBO method approve.
public void approve(PersonnelBO createdBy, String comment, LocalDate approvalDate) {
AccountStateEntity approvedState = new AccountStateEntity(AccountState.LOAN_APPROVED);
AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), approvedState, createdBy, this);
AccountNotesEntity accountNotesEntity = new AccountNotesEntity(approvalDate.toDateMidnight().toDate(), comment, createdBy, this);
this.addAccountStatusChangeHistory(historyEntity);
this.setAccountState(approvedState);
this.addAccountNotes(accountNotesEntity);
}
use of org.mifos.accounts.business.AccountNotesEntity in project head by mifos.
the class LoanAccountServiceFacadeWebTier method addNote.
@Override
public void addNote(CreateAccountNote accountNote) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
PersonnelBO createdBy = this.personnelDao.findPersonnelById(accountNote.getCreatedById().shortValue());
LoanBO loanAccount = this.loanDao.findById(accountNote.getAccountId());
AccountNotesEntity accountNotes = new AccountNotesEntity(new java.sql.Date(accountNote.getCommentDate().toDateMidnight().toDate().getTime()), accountNote.getComment(), createdBy, loanAccount);
try {
this.transactionHelper.startTransaction();
loanAccount.updateDetails(userContext);
loanAccount.addAccountNotes(accountNotes);
this.loanDao.save(loanAccount);
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
Aggregations