use of org.mifos.accounts.savings.interest.InterestPostingPeriodResult in project head by mifos.
the class SavingsPostInterestTest method whenPostingInterestASingleAccountPaymentIsMade.
@Test
public void whenPostingInterestASingleAccountPaymentIsMade() {
// setup
InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
Money interestToBePosted = TestUtils.createMoney("100");
DateTime activationDate = new DateTime().withDate(2010, 7, 20);
DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
// pre verification
assertTrue(savingsAccount.getAccountPayments().isEmpty());
InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
PersonnelBO createdBy = new PersonnelBuilder().build();
// exercise
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
// verification
assertFalse(savingsAccount.getAccountPayments().isEmpty());
AccountPaymentEntity interestPostingPayment = savingsAccount.getAccountPayments().get(0);
assertThat(interestPostingPayment.getAccount(), is((AccountBO) savingsAccount));
assertThat(interestPostingPayment.getAmount(), is(interestToBePosted));
assertThat(interestPostingPayment.getPaymentType().getId(), is(SavingsConstants.DEFAULT_PAYMENT_TYPE));
assertThat(new LocalDate(interestPostingPayment.getPaymentDate()), is(nextInterestPostingDate.toLocalDate()));
}
use of org.mifos.accounts.savings.interest.InterestPostingPeriodResult in project head by mifos.
the class SavingsPostInterestTest method whenPostingInterestNextInterestPostingDateIsPopulatedWithNextPostingDate.
@Test
public void whenPostingInterestNextInterestPostingDateIsPopulatedWithNextPostingDate() {
// setup
InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
DateTime activationDate = new DateTime().withDate(2010, 7, 20);
DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
// pre verification
assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(nextInterestPostingDate.toLocalDate()));
InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
PersonnelBO createdBy = new PersonnelBuilder().build();
// exercise
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
// verification
assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(endOfMonthAfter(nextInterestPostingDate)));
}
use of org.mifos.accounts.savings.interest.InterestPostingPeriodResult in project head by mifos.
the class SavingsPostInterestTest method whenPostingInterestASavingsAcitvityIsAddedForInterestPostingEvent.
@Test
public void whenPostingInterestASavingsAcitvityIsAddedForInterestPostingEvent() {
// setup
InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
DateTime activationDate = new DateTime().withDate(2010, 7, 20);
savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
// pre verification
List<SavingsActivityEntity> preSavingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
assertThat(preSavingsActivityityDetails.size(), is(0));
InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().with(calculationPeriod).build();
PersonnelBO createdBy = new PersonnelBuilder().build();
// exercise
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
// verification
List<SavingsActivityEntity> savingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
assertThat(savingsActivityityDetails.size(), is(1));
}
use of org.mifos.accounts.savings.interest.InterestPostingPeriodResult in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveClosingDetails.
@Override
public SavingsAccountClosureDto retrieveClosingDetails(Long savingsId, LocalDate closureDate) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
InterestScheduledEvent postingSchedule = savingsInterestScheduledEventFactory.createScheduledEventFrom(savingsAccount.getInterestPostingMeeting());
LocalDate nextPostingDate = new LocalDate(savingsAccount.getNextIntPostDate());
LocalDate startOfPostingPeriod = postingSchedule.findFirstDateOfPeriodForMatchingDate(nextPostingDate);
CalendarPeriod postingPeriodAtClosure;
if (startOfPostingPeriod.isAfter(closureDate)) {
postingPeriodAtClosure = new CalendarPeriod(closureDate, closureDate);
} else {
postingPeriodAtClosure = new CalendarPeriod(startOfPostingPeriod, closureDate);
}
List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao.retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), Long.valueOf(savingsId));
InterestPostingPeriodResult postingPeriodAtClosureResult = determinePostingPeriodResult(postingPeriodAtClosure, savingsAccount, allEndOfDayDetailsForAccount);
Money endOfAccountBalance = postingPeriodAtClosureResult.getPeriodBalance();
Money interestAmountAtClosure = postingPeriodAtClosureResult.getPeriodInterest();
List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
return new SavingsAccountClosureDto(new LocalDate(), endOfAccountBalance.toString(), interestAmountAtClosure.toString(), depositPaymentTypes);
}
use of org.mifos.accounts.savings.interest.InterestPostingPeriodResult in project head by mifos.
the class SavingsServiceFacadeWebTier method postInterestForAccount.
private void postInterestForAccount(Integer savingsId, UserContext userContext, PersonnelBO createdBy, boolean inTransaction) {
SavingsBO savingsAccount = this.savingsDao.findById(Long.valueOf(savingsId));
savingsAccount.updateDetails(userContext);
List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao.retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), Long.valueOf(savingsId));
LocalDate interestPostingDate = new LocalDate(savingsAccount.getNextIntPostDate());
InterestScheduledEvent postingSchedule = savingsInterestScheduledEventFactory.createScheduledEventFrom(savingsAccount.getInterestPostingMeeting());
LocalDate startOfPeriod = postingSchedule.findFirstDateOfPeriodForMatchingDate(interestPostingDate);
CalendarPeriod lastInterestPostingPeriod = new CalendarPeriod(startOfPeriod, interestPostingDate);
InterestPostingPeriodResult interestPostingPeriodResult = determinePostingPeriodResult(lastInterestPostingPeriod, savingsAccount, allEndOfDayDetailsForAccount);
savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
StringBuilder postingInfoMessage = new StringBuilder().append("account id: ").append(savingsAccount.getAccountId()).append("posting interest: ").append(interestPostingPeriodResult);
logger.info(postingInfoMessage.toString());
try {
if (!inTransaction) {
this.transactionHelper.startTransaction();
}
this.savingsDao.save(savingsAccount);
if (!inTransaction) {
this.transactionHelper.commitTransaction();
}
} catch (Exception e) {
if (!inTransaction) {
this.transactionHelper.rollbackTransaction();
}
throw new BusinessRuleException(savingsAccount.getAccountId().toString(), e);
} finally {
if (!inTransaction) {
this.transactionHelper.closeSession();
}
}
}
Aggregations