diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java index 2725a38fa..68ccffaa1 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java @@ -2,7 +2,10 @@ package org.mifosplatform.integrationtests; import static org.junit.Assert.assertEquals; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.HashMap; import org.junit.Assert; @@ -16,10 +19,16 @@ import org.mifosplatform.integrationtests.common.accounting.AccountHelper; import org.mifosplatform.integrationtests.common.accounting.JournalEntry; import org.mifosplatform.integrationtests.common.accounting.JournalEntryHelper; import org.mifosplatform.integrationtests.common.charges.ChargesHelper; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositAccountHelper; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositAccountStatusChecker; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositProductHelper; import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker; import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; +import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositAccountHelper; +import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositAccountStatusChecker; +import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositProductHelper; import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper; import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; @@ -30,7 +39,7 @@ import com.jayway.restassured.http.ContentType; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; -@SuppressWarnings({ "rawtypes", "unchecked", "static-access" }) +@SuppressWarnings({ "unused", "rawtypes", "unchecked", "static-access" }) public class AccountingScenarioIntegrationTest { private static RequestSpecification requestSpec; @@ -66,6 +75,10 @@ public class AccountingScenarioIntegrationTest { private AccountHelper accountHelper; private JournalEntryHelper journalEntryHelper; private SavingsAccountHelper savingsAccountHelper; + private FixedDepositProductHelper fixedDepositProductHelper; + private FixedDepositAccountHelper fixedDepositAccountHelper; + private RecurringDepositProductHelper recurringDepositProductHelper; + private RecurringDepositAccountHelper recurringDepositAccountHelper; @Before public void setup() { @@ -300,6 +313,166 @@ public class AccountingScenarioIntegrationTest { assertEquals("Verifying Balance", balance, summary.get("accountBalance")); } + @Test + public void testFixedDepositAccountingFlow() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + 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()); + + Integer currentDate = new Integer(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 Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO, assetAccount, incomeAccount, expenseAccount, + liabilityAccount); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, FixedDepositTest.WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap accountSummary = this.fixedDepositAccountHelper.getFixedDepositSummary(fixedDepositAccountId); + + Float depositAmount = (Float) accountSummary.get("totalDeposits"); + + // Checking initial Journal entries after Activation. + final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(depositAmount, JournalEntry.TransactionType.DEBIT) }; + final JournalEntry[] liablilityAccountInitialEntry = { new JournalEntry(depositAmount, JournalEntry.TransactionType.CREDIT) }; + this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, ACTIVATION_DATE, assetAccountInitialEntry); + this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, ACTIVATION_DATE, liablilityAccountInitialEntry); + + Integer transactionIdForPostInterest = this.fixedDepositAccountHelper.postInterestForFixedDeposit(fixedDepositAccountId); + Assert.assertNotNull(transactionIdForPostInterest); + + accountSummary = this.fixedDepositAccountHelper.getFixedDepositSummary(fixedDepositAccountId); + Float totalInterestPosted = (Float) accountSummary.get("totalInterestPosted"); + + // Checking initial Journal entries after Interest Posting. + final JournalEntry[] expenseAccountEntry = { new JournalEntry(totalInterestPosted, JournalEntry.TransactionType.DEBIT) }; + final JournalEntry[] liablilityAccountEntry = { new JournalEntry(totalInterestPosted, JournalEntry.TransactionType.CREDIT) }; + this.journalEntryHelper.checkJournalEntryForAssetAccount(expenseAccount, INTEREST_POSTED_DATE, expenseAccountEntry); + this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, INTEREST_POSTED_DATE, liablilityAccountEntry); + + } + + @Test + public void testRecurringDepositAccountingFlow() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + 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"); + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + + Integer currentDate = new Integer(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()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO, assetAccount, liabilityAccount, incomeAccount, expenseAccount); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, RecurringDepositTest.WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, depositAmount, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + + // Checking initial Journal entries after Activation. + final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(depositAmount, JournalEntry.TransactionType.DEBIT) }; + final JournalEntry[] liablilityAccountInitialEntry = { new JournalEntry(depositAmount, JournalEntry.TransactionType.CREDIT) }; + this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, EXPECTED_FIRST_DEPOSIT_ON_DATE, assetAccountInitialEntry); + this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, EXPECTED_FIRST_DEPOSIT_ON_DATE, liablilityAccountInitialEntry); + + Integer interestPostingTransactionId = this.recurringDepositAccountHelper + .postInterestForRecurringDeposit(recurringDepositAccountId); + Assert.assertNotNull(interestPostingTransactionId); + + HashMap accountSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float totalInterestPosted = (Float) accountSummary.get("totalInterestPosted"); + + // Checking initial Journal entries after Interest Posting. + final JournalEntry[] expenseAccountEntry = { new JournalEntry(totalInterestPosted, JournalEntry.TransactionType.DEBIT) }; + final JournalEntry[] liablilityAccountEntry = { new JournalEntry(totalInterestPosted, JournalEntry.TransactionType.CREDIT) }; + this.journalEntryHelper.checkJournalEntryForAssetAccount(expenseAccount, INTEREST_POSTED_DATE, expenseAccountEntry); + this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, INTEREST_POSTED_DATE, liablilityAccountEntry); + + } + public static Integer createSavingsProduct(final String minOpenningBalance, final Account... accounts) { System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); final String savingsProductJSON = new SavingsProductHelper().withInterestCompoundingPeriodTypeAsDaily() // @@ -308,4 +481,41 @@ public class AccountingScenarioIntegrationTest { .withMinimumOpenningBalance(minOpenningBalance).withAccountingRuleAsCashBased(accounts).build(); return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); } + + private Integer createFixedDepositProduct(final String validFrom, final String validTo, Account... accounts) { + System.out.println("------------------------------CREATING NEW FIXED DEPOSIT PRODUCT ---------------------------------------"); + FixedDepositProductHelper fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + final String fixedDepositProductJSON = fixedDepositProductHelper // + .withAccountingRuleAsCashBased(accounts).build(validFrom, validTo); + return FixedDepositProductHelper.createFixedDepositProduct(fixedDepositProductJSON, requestSpec, responseSpec); + } + + private Integer applyForFixedDepositApplication(final String clientID, final String productID, final String validFrom, + final String validTo, final String submittedOnDate, final String penalInterestType) { + System.out.println("--------------------------------APPLYING FOR FIXED DEPOSIT ACCOUNT --------------------------------"); + final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) // + .withSubmittedOnDate(submittedOnDate).build(clientID, productID, validFrom, validTo, penalInterestType); + return this.fixedDepositAccountHelper + .applyFixedDepositApplication(fixedDepositApplicationJSON, this.requestSpec, this.responseSpec); + } + + private Integer createRecurringDepositProduct(final String validFrom, final String validTo, Account... accounts) { + System.out.println("------------------------------CREATING NEW RECURRING DEPOSIT PRODUCT ---------------------------------------"); + RecurringDepositProductHelper recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + final String recurringDepositProductJSON = recurringDepositProductHelper // + .withAccountingRuleAsCashBased(accounts) + .build(validFrom, validTo); + return RecurringDepositProductHelper.createRecurringDepositProduct(recurringDepositProductJSON, requestSpec, responseSpec); + } + + private Integer applyForRecurringDepositApplication(final String clientID, final String productID, final String validFrom, + final String validTo, final String submittedOnDate, final String penalInterestType, final String expectedFirstDepositOnDate) { + System.out.println("--------------------------------APPLYING FOR RECURRING DEPOSIT ACCOUNT --------------------------------"); + final String recurringDepositApplicationJSON = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec) + // + .withSubmittedOnDate(submittedOnDate).withExpectedFirstDepositOnDate(expectedFirstDepositOnDate) + .build(clientID, productID, validFrom, validTo, penalInterestType); + return this.recurringDepositAccountHelper.applyRecurringDepositApplication(recurringDepositApplicationJSON, this.requestSpec, + this.responseSpec); + } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FixedDepositTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FixedDepositTest.java index fb8dd4431..2a493ac35 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FixedDepositTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FixedDepositTest.java @@ -8,6 +8,7 @@ import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.List; @@ -46,11 +47,12 @@ public class FixedDepositTest { private AccountHelper accountHelper; private SavingsAccountHelper savingsAccountHelper; - private static final String WHOLE_TERM = "1"; - private static final String TILL_PREMATURE_WITHDRAWAL = "2"; + public static final String WHOLE_TERM = "1"; + public static final String TILL_PREMATURE_WITHDRAWAL = "2"; private static final String DAILY = "1"; private static final String MONTHLY = "4"; private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; private static final String ANNUALLY = "7"; private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; @@ -62,6 +64,11 @@ public class FixedDepositTest { public static final String CLOSURE_TYPE_WITHDRAW_DEPOSIT = "100"; public static final String CLOSURE_TYPE_TRANSFER_TO_SAVINGS = "200"; public static final String CLOSURE_TYPE_REINVEST = "300"; + public static final Integer DAILY_COMPOUNDING_INTERVAL = 0; + public static final Integer MONTHLY_INTERVAL = 1; + public static final Integer QUARTERLY_INTERVAL = 3; + public static final Integer BIANNULLY_INTERVAL = 6; + public static final Integer ANNUL_INTERVAL = 12; @Before public void setup() { @@ -97,11 +104,6 @@ public class FixedDepositTest { todaysDate.add(Calendar.MONTH, 1); final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); - final Account assetAccount = this.accountHelper.createAssetAccount(); - final Account incomeAccount = this.accountHelper.createIncomeAccount(); - final Account expenseAccount = this.accountHelper.createExpenseAccount(); - final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); - Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); Assert.assertNotNull(clientId); @@ -109,7 +111,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -141,48 +143,6 @@ public class FixedDepositTest { } - @Test - public void testFixedDepositAccountUpdation() { - this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); - this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); - - DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); - DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); - - 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 MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); - String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime()); - - Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); - Assert.assertNotNull(clientId); - - Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); - Assert.assertNotNull(fixedDepositProductId); - - ArrayList allFixedDepositProductsData = this.fixedDepositProductHelper.retrieveAllFixedDepositProducts(this.requestSpec, - this.responseSpec); - HashMap fixedDepositProductData = this.fixedDepositProductHelper.retrieveFixedDepositProductById(this.requestSpec, - this.responseSpec, fixedDepositProductId.toString()); - - Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); - Assert.assertNotNull(fixedDepositAccountId); - - todaysDate.add(Calendar.DATE, -1); - SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime()); - HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateFixedDepositAccount(clientId.toString(), - fixedDepositProductId.toString(), fixedDepositAccountId.toString(), VALID_FROM, VALID_TO, WHOLE_TERM, SUBMITTED_ON_DATE); - Assert.assertTrue(modificationsHashMap.containsKey("submittedOnDate")); - - } - @Test public void testFixedDepositAccountWithPrematureClosureTypeTransferToSavings() { this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); @@ -230,7 +190,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -272,7 +232,7 @@ public class FixedDepositTest { Float balanceAfter = (Float) savingsSummaryAfter.get("accountBalance"); Float expectedSavingsBalance = balanceBefore + prematurityAmount; - Assert.assertEquals("Verifying Savings Account Balance after Premature Closure", balanceAfter, expectedSavingsBalance); + Assert.assertEquals("Verifying Savings Account Balance after Premature Closure", expectedSavingsBalance, balanceAfter); } @@ -311,7 +271,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -341,6 +301,48 @@ public class FixedDepositTest { } + @Test + public void testFixedDepositAccountUpdation() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + + 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 MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + ArrayList allFixedDepositProductsData = this.fixedDepositProductHelper.retrieveAllFixedDepositProducts(this.requestSpec, + this.responseSpec); + HashMap fixedDepositProductData = this.fixedDepositProductHelper.retrieveFixedDepositProductById(this.requestSpec, + this.responseSpec, fixedDepositProductId.toString()); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + todaysDate.add(Calendar.DATE, -1); + SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime()); + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateFixedDepositAccount(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), VALID_FROM, VALID_TO, WHOLE_TERM, SUBMITTED_ON_DATE); + Assert.assertTrue(modificationsHashMap.containsKey("submittedOnDate")); + + } + @Test public void testFixedDepositAccountUndoApproval() { this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); @@ -368,7 +370,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -410,7 +412,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -450,7 +452,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -488,7 +490,7 @@ public class FixedDepositTest { Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, null); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -500,17 +502,156 @@ public class FixedDepositTest { } @Test - public void testFixedDepositAccountWithLinkedAccount() { + public void testMaturityAmountForMonthlyCompoundingAndMonthlyPosting_With_365_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Float maturityAmount = (Float) fixedDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, MONTHLY_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Fixed Deposit Account", principal, maturityAmount); + } + + @Test + public void testMaturityAmountForMonthlyCompoundingAndMonthlyPosting_With_360_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Float maturityAmount = (Float) fixedDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, MONTHLY_INTERVAL, MONTHLY_INTERVAL); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Fixed Deposit Account", principal, maturityAmount); + } + + @Test + public void testPrematureClosureAmountWithPenalInterestForWholeTerm_With_365() { 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); - FixedDepositAccountHelper fixedDepositAccountHelperValidationError = new FixedDepositAccountHelper(this.requestSpec, - new ResponseSpecBuilder().build()); - DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); Calendar todaysDate = Calendar.getInstance(); todaysDate.add(Calendar.MONTH, -3); @@ -529,17 +670,12 @@ public class FixedDepositTest { Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); Assert.assertNotNull(clientId); - Float balance = new Float(MINIMUM_OPENING_BALANCE) + new Float(FixedDepositAccountHelper.depositAmount); - final Integer savingsId = createSavings(clientId, String.valueOf(balance)); - - HashMap summary = savingsAccountHelper.getSavingsSummary(savingsId); - assertEquals("Verifying opening Balance", balance, summary.get("accountBalance")); Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); Assert.assertNotNull(fixedDepositProductId); Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, - VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, savingsId.toString()); + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); Assert.assertNotNull(fixedDepositAccountId); HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, @@ -551,28 +687,1034 @@ public class FixedDepositTest { fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); - summary = savingsAccountHelper.getSavingsSummary(savingsId); - balance = new Float(MINIMUM_OPENING_BALANCE); - assertEquals("Verifying opening Balance", balance, summary.get("accountBalance")); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) fixedDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + todaysDate.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth; + todaysDate.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(todaysDate.getTime())); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap fixedDepositPrematureData = this.fixedDepositAccountHelper.calculatePrematureAmountForFixedDeposit(fixedDepositAccountId, + CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.fixedDepositAccountHelper.prematureCloseForFixedDeposit( + fixedDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositAccountIsPrematureClosed(fixedDepositAccountStatusHashMap); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); } - private Integer createFixedDepositProduct(final String validFrom, final String validTo, Account... accounts) { + @Test + public void testPrematureClosureAmountWithPenalInterestForWholeTerm_With_360() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) fixedDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + todaysDate.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth; + todaysDate.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(todaysDate.getTime())); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap fixedDepositPrematureData = this.fixedDepositAccountHelper.calculatePrematureAmountForFixedDeposit(fixedDepositAccountId, + CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.fixedDepositAccountHelper.prematureCloseForFixedDeposit( + fixedDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositAccountIsPrematureClosed(fixedDepositAccountStatusHashMap); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestTillPrematureWithdrawal_With_365_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, TILL_PREMATURE_WITHDRAWAL); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) fixedDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Calendar activationDate = Calendar.getInstance(); + activationDate.add(Calendar.MONTH, -1); + DateTime startDate = new DateTime(activationDate.getTime()); + + Calendar prematureClosureDate = Calendar.getInstance(); + DateTime endDate = new DateTime(prematureClosureDate.getTime()); + + Integer depositedPeriod = Months.monthsBetween(startDate, endDate).getMonths(); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositedPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + todaysDate.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth; + todaysDate.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(todaysDate.getTime())); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap fixedDepositPrematureData = this.fixedDepositAccountHelper.calculatePrematureAmountForFixedDeposit(fixedDepositAccountId, + CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.fixedDepositAccountHelper.prematureCloseForFixedDeposit( + fixedDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositAccountIsPrematureClosed(fixedDepositAccountStatusHashMap); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestTillPrematureWithdrawal_With_360_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, TILL_PREMATURE_WITHDRAWAL); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + TILL_PREMATURE_WITHDRAWAL, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) fixedDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Calendar activationDate = Calendar.getInstance(); + activationDate.add(Calendar.MONTH, -1); + DateTime startDate = new DateTime(activationDate.getTime()); + + Calendar prematureClosureDate = Calendar.getInstance(); + DateTime endDate = new DateTime(prematureClosureDate.getTime()); + + Integer depositedPeriod = Months.monthsBetween(startDate, endDate).getMonths(); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositedPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + todaysDate.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth; + todaysDate.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(todaysDate.getTime())); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap fixedDepositPrematureData = this.fixedDepositAccountHelper.calculatePrematureAmountForFixedDeposit(fixedDepositAccountId, + CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.fixedDepositAccountHelper.prematureCloseForFixedDeposit( + fixedDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositAccountIsPrematureClosed(fixedDepositAccountStatusHashMap); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndMonthlyPosting_With_365_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_365, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, MONTHLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Float maturityAmount = (Float) fixedDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, DAILY_COMPOUNDING_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Fixed Deposit Account", principal, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndMonthlyPosting_With_360_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, MONTHLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Float maturityAmount = (Float) fixedDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, DAILY_COMPOUNDING_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Fixed Deposit Account", principal, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndAnnuallyPosting_With_365_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_365, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, ANNUALLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, DAILY_COMPOUNDING_INTERVAL, ANNUL_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testMaturityAmountDailyCompoundingAndAnnuallyPostingWith_360_Days() { + this.fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); + this.fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, ANNUALLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, DAILY_COMPOUNDING_INTERVAL, ANNUL_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testFixedDepositWithBi_AnnualCompoundingAndPosting_365_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_365, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, BI_ANNUALLY, BI_ANNUALLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, BIANNULLY_INTERVAL, BIANNULLY_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testFixedDepositWithBi_AnnualCompoundingAndPosting_360_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, BI_ANNUALLY, BI_ANNUALLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, BIANNULLY_INTERVAL, BIANNULLY_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testFixedDepositWithQuarterlyCompoundingAndQuarterlyPosting_365_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_365, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, QUARTERLY, QUARTERLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, QUARTERLY_INTERVAL, QUARTERLY_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + } + + @Test + public void testFixedDepositWithQuarterlyCompoundingAndQuarterlyPosting_360_Days() { + 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); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(fixedDepositProductId); + + Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM, + VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM); + Assert.assertNotNull(fixedDepositAccountId); + + HashMap modificationsHashMap = this.fixedDepositAccountHelper.updateInterestCalculationConfigForFixedDeposit(clientId.toString(), + fixedDepositProductId.toString(), fixedDepositAccountId.toString(), SUBMITTED_ON_DATE, VALID_FROM, VALID_TO, DAYS_360, + WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, QUARTERLY, QUARTERLY); + + HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec, + this.responseSpec, fixedDepositAccountId.toString()); + FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap); + + fixedDepositAccountStatusHashMap = this.fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap); + + HashMap fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + Float principal = (Float) fixedDepositAccountData.get("depositAmount"); + Integer depositPeriod = (Integer) fixedDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) fixedDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.fixedDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, fixedDepositProductId); + + Float interestRate = this.fixedDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.fixedDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositPeriod, + interestPerDay, QUARTERLY_INTERVAL, QUARTERLY_INTERVAL); + + fixedDepositAccountData = this.fixedDepositAccountHelper.getFixedDepositAccountById(this.requestSpec, this.responseSpec, + fixedDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(fixedDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + } + + private Integer createFixedDepositProduct(final String validFrom, final String validTo) { System.out.println("------------------------------CREATING NEW FIXED DEPOSIT PRODUCT ---------------------------------------"); FixedDepositProductHelper fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec); final String fixedDepositProductJSON = fixedDepositProductHelper // - // .withAccountingRuleAsCashBased(accounts) .build(validFrom, validTo); return FixedDepositProductHelper.createFixedDepositProduct(fixedDepositProductJSON, requestSpec, responseSpec); } private Integer applyForFixedDepositApplication(final String clientID, final String productID, final String validFrom, - final String validTo, final String submittedOnDate, final String penalInterestType, String savingsId) { + final String validTo, final String submittedOnDate, final String penalInterestType) { System.out.println("--------------------------------APPLYING FOR FIXED DEPOSIT ACCOUNT --------------------------------"); - final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) - // - .withSubmittedOnDate(submittedOnDate).withSavings(savingsId) - .build(clientID, productID, validFrom, validTo, penalInterestType); + final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) // + .withSubmittedOnDate(submittedOnDate).build(clientID, productID, validFrom, validTo, penalInterestType); return this.fixedDepositAccountHelper .applyFixedDepositApplication(fixedDepositApplicationJSON, this.requestSpec, this.responseSpec); } @@ -588,24 +1730,4 @@ public class FixedDepositTest { .withMinimumOpenningBalance(minOpenningBalance).build(); return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); } - - private Integer createSavings(Integer clientID, String openningBalance) { - final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, openningBalance); - Assert.assertNotNull(savingsProductID); - - SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); - - final Integer savingsId = savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); - Assert.assertNotNull(savingsProductID); - - HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); - SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); - - savingsStatusHashMap = savingsAccountHelper.approveSavings(savingsId); - SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); - - savingsStatusHashMap = savingsAccountHelper.activateSavings(savingsId); - SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); - return savingsId; - } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java index 9cc084fe6..ef1f369f7 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/RecurringDepositTest.java @@ -9,6 +9,10 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; +import net.sf.ehcache.transaction.xa.EhcacheXAException; + +import org.joda.time.DateTime; +import org.joda.time.Months; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -17,6 +21,9 @@ import org.mifosplatform.integrationtests.common.CommonConstants; import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.accounting.Account; import org.mifosplatform.integrationtests.common.accounting.AccountHelper; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositAccountHelper; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositAccountStatusChecker; +import org.mifosplatform.integrationtests.common.fixeddeposit.FixedDepositProductHelper; import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositAccountHelper; import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositAccountStatusChecker; import org.mifosplatform.integrationtests.common.recurringdeposit.RecurringDepositProductHelper; @@ -40,14 +47,30 @@ public class RecurringDepositTest { private AccountHelper accountHelper; private RecurringDepositAccountHelper recurringDepositAccountHelper; - private static final String WHOLE_TERM = "1"; + public static final String WHOLE_TERM = "1"; private static final String TILL_PREMATURE_WITHDRAWAL = "2"; + private static final String DAILY = "1"; + private static final String MONTHLY = "4"; + private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; + private static final String ANNUALLY = "7"; + private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; + private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; + private static final String DAYS_360 = "360"; + private static final String DAYS_365 = "365"; public static final String MINIMUM_OPENING_BALANCE = "1000.0"; public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL"; public static final String CLOSURE_TYPE_WITHDRAW_DEPOSIT = "100"; public static final String CLOSURE_TYPE_TRANSFER_TO_SAVINGS = "200"; public static final String CLOSURE_TYPE_REINVEST = "300"; + public static final Integer DAILY_COMPOUNDING_INTERVAL = 0; + public static final Integer MONTHLY_INTERVAL = 1; + public static final Integer QUARTERLY_INTERVAL = 3; + public static final Integer BIANNULLY_INTERVAL = 6; + public static final Integer ANNUL_INTERVAL = 12; + + public static final Float DEPOSIT_AMOUNT = 2000.0f; @Before public void setup() { @@ -64,11 +87,6 @@ public class RecurringDepositTest { this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); - 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"); DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); @@ -110,6 +128,10 @@ public class RecurringDepositTest { ACTIVATION_DATE); RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + recurringDepositAccountId = this.recurringDepositAccountHelper.calculateInterestForRecurringDeposit(recurringDepositAccountId); Assert.assertNotNull(recurringDepositAccountId); @@ -198,6 +220,10 @@ public class RecurringDepositTest { ACTIVATION_DATE); RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + recurringDepositAccountId = this.recurringDepositAccountHelper.calculateInterestForRecurringDeposit(recurringDepositAccountId); Assert.assertNotNull(recurringDepositAccountId); @@ -230,7 +256,7 @@ public class RecurringDepositTest { Float expectedSavingsBalance = balanceBefore + prematurityAmount; DecimalFormat decimalFormat = new DecimalFormat(); - decimalFormat.applyPattern(".00"); + decimalFormat.applyPattern("."); Assert.assertEquals("Verifying Savings Account Balance after Premature Closure", decimalFormat.format(expectedSavingsBalance), decimalFormat.format(balanceAfter)); @@ -293,6 +319,10 @@ public class RecurringDepositTest { ACTIVATION_DATE); RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + recurringDepositAccountId = this.recurringDepositAccountHelper.calculateInterestForRecurringDeposit(recurringDepositAccountId); Assert.assertNotNull(recurringDepositAccountId); @@ -518,7 +548,7 @@ public class RecurringDepositTest { } @Test - public void testDepositForRecurringDepositAccount() { + public void testUpdateAndUndoTransactionForRecurringDepositAccount() { this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); @@ -573,19 +603,1475 @@ public class RecurringDepositTest { Float balanceBefore = (Float) recurringDepositSummaryBefore.get("accountBalance"); Integer transactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, - DEPOSIT_DATE); + DEPOSIT_AMOUNT, DEPOSIT_DATE); Assert.assertNotNull(transactionIdForDeposit); + Float expectedBalanceAfter = balanceBefore + DEPOSIT_AMOUNT; HashMap recurringDepositSummaryAfter = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); Float balanceAfter = (Float) recurringDepositSummaryAfter.get("accountBalance"); + Assert.assertEquals("Verifying account balance after deposit", expectedBalanceAfter, balanceAfter); + + Float updatedTransactionAmount = DEPOSIT_AMOUNT - 1000.0f; + + Integer updateTransactionId = this.recurringDepositAccountHelper.updateTransactionForRecurringDeposit(recurringDepositAccountId, + transactionIdForDeposit, DEPOSIT_DATE, updatedTransactionAmount); + Assert.assertNotNull(updateTransactionId); + + expectedBalanceAfter = DEPOSIT_AMOUNT - updatedTransactionAmount; + recurringDepositSummaryAfter = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + balanceAfter = (Float) recurringDepositSummaryAfter.get("accountBalance"); + + Assert.assertEquals("Verifying account balance after updating Transaction", expectedBalanceAfter, balanceAfter); + + Integer undoTransactionId = this.recurringDepositAccountHelper.undoTransactionForRecurringDeposit(recurringDepositAccountId, + updateTransactionId, DEPOSIT_DATE, 0.0f); + Assert.assertNotNull(undoTransactionId); + + expectedBalanceAfter = expectedBalanceAfter - updatedTransactionAmount; + recurringDepositSummaryAfter = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + balanceAfter = (Float) recurringDepositSummaryAfter.get("accountBalance"); + + Assert.assertEquals("Verifying account balance after Undo Transaction", expectedBalanceAfter, balanceAfter); + + } + + @Test + public void testMaturityAmountForMonthlyCompoundingAndMonthlyPosting_With_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Float maturityAmount = (Float) recurringDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositAmount, + depositPeriod, interestPerDay, MONTHLY_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Recurring Deposit Account", principal, maturityAmount); + } + + @Test + public void testMaturityAmountForMonthlyCompoundingAndMonthlyPosting_With_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Float maturityAmount = (Float) recurringDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, depositAmount, + depositPeriod, interestPerDay, MONTHLY_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Recurring Deposit Account", principal, maturityAmount); + } + + @Test + public void testPostInterestForRecurringDeposit() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("totalDeposits"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestToBePosted = new Float(decimalFormat.format(interestPerDay * principal * daysInMonth)); + principal += interestToBePosted; + + Float expectedBalanceAfter = new Float(decimalFormat.format(principal)); + System.out.println(expectedBalanceAfter); + + Integer transactionIdForPostInterest = this.recurringDepositAccountHelper + .postInterestForRecurringDeposit(recurringDepositAccountId); + Assert.assertNotNull(transactionIdForPostInterest); + + HashMap recurringDepositAccountSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float interestAmountPosted = new Float(decimalFormat.format(recurringDepositAccountSummary.get("totalInterestPosted"))); + Float principalAfter = new Float(decimalFormat.format(recurringDepositAccountSummary.get("accountBalance"))); + + Assert.assertEquals("Verifying Amount of Interest Posted to Recurring Deposit Account", interestToBePosted, interestAmountPosted); + Assert.assertEquals("Verifying Principal Amount after Interest Posting", expectedBalanceAfter, principalAfter); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestForWholeTerm_With_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + String EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) recurringDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("totalDeposits"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(calendar.getTime())); + Integer daysInMonth = calendar.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth + depositAmount; + calendar.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(calendar.getTime())); + + EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(calendar.getTime()); + Integer transactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(transactionIdForDeposit); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap recurringDepositPrematureData = this.recurringDepositAccountHelper.calculatePrematureAmountForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.recurringDepositAccountHelper.prematureCloseForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount(this.requestSpec, + this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositAccountIsPrematureClosed(recurringDepositAccountStatusHashMap); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestForWholeTerm_With_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + String EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) recurringDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("totalDeposits"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(calendar.getTime())); + Integer daysInMonth = calendar.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth + depositAmount; + calendar.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(calendar.getTime())); + + EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(calendar.getTime()); + Integer transactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(transactionIdForDeposit); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap recurringDepositPrematureData = this.recurringDepositAccountHelper.calculatePrematureAmountForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.recurringDepositAccountHelper.prematureCloseForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount(this.requestSpec, + this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositAccountIsPrematureClosed(recurringDepositAccountStatusHashMap); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestTillPrematureWithdrawal_With_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + String EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, TILL_PREMATURE_WITHDRAWAL, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) recurringDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Calendar activationDate = Calendar.getInstance(); + activationDate.add(Calendar.MONTH, -1); + DateTime start = new DateTime(activationDate.getTime()); + + Calendar prematureClosureDate = Calendar.getInstance(); + DateTime end = new DateTime(prematureClosureDate.getTime()); + + Integer depositedPeriod = Months.monthsBetween(start, end).getMonths(); + + Integer depositTransactionId = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(depositTransactionId); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("totalDeposits"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositedPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(calendar.getTime())); + Integer daysInMonth = calendar.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth + depositAmount; + calendar.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(calendar.getTime())); + + EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(calendar.getTime()); + Integer transactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(transactionIdForDeposit); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap recurringDepositPrematureData = this.recurringDepositAccountHelper.calculatePrematureAmountForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.recurringDepositAccountHelper.prematureCloseForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount(this.requestSpec, + this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositAccountIsPrematureClosed(recurringDepositAccountStatusHashMap); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); + + } + + @Test + public void testPrematureClosureAmountWithPenalInterestTillPrematureWithdrawal_With_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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()); + String EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + todaysDate.add(Calendar.MONTH, 1); + final String CLOSED_ON_DATE = dateFormat.format(todaysDate.getTime()); + + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, TILL_PREMATURE_WITHDRAWAL, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, TILL_PREMATURE_WITHDRAWAL, INTEREST_CALCULATION_USING_DAILY_BALANCE, MONTHLY, MONTHLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.activateRecurringDeposit(recurringDepositAccountId, + ACTIVATION_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsActive(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + Float depositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Float preClosurePenalInterestRate = (Float) recurringDepositAccountData.get("preClosurePenalInterest"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Calendar activationDate = Calendar.getInstance(); + activationDate.add(Calendar.MONTH, -1); + DateTime start = new DateTime(activationDate.getTime()); + + Calendar prematureClosureDate = Calendar.getInstance(); + DateTime end = new DateTime(prematureClosureDate.getTime()); + + Integer depositedPeriod = Months.monthsBetween(start, end).getMonths(); + + Integer transactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(transactionIdForDeposit); + + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("totalDeposits"); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositedPeriod); + interestRate -= preClosurePenalInterestRate; + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Integer currentDate = new Integer(currentDateFormat.format(calendar.getTime())); + Integer daysInMonth = calendar.getActualMaximum(Calendar.DATE); + daysInMonth = (daysInMonth - currentDate) + 1; + Float interestPerMonth = (float) (interestPerDay * principal * daysInMonth); + principal += interestPerMonth + depositAmount; + calendar.add(Calendar.DATE, daysInMonth); + System.out.println(monthDayFormat.format(calendar.getTime())); + + EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(calendar.getTime()); + Integer newTransactionIdForDeposit = this.recurringDepositAccountHelper.depositToRecurringDepositAccount(recurringDepositAccountId, + DEPOSIT_AMOUNT, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(newTransactionIdForDeposit); + + interestPerMonth = (float) (interestPerDay * principal * currentDate); + System.out.println("IPM = " + interestPerMonth); + principal += interestPerMonth; + System.out.println("principal = " + principal); + + HashMap recurringDepositPrematureData = this.recurringDepositAccountHelper.calculatePrematureAmountForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE); + + Integer prematureClosureTransactionId = (Integer) this.recurringDepositAccountHelper.prematureCloseForRecurringDeposit( + recurringDepositAccountId, CLOSED_ON_DATE, CLOSURE_TYPE_WITHDRAW_DEPOSIT, null, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(prematureClosureTransactionId); + + recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount(this.requestSpec, + this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositAccountIsPrematureClosed(recurringDepositAccountStatusHashMap); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + + principal = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", principal, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndMonthlyPosting_With_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_365, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, MONTHLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Float maturityAmount = (Float) recurringDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, DAILY_COMPOUNDING_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Recurring Deposit Account", principal, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndMonthlyPosting_With_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + 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); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + todaysDate.add(Calendar.DATE, -(currentDate - 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, MONTHLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Float maturityAmount = (Float) recurringDepositAccountData.get("maturityAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, DAILY_COMPOUNDING_INTERVAL, MONTHLY_INTERVAL); + + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + principal = new Float(decimalFormat.format(principal)); + maturityAmount = new Float(decimalFormat.format(maturityAmount)); + System.out.println(principal); + Assert.assertEquals("Verifying Maturity amount for Recurring Deposit Account", principal, maturityAmount); + + } + + @Test + public void testRecurringDepositWithBi_AnnualCompoundingAndPosting_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_365, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, BI_ANNUALLY, BI_ANNUALLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, BIANNULLY_INTERVAL, BIANNULLY_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testRecurringDepositWithBi_AnnualCompoundingAndPosting_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, BI_ANNUALLY, BI_ANNUALLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, BIANNULLY_INTERVAL, BIANNULLY_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndAnnuallyPosting_With_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_365, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, ANNUALLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, DAILY_COMPOUNDING_INTERVAL, ANNUL_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testMaturityAmountForDailyCompoundingAndAnnuallyPosting_With_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, DAILY, ANNUALLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, DAILY_COMPOUNDING_INTERVAL, ANNUL_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testRecurringDepositQuarterlyCompoundingAndQuarterlyPosting_365_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_365, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, QUARTERLY, QUARTERLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, QUARTERLY_INTERVAL, QUARTERLY_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + + } + + @Test + public void testRecurringDepositQuarterlyCompoundingAndQuarterlyPosting_360_Days() { + this.recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec); + + DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); + DateFormat monthDayFormat = new SimpleDateFormat("dd MMM"); + DateFormat currentMonthFormat = new SimpleDateFormat("MM"); + DateFormat currentDateFormat = new SimpleDateFormat("dd"); + + Calendar todaysDate = Calendar.getInstance(); + todaysDate.add(Calendar.YEAR, -1); + Integer currentMonth = new Integer(currentMonthFormat.format(todaysDate.getTime())); + Integer numberOfMonths = 12 - currentMonth; + todaysDate.add(Calendar.MONTH, numberOfMonths); + Integer currentDate = new Integer(currentDateFormat.format(todaysDate.getTime())); + Integer daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + Integer daysLeft = daysInMonth - currentDate; + todaysDate.add(Calendar.DATE, (daysLeft + 1)); + daysInMonth = todaysDate.getActualMaximum(Calendar.DATE); + System.out.println(dateFormat.format(todaysDate.getTime())); + final String VALID_FROM = dateFormat.format(todaysDate.getTime()); + + final String VALID_TO = null; + 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 EXPECTED_FIRST_DEPOSIT_ON_DATE = dateFormat.format(todaysDate.getTime()); + final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); + + Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientId); + + Integer recurringDepositProductId = createRecurringDepositProduct(VALID_FROM, VALID_TO); + Assert.assertNotNull(recurringDepositProductId); + + Integer recurringDepositAccountId = applyForRecurringDepositApplication(clientId.toString(), recurringDepositProductId.toString(), + VALID_FROM, VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, EXPECTED_FIRST_DEPOSIT_ON_DATE); + Assert.assertNotNull(recurringDepositAccountId); + + HashMap modificationsHashMap = this.recurringDepositAccountHelper.updateInterestCalculationConfigForRecurringDeposit( + clientId.toString(), recurringDepositProductId.toString(), recurringDepositAccountId.toString(), SUBMITTED_ON_DATE, + VALID_FROM, VALID_TO, DAYS_360, WHOLE_TERM, INTEREST_CALCULATION_USING_DAILY_BALANCE, QUARTERLY, QUARTERLY, + EXPECTED_FIRST_DEPOSIT_ON_DATE); + + HashMap recurringDepositAccountStatusHashMap = RecurringDepositAccountStatusChecker.getStatusOfRecurringDepositAccount( + this.requestSpec, this.responseSpec, recurringDepositAccountId.toString()); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsPending(recurringDepositAccountStatusHashMap); + + recurringDepositAccountStatusHashMap = this.recurringDepositAccountHelper.approveRecurringDeposit(recurringDepositAccountId, + APPROVED_ON_DATE); + RecurringDepositAccountStatusChecker.verifyRecurringDepositIsApproved(recurringDepositAccountStatusHashMap); + + HashMap recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + HashMap recurringDepositSummary = this.recurringDepositAccountHelper.getRecurringDepositSummary(recurringDepositAccountId); + Float principal = (Float) recurringDepositSummary.get("accountBalance"); + Float recurringDepositAmount = (Float) recurringDepositAccountData.get("recurringDepositAmount"); + Integer depositPeriod = (Integer) recurringDepositAccountData.get("depositPeriod"); + HashMap daysInYearMap = (HashMap) recurringDepositAccountData.get("interestCalculationDaysInYearType"); + Integer daysInYear = (Integer) daysInYearMap.get("id"); + ArrayList> interestRateChartData = this.recurringDepositProductHelper.getInterestRateChartSlabsByProductId( + this.requestSpec, this.responseSpec, recurringDepositProductId); + + Float interestRate = this.recurringDepositAccountHelper.getInterestRate(interestRateChartData, depositPeriod); + double interestRateInFraction = (interestRate / 100); + double perDay = (double) 1 / (daysInYear); + System.out.println("per day = " + perDay); + double interestPerDay = interestRateInFraction * perDay; + + principal = this.recurringDepositAccountHelper.getPrincipalAfterCompoundingInterest(todaysDate, principal, recurringDepositAmount, + depositPeriod, interestPerDay, QUARTERLY_INTERVAL, QUARTERLY_INTERVAL); + + recurringDepositAccountData = this.recurringDepositAccountHelper.getRecurringDepositAccountById(this.requestSpec, + this.responseSpec, recurringDepositAccountId); + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.applyPattern("."); + Float expectedPrematureAmount = new Float(decimalFormat.format(principal)); + Float maturityAmount = new Float(decimalFormat.format(recurringDepositAccountData.get("maturityAmount"))); + + Assert.assertEquals("Verifying Pre-Closure maturity amount", expectedPrematureAmount, maturityAmount); + } private Integer createRecurringDepositProduct(final String validFrom, final String validTo, Account... accounts) { System.out.println("------------------------------CREATING NEW RECURRING DEPOSIT PRODUCT ---------------------------------------"); RecurringDepositProductHelper recurringDepositProductHelper = new RecurringDepositProductHelper(this.requestSpec, this.responseSpec); final String recurringDepositProductJSON = recurringDepositProductHelper // - // .withAccountingRuleAsCashBased(accounts) .build(validFrom, validTo); return RecurringDepositProductHelper.createRecurringDepositProduct(recurringDepositProductJSON, requestSpec, responseSpec); } @@ -594,7 +2080,6 @@ public class RecurringDepositTest { final String validTo, final String submittedOnDate, final String penalInterestType, final String expectedFirstDepositOnDate) { System.out.println("--------------------------------APPLYING FOR RECURRING DEPOSIT ACCOUNT --------------------------------"); final String recurringDepositApplicationJSON = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec) - // .withSubmittedOnDate(submittedOnDate).withExpectedFirstDepositOnDate(expectedFirstDepositOnDate) .build(clientID, productID, validFrom, validTo, penalInterestType); return this.recurringDepositAccountHelper.applyRecurringDepositApplication(recurringDepositApplicationJSON, this.requestSpec, diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java index be314127e..62314b7c9 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java @@ -56,6 +56,7 @@ public class FixedDepositAccountHelper { private static final String DAILY = "1"; private static final String MONTHLY = "4"; private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; private static final String ANNUALLY = "7"; private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; @@ -78,11 +79,10 @@ public class FixedDepositAccountHelper { private final boolean preClosurePenalApplicable = true; private final boolean isActiveChart = true; private final String currencyCode = USD; - public static final String depositAmount = "100000"; + private final String depositAmount = "100000"; private final String depositPeriod = "14"; private final String depositPeriodFrequencyId = MONTHS; private String submittedOnDate = ""; - private String savingsId = null; public String build(final String clientId, final String productId, final String validFrom, final String validTo, final String penalInterestType) { @@ -157,11 +157,10 @@ public class FixedDepositAccountHelper { map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId); map.put("preClosurePenalInterest", this.preClosurePenalInterest); map.put("preClosurePenalInterestOnTypeId", penalInterestType); - map.put("depositAmount", depositAmount); + map.put("depositAmount", this.depositAmount); map.put("depositPeriod", this.depositPeriod); map.put("depositPeriodFrequencyId", this.depositPeriodFrequencyId); map.put("submittedOnDate", this.submittedOnDate); - map.put("linkAccountId", savingsId); String fixedDepositAccountJson = new Gson().toJson(map); System.out.println(fixedDepositAccountJson); @@ -188,8 +187,9 @@ public class FixedDepositAccountHelper { return response; } - public static Float getInterestRate(ArrayList> interestSlabData, Integer depositPeriod, Float annualInterestRate) { + public static Float getInterestRate(ArrayList> interestSlabData, Integer depositPeriod) { + Float annualInterestRate = 0.0f; for (Integer slabIndex = 0; slabIndex < interestSlabData.get(0).size(); slabIndex++) { Integer fromPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("fromPeriod"); Integer toPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("toPeriod"); @@ -201,6 +201,35 @@ public class FixedDepositAccountHelper { return annualInterestRate; } + + public static Float getPrincipalAfterCompoundingInterest(Calendar currentDate, Float principal, Integer depositPeriod, double interestPerDay, Integer compoundingInterval, Integer postingInterval) { + + Float totalInterest = 0.0f; + Float interestEarned = 0.0f; + + for (int i = 1; i <= depositPeriod; i++) { + Integer daysInMonth = currentDate.getActualMaximum(Calendar.DATE); + for (int j = 0; j < daysInMonth; j++) { + + interestEarned = (float) (principal * interestPerDay); + totalInterest += interestEarned; + if (compoundingInterval == 0) { + principal += interestEarned; + } + } + if ((i % postingInterval) == 0 || i == depositPeriod) { + if (compoundingInterval != 0) { + principal += totalInterest; + } + totalInterest = 0.0f; + System.out.println(principal); + + } + currentDate.add(Calendar.MONTH, 1); + interestEarned = 0.0f; + } + return principal; + } public HashMap updateFixedDepositAccount(final String clientID, final String productID, final String accountID, final String validFrom, final String validTo, final String penalInterestType, final String submittedOnDate) { @@ -213,10 +242,9 @@ public class FixedDepositAccountHelper { + Utils.TENANT_IDENTIFIER, fixedDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES); } - public HashMap updateInterestCalculationConfigForFixedDeposit(final String clientID, final String productID, final String accountID, - final String submittedOnDate, final String validFrom, final String validTo, final String numberOfDaysPerYear, - final String penalInterestType, final String interestCalculationType, final String interestCompoundingPeriodType, - final String interestPostingPeriodType) { + public HashMap updateInterestCalculationConfigForFixedDeposit(final String clientID, final String productID, final String accountID, final String submittedOnDate, + final String validFrom, final String validTo, final String numberOfDaysPerYear, final String penalInterestType, + final String interestCalculationType, final String interestCompoundingPeriodType, final String interestPostingPeriodType) { final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) // .withSubmittedOnDate(submittedOnDate) // @@ -428,8 +456,4 @@ public class FixedDepositAccountHelper { return this; } - public FixedDepositAccountHelper withSavings(final String savingsId) { - this.savingsId = savingsId; - return this; - } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java index ad5328514..1492e5abd 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java @@ -44,6 +44,7 @@ public class FixedDepositProductHelper { private static final String DAILY = "1"; private static final String MONTHLY = "4"; private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; private static final String ANNUALLY = "7"; private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; @@ -51,6 +52,8 @@ public class FixedDepositProductHelper { private static final String DAYS_365 = "365"; private static final String NONE = "1"; private static final String CASH_BASED = "2"; + private static final String ACCRUAL_PERIODIC = "3"; + private static final String ACCRUAL_UPFRONT = "4"; private static final String WHOLE_TERM = "1"; private static final String TILL_PREMATURE_WITHDRAWAL = "2"; @@ -161,7 +164,7 @@ public class FixedDepositProductHelper { System.out.println(FixedDepositProductCreateJson); return FixedDepositProductCreateJson; } - + public FixedDepositProductHelper withAccountingRuleAsNone() { this.accountingRule = NONE; return this; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java index 40ff5517d..b41f2ec4b 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java @@ -243,6 +243,7 @@ public class LoanProductTestBuilder { map.put("interestOnLoanAccountId", ID); map.put("incomeFromFeeAccountId", ID); map.put("incomeFromPenaltyAccountId", ID); + map.put("incomeFromRecoveryAccountId", ID); } if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) { final String ID = this.accountList[i].getAccountID().toString(); @@ -274,6 +275,7 @@ public class LoanProductTestBuilder { map.put("interestOnLoanAccountId", ID); map.put("incomeFromFeeAccountId", ID); map.put("incomeFromPenaltyAccountId", ID); + map.put("incomeFromRecoveryAccountId", ID); } if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) { final String ID = this.accountList[i].getAccountID().toString(); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositAccountHelper.java index 4cd32968c..7e5ad8841 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositAccountHelper.java @@ -38,6 +38,8 @@ public class RecurringDepositAccountHelper { private static final String CALCULATE_PREMATURE_AMOUNT_COMMAND = "calculatePrematureAmount"; private static final String PREMATURE_CLOSE_COMMAND = "prematureClose"; private static final String DEPOSIT_INTO_RECURRING_DEPOSIT_COMMAND = "deposit"; + private static final String MODIFY_TRANSACTION_COMMAND = "modify"; + private static final String UNDO_TRANSACTION_COMMAND = "undo"; private static final String LOCALE = "en_GB"; private static final String DIGITS_AFTER_DECIMAL = "4"; @@ -50,15 +52,20 @@ public class RecurringDepositAccountHelper { private static final String DAILY = "1"; private static final String MONTHLY = "4"; private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; private static final String ANNUALLY = "7"; private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; private static final String DAYS_360 = "360"; private static final String DAYS_365 = "365"; + private static final String NONE = "1"; + private static final String CASH_BASED = "2"; + private static final String ACCRUAL_PERIODIC = "3"; + private static final String ACCRUAL_UPFRONT = "4"; - private final String interestCompoundingPeriodType = MONTHLY; - private final String interestPostingPeriodType = MONTHLY; - private final String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE; + private String interestCompoundingPeriodType = MONTHLY; + private String interestPostingPeriodType = MONTHLY; + private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE; private final String lockinPeriodFrequency = "6"; private final String lockingPeriodFrequencyType = MONTHS; private final String minDepositTerm = "6"; @@ -71,7 +78,7 @@ public class RecurringDepositAccountHelper { private final boolean preClosurePenalApplicable = true; private final boolean isActiveChart = true; private final String currencyCode = USD; - private final String interestCalculationDaysInYearType = DAYS_365; + private String interestCalculationDaysInYearType = DAYS_365; private final String depositAmount = "2000"; private final String depositPeriod = "14"; private final String depositPeriodFrequencyId = MONTHS; @@ -188,8 +195,9 @@ public class RecurringDepositAccountHelper { return response; } - public static Float getInterestRate(ArrayList> interestSlabData, Integer depositPeriod, Float annualInterestRate) { + public static Float getInterestRate(ArrayList> interestSlabData, Integer depositPeriod) { + Float annualInterestRate = 0.0f; for (Integer slabIndex = 0; slabIndex < interestSlabData.get(0).size(); slabIndex++) { Integer fromPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("fromPeriod"); Integer toPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("toPeriod"); @@ -202,6 +210,38 @@ public class RecurringDepositAccountHelper { return annualInterestRate; } + public static Float getPrincipalAfterCompoundingInterest(Calendar currentDate, Float principal, Float depositAmount, Integer depositPeriod, + double interestPerDay, Integer compoundingInterval, Integer postingInterval) { + + Float totalInterest = 0.0f; + Float interestEarned = 0.0f; + + for (int i = 1; i <= depositPeriod; i++) { + Integer daysInMonth = currentDate.getActualMaximum(Calendar.DATE); + principal += depositAmount; + for (int j = 0; j < daysInMonth; j++) { + + interestEarned = (float) (principal * interestPerDay); + totalInterest += interestEarned; + if (compoundingInterval == 0) { + principal += interestEarned; + } + + } + if ((i % postingInterval) == 0 || i == depositPeriod) { + if (compoundingInterval != 0) { + principal += totalInterest; + } + totalInterest = 0.0f; + System.out.println(principal); + + } + currentDate.add(Calendar.MONTH, 1); + interestEarned = 0.0f; + } + return principal; + } + public HashMap updateRecurringDepositAccount(final String clientID, final String productID, final String accountID, final String validFrom, final String validTo, final String penalInterestType, final String submittedOnDate) { @@ -219,6 +259,40 @@ public class RecurringDepositAccountHelper { + Utils.TENANT_IDENTIFIER, recurringDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES); } + public HashMap updateInterestCalculationConfigForRecurringDeposit(final String clientID, final String productID, + final String accountID, final String submittedOnDate, final String validFrom, final String validTo, + final String numberOfDaysPerYear, final String penalInterestType, final String interestCalculationType, + final String interestCompoundingPeriodType, final String interestPostingPeriodType, final String expectedFirstDepositOnDate) { + + final String recurringDepositApplicationJSON = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec) // + .withSubmittedOnDate(submittedOnDate) // + .withNumberOfDaysPerYear(numberOfDaysPerYear) // + .withInterestCalculationPeriodType(interestCalculationType) // + .withInterestCompoundingPeriodType(interestCompoundingPeriodType) // + .withInterestPostingPeriodType(interestPostingPeriodType) // + .withExpectedFirstDepositOnDate(expectedFirstDepositOnDate) // + .build(clientID, productID, validFrom, validTo, penalInterestType); + + return Utils.performServerPut(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + + Utils.TENANT_IDENTIFIER, recurringDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES); + } + + public Integer updateTransactionForRecurringDeposit(final Integer accountID, final Integer transactionId, final String transactionDate, + final Float transactionAmount) { + System.out.println("--------------------------------- UPDATE RECURRING DEPOSIT TRANSACTION ------------------------------------"); + return Utils.performServerPost(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + + "/transactions/" + transactionId + "?command=" + MODIFY_TRANSACTION_COMMAND, + getUpdateTransactionAsJSON(transactionDate, transactionAmount), CommonConstants.RESPONSE_RESOURCE_ID); + } + + public Integer undoTransactionForRecurringDeposit(final Integer accountID, final Integer transactionId, final String transactionDate, + final Float transactionAmount) { + System.out.println("--------------------------------- UNDO RECURRING DEPOSIT TRANSACTION ------------------------------------"); + return Utils.performServerPost(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + + "/transactions/" + transactionId + "?command=" + UNDO_TRANSACTION_COMMAND, + getUpdateTransactionAsJSON(transactionDate, transactionAmount), CommonConstants.RESPONSE_RESOURCE_ID); + } + public HashMap approveRecurringDeposit(final Integer recurringDepositAccountID, final String approvedOnDate) { System.out .println("--------------------------------- APPROVING RECURRING DEPOSIT APPLICATION ------------------------------------"); @@ -278,11 +352,12 @@ public class RecurringDepositAccountHelper { getCalculatedInterestForRecurringDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID); } - public Integer depositToRecurringDepositAccount(final Integer recurringDepositAccountId, final String depositedOnDate) { + public Integer depositToRecurringDepositAccount(final Integer recurringDepositAccountId, final Float depositAmount, + final String depositedOnDate) { System.out.println("--------------------------------- DEPOSIT TO RECURRING DEPOSIT ACCOUNT --------------------------------"); return (Integer) performRecurringDepositActions( createDepositToRecurringDepositURL(DEPOSIT_INTO_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountId), - getDepositToRecurringDepositAccountAsJSON(depositedOnDate), CommonConstants.RESPONSE_RESOURCE_ID); + getDepositToRecurringDepositAccountAsJSON(depositAmount, depositedOnDate), CommonConstants.RESPONSE_RESOURCE_ID); } public HashMap calculatePrematureAmountForRecurringDeposit(final Integer recurringDepositAccountId, final String closedOnDate) { @@ -311,6 +386,17 @@ public class RecurringDepositAccountHelper { return recurringDepositAccountApproveJson; } + private String getUpdateTransactionAsJSON(final String transactionDate, final Float transactionAmount) { + final HashMap map = new HashMap(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("transactionDate", transactionDate); + map.put("transactionAmount", transactionAmount); + String updateTransactionJson = new Gson().toJson(map); + System.out.println(updateTransactionJson); + return updateTransactionJson; + } + private String getRejectedRecurringDepositAsJSON(final String rejectedOnDate) { final HashMap map = new HashMap(); map.put("locale", CommonConstants.locale); @@ -360,11 +446,11 @@ public class RecurringDepositAccountHelper { return recurringDepositAccountPrematureClosureJson; } - private String getDepositToRecurringDepositAccountAsJSON(final String depositedOnDate) { + private String getDepositToRecurringDepositAccountAsJSON(final Float depositAmount, final String depositedOnDate) { final HashMap map = new HashMap(); map.put("locale", CommonConstants.locale); map.put("dateFormat", CommonConstants.dateFormat); - map.put("transactionAmount", this.recurringDepositAmount); + map.put("transactionAmount", depositAmount); map.put("transactionDate", depositedOnDate); String recurringDepositAccountPrematureClosureJson = new Gson().toJson(map); System.out.println(recurringDepositAccountPrematureClosureJson); @@ -426,4 +512,24 @@ public class RecurringDepositAccountHelper { return this; } + public RecurringDepositAccountHelper withNumberOfDaysPerYear(final String numberOfDaysPerYearTypeId) { + this.interestCalculationDaysInYearType = numberOfDaysPerYearTypeId; + return this; + } + + public RecurringDepositAccountHelper withInterestCalculationPeriodType(final String interestCalculationTypeId) { + this.interestCalculationType = interestCalculationTypeId; + return this; + } + + public RecurringDepositAccountHelper withInterestCompoundingPeriodType(final String interestCompoundingPeriodTypeId) { + this.interestCompoundingPeriodType = interestCompoundingPeriodTypeId; + return this; + } + + public RecurringDepositAccountHelper withInterestPostingPeriodType(final String interestPostingPeriodTypeId) { + this.interestPostingPeriodType = interestPostingPeriodTypeId; + return this; + } + } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositProductHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositProductHelper.java index b4e2ca1a4..e17859932 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositProductHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/recurringdeposit/RecurringDepositProductHelper.java @@ -45,6 +45,8 @@ public class RecurringDepositProductHelper { private static final String DAYS_365 = "365"; private static final String NONE = "1"; private static final String CASH_BASED = "2"; + private static final String ACCRUAL_PERIODIC = "3"; + private static final String ACCRUAL_UPFRONT = "4"; private static final String WHOLE_TERM = "1"; private static final String TILL_PREMATURE_WITHDRAWAL = "2"; private static final String VOLUNTARY = "1"; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java index 956172f4c..d884db4ae 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/producttoaccountmapping/service/ProductToGLAccountMappingWritePlatformServiceImpl.java @@ -182,9 +182,11 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(), savingProductId, CASH_ACCOUNTS_FOR_SAVINGS.INCOME_FROM_PENALTIES.getValue()); - this.savingsProductToGLAccountMappingHelper.saveSavingsToIncomeAccountMapping(element, - SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_INTEREST.getValue(), savingProductId, - CASH_ACCOUNTS_FOR_SAVINGS.INCOME_FROM_INTEREST.getValue()); + if (!accountType.equals(DepositAccountType.RECURRING_DEPOSIT) && !accountType.equals(DepositAccountType.FIXED_DEPOSIT)) { + this.savingsProductToGLAccountMappingHelper.saveSavingsToIncomeAccountMapping(element, + SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_INTEREST.getValue(), savingProductId, + CASH_ACCOUNTS_FOR_SAVINGS.INCOME_FROM_INTEREST.getValue()); + } // expenses this.savingsProductToGLAccountMappingHelper.saveSavingsToExpenseAccountMapping(element,