FINERACT-1390:WithdrawChargesPerPaymentType
This commit is contained in:
+83
@@ -42,6 +42,7 @@ import java.util.Locale;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.TaxComponentHelper;
|
||||
import org.apache.fineract.integrationtests.common.TaxGroupHelper;
|
||||
@@ -2127,4 +2128,86 @@ public class ClientSavingsIntegrationTest {
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance is -300");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccountWithdrawalChargesOnPaymentTypes() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final String MINIMUM_OPENING_BALANCE = "10000";
|
||||
final String withdrawalAmountOne = "1000";
|
||||
final String withdrawalAmountTwo = "2000";
|
||||
final Integer withdrawalChargeOne = 10;
|
||||
final Integer withdrawalChargeTwo = 20;
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
|
||||
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
|
||||
Boolean isCashPayment = false;
|
||||
Integer position = 1;
|
||||
|
||||
Integer paymentTypeIdOne = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment,
|
||||
position);
|
||||
Assertions.assertNotNull(paymentTypeIdOne);
|
||||
|
||||
final Integer chargeIdOne = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.paymentTypeCharge(withdrawalChargeOne, true, paymentTypeIdOne));
|
||||
Assertions.assertNotNull(chargeIdOne);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeIdOne, false, BigDecimal.valueOf(withdrawalChargeOne));
|
||||
|
||||
Integer withdrawTransactionIdOne = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccountWithPaymentType(savingsId,
|
||||
withdrawalAmountOne, SavingsAccountHelper.TRANSACTION_DATE, paymentTypeIdOne.toString(),
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
Float balance = Float.parseFloat("8990");
|
||||
// Withdraw charge from paymentType 1 is 10 So balance should be 10,000(deposit)-1000(wd)-"10(charge)" = 8990
|
||||
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying Balance after withdrawal charge ");
|
||||
|
||||
String paymentTypeNameTwo = PaymentTypeHelper.randomNameGenerator("P_T", 5);
|
||||
|
||||
Integer paymentTypeIdTwo = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeNameTwo, description,
|
||||
isCashPayment, position);
|
||||
Assertions.assertNotNull(paymentTypeIdTwo);
|
||||
|
||||
final Integer chargeIdTwo = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.paymentTypeCharge(withdrawalChargeTwo, true, paymentTypeIdTwo));
|
||||
Assertions.assertNotNull(chargeIdTwo);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeIdTwo, false, BigDecimal.valueOf(withdrawalChargeTwo));
|
||||
|
||||
Integer withdrawTransactionIdTwo = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccountWithPaymentType(savingsId,
|
||||
withdrawalAmountTwo, SavingsAccountHelper.TRANSACTION_DATE, paymentTypeIdTwo.toString(),
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
Float balanceAfterChargeTwo = Float.parseFloat("6970");
|
||||
// Withdraw charge from paymentType 2 is 20 So balance should be 8990(balance)-2000(wd)-"20(charge)" = 6970
|
||||
|
||||
HashMap summaryTwo = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(balanceAfterChargeTwo, summaryTwo.get("accountBalance"), "Verifying Balance after withdrawal charge two ");
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -188,6 +188,27 @@ public final class ChargesHelper {
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String paymentTypeCharge(Integer amount, final boolean enablePaymentType, final Integer paymentTypeId) {
|
||||
return paymentTypeChargeJSON(amount, enablePaymentType, paymentTypeId);
|
||||
}
|
||||
|
||||
public static String paymentTypeChargeJSON(Integer amount, final boolean enablePaymentType, final Integer paymentTypeId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("active", ChargesHelper.ACTIVE);
|
||||
map.put("amount", amount);
|
||||
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_SAVINGS);
|
||||
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
|
||||
map.put("currencyCode", ChargesHelper.CURRENCY_CODE);
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("monthDayFormat", ChargesHelper.MONTH_DAY_FORMAT);
|
||||
map.put("name", Utils.randomNameGenerator("Charge_Savings_", 6));
|
||||
map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE);
|
||||
map.put("enablePaymentType", enablePaymentType);
|
||||
map.put("paymentTypeId", paymentTypeId);
|
||||
String paymentTypeJson = new Gson().toJson(map);
|
||||
return paymentTypeJson;
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateJSON() {
|
||||
return getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.AMOUNT, ChargesHelper.PENALTY);
|
||||
}
|
||||
|
||||
+19
@@ -253,6 +253,13 @@ public class SavingsAccountHelper {
|
||||
getSavingsTransactionJSON(amount, date), jsonAttributeToGetback);
|
||||
}
|
||||
|
||||
public Object withdrawalFromSavingsAccountWithPaymentType(final Integer savingsId, final String amount, String date, String paymentType,
|
||||
String jsonAttributeToGetback) {
|
||||
LOG.info("\n--------------------------------- SAVINGS TRANSACTION WITHDRAWAL WITH PAYMENT TYPE--------------------------------");
|
||||
return performSavingActions(createSavingsTransactionURL(WITHDRAW_SAVINGS_COMMAND, savingsId),
|
||||
getSavingsTransactionPaymentTypeJSON(amount, date, paymentType), jsonAttributeToGetback);
|
||||
}
|
||||
|
||||
public Integer updateSavingsAccountTransaction(final Integer savingsId, final Integer transactionId, final String amount) {
|
||||
LOG.info("\n--------------------------------- MODIFY SAVINGS TRANSACTION --------------------------------");
|
||||
return (Integer) performSavingActions(createAdjustTransactionURL(MODIFY_TRASACTION_COMMAND, savingsId, transactionId),
|
||||
@@ -432,6 +439,18 @@ public class SavingsAccountHelper {
|
||||
return savingsAccountWithdrawalJson;
|
||||
}
|
||||
|
||||
private String getSavingsTransactionPaymentTypeJSON(final String amount, final String transactionDate, final String paymentTypeId) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("transactionAmount", amount);
|
||||
map.put("paymentTypeId", paymentTypeId);
|
||||
String savingsAccountWithdrawalJson = new Gson().toJson(map);
|
||||
LOG.info(savingsAccountWithdrawalJson);
|
||||
return savingsAccountWithdrawalJson;
|
||||
}
|
||||
|
||||
private String getCalculatedInterestForSavingsApplicationAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String savingsAccountCalculatedInterestJson = new Gson().toJson(map);
|
||||
|
||||
Reference in New Issue
Block a user