From 7f5ff5780ff400313ae5d033ecde2a304ab22d61 Mon Sep 17 00:00:00 2001 From: rainerh Date: Sat, 14 Jun 2014 12:06:24 -0700 Subject: [PATCH] MIFOSX-1161: Enforce minRequiredBalance --- .../portfolio/savings/domain/SavingsAccount.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 042797814..942fdc0bf 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 @@ -789,9 +789,16 @@ public class SavingsAccount extends AbstractPersistable { runningBalance = runningBalance.minus(transaction.getAmount(this.currency)); } + final BigDecimal withdrawalFee = null; + // deal with potential minRequiredBalance and allowOverdraftMinBalance + if (this.minRequiredBalance != null && !this.allowOverdraftMinBalance) { + if (runningBalance.minus(this.minRequiredBalance).isLessThanZero()) { + throw new InsufficientAccountBalanceException("transactionAmount", + getAccountBalance(), withdrawalFee, transactionAmount); + } + } + if (runningBalance.isLessThanZero()) { - // - final BigDecimal withdrawalFee = null; Money limit = runningBalance.zero(); if (this.allowOverdraft) { if (this.overdraftLimit != null) {