FINERACT-1440 : Enable Daily Interest Posting for Savings
This commit is contained in:
+4
@@ -28,6 +28,7 @@ import java.util.List;
|
|||||||
public enum SavingsPostingInterestPeriodType {
|
public enum SavingsPostingInterestPeriodType {
|
||||||
|
|
||||||
INVALID(0, "savingsPostingInterestPeriodType.invalid"), //
|
INVALID(0, "savingsPostingInterestPeriodType.invalid"), //
|
||||||
|
DAILY(1, "savingsPostingInterestPeriodType.daily"), //
|
||||||
MONTHLY(4, "savingsPostingInterestPeriodType.monthly"), //
|
MONTHLY(4, "savingsPostingInterestPeriodType.monthly"), //
|
||||||
QUATERLY(5, "savingsPostingInterestPeriodType.quarterly"), //
|
QUATERLY(5, "savingsPostingInterestPeriodType.quarterly"), //
|
||||||
BIANNUAL(6, "savingsPostingInterestPeriodType.biannual"), ANNUAL(7, "savingsPostingInterestPeriodType.annual");
|
BIANNUAL(6, "savingsPostingInterestPeriodType.biannual"), ANNUAL(7, "savingsPostingInterestPeriodType.annual");
|
||||||
@@ -63,6 +64,9 @@ public enum SavingsPostingInterestPeriodType {
|
|||||||
SavingsPostingInterestPeriodType repaymentFrequencyType = SavingsPostingInterestPeriodType.INVALID;
|
SavingsPostingInterestPeriodType repaymentFrequencyType = SavingsPostingInterestPeriodType.INVALID;
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
repaymentFrequencyType = SavingsPostingInterestPeriodType.DAILY;
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
repaymentFrequencyType = SavingsPostingInterestPeriodType.MONTHLY;
|
repaymentFrequencyType = SavingsPostingInterestPeriodType.MONTHLY;
|
||||||
break;
|
break;
|
||||||
|
|||||||
+4
@@ -2813,6 +2813,10 @@ public class SavingsAccount extends AbstractPersistableCustom {
|
|||||||
|
|
||||||
public void validateInterestPostingAndCompoundingPeriodTypes(final DataValidatorBuilder baseDataValidator) {
|
public void validateInterestPostingAndCompoundingPeriodTypes(final DataValidatorBuilder baseDataValidator) {
|
||||||
Map<SavingsPostingInterestPeriodType, List<SavingsCompoundingInterestPeriodType>> postingtoCompoundMap = new HashMap<>();
|
Map<SavingsPostingInterestPeriodType, List<SavingsCompoundingInterestPeriodType>> postingtoCompoundMap = new HashMap<>();
|
||||||
|
|
||||||
|
postingtoCompoundMap.put(SavingsPostingInterestPeriodType.DAILY,
|
||||||
|
Arrays.asList(new SavingsCompoundingInterestPeriodType[] { SavingsCompoundingInterestPeriodType.DAILY }));
|
||||||
|
|
||||||
postingtoCompoundMap.put(SavingsPostingInterestPeriodType.MONTHLY, Arrays.asList(new SavingsCompoundingInterestPeriodType[] {
|
postingtoCompoundMap.put(SavingsPostingInterestPeriodType.MONTHLY, Arrays.asList(new SavingsCompoundingInterestPeriodType[] {
|
||||||
SavingsCompoundingInterestPeriodType.DAILY, SavingsCompoundingInterestPeriodType.MONTHLY }));
|
SavingsCompoundingInterestPeriodType.DAILY, SavingsCompoundingInterestPeriodType.MONTHLY }));
|
||||||
|
|
||||||
|
|||||||
+4
@@ -118,6 +118,10 @@ public final class SavingsHelper {
|
|||||||
switch (interestPostingPeriodType) {
|
switch (interestPostingPeriodType) {
|
||||||
case INVALID:
|
case INVALID:
|
||||||
break;
|
break;
|
||||||
|
case DAILY:
|
||||||
|
// produce period end date on current day
|
||||||
|
periodEndDate = periodStartDate;
|
||||||
|
break;
|
||||||
case MONTHLY:
|
case MONTHLY:
|
||||||
// produce period end date on last day of current month
|
// produce period end date on last day of current month
|
||||||
periodEndDate = periodStartDate.with(TemporalAdjusters.lastDayOfMonth());
|
periodEndDate = periodStartDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||||
|
|||||||
+6
-8
@@ -56,10 +56,6 @@ public class SavingsDropdownReadPlatformServiceImpl implements SavingsDropdownRe
|
|||||||
public Collection<EnumOptionData> retrieveCompoundingInterestPeriodTypeOptions() {
|
public Collection<EnumOptionData> retrieveCompoundingInterestPeriodTypeOptions() {
|
||||||
final List<EnumOptionData> allowedOptions = Arrays.asList(
|
final List<EnumOptionData> allowedOptions = Arrays.asList(
|
||||||
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.DAILY),
|
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.DAILY),
|
||||||
// SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.WEEKLY),
|
|
||||||
// //
|
|
||||||
// SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.BIWEEKLY),
|
|
||||||
// //
|
|
||||||
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.MONTHLY),
|
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.MONTHLY),
|
||||||
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.QUATERLY),
|
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.QUATERLY),
|
||||||
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.BI_ANNUAL),
|
SavingsEnumerations.compoundingInterestPeriodType(SavingsCompoundingInterestPeriodType.BI_ANNUAL),
|
||||||
@@ -75,10 +71,12 @@ public class SavingsDropdownReadPlatformServiceImpl implements SavingsDropdownRe
|
|||||||
@Override
|
@Override
|
||||||
public Collection<EnumOptionData> retrieveInterestPostingPeriodTypeOptions() {
|
public Collection<EnumOptionData> retrieveInterestPostingPeriodTypeOptions() {
|
||||||
final List<EnumOptionData> allowedOptions = Arrays.asList(
|
final List<EnumOptionData> allowedOptions = Arrays.asList(
|
||||||
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.MONTHLY),
|
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.DAILY), //
|
||||||
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.QUATERLY),
|
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.MONTHLY), //
|
||||||
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.BIANNUAL),
|
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.QUATERLY), //
|
||||||
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.ANNUAL));
|
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.BIANNUAL), //
|
||||||
|
SavingsEnumerations.interestPostingPeriodType(SavingsPostingInterestPeriodType.ANNUAL) //
|
||||||
|
);
|
||||||
|
|
||||||
return allowedOptions;
|
return allowedOptions;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -364,6 +364,10 @@ public final class SavingsEnumerations {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case INVALID:
|
case INVALID:
|
||||||
break;
|
break;
|
||||||
|
case DAILY:
|
||||||
|
optionData = new EnumOptionData(SavingsPostingInterestPeriodType.DAILY.getValue().longValue(),
|
||||||
|
codePrefix + SavingsPostingInterestPeriodType.DAILY.getCode(), "Daily");
|
||||||
|
break;
|
||||||
case MONTHLY:
|
case MONTHLY:
|
||||||
optionData = new EnumOptionData(SavingsPostingInterestPeriodType.MONTHLY.getValue().longValue(),
|
optionData = new EnumOptionData(SavingsPostingInterestPeriodType.MONTHLY.getValue().longValue(),
|
||||||
codePrefix + SavingsPostingInterestPeriodType.MONTHLY.getCode(), "Monthly");
|
codePrefix + SavingsPostingInterestPeriodType.MONTHLY.getCode(), "Monthly");
|
||||||
|
|||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.integrationtests;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import io.restassured.builder.RequestSpecBuilder;
|
||||||
|
import io.restassured.builder.ResponseSpecBuilder;
|
||||||
|
import io.restassured.http.ContentType;
|
||||||
|
import io.restassured.specification.RequestSpecification;
|
||||||
|
import io.restassured.specification.ResponseSpecification;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||||
|
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
|
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
|
||||||
|
public class SavingsInterestPostingIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(SavingsInterestPostingIntegrationTest.class);
|
||||||
|
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||||
|
|
||||||
|
private ResponseSpecification responseSpec;
|
||||||
|
private RequestSpecification requestSpec;
|
||||||
|
private SavingsProductHelper savingsProductHelper;
|
||||||
|
private SavingsAccountHelper savingsAccountHelper;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
Utils.initializeRESTAssured();
|
||||||
|
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||||
|
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
|
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||||
|
this.savingsProductHelper = new SavingsProductHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSavingsDailyInterestPosting() {
|
||||||
|
// client activation, savings activation and 1st transaction date
|
||||||
|
final String startDate = "01 November 2021";
|
||||||
|
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||||
|
Assertions.assertNotNull(clientID);
|
||||||
|
|
||||||
|
final Integer savingsId = createSavingsAccountDailyPosting(clientID, startDate);
|
||||||
|
|
||||||
|
this.savingsAccountHelper.depositToSavingsAccount(savingsId, "1000", startDate, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Perform Post interest transaction and verify the posted transaction date
|
||||||
|
*/
|
||||||
|
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||||
|
HashMap accountDetails = this.savingsAccountHelper.getSavingsDetails(savingsId);
|
||||||
|
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) accountDetails.get("transactions");
|
||||||
|
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 2);
|
||||||
|
for (Map.Entry<String, Object> entry : interestPostingTransaction.entrySet()) {
|
||||||
|
LOG.info("{} - {}", entry.getKey(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
assertEquals("0.274", interestPostingTransaction.get("amount").toString(), "Equality check for interest posted amount");
|
||||||
|
assertEquals("[2021, 11, 2]", interestPostingTransaction.get("date").toString(), "Date check for Interest Posting transaction");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer createSavingsAccountDailyPosting(final Integer clientID, final String startDate) {
|
||||||
|
final Integer savingsProductID = createSavingsProductDailyPosting();
|
||||||
|
Assertions.assertNotNull(savingsProductID);
|
||||||
|
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientID, savingsProductID,
|
||||||
|
ACCOUNT_TYPE_INDIVIDUAL, startDate);
|
||||||
|
Assertions.assertNotNull(savingsId);
|
||||||
|
HashMap savingsStatusHashMap = this.savingsAccountHelper.approveSavingsOnDate(savingsId, startDate);
|
||||||
|
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||||
|
savingsStatusHashMap = this.savingsAccountHelper.activateSavingsAccount(savingsId, startDate);
|
||||||
|
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||||
|
return savingsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer createSavingsProductDailyPosting() {
|
||||||
|
final String savingsProductJSON = this.savingsProductHelper.withInterestCompoundingPeriodTypeAsDaily()
|
||||||
|
.withInterestPostingPeriodTypeAsDaily().withInterestCalculationPeriodTypeAsDailyBalance().build();
|
||||||
|
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset configuration fields
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() {
|
||||||
|
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||||
|
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -190,6 +190,11 @@ public class SavingsProductHelper {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SavingsProductHelper withInterestPostingPeriodTypeAsDaily() {
|
||||||
|
this.interestPostingPeriodType = DAILY;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public SavingsProductHelper withInterestCalculationPeriodTypeAsDailyBalance() {
|
public SavingsProductHelper withInterestCalculationPeriodTypeAsDailyBalance() {
|
||||||
this.interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
|
this.interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user