System.out.println("-------------------------------DISBURSE LOAN-------------------------------------------");
loanStatusHashMap = this.loanTransactionHelper.disburseLoan("20 September 2011", loanID);
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(Float.valueOf("605.94"), JournalEntry.TransactionType.DEBIT),
new JournalEntry(Float.valueOf("126.06"), JournalEntry.TransactionType.DEBIT),
new JournalEntry(Float.valueOf("126.04"), JournalEntry.TransactionType.DEBIT),
new JournalEntry(Float.valueOf("12000.00"), JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("12000.00"), JournalEntry.TransactionType.DEBIT) };
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", assetAccountInitialEntry);
this.journalEntryHelper.checkJournalEntryForIncomeAccount(incomeAccount, "20 September 2011",
new JournalEntry(Float.valueOf("605.94"), JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("126.06"),
JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("126.04"), JournalEntry.TransactionType.CREDIT));
this.loanTransactionHelper.addChargesForLoan(
loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 September 2011", "1"));
loanCharges.clear();
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.0", "126.06", "0.0");
validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "126.06", "0.0", "0.0");
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "29 September 2011",
new JournalEntry(Float.valueOf("126.06"), JournalEntry.TransactionType.DEBIT));
this.journalEntryHelper.checkJournalEntryForIncomeAccount(incomeAccount, "29 September 2011",
new JournalEntry(Float.valueOf("126.06"), JournalEntry.TransactionType.CREDIT));
System.out.println("-------------Make repayment 1-----------");
this.loanTransactionHelper.makeRepayment("20 October 2011", Float.valueOf("3309.06"), loanID);
loanCharges.clear();
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
validateCharge(amountPlusInterestPercentageDisbursementCharge, loanCharges, "1", "0.00", "126.06", "0.0");
validateCharge(amountPlusInterestPercentageSpecifiedDueDateCharge, loanCharges, "1", "0.00", "126.06", "0.0");
validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "94.53", "31.51", "0.0");
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011", new JournalEntry(
Float.valueOf("3309.06"), JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("157.57"),
JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("240"), JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("2911.49"), JournalEntry.TransactionType.CREDIT));
this.loanTransactionHelper.addChargesForLoan(
loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
String.valueOf(amountPlusInterestPercentageSpecifiedDueDateCharge), "29 October 2011", "1"));
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
secondInstallment = loanSchedule.get(2);
validateNumberForEqual("157.57", String.valueOf(secondInstallment.get("feeChargesDue")));
System.out.println("----------- Waive installment charge for 2nd installment ---------");
this.loanTransactionHelper.waiveChargesForLoan(loanID,
(Integer) getloanCharge(amountPlusInterestPercentageInstallmentFee, loanCharges).get("id"),
LoanTransactionHelper.getWaiveChargeJSON(String.valueOf(2)));
loanCharges.clear();
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
validateCharge(amountPlusInterestPercentageInstallmentFee, loanCharges, "1", "63.02", "31.51", "31.51");
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 September 2011", new JournalEntry(
Float.valueOf("31.51"), JournalEntry.TransactionType.CREDIT));
this.journalEntryHelper.checkJournalEntryForExpenseAccount(expenseAccount, "20 September 2011",
new JournalEntry(Float.valueOf("31.51"), JournalEntry.TransactionType.DEBIT));
System.out.println("----------Make repayment 2------------");
this.loanTransactionHelper.makeRepayment("20 November 2011", Float.valueOf("3277.54"), loanID);
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
new JournalEntry(Float.valueOf("3277.54"), JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("126.06"),
JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("181.77"), JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("2969.71"),
JournalEntry.TransactionType.CREDIT));
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
secondInstallment = loanSchedule.get(2);
validateNumberForEqual("0", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
System.out.println("--------------Waive interest---------------");
this.loanTransactionHelper.waiveInterest("20 December 2011", String.valueOf(61.79), loanID);
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
HashMap thirdInstallment = loanSchedule.get(3);
validateNumberForEqual("60.59", String.valueOf(thirdInstallment.get("interestOutstanding")));
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 December 2011", new JournalEntry(Float.valueOf("61.79"),
JournalEntry.TransactionType.CREDIT));
this.journalEntryHelper.checkJournalEntryForExpenseAccount(expenseAccount, "20 December 2011",
new JournalEntry(Float.valueOf("61.79"), JournalEntry.TransactionType.DEBIT));
Integer amountPlusInterestPercentagePenaltySpecifiedDueDate = ChargesHelper.createCharges(requestSpec, responseSpec,
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT, "1", true));
this.loanTransactionHelper.addChargesForLoan(
loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "29 September 2011", "1"));
loanCharges.clear();
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
validateCharge(amountPlusInterestPercentagePenaltySpecifiedDueDate, loanCharges, "1", "0.0", "120.0", "0.0");
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
secondInstallment = loanSchedule.get(2);
validateNumberForEqual("120", String.valueOf(secondInstallment.get("totalOutstandingForPeriod")));
// checking the journal entry as applied penalty has been collected
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 October 2011", new JournalEntry(
Float.valueOf("3309.06"), JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("120"),
JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("157.57"), JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("240"), JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("2791.49"),
JournalEntry.TransactionType.CREDIT));
System.out.println("----------Make repayment 3 advance------------");
this.loanTransactionHelper.makeRepayment("20 November 2011", Float.valueOf("3302.99"), loanID);
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 November 2011",
new JournalEntry(Float.valueOf("3302.99"), JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("31.51"),
JournalEntry.TransactionType.CREDIT),
new JournalEntry(Float.valueOf("122.38"), JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("3149.10"),
JournalEntry.TransactionType.CREDIT));
this.loanTransactionHelper.addChargesForLoan(
loanID,
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
String.valueOf(amountPlusInterestPercentagePenaltySpecifiedDueDate), "10 January 2012", "1"));
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
HashMap fourthInstallment = loanSchedule.get(4);
validateNumberForEqual("120", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
validateNumberForEqual("3241.21", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
System.out.println("----------Pay applied penalty ------------");
this.loanTransactionHelper.makeRepayment("20 January 2012", Float.valueOf("120"), loanID);
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012", new JournalEntry(Float.valueOf("120"),
JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("120"), JournalEntry.TransactionType.CREDIT));
loanSchedule.clear();
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
fourthInstallment = loanSchedule.get(4);
validateNumberForEqual("0", String.valueOf(fourthInstallment.get("penaltyChargesOutstanding")));
validateNumberForEqual("3121.21", String.valueOf(fourthInstallment.get("totalOutstandingForPeriod")));
System.out.println("----------Make over payment for repayment 4 ------------");
this.loanTransactionHelper.makeRepayment("20 January 2012", Float.valueOf("3221.61"), loanID);
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "20 January 2012", new JournalEntry(
Float.valueOf("3121.21"), JournalEntry.TransactionType.DEBIT), new JournalEntry(Float.valueOf("31.51"),
JournalEntry.TransactionType.CREDIT), new JournalEntry(Float.valueOf("3089.70"), JournalEntry.TransactionType.CREDIT));
loanStatusHashMap = (HashMap) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, loanID, "status");
LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);
}