From d2036447b1bf12810328bf791c0415d5cb53a28e Mon Sep 17 00:00:00 2001 From: goutham-M Date: Mon, 3 Jun 2013 21:22:11 +0530 Subject: [PATCH] balance amount in savings account showing negative balance(fixed) withdrawl amount from savings account, showing negative balance(fixed) --- .../portfolio/savings/domain/SavingsAccount.java | 12 ++++-------- .../InsufficientAccountBalanceException.java | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java index 82b6da017..6db422eb3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java @@ -798,9 +798,10 @@ public class SavingsAccount extends AbstractPersistable { existingReversedTransactionIds.addAll(findExistingReversedTransactionIds()); final Money amount = Money.of(this.currency, transactionAmount); + final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, paymentDetail, transactionDate, amount); this.transactions.add(transaction); - + this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); final LocalDate today = DateUtils.getLocalDateOfTenant(); @@ -875,9 +876,9 @@ public class SavingsAccount extends AbstractPersistable { final Money transactionAmountMoney = Money.of(this.currency, transactionAmount); - if (isNotEnoughFundsToWithdraw(transactionAmountMoney)) { + if (this.summary.getAccountBalance(this.currency).isLessThan(transactionAmountMoney.plus(this.withdrawalFeeAmount))) { // - throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), transactionAmount); + throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), this.withdrawalFeeAmount, transactionAmount); } final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, paymentDetail, transactionDate, @@ -906,11 +907,6 @@ public class SavingsAccount extends AbstractPersistable { } } - /***TODO Fixme: Annual fee seems to be added for all withdrawals?**/ - final Money annualFee = Money.of(this.currency, this.annualFeeAmount); - SavingsAccountTransaction annualFeeTransaction = SavingsAccountTransaction.annualFee(this, transactionDate, annualFee); - this.transactions.add(annualFeeTransaction); - this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); final LocalDate today = DateUtils.getLocalDateOfTenant(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/exception/InsufficientAccountBalanceException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/exception/InsufficientAccountBalanceException.java index 8a69c663f..321be2827 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/exception/InsufficientAccountBalanceException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/exception/InsufficientAccountBalanceException.java @@ -15,8 +15,8 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul */ public class InsufficientAccountBalanceException extends AbstractPlatformDomainRuleException { - public InsufficientAccountBalanceException(final String paramName, final BigDecimal accountBalance, final BigDecimal withdrawalRequested) { - super("error.msg.savingsaccount.transaction.insufficient.account.balance", "Insufficient account balance.", paramName, - accountBalance, withdrawalRequested); + public InsufficientAccountBalanceException(final String paramName, final BigDecimal accountBalance, final BigDecimal withdrawalFee, final BigDecimal transactionAmount) { + super(withdrawalFee != null? "error.msg.savingsaccount.transaction.insufficient.account.balance.withdraw" : "error.msg.savingsaccount.transaction.insufficient.account.balance", + "Insufficient account balance.", paramName, accountBalance, withdrawalFee, transactionAmount); } } \ No newline at end of file