diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 590a876e3..a620dbff7 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -17757,6 +17757,25 @@ Request Body:

Close a savings account

Results in an Activated savings application being converted into an 'closed' savings account.

+

closedOnDate is closure date of savings account

+

withdrawBalance is a boolean value, true value of this field performs a withdrawal transaction with account's running balance.

+ + + + + + + +
Mandatory Fields
dateFormat,locale,closedOnDate
+
+ + + + + + + +
Optional Fields
note, withdrawBalance, paymentTypeId, accountNumber, checkNumber, routingCode, receiptNumber, bankNumber
POST https://Domain Name/api/v1/savingsaccounts/{savingsId}?command=close diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java index 473d9c9f9..cecc99469 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java @@ -170,9 +170,12 @@ public class ClientSavingsIntegrationTest { savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + Calendar todaysDate = Calendar.getInstance(); + final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime()); String withdrawBalance = "false"; ArrayList savingsAccountErrorData = (ArrayList) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField( - savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR); + savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE); assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero", savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); @@ -521,9 +524,12 @@ public class ClientSavingsIntegrationTest { * balance, perform transactions then post interest and verify posted * interest */ + @SuppressWarnings("unchecked") @Test public void testSavingsAccountWithOverdraft() { this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build(); + final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse); /*** * Create a client to apply for savings account (overdraft account). @@ -647,6 +653,14 @@ public class ClientSavingsIntegrationTest { interestPosted = new Float(decimalFormat.format(interestPosted)); actualInterestPosted = new Float(decimalFormat.format(actualInterestPosted)); assertEquals("Verifying interest posted", interestPosted, actualInterestPosted); + + todaysDate = Calendar.getInstance(); + final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime()); + String withdrawBalance = "false"; + ArrayList savingsAccountErrorData = (ArrayList) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField( + savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE); + assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero", + savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); } private HashMap activateSavingsAccount(final Integer savingsId, final String activationDate) { diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java index c0fdc7b23..2bfcbb2b4 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java @@ -3,6 +3,7 @@ package org.mifosplatform.integrationtests; import static org.junit.Assert.assertEquals; import java.math.BigDecimal; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -134,9 +135,12 @@ public class GroupSavingsIntegrationTest { savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + Calendar todaysDate = Calendar.getInstance(); + final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime()); String withdrawBalance = "false"; ArrayList savingsAccountErrorData = (ArrayList) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField( - savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR); + savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE); assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero", savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java index db0fb304e..53be5ebac 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java @@ -106,7 +106,7 @@ public class SavingsAccountHelper { public HashMap closeSavingsAccount(final Integer savingsID, String withdrawBalance) { System.out.println("---------------------------------- CLOSE SAVINGS APPLICATION ----------------------------------"); - return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), getCloseAccountJSON(withdrawBalance)); + return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), getCloseAccountJSON(withdrawBalance, LAST_TRANSACTION_DATE)); } public Object deleteSavingsApplication(final Integer savingsId, final String jsonAttributeToGetBack) { @@ -266,11 +266,11 @@ public class SavingsAccountHelper { return josn; } - private String getCloseAccountJSON(String withdrawBalance) { + private String getCloseAccountJSON(String withdrawBalance, String closedOnDate) { final HashMap map = new HashMap<>(); map.put("locale", CommonConstants.locale); map.put("dateFormat", CommonConstants.dateFormat); - map.put("closedOnDate", LAST_TRANSACTION_DATE); + map.put("closedOnDate", closedOnDate); map.put("withdrawBalance", withdrawBalance); map.put("note", "Close Test"); String josn = new Gson().toJson(map); @@ -354,10 +354,10 @@ public class SavingsAccountHelper { } public Object closeSavingsAccountAndGetBackRequiredField(final Integer savingsID, String withdrawBalance, - final String jsonAttributeToGetBack) { + final String jsonAttributeToGetBack, final String closedOnDate) { System.out.println("---------------------------------- CLOSE SAVINGS APPLICATION ----------------------------------"); - return performSavingActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), getCloseAccountJSON(withdrawBalance), - jsonAttributeToGetBack); + return performSavingActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), + getCloseAccountJSON(withdrawBalance, closedOnDate), jsonAttributeToGetBack); } private String getPeriodChargeRequestJSON(Integer chargeId) { 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 0959b2d9a..454beb82c 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 @@ -1707,7 +1707,7 @@ public class SavingsAccount extends AbstractPersistable { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } } - if (getAccountBalance().doubleValue() > 0) { + if (getAccountBalance().doubleValue() != 0) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("results.in.balance.not.zero"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }