From 1164bf40a3e917ae4ddac9bc92628b849c6c6956 Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Fri, 31 Oct 2014 11:11:44 +0530 Subject: [PATCH 1/2] MIFOSX-1632 : corrected accruals(intriduced with fine tune) for specific due date --- .../AccountingScenarioIntegrationTest.java | 2 +- .../service/LoanAccrualWritePlatformServiceImpl.java | 11 ++++------- .../LoanWritePlatformServiceJpaRepositoryImpl.java | 3 +++ 3 files changed, 8 insertions(+), 8 deletions(-) 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 8facf4c95..631f2161b 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java @@ -867,7 +867,7 @@ public class AccountingScenarioIntegrationTest { runOndate = dateFormat.format(todayDate.getTime()); this.periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(runOndate); - float interestPerDay = totalInterest / totalDaysInPeriod; + float interestPerDay = (totalInterest / totalDaysInPeriod *4) - INTEREST_3_DAYS ; interestPerDay = new Float(numberFormat.format(interestPerDay)); this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(runOndate), interestPerDay, NEXT_FEE_PORTION, NEXT_PENALTY_PORTION, loanID); 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 493467a67..b2dcc02ca 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 @@ -152,7 +152,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat updateCharges(loanChargeMap.get(accrualData.getLoanId()), accrualData, accrualData.getFromDateAsLocaldate(), tilldate); updateInterestIncome(accrualData, loanWaiverTansactions, loanWaiverSchedules, tilldate); - addAccrualTillSpecificDate(tilldate, accrualData, accruredTill); + addAccrualTillSpecificDate(tilldate, accrualData); } } else { updateCharges(loanChargeMap.get(accrualData.getLoanId()), accrualData, accrualData.getFromDateAsLocaldate(), @@ -176,8 +176,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat return sb.toString(); } - private void addAccrualTillSpecificDate(final LocalDate tilldate, final LoanScheduleAccrualData accrualData, - final LocalDate accruredTill) throws Exception { + private void addAccrualTillSpecificDate(final LocalDate tilldate, final LoanScheduleAccrualData accrualData) throws Exception { LocalDate interestStartDate = accrualData.getFromDateAsLocaldate(); if (accrualData.getInterestCalculatedFrom() != null && accrualData.getFromDateAsLocaldate().isBefore(accrualData.getInterestCalculatedFrom())) { @@ -189,10 +188,7 @@ public class LoanAccrualWritePlatformServiceImpl implements LoanAccrualWritePlat } int totalNumberOfDays = Days.daysBetween(interestStartDate, accrualData.getDueDateAsLocaldate()).getDays(); - LocalDate startDate = accruredTill; - if (startDate == null) { - startDate = accrualData.getFromDateAsLocaldate(); - } + LocalDate startDate = accrualData.getFromDateAsLocaldate(); if (accrualData.getInterestCalculatedFrom() != null && startDate.isBefore(accrualData.getInterestCalculatedFrom())) { if (accrualData.getInterestCalculatedFrom().isBefore(tilldate)) { startDate = accrualData.getInterestCalculatedFrom(); @@ -222,6 +218,7 @@ 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) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index d84695520..2d51fa75b 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -1183,6 +1183,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final String defaultUserMessage = "Installment charge cannot be added to the loan."; throw new LoanChargeCannotBeAddedException("loanCharge", "overdue.charge", defaultUserMessage, null, chargeDefinition.getName()); + } else if(loanCharge.getDueLocalDate() != null && loanCharge.getDueLocalDate().isBefore(loan.getLastUserTransactionForChargeCalc())){ + final String defaultUserMessage = "charge after last transaction date can not be added to loan."; + throw new LoanChargeCannotBeAddedException("loanCharge", "date.is.after.last.transaction.date", defaultUserMessage, null, chargeDefinition.getName()); } final List existingTransactionIds = new ArrayList<>(loan.findExistingTransactionIds()); From 3bba3b91926d170319363db7f9c352d97c0e42c0 Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Fri, 31 Oct 2014 12:42:40 +0530 Subject: [PATCH 2/2] corrected standing instruction testcase for edge case scenario --- .../integrationtests/SchedulerJobsTestResults.java | 2 +- .../integrationtests/common/StandingInstructionsHelper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java index 77c37a888..565207e1c 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java @@ -569,7 +569,7 @@ public class SchedulerJobsTestResults { DateFormat monthDayFormat = new SimpleDateFormat("dd MMMM", Locale.US); Calendar todaysDate = Calendar.getInstance(); - todaysDate.add(Calendar.MONTH, -1); + todaysDate.add(Calendar.WEEK_OF_YEAR, -1); final String VALID_FROM = dateFormat.format(todaysDate.getTime()); final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime()); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StandingInstructionsHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StandingInstructionsHelper.java index 50bc5e04b..7b18e47f5 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StandingInstructionsHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StandingInstructionsHelper.java @@ -77,7 +77,7 @@ public class StandingInstructionsHelper { map.put("validTill", validTo); map.put("recurrenceType", RECURRENCE_TYPE_PERIODIC); map.put("recurrenceInterval", "1"); - map.put("recurrenceFrequency", RECURRENCE_FREQUENCY_MONTHS); + map.put("recurrenceFrequency", RECURRENCE_FREQUENCY_WEEKS); map.put("recurrenceOnMonthDay", monthDay); String savingsApplicationJSON = new Gson().toJson(map); System.out.println(savingsApplicationJSON);