add latest dump, add patch for updating currency symbols in reference data. add quick one liner to test daily interest calculation for declining works as per example from shiva of hugo tech.

This commit is contained in:
Keith Woodlock
2012-04-28 02:14:32 +01:00
parent def1c12fb7
commit 5fefc02752
5 changed files with 1072 additions and 7 deletions
@@ -818,7 +818,8 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
@Override
public LoanProductData retrieveLoanProduct(final Long loanProductId) {
List<CurrencyData> allowedCurrencies = retrieveAllowedCurrencies();
// TODO - switch back to retrieve all allowed organisation currencies
List<CurrencyData> allowedCurrencies = retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema() + " where lp.id = ?";
@@ -958,13 +959,15 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
@Override
public List<EnumOptionReadModel> retrieveInterestFrequencyOptions() {
EnumOptionReadModel daily = new EnumOptionReadModel("Daily",
PeriodFrequencyType.DAYS.getValue().longValue());
EnumOptionReadModel perWeek = new EnumOptionReadModel("Per week",
PeriodFrequencyType.WEEKS.getValue().longValue());
EnumOptionReadModel perMonth = new EnumOptionReadModel("Per month",
PeriodFrequencyType.MONTHS.getValue().longValue());
EnumOptionReadModel perYear = new EnumOptionReadModel("Per year",
PeriodFrequencyType.YEARS.getValue().longValue());
List<EnumOptionReadModel> repaymentFrequencyOptions = Arrays.asList(
List<EnumOptionReadModel> repaymentFrequencyOptions = Arrays.asList(daily,
perWeek, perMonth, perYear);
return repaymentFrequencyOptions;
}
@@ -6,6 +6,7 @@ import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.mifosng.data.CurrencyData;
import org.mifosng.data.LoanSchedule;
@@ -46,6 +47,11 @@ public class DecliningBalanceEqualInstallmentsLoanScheduleGenerator implements
.divide(BigDecimal.valueOf(Double.valueOf("100.0")), mc)
.multiply(BigDecimal.valueOf(loanScheduleInfo.getRepayEvery()));
BigDecimal dailyInterestRate = loanScheduleInfo.getAnnualNominalInterestRate()
.divide(BigDecimal.valueOf(Long.valueOf(365)), mc)
.divide(BigDecimal.valueOf(Double.valueOf("100.0")), mc)
.multiply(BigDecimal.valueOf(loanScheduleInfo.getRepayEvery()));
double interestRateFraction = periodicInterestRate.doubleValue();
double futureValue = 0;
@@ -72,7 +78,14 @@ public class DecliningBalanceEqualInstallmentsLoanScheduleGenerator implements
int installmentNumber = 1;
for (LocalDate scheduledDueDate : scheduledDates) {
Money interestPerInstallment = outstandingBalance.multiplyRetainScale(periodicInterestRate, RoundingMode.HALF_EVEN);
// number of days from startDate to this scheduledDate
int daysInPeriod = Days.daysBetween(startDate.toDateMidnight().toDateTime(), scheduledDueDate.toDateMidnight().toDateTime()).getDays();
BigDecimal interestRateToApply = dailyInterestRate.multiply(BigDecimal.valueOf(Long.valueOf(daysInPeriod)));
Money interestDueBasedOnDays = outstandingBalance.multiplyRetainScale(interestRateToApply, RoundingMode.HALF_EVEN);
Money interestPerInstallment = interestDueBasedOnDays; //outstandingBalance.multiplyRetainScale(periodicInterestRate, RoundingMode.HALF_EVEN);
Money principalPerInstallment = totalDuePerInstallment.minus(interestPerInstallment);
if (interestCalculationGraceOnRepaymentPeriodFraction >= Integer.valueOf(1).doubleValue()) {