Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,175 @@ public void testFixedDepositWithQuarterlyCompoundingAndQuarterlyPosting_360_Days
Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount);
}

/***
* Test case for Fixed Deposit Account rollover with maturity
* instruction as re invest maturity amount(principal+interest)
*/
@Test
public void testFixedDepositAccountWithRolloverMaturityAmount() {
this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec);
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec);

/***
* Create GL Accounts for product account mapping
*/
final Account assetAccount = this.accountHelper.createAssetAccount();
final Account incomeAccount = this.accountHelper.createIncomeAccount();
final Account expenseAccount = this.accountHelper.createExpenseAccount();
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();

DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
DateFormat monthDayFormat = new SimpleDateFormat("dd MMM", Locale.US);
DateFormat currentDateFormat = new SimpleDateFormat("dd");

Calendar todaysDate = Calendar.getInstance();
todaysDate.add(Calendar.MONTH, -3);
final String VALID_FROM = dateFormat.format(todaysDate.getTime());
todaysDate.add(Calendar.YEAR, 10);
final String VALID_TO = dateFormat.format(todaysDate.getTime());

todaysDate = Calendar.getInstance();
todaysDate.add(Calendar.MONTH, -1);
final String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime());
final String APPROVED_ON_DATE = dateFormat.format(todaysDate.getTime());
final String ACTIVATION_DATE = dateFormat.format(todaysDate.getTime());
final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime());

Integer currentDate = Integer.valueOf(currentDateFormat.format(todaysDate.getTime()));
Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE);
Integer numberOfDaysLeft = (daysInMonth - currentDate) + 1;
todaysDate.add(Calendar.DATE, numberOfDaysLeft);
final String INTEREST_POSTED_DATE = dateFormat.format(todaysDate.getTime());
final String CLOSED_ON_DATE = dateFormat.format(Calendar.getInstance().getTime());

Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientId);

/***
* Create FD product with CashBased accounting enabled
*/
final String accountingRule = CASH_BASED;
Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO, accountingRule, assetAccount, liabilityAccount,
incomeAccount, expenseAccount);
Assert.assertNotNull(fixedDepositProductId);

/***
* Set maturityInstructionId as re-invest principal+interest
* */
final Integer maturityInstructionId = 300;

/***
* Apply for FD account with created product and verify status
*/
Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), SUBMITTED_ON_DATE,
WHOLE_TERM, maturityInstructionId);

Assert.assertNotNull(fixedDepositAccountId);

HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec,
this.responseSpec, fixedDepositAccountId.toString());
FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap);

/***
* Approve the FD account and verify whether account is approved
*/
fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE);
FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap);

/***
* Activate the FD Account and verify whether account is activated
*/
fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE);
FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap);
}


/***
* Test case for Fixed Deposit Account rollover with maturity
* instruction as re invest principal only
*/
@Test
public void testFixedDepositAccountWithRolloverPrincipal() {
this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec);
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec);

/***
* Create GL Accounts for product account mapping
*/
final Account assetAccount = this.accountHelper.createAssetAccount();
final Account incomeAccount = this.accountHelper.createIncomeAccount();
final Account expenseAccount = this.accountHelper.createExpenseAccount();
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();

DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
DateFormat monthDayFormat = new SimpleDateFormat("dd MMM", Locale.US);
DateFormat currentDateFormat = new SimpleDateFormat("dd");

Calendar todaysDate = Calendar.getInstance();
todaysDate.add(Calendar.MONTH, -3);
final String VALID_FROM = dateFormat.format(todaysDate.getTime());
todaysDate.add(Calendar.YEAR, 10);
final String VALID_TO = dateFormat.format(todaysDate.getTime());

todaysDate = Calendar.getInstance();
todaysDate.add(Calendar.MONTH, -1);
final String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime());
final String APPROVED_ON_DATE = dateFormat.format(todaysDate.getTime());
final String ACTIVATION_DATE = dateFormat.format(todaysDate.getTime());
final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime());

Integer currentDate = Integer.valueOf(currentDateFormat.format(todaysDate.getTime()));
Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE);
Integer numberOfDaysLeft = (daysInMonth - currentDate) + 1;
todaysDate.add(Calendar.DATE, numberOfDaysLeft);
final String INTEREST_POSTED_DATE = dateFormat.format(todaysDate.getTime());
final String CLOSED_ON_DATE = dateFormat.format(Calendar.getInstance().getTime());

Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientId);

/***
* Create FD product with CashBased accounting enabled
*/
final String accountingRule = CASH_BASED;
Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO, accountingRule, assetAccount, liabilityAccount,
incomeAccount, expenseAccount);
Assert.assertNotNull(fixedDepositProductId);

/***
* Set maturityInstructionId as re-invest principal
* */
final Integer maturityInstructionId = 400;

/***
* Apply for FD account with created product and verify status
*/
Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), SUBMITTED_ON_DATE,
WHOLE_TERM, maturityInstructionId);

Assert.assertNotNull(fixedDepositAccountId);

HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec,
this.responseSpec, fixedDepositAccountId.toString());
FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap);

/***
* Approve the FD account and verify whether account is approved
*/
fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE);
FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap);

/***
* Activate the FD Account and verify whether account is activated
*/
fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE);
FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap);
}

private Integer createFixedDepositProduct(final String validFrom, final String validTo, final String accountingRule,
Account... accounts) {
LOG.info("------------------------------CREATING NEW FIXED DEPOSIT PRODUCT ---------------------------------------");
Expand Down Expand Up @@ -2470,6 +2639,17 @@ private Integer applyForFixedDepositApplication(final String clientID, final Str
.applyFixedDepositApplication(fixedDepositApplicationJSON, this.requestSpec, this.responseSpec);
}

private Integer applyForFixedDepositApplication(final String clientID, final String productID, final String submittedOnDate,
final String penalInterestType, final Integer maturityInstructionId) {
LOG.info("--------------------------------APPLYING FOR FIXED DEPOSIT ACCOUNT --------------------------------");
final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) //
.withSubmittedOnDate(submittedOnDate)
.withMaturityInstructionId(maturityInstructionId)
.build(clientID, productID, penalInterestType);
return this.fixedDepositAccountHelper
.applyFixedDepositApplication(fixedDepositApplicationJSON, this.requestSpec, this.responseSpec);
}

private Integer applyForFixedDepositApplication(final String clientID, final String productID, final String submittedOnDate,
final String penalInterestType, final String depositAmount, final String depositPeriod) {
LOG.info("--------------------------------APPLYING FOR FIXED DEPOSIT ACCOUNT --------------------------------");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public FixedDepositAccountHelper(final RequestSpecification requestSpec, final R
private String submittedOnDate = "";
private String savingsId = null;
private boolean transferInterest = false;
private Integer maturityInstructionId;

public String build(final String clientId, final String productId, final String penalInterestType) {
final HashMap<String, Object> map = new HashMap<>();
Expand Down Expand Up @@ -127,6 +128,7 @@ public String build(final String clientId, final String productId, final String
map.put("submittedOnDate", this.submittedOnDate);
map.put("linkAccountId", savingsId);
map.put("transferInterestToSavings", transferInterest);
map.put("maturityInstructionId", maturityInstructionId);

String fixedDepositAccountJson = new Gson().toJson(map);
LOG.info("{}", fixedDepositAccountJson);
Expand Down Expand Up @@ -489,4 +491,9 @@ private String getDepositAmount() {
}
return this.newDepositAmount;
}

public FixedDepositAccountHelper withMaturityInstructionId(Integer maturityInstructionId){
this.maturityInstructionId = maturityInstructionId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public static JsonCommand fromJsonElement(final Long resourceId, final JsonEleme
return new JsonCommand(resourceId, parsedCommand);
}

public static JsonCommand fromJsonElement(final Long resourceId, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper) {
return new JsonCommand(resourceId, parsedCommand, fromApiJsonHelper);
}

public JsonCommand(final Long resourceId, final JsonElement parsedCommand) {
this.parsedCommand = parsedCommand;
this.resourceId = resourceId;
Expand All @@ -150,6 +154,25 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand) {
this.organisationCreditBureauId=null;
}

public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper) {
this.parsedCommand = parsedCommand;
this.resourceId = resourceId;
this.commandId = null;
this.jsonCommand = null;
this.fromApiJsonHelper = fromApiJsonHelper;
this.entityName = null;
this.subresourceId = null;
this.groupId = null;
this.clientId = null;
this.loanId = null;
this.savingsId = null;
this.transactionId = null;
this.url = null;
this.productId = null;
this.creditBureauId=null;
this.organisationCreditBureauId=null;
}

public Long getOrganisationCreditBureauId() {
return this.organisationCreditBureauId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface AccountAssociationsReadPlatformService {
public PortfolioAccountData retriveSavingsLinkedAssociation(final Long savingsId);

public Collection<AccountAssociationsData> retriveLoanAssociations(Long loanId, Integer associationType);

PortfolioAccountData retriveSavingsAccount(Long savingsId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,9 @@ public AccountAssociationsData mapRow(final ResultSet rs, @SuppressWarnings("unu
}

}
@Override
public PortfolioAccountData retriveSavingsAccount(final Long savingsId){
String accountNo = jdbcTemplate.queryForObject("select account_no from m_savings_account where id = ?", String.class, savingsId);
return PortfolioAccountData.lookup(savingsId, accountNo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public enum DepositAccountOnClosureType {
INVALID(0, "depositAccountClosureType.invalid"), //
WITHDRAW_DEPOSIT(100, "depositAccountClosureType.withdrawDeposit"), //
TRANSFER_TO_SAVINGS(200, "depositAccountClosureType.transferToSavings"), //
REINVEST(300, "depositAccountClosureType.reinvest"); //
REINVEST_PRINCIPAL_AND_INTEREST(300, "depositAccountClosureType.reinvestPrincipalAndInterest"),
REINVEST_PRINCIPAL_ONLY(400, "depositAccountClosureType.reinvestPrincipalOnly"); //

private final Integer value;
private final String code;
Expand Down Expand Up @@ -63,7 +64,10 @@ public static DepositAccountOnClosureType fromInt(final Integer closureTypeValue
accountOnClosureType = DepositAccountOnClosureType.TRANSFER_TO_SAVINGS;
break;
case 300:
accountOnClosureType = DepositAccountOnClosureType.REINVEST;
accountOnClosureType = DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST;
break;
case 400:
accountOnClosureType = DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY;
break;
}
return accountOnClosureType;
Expand All @@ -78,7 +82,16 @@ public boolean isTransferToSavings() {
}

public boolean isReinvest() {
return this.value.equals(DepositAccountOnClosureType.REINVEST.getValue());
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST.getValue()) ||
this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getValue());
}

public boolean isReinvestPrincipal() {
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getValue());
}

public boolean isReinvestPrincipalAndInterest() {
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST.getValue());
}

public boolean isInvalid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public class DepositsApiConstants {
public static final String transferDescriptionParamName = "transferDescription";
public static final String toSavingsAccountIdParamName = "toSavingsAccountId";
public static final String savingsAccounts = "savingsAccounts";
public static final String maturityInstructionIdParamName = "maturityInstructionId";
public static final String transferToSavingsIdParamName = "transferToSavingsId";

public static final String preMatureCloseOnDateParamName = "preMatureCloseOnDate";

Expand Down Expand Up @@ -298,7 +300,8 @@ private static Set<String> recurringDepositProductResponseData() {
interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName,
lockinPeriodFrequencyParamName, lockinPeriodFrequencyTypeParamName, chargesParamName,
chartsParamName, depositAmountParamName, depositPeriodParamName, depositPeriodFrequencyIdParamName,
savingsAccounts, expectedFirstDepositOnDateParamName, SavingsApiConstants.withHoldTaxParamName));
savingsAccounts, expectedFirstDepositOnDateParamName, SavingsApiConstants.withHoldTaxParamName,
maturityInstructionIdParamName, transferToSavingsIdParamName));

public static final Set<String> FIXED_DEPOSIT_ACCOUNT_REQUEST_DATA_PARAMETERS = fixedDepositAccountRequestData();
public static final Set<String> FIXED_DEPOSIT_ACCOUNT_RESPONSE_DATA_PARAMETERS = fixedDepositAccountResponseData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private FixedDepositAccountData populateTemplateAndAssociations(final Long accou
Collection<SavingsAccountTransactionData> transactions = null;
Collection<SavingsAccountChargeData> charges = null;
PortfolioAccountData linkedAccount = null;
PortfolioAccountData transferToSavingsAccount = null;

final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
if (!associationParameters.isEmpty()) {
Expand Down Expand Up @@ -272,6 +273,10 @@ private FixedDepositAccountData populateTemplateAndAssociations(final Long accou
}
}

if(savingsAccount.getTransferToSavingsId() !=null){
transferToSavingsAccount = this.accountAssociationsReadPlatformService.retriveSavingsAccount(savingsAccount.getTransferToSavingsId());
}

FixedDepositAccountData templateData = null;
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());

Expand All @@ -281,7 +286,7 @@ private FixedDepositAccountData populateTemplateAndAssociations(final Long accou
staffInSelectedOfficeOnly);
}

return FixedDepositAccountData.associationsAndTemplate(savingsAccount, templateData, transactions, charges, linkedAccount);
return FixedDepositAccountData.associationsAndTemplate(savingsAccount, templateData, transactions, charges, linkedAccount, transferToSavingsAccount);
}

@PUT
Expand Down
Loading