Skip to content

Commit

Permalink
Merge pull request #20 from FITER1/MON-92-new
Browse files Browse the repository at this point in the history
MON-92 - Fixed Deposit Top Up
  • Loading branch information
hiteshprajapati authored Nov 15, 2022
2 parents ff6b05d + 05b8f56 commit 5e6f270
Show file tree
Hide file tree
Showing 42 changed files with 3,039 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3511,4 +3511,12 @@ public CommandWrapperBuilder savingsAccountAccrualInterestPosting(final Long acc
return this;
}

public CommandWrapperBuilder topUpFixedDepositAccount(final Long accountId) {
this.actionName = "TOP_UP";
this.entityName = "FIXEDDEPOSITACCOUNT";
this.entityId = accountId;
this.href = "/fixeddepositaccounts/" + accountId + "?command=topUp";
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,8 @@ public static LocalDate getBusinessLocalDate() {
return ThreadLocalContextUtil.getBusinessDate();
}

public static DateTimeFormatter getDefaultFormatter() {
return DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public class SavingsAccountSummaryData {

// differentiate deposit accounts Savings, FD and RD accounts
private final EnumOptionData depositType;
private final String closedFixedDepositAccountNumber;

public SavingsAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
final String productName, final String shortProductName, final SavingsAccountStatusEnumData status, final CurrencyData currency,
final BigDecimal accountBalance, final EnumOptionData accountType, final SavingsAccountApplicationTimelineData timeline,
final EnumOptionData depositType, final SavingsAccountSubStatusEnumData subStatus, final LocalDate lastActiveTransactionDate) {
final EnumOptionData depositType, final SavingsAccountSubStatusEnumData subStatus, final LocalDate lastActiveTransactionDate,
final String closedFixedDepositAccountNumber) {
this.id = id;
this.accountNo = accountNo;
this.externalId = externalId;
Expand All @@ -68,6 +70,7 @@ public SavingsAccountSummaryData(final Long id, final String accountNo, final St
this.depositType = depositType;
this.subStatus = subStatus;
this.lastActiveTransactionDate = lastActiveTransactionDate;
this.closedFixedDepositAccountNumber = closedFixedDepositAccountNumber;
}

public String getAccountNo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ private static final class SavingsAccountSummaryDataMapper implements RowMapper<
final StringBuilder accountsSummary = new StringBuilder();
accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, sa.status_enum as statusEnum, ");
accountsSummary.append("sa.account_type_enum as accountType, ");
accountsSummary.append("sa.account_balance_derived as accountBalance, ");
accountsSummary.append(
"sa.account_balance_derived as accountBalance, sa.closed_fixed_deposit_account_no as closedFixedDepositAccountNumber,");

accountsSummary.append("sa.submittedon_date as submittedOnDate,");
accountsSummary.append("sbu.username as submittedByUsername,");
Expand Down Expand Up @@ -380,6 +381,7 @@ public SavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("u

final Long id = JdbcSupport.getLong(rs, "id");
final String accountNo = rs.getString("accountNo");
final String closedFixedDepositAccountNumber = rs.getString("closedFixedDepositAccountNumber");
final String externalId = rs.getString("externalId");
final Long productId = JdbcSupport.getLong(rs, "productId");
final String productName = rs.getString("productName");
Expand Down Expand Up @@ -442,7 +444,8 @@ public SavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("u
activatedByLastname, closedOnDate, closedByUsername, closedByFirstname, closedByLastname);

return new SavingsAccountSummaryData(id, accountNo, externalId, productId, productName, shortProductName, status, currency,
accountBalance, accountTypeData, timeline, depositTypeData, subStatus, lastActiveTransactionDate);
accountBalance, accountTypeData, timeline, depositTypeData, subStatus, lastActiveTransactionDate,
closedFixedDepositAccountNumber);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,10 @@ public void setTaxGroup(TaxGroup taxGroup) {
this.taxGroup = taxGroup;
}

public boolean isPartialLiquidationCharge() {
return ChargeTimeType.fromInt(this.chargeTimeType).equals(ChargeTimeType.FDA_PARTIAL_LIQUIDATION_FEE);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public enum ChargeTimeType {
// loan
SHAREACCOUNT_ACTIVATION(13, "chargeTimeType.activation"), // only for loan
SHARE_PURCHASE(14, "chargeTimeType.sharespurchase"), SHARE_REDEEM(15, "chargeTimeType.sharesredeem"),

SAVINGS_NOACTIVITY_FEE(16, "chargeTimeType.savingsNoActivityFee"), DISBURSE_TO_SAVINGS(17,
"chargeTimeType.disburseToSavings"), FDA_PRE_CLOSURE_FEE(18,
"chargeTimeType.fdaPreclosureFee"), FDA_PARTIAL_LIQUIDATION_FEE(19, "chargeTimeType.fdaPartialLiquidationFee");

SAVINGS_NOACTIVITY_FEE(16, "chargeTimeType.savingsNoActivityFee"), DISBURSE_TO_SAVINGS(17, "chargeTimeType.disburseToSavings"); // only
// for
// loan
// charges

private final Integer value;
private final String code;
Expand Down Expand Up @@ -140,6 +140,12 @@ public static ChargeTimeType fromInt(final Integer chargeTime) {
case 17:
chargeTimeType = DISBURSE_TO_SAVINGS;
break;
case 18:
chargeTimeType = FDA_PRE_CLOSURE_FEE;
break;
case 19:
chargeTimeType = FDA_PARTIAL_LIQUIDATION_FEE;
break;
default:
chargeTimeType = INVALID;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private DepositsApiConstants() {
public static final String preClosurePenalInterestOnTypeIdParamName = "preClosurePenalInterestOnTypeId";
public static final String interestFreePeriodFrequencyType = "interestFreePeriodFrequencyType";
public static final String preClosurePenalInterestOnType = "preClosurePenalInterestOnType";
public static final String preClosureChargeApplicableParamName = "preClosureChargeApplicable";

// term paramters
public static final String minDepositTermParamName = "minDepositTerm";
Expand All @@ -130,12 +131,14 @@ private DepositsApiConstants() {
public static final String inMultiplesOfDepositTermParamName = "inMultiplesOfDepositTerm";
public static final String inMultiplesOfDepositTermTypeIdParamName = "inMultiplesOfDepositTermTypeId";
public static final String inMultiplesOfDepositTermType = "inMultiplesOfDepositTermType";
public static final String autoRolloverParamName = "autoRollover";

public static final String depositAmountParamName = "depositAmount";
public static final String depositMinAmountParamName = "minDepositAmount";
public static final String depositMaxAmountParamName = "maxDepositAmount";
public static final String depositPeriodParamName = "depositPeriod";
public static final String depositPeriodFrequencyIdParamName = "depositPeriodFrequencyId";
public static final String changeTenureParamName = "changeTenure";

// recurring parameters
public static final String mandatoryRecommendedDepositAmountParamName = "mandatoryRecommendedDepositAmount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public class SavingsApiConstants {
public static final String amountPaidParamName = "amountPaid";
public static final String chargeOptionsParamName = "chargeOptions";
public static final String chargePaymentModeParamName = "chargePaymentMode";
public static final String nicknameParamName = "nickname";

public static final String noteParamName = "note";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ public String handleCommands(@PathParam("accountId") @Parameter(description = "a
} else if (is(commandParam, "prematureClose")) {
final CommandWrapper commandRequest = builder.prematureCloseFixedDepositAccount(accountId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "topUp")) {
final CommandWrapper commandRequest = builder.topUpFixedDepositAccount(accountId).withJson(apiRequestBodyAsJson).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "calculatePrematureAmount")) {
final JsonElement parsedQuery = this.fromJsonHelper.parse(apiRequestBodyAsJson);
final JsonQuery query = JsonQuery.from(apiRequestBodyAsJson, parsedQuery, this.fromJsonHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.bankNumberParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.checkNumberParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.closedOnDateParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.depositPeriodParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.onAccountClosureIdParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.paymentTypeIdParamName;
import static org.apache.fineract.portfolio.savings.DepositsApiConstants.receiptNumberParamName;
Expand Down Expand Up @@ -53,6 +55,7 @@
import org.apache.fineract.portfolio.savings.DepositAccountType;
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
import org.apache.fineract.portfolio.savings.SavingsPeriodFrequencyType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -79,6 +82,12 @@ public class DepositAccountTransactionDataValidator {
private static final Set<String> DEPOSIT_ACCOUNT_PRE_MATURE_CALCULATION_REQUEST_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(DepositsApiConstants.localeParamName, DepositsApiConstants.dateFormatParamName, closedOnDateParamName));

private static final Set<String> DEPOSIT_ACCOUNT_TOP_UP_REQUEST_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(DepositsApiConstants.localeParamName, DepositsApiConstants.dateFormatParamName,
DepositsApiConstants.submittedOnDateParamName, DepositsApiConstants.depositPeriodParamName,
DepositsApiConstants.depositPeriodFrequencyIdParamName, DepositsApiConstants.depositAmountParamName,
DepositsApiConstants.changeTenureParamName, SavingsApiConstants.nicknameParamName));

@Autowired
public DepositAccountTransactionDataValidator(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
Expand Down Expand Up @@ -251,4 +260,48 @@ private void throwExceptionIfValidationWarningsExist(final List<ApiParameterErro
dataValidationErrors);
}
}

public void validateTopUp(JsonCommand command) {
final JsonElement element = command.parsedJson();
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(DepositAccountType.FIXED_DEPOSIT.resourceName());
this.checkForUnsupportedParameters(command, DEPOSIT_ACCOUNT_TOP_UP_REQUEST_DATA_PARAMETERS);
this.validateDepositPeriod(baseDataValidator, element);

final BigDecimal depositAmount = this.fromApiJsonHelper
.extractBigDecimalWithLocaleNamed(DepositsApiConstants.depositAmountParamName, element);
baseDataValidator.reset().parameter(DepositsApiConstants.depositAmountParamName).value(depositAmount).notLessThanMin(BigDecimal.ONE)
.notNull();

throwExceptionIfValidationWarningsExist(dataValidationErrors);
}

private void checkForUnsupportedParameters(JsonCommand command, Set<String> supportedParams) {
String json = command.json();
validateJson(json);
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
}

private void validateJson(String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
}

private void validateDepositPeriod(DataValidatorBuilder baseDataValidator, JsonElement element) {
final LocalDate submitDate = this.fromApiJsonHelper.extractLocalDateNamed(DepositsApiConstants.submittedOnDateParamName, element);
baseDataValidator.reset().parameter(DepositsApiConstants.submittedOnDateParamName).value(submitDate).notNull();

if (this.fromApiJsonHelper.parameterExists(depositPeriodParamName, element)) {
final Integer depositPeriod = fromApiJsonHelper.extractIntegerSansLocaleNamed(depositPeriodParamName, element);
baseDataValidator.reset().parameter(depositPeriodParamName).value(depositPeriod).notNull().integerGreaterThanZero();
}

final Integer depositPeriodFrequencyId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(depositPeriodFrequencyIdParamName,
element);
baseDataValidator.reset().parameter(depositPeriodFrequencyIdParamName).value(depositPeriodFrequencyId)
.isOneOfTheseValues(SavingsPeriodFrequencyType.integerValues());
}
}
Loading

0 comments on commit 5e6f270

Please sign in to comment.