MIFOSX-1643 : modified charge payment to bypass running balance check

This commit is contained in:
Pramod Nuthakki
2014-11-07 15:56:33 +05:30
parent 2418c09701
commit 915f187bef
5 changed files with 34 additions and 4 deletions
@@ -202,9 +202,10 @@ public class ClientSavingsIntegrationTest {
Assert.assertNotNull(clientID); Assert.assertNotNull(clientID);
final String minBalanceForInterestCalculation = null; final String minBalanceForInterestCalculation = null;
final String minRequiredBalance = "1500.0"; final String minRequiredBalance = "1500.0";
final String openningBalance = "1600";
final String enforceMinRequiredBalance = "true"; final String enforceMinRequiredBalance = "true";
final boolean allowOverdraft = false; final boolean allowOverdraft = false;
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, openningBalance ,
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft); minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
Assert.assertNotNull(savingsProductID); Assert.assertNotNull(savingsProductID);
@@ -227,7 +228,7 @@ public class ClientSavingsIntegrationTest {
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId); HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
Float balance = new Float(MINIMUM_OPENING_BALANCE); Float balance = new Float(openningBalance);
Float chargeAmt = 100f; Float chargeAmt = 100f;
balance -= chargeAmt; balance -= chargeAmt;
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance")); assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
@@ -870,7 +870,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final BigDecimal withdrawalFee = null; final BigDecimal withdrawalFee = null;
// deal with potential minRequiredBalance and // deal with potential minRequiredBalance and
// enforceMinRequiredBalance // enforceMinRequiredBalance
if (!isWithdrawBalance && transaction.isDebit()) { if (!isWithdrawBalance && transaction.canProcessBalanceCheck()) {
if (runningBalance.minus(minRequiredBalance).isLessThanZero()) { throw new InsufficientAccountBalanceException( if (runningBalance.minus(minRequiredBalance).isLessThanZero()) { throw new InsufficientAccountBalanceException(
"transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); } "transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); }
} }
@@ -891,7 +891,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
} }
// enforceMinRequiredBalance // enforceMinRequiredBalance
if (transaction.isDebit()) { if (transaction.canProcessBalanceCheck()) {
if (runningBalance.minus(minRequiredBalance).isLessThanZero()) { if (runningBalance.minus(minRequiredBalance).isLessThanZero()) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
@@ -40,6 +40,10 @@ import org.mifosplatform.portfolio.charge.domain.ChargeTimeType;
import org.mifosplatform.portfolio.charge.exception.SavingsAccountChargeWithoutMandatoryFieldException; import org.mifosplatform.portfolio.charge.exception.SavingsAccountChargeWithoutMandatoryFieldException;
import org.springframework.data.jpa.domain.AbstractPersistable; import org.springframework.data.jpa.domain.AbstractPersistable;
/**
* @author dv6
*
*/
@Entity @Entity
@Table(name = "m_savings_account_charge") @Table(name = "m_savings_account_charge")
public class SavingsAccountCharge extends AbstractPersistable<Long> { public class SavingsAccountCharge extends AbstractPersistable<Long> {
@@ -823,4 +827,16 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
public boolean isNotActive() { public boolean isNotActive() {
return !isActive(); return !isActive();
} }
/**
* This method is to identify the charges which can override the savings
* rules(for example if there is a minimum enforced balance of 1000 on
* savings account with account balance of 1000, still these charges can be
* collected as these charges are initiated by system and it can bring down
* the balance below the enforced minimum balance).
*
*/
public boolean canOverriteSavingAccountRules() {
return !(this.isSavingsActivation() || this.isWithdrawalFee());
}
} }
@@ -77,4 +77,8 @@ public class SavingsAccountChargePaidBy extends AbstractPersistable<Long> {
public boolean isPenaltyCharge() { public boolean isPenaltyCharge() {
return (this.savingsAccountCharge == null) ? false : this.savingsAccountCharge.isPenaltyCharge(); return (this.savingsAccountCharge == null) ? false : this.savingsAccountCharge.isPenaltyCharge();
} }
public boolean canOverriteSavingAccountRules() {
return (this.savingsAccountCharge == null) ? false : this.savingsAccountCharge.canOverriteSavingAccountRules();
}
} }
@@ -514,6 +514,15 @@ public final class SavingsAccountTransaction extends AbstractPersistable<Long> {
return SavingsAccountTransactionType.fromInt(this.typeOf).isWaiveCharge(); return SavingsAccountTransactionType.fromInt(this.typeOf).isWaiveCharge();
} }
private boolean canOverriteSavingAccountRules() {
final SavingsAccountChargePaidBy chargePaidBy = getSavingsAccountChargePaidBy();
return (isChargeTransaction() && chargePaidBy != null) ? chargePaidBy.canOverriteSavingAccountRules() : false;
}
public boolean canProcessBalanceCheck() {
return isDebit() && !canOverriteSavingAccountRules();
}
public boolean isFeeCharge() { public boolean isFeeCharge() {
final SavingsAccountChargePaidBy chargePaidBy = getSavingsAccountChargePaidBy(); final SavingsAccountChargePaidBy chargePaidBy = getSavingsAccountChargePaidBy();
return (isPayCharge() && chargePaidBy != null) ? chargePaidBy.isFeeCharge() : false; return (isPayCharge() && chargePaidBy != null) ? chargePaidBy.isFeeCharge() : false;