From 32746c09815e23efcd963933b951722dd5b557cc Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Thu, 16 Oct 2014 14:17:30 +0530 Subject: [PATCH] MIFOSX-1595 : corrected interest posting if run 2 times in a period --- .../AccountingScenarioIntegrationTest.java | 28 +++++++++++++++++++ .../LoanAccrualWritePlatformServiceImpl.java | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) 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 250aa2231..8facf4c95 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java @@ -768,11 +768,19 @@ public class AccountingScenarioIntegrationTest { final float FEE_PORTION = 50.0f; final float PENALTY_PORTION = 100.0f; + final float NEXT_FEE_PORTION = 55.0f; + final float NEXT_PENALTY_PORTION = 105.0f; + Integer flat = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, String.valueOf(FEE_PORTION), false)); Integer flatSpecifiedDueDate = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanSpecifiedDueDateJSON( ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, String.valueOf(PENALTY_PORTION), true)); + Integer flatNext = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanSpecifiedDueDateJSON( + ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, String.valueOf(NEXT_FEE_PORTION), false)); + Integer flatSpecifiedDueDateNext = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper + .getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, String.valueOf(NEXT_PENALTY_PORTION), true)); + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); @@ -804,12 +812,24 @@ public class AccountingScenarioIntegrationTest { dateFormat.format(todayDate.getTime()), String.valueOf(PENALTY_PORTION))); todayDate.add(Calendar.DATE, 1); String runOndate = dateFormat.format(todayDate.getTime()); + this.loanTransactionHelper .addChargesForLoan( loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flat), runOndate, String.valueOf(FEE_PORTION))); + todayDate.add(Calendar.DATE, 1); + this.loanTransactionHelper.addChargesForLoan( + loanID, + LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatSpecifiedDueDateNext), + dateFormat.format(todayDate.getTime()), String.valueOf(NEXT_PENALTY_PORTION))); + + this.loanTransactionHelper.addChargesForLoan( + loanID, + LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flatNext), + dateFormat.format(todayDate.getTime()), String.valueOf(NEXT_FEE_PORTION))); + // CHECK ACCOUNT ENTRIES System.out.println("Entries ......"); final float PRINCIPAL_VALUE_FOR_EACH_PERIOD = 2000.0f; @@ -844,6 +864,14 @@ public class AccountingScenarioIntegrationTest { this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(runOndate), INTEREST_3_DAYS, FEE_PORTION, PENALTY_PORTION, loanID); + runOndate = dateFormat.format(todayDate.getTime()); + + this.periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(runOndate); + float interestPerDay = totalInterest / totalDaysInPeriod; + interestPerDay = new Float(numberFormat.format(interestPerDay)); + this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(runOndate), interestPerDay, NEXT_FEE_PORTION, + NEXT_PENALTY_PORTION, loanID); + } private Integer createLoanProductWithPeriodicAccrualAccountingEnabled(final Account... accounts) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java index 3ccdf79cc..04e8525b6 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAccrualWritePlatformServiceImpl.java @@ -222,7 +222,6 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat if (totalAccInterest == null) { totalAccInterest = BigDecimal.ZERO; } - interestportion = interestportion.subtract(totalAccInterest); amount = amount.add(interestportion); totalAccInterest = totalAccInterest.add(interestportion); if (interestportion.compareTo(BigDecimal.ZERO) == 0) {