MIFOSX-671: ensure summary fields like balance on transactions are updated in the case where account is activated and deposit automatically made.

This commit is contained in:
Keith Woodlock
2013-09-18 12:30:32 +01:00
parent b2168bff2c
commit 7aa8332b30
@@ -12,8 +12,8 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.localePara
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeriodFrequencyParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeriodFrequencyTypeParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeAmountParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeTypeParamName;
import java.math.BigDecimal;
import java.math.MathContext;
@@ -168,7 +168,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
/**
* The interest period is the span of time at the end of which savings in a
* client's account earn interest.
*
*
* A value from the {@link SavingsCompoundingInterestPeriodType}
* enumeration.
*/
@@ -261,7 +261,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance,
final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType,
final BigDecimal withdrawalFeeAmount, final SavingsWithdrawalFeesType withdrawalFeeType,
boolean withdrawalFeeApplicableForTransfer, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay) {
final boolean withdrawalFeeApplicableForTransfer, final BigDecimal annualFeeAmount, final MonthDay annualFeeOnMonthDay) {
final SavingsAccountStatusType status = SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL;
return new SavingsAccount(client, group, product, fieldOfficer, accountNo, externalId, status, accountType, submittedOnDate,
@@ -423,11 +423,11 @@ public class SavingsAccount extends AbstractPersistable<Long> {
/**
* All interest calculation based on END-OF-DAY-BALANCE.
*
*
* Interest calculation is performed on-the-fly over all account
* transactions.
*
*
*
*
* 1. Calculate Interest From Beginning Of Account 1a. determine the
* 'crediting' periods that exist for this savings acccount 1b. determine
* the 'compounding' periods that exist within each 'crediting' period
@@ -607,7 +607,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
return activationLocalDate;
}
public SavingsAccountTransaction withdraw(SavingsAccountTransactionDTO transactionDTO, final boolean applyWithdrawFee) {
public SavingsAccountTransaction withdraw(final SavingsAccountTransactionDTO transactionDTO, final boolean applyWithdrawFee) {
if (isNotActive()) {
@@ -728,7 +728,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
}
}
public void validateAccountBalanceDoesNotBecomeNegative(String transactionAction) {
public void validateAccountBalanceDoesNotBecomeNegative(final String transactionAction) {
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
Money runningBalance = Money.zero(this.currency);
@@ -1669,9 +1669,17 @@ public class SavingsAccount extends AbstractPersistable<Long> {
// activating account.
final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance);
if (minRequiredOpeningBalance.isGreaterThanZero()) {
SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, activationDate, minRequiredOpeningBalance.getAmount(),
final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, activationDate, minRequiredOpeningBalance.getAmount(),
existingTransactionIds, existingReversedTransactionIds, null);
deposit(transactionDTO);
// no openingBalance concept supported yet but probably will to allow
// for migrations.
final Money openingAccountBalance = Money.zero(this.currency);
// update existing transactions so derived balance fields are
// correct.
recalculateDailyBalances(openingAccountBalance);
}
return actualChanges;
@@ -1705,9 +1713,9 @@ public class SavingsAccount extends AbstractPersistable<Long> {
.failWithCode("cannot.be.a.future.date");
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
}
List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
if (savingsAccountTransactions.size() > 0) {
SavingsAccountTransaction accountTransaction = savingsAccountTransactions.get(savingsAccountTransactions.size() - 1);
final SavingsAccountTransaction accountTransaction = savingsAccountTransactions.get(savingsAccountTransactions.size() - 1);
if (accountTransaction.isAfter(closedDate)) {
baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
.failWithCode("must.be.after.last.transaction.date");