http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java index fa7f26a..45b0ba4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java @@ -84,14 +84,12 @@ public class InterestRateChartSlabDataValidator { final String currencyCode = this.fromApiJsonHelper.extractStringNamed(currencyCodeParamName, element); baseDataValidator.reset().parameter(currencyCodeParamName).value(currencyCode).notBlank().notExceedingLengthOf(3); - final Boolean isPrimaryGroupingByAmount = null; - validateChartSlabsCreate(element, baseDataValidator, locale, isPrimaryGroupingByAmount); + validateChartSlabsCreate(element, baseDataValidator, locale); throwExceptionIfValidationWarningsExist(dataValidationErrors); } - public void validateChartSlabsCreate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale, - final Boolean isPrimaryGroupingByAmount) { + public void validateChartSlabsCreate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale) { if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); @@ -99,25 +97,17 @@ public class InterestRateChartSlabDataValidator { } final Integer periodType = this.fromApiJsonHelper.extractIntegerNamed(periodTypeParamName, element, locale); - if (this.fromApiJsonHelper.parameterExists(periodTypeParamName, element)) { - baseDataValidator.reset().parameter(periodTypeParamName).value(periodType) - .isOneOfTheseValues(PeriodFrequencyType.integerValues()); - } + baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull() + .isOneOfTheseValues(PeriodFrequencyType.integerValues()); + Integer toPeriod = null; final Integer fromPeriod = this.fromApiJsonHelper.extractIntegerNamed(fromPeriodParamName, element, locale); - if (this.fromApiJsonHelper.parameterExists(fromPeriodParamName, element)) { - baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).integerZeroOrGreater(); - } - - if ((isPrimaryGroupingByAmount != null && !isPrimaryGroupingByAmount) || (periodType != null || fromPeriod != null)) { - baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull(); - baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).notNull(); - } + baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).notNull().integerZeroOrGreater(); if (this.fromApiJsonHelper.parameterExists(toPeriodParamName, element)) { toPeriod = this.fromApiJsonHelper.extractIntegerNamed(toPeriodParamName, element, locale); - baseDataValidator.reset().parameter(toPeriodParamName).value(toPeriod).integerGreaterThanZero(); + baseDataValidator.reset().parameter(toPeriodParamName).value(toPeriod).notNull().integerZeroOrGreater(); } if (fromPeriod != null && toPeriod != null) { @@ -125,26 +115,21 @@ public class InterestRateChartSlabDataValidator { baseDataValidator.parameter(fromPeriodParamName).value(fromPeriod).failWithCode("fromperiod.greater.than.to.period"); } } - final BigDecimal amountRangeFrom = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeFromParamName, element, locale); - final BigDecimal amountRangeTo = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeToParamName, element, locale); + BigDecimal amountRangeFrom = null; + BigDecimal amountRangeTo = null; if (this.fromApiJsonHelper.parameterExists(amountRangeFromParamName, element)) { - baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).zeroOrPositiveAmount(); - if (isPrimaryGroupingByAmount != null && isPrimaryGroupingByAmount) { - baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).notNull(); - } + amountRangeFrom = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeFromParamName, element, locale); + baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).notNull().positiveAmount(); } if (this.fromApiJsonHelper.parameterExists(amountRangeToParamName, element)) { - baseDataValidator.reset().parameter(amountRangeToParamName).value(amountRangeTo).positiveAmount(); - } - - if (amountRangeFrom == null && fromPeriod == null) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("fromperiod.or.amountRangeFrom.required"); + amountRangeTo = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeToParamName, element, locale); + baseDataValidator.reset().parameter(amountRangeToParamName).value(amountRangeTo).notNull().positiveAmount(); } if (amountRangeFrom != null && amountRangeTo != null) { if (amountRangeFrom.compareTo(amountRangeTo) > 1) { - baseDataValidator.parameter(amountRangeFromParamName).value(fromPeriod).failWithCode("from.amount.greater.than.to.amount"); + baseDataValidator.parameter(fromPeriodParamName).value(fromPeriod).failWithCode("fromperiod.greater.than.toperiod"); } } @@ -167,14 +152,12 @@ public class InterestRateChartSlabDataValidator { final JsonElement element = this.fromApiJsonHelper.parse(json); final JsonObject objectElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(objectElement); - final Boolean isPrimaryGroupingByAmount = null; - validateChartSlabsUpdate(element, baseDataValidator, locale, isPrimaryGroupingByAmount); + validateChartSlabsUpdate(element, baseDataValidator, locale); throwExceptionIfValidationWarningsExist(dataValidationErrors); } - public void validateChartSlabsUpdate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale, - final Boolean isPrimaryGroupingByAmount) { + public void validateChartSlabsUpdate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale) { if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); @@ -183,12 +166,8 @@ public class InterestRateChartSlabDataValidator { if (this.fromApiJsonHelper.parameterExists(periodTypeParamName, element)) { final Integer periodType = this.fromApiJsonHelper.extractIntegerNamed(periodTypeParamName, element, locale); - baseDataValidator.reset().parameter(periodTypeParamName).value(periodType) + baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull() .isOneOfTheseValues(PeriodFrequencyType.integerValues()); - if (isPrimaryGroupingByAmount != null && !isPrimaryGroupingByAmount) { - baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull(); - } - } Integer fromPeriod = null; @@ -196,15 +175,12 @@ public class InterestRateChartSlabDataValidator { if (this.fromApiJsonHelper.parameterExists(fromPeriodParamName, element)) { fromPeriod = this.fromApiJsonHelper.extractIntegerNamed(fromPeriodParamName, element, locale); - baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).integerZeroOrGreater(); - if (isPrimaryGroupingByAmount != null && !isPrimaryGroupingByAmount) { - baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).notNull(); - } + baseDataValidator.reset().parameter(fromPeriodParamName).value(fromPeriod).notNull().integerGreaterThanNumber(-1); } if (this.fromApiJsonHelper.parameterExists(toPeriodParamName, element)) { toPeriod = this.fromApiJsonHelper.extractIntegerNamed(toPeriodParamName, element, locale); - baseDataValidator.reset().parameter(toPeriodParamName).value(toPeriod).integerGreaterThanZero(); + baseDataValidator.reset().parameter(toPeriodParamName).value(toPeriod).notNull().integerGreaterThanNumber(-1); } if (fromPeriod != null && toPeriod != null) { @@ -216,15 +192,12 @@ public class InterestRateChartSlabDataValidator { BigDecimal amountRangeTo = null; if (this.fromApiJsonHelper.parameterExists(amountRangeFromParamName, element)) { amountRangeFrom = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeFromParamName, element, locale); - baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).zeroOrPositiveAmount(); - if (isPrimaryGroupingByAmount != null && isPrimaryGroupingByAmount) { - baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).notNull(); - } + baseDataValidator.reset().parameter(amountRangeFromParamName).value(amountRangeFrom).notNull().positiveAmount(); } if (this.fromApiJsonHelper.parameterExists(amountRangeToParamName, element)) { amountRangeTo = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeToParamName, element, locale); - baseDataValidator.reset().parameter(amountRangeToParamName).value(amountRangeTo).positiveAmount(); + baseDataValidator.reset().parameter(amountRangeToParamName).value(amountRangeTo).notNull().positiveAmount(); } if (amountRangeFrom != null && amountRangeTo != null) {
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java index 3537106..428acb3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java @@ -51,7 +51,6 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants; -import org.apache.fineract.portfolio.interestratechart.InterestRateChartSlabApiConstants; import org.apache.fineract.portfolio.savings.SavingsPeriodFrequencyType; import org.joda.time.LocalDate; import org.springframework.data.jpa.domain.AbstractPersistable; @@ -83,11 +82,12 @@ public class InterestRateChart extends AbstractPersistable<Long> { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(INTERESTRATE_CHART_RESOURCE_NAME); - this.chartFields = chartFields; + // validate before setting the other fields this.validateChartSlabs(baseDataValidator); this.throwExceptionIfValidationWarningsExist(dataValidationErrors); + this.chartFields = chartFields; this.addChartSlabs(interestRateChartSlabs); } @@ -97,85 +97,22 @@ public class InterestRateChart extends AbstractPersistable<Long> { Integer tmpPeriodType = null; List<InterestRateChartSlab> chartSlabsList = new ArrayList<>(chartSlabs); - boolean isPrimaryGroupingByAmount = this.chartFields.isPrimaryGroupingByAmount(); - chartSlabsList.sort(new InterestRateChartSlabComparator<InterestRateChartSlab>(isPrimaryGroupingByAmount)); - boolean isPeriodChart = !isPrimaryGroupingByAmount; - boolean isAmountChart = isPrimaryGroupingByAmount; for (int i = 0; i < chartSlabsList.size(); i++) { InterestRateChartSlab iSlabs = chartSlabsList.get(i); - if (!iSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)) { - if (isPrimaryGroupingByAmount) { - baseDataValidator.parameter(InterestRateChartSlabApiConstants.amountRangeFromParamName).failWithCode("cannot.be.blank"); - } else { - baseDataValidator.parameter(InterestRateChartSlabApiConstants.fromPeriodParamName).failWithCode("cannot.be.blank"); - } - - } else if (i > 0) { - if (isPeriodChart ^ iSlabs.slabFields().fromPeriod() != null) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.incomplete"); - isPeriodChart = isPeriodChart || iSlabs.slabFields().fromPeriod() != null; - } - if (isAmountChart ^ iSlabs.slabFields().getAmountRangeFrom() != null) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.incomplete"); - isAmountChart = isAmountChart || iSlabs.slabFields().getAmountRangeFrom() != null; - } - } - - if (i == 0) { + if (tmpPeriodType == null) { tmpPeriodType = iSlabs.slabFields().periodType(); - if (iSlabs.slabFields().isNotProperChartStart()) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.start.incorrect", iSlabs.slabFields() - .fromPeriod(), iSlabs.slabFields().getAmountRangeFrom()); - } - isAmountChart = isAmountChart || iSlabs.slabFields().getAmountRangeFrom() != null; - isPeriodChart = isPeriodChart || iSlabs.slabFields().fromPeriod() != null; - } else if (iSlabs.slabFields().periodType() != null && !iSlabs.slabFields().periodType().equals(tmpPeriodType)) { + } else if (!iSlabs.slabFields().periodType().equals(tmpPeriodType)) { baseDataValidator.parameter(periodTypeParamName).value(iSlabs.slabFields().periodType()) .failWithCode("period.type.is.not.same", tmpPeriodType); } - if (i + 1 < chartSlabsList.size()) { - InterestRateChartSlab nextSlabs = chartSlabsList.get(i + 1); - if (iSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount) - && nextSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)) { - if (iSlabs.slabFields().isRateChartOverlapping(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.overlapping", iSlabs.slabFields() - .fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(), nextSlabs.slabFields() - .toPeriod(), iSlabs.slabFields().getAmountRangeFrom(), iSlabs.slabFields().getAmountRangeTo(), nextSlabs - .slabFields().getAmountRangeFrom(), nextSlabs.slabFields().getAmountRangeTo()); - } else if (iSlabs.slabFields().isRateChartHasGap(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.has.gap", iSlabs.slabFields() - .fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(), nextSlabs.slabFields() - .toPeriod(), iSlabs.slabFields().getAmountRangeFrom(), iSlabs.slabFields().getAmountRangeTo(), nextSlabs - .slabFields().getAmountRangeFrom(), nextSlabs.slabFields().getAmountRangeTo()); - } - if (isPrimaryGroupingByAmount) { - if (!iSlabs.slabFields().isAmountSame(nextSlabs.slabFields())) { - if (InterestRateChartSlabFields.isNotProperPeriodStart(nextSlabs.slabFields())) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.start.incorrect", - nextSlabs.slabFields().toPeriod()); - } - if (iSlabs.slabFields().toPeriod() != null) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.end.incorrect", iSlabs - .slabFields().toPeriod()); - } - - } - } else if (!iSlabs.slabFields().isPeriodsSame(nextSlabs.slabFields())) { - if (InterestRateChartSlabFields.isNotProperAmountStart(nextSlabs.slabFields())) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.start.incorrect", nextSlabs - .slabFields().getAmountRangeFrom()); - } - if (iSlabs.slabFields().getAmountRangeTo() != null) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.end.incorrect", iSlabs - .slabFields().getAmountRangeTo()); - } - - } + for (int j = i + 1; j < chartSlabsList.size(); j++) { + InterestRateChartSlab jSlabs = chartSlabsList.get(j); + if (iSlabs.slabFields().isPeriodOverlapping(jSlabs.slabFields())) { + baseDataValidator + .failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.overlapping", iSlabs.slabFields().fromPeriod(), + iSlabs.slabFields().toPeriod(), jSlabs.slabFields().fromPeriod(), jSlabs.slabFields().toPeriod()); } - } else if (iSlabs.slabFields().isNotProperPriodEnd()) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.end.incorrect", - iSlabs.slabFields().toPeriod(), iSlabs.slabFields().getAmountRangeTo()); } } } http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java index 2b7b7a8..ca1f1b0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartFields.java @@ -24,7 +24,6 @@ import static org.apache.fineract.portfolio.interestratechart.InterestRateChartA import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.fromDateParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.localeParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.nameParamName; -import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.isPrimaryGroupingByAmountParamName; import java.util.Date; import java.util.Map; @@ -57,24 +56,19 @@ public class InterestRateChartFields { @Column(name = "end_date", nullable = false) private Date endDate; - @Column(name = "is_primary_grouping_by_amount", nullable = false) - private boolean isPrimaryGroupingByAmount; - protected InterestRateChartFields() { // } - public static InterestRateChartFields createNew(String name, String description, LocalDate fromDate, LocalDate toDate, - boolean isPrimaryGroupingByAmount) { - return new InterestRateChartFields(name, description, fromDate, toDate, isPrimaryGroupingByAmount); + public static InterestRateChartFields createNew(String name, String description, LocalDate fromDate, LocalDate toDate) { + return new InterestRateChartFields(name, description, fromDate, toDate); } - private InterestRateChartFields(String name, String description, LocalDate fromDate, LocalDate toDate, boolean isPrimaryGroupingByAmount) { + private InterestRateChartFields(String name, String description, LocalDate fromDate, LocalDate toDate) { this.name = name; this.description = description; this.fromDate = fromDate.toDate(); this.endDate = (toDate == null) ? null : toDate.toDate(); - this.isPrimaryGroupingByAmount = isPrimaryGroupingByAmount; } public void update(JsonCommand command, final Map<String, Object> actualChanges, final DataValidatorBuilder baseDataValidator) { @@ -112,12 +106,6 @@ public class InterestRateChartFields { this.endDate = newValue.toDate(); } - if (command.isChangeInBooleanParameterNamed(isPrimaryGroupingByAmountParamName, this.isPrimaryGroupingByAmount)) { - final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(isPrimaryGroupingByAmountParamName); - actualChanges.put(isPrimaryGroupingByAmountParamName, newValue); - this.isPrimaryGroupingByAmount = newValue; - } - if (isFromDateAfterToDate()) { baseDataValidator.parameter(fromDateParamName).value(fromDate).failWithCode("from.date.is.after.to.date"); } @@ -156,22 +144,20 @@ public class InterestRateChartFields { final LocalDate thatFromDate = that.getFromDateAsLocalDate(); LocalDate thatEndDate = that.getEndDateAsLocalDate(); thatEndDate = thatEndDate == null ? DateUtils.getLocalDateOfTenant() : thatEndDate; - + final LocalDateInterval thisInterval = LocalDateInterval.create(thisFromDate, thisEndDate); final LocalDateInterval thatInterval = LocalDateInterval.create(thatFromDate, thatEndDate); - - if (thisInterval.containsPortionOf(thatInterval) || thatInterval.containsPortionOf(thisInterval)) { return true; } + + if(thisInterval.containsPortionOf(thatInterval) || thatInterval.containsPortionOf(thisInterval)){ + return true; + } return false;// no overlapping } - - public boolean isApplicableChartFor(final LocalDate target) { + + public boolean isApplicableChartFor(final LocalDate target){ final LocalDate endDate = this.endDate == null ? DateUtils.getLocalDateOfTenant() : this.getEndDateAsLocalDate(); final LocalDateInterval interval = LocalDateInterval.create(getFromDateAsLocalDate(), endDate); return interval.contains(target); } - public boolean isPrimaryGroupingByAmount() { - return this.isPrimaryGroupingByAmount; - } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabComparator.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabComparator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabComparator.java deleted file mode 100644 index 19f4147..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabComparator.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.interestratechart.domain; - -import java.math.BigDecimal; -import java.util.Comparator; - -import org.apache.fineract.portfolio.savings.domain.DepositAccountInterestRateChartSlabs; - -/** - * Sort InterestRateChartSlab by input range - */ -public class InterestRateChartSlabComparator<T> implements Comparator<T> { - - private final boolean isPrimaryGroupingByAmount; - - public InterestRateChartSlabComparator(final boolean isPrimaryGroupingByAmount) { - this.isPrimaryGroupingByAmount = isPrimaryGroupingByAmount; - } - - @Override - public int compare(final T o1, final T o2) { - int compareResult = 0; - InterestRateChartSlabFields slabs1 = null; - InterestRateChartSlabFields slabs2 = null; - if (o1 instanceof InterestRateChartSlab) { - slabs1 = ((InterestRateChartSlab) o1).slabFields(); - slabs2 = ((InterestRateChartSlab) o2).slabFields(); - } else if (o1 instanceof DepositAccountInterestRateChartSlabs) { - slabs1 = ((DepositAccountInterestRateChartSlabs) o1).slabFields(); - slabs2 = ((DepositAccountInterestRateChartSlabs) o2).slabFields(); - } else { - return compareResult; - } - - if (slabs1.isPeriodsSame(slabs2) && slabs1.isAmountSame(slabs2)) { - compareResult = 0; - } else { - if (isPrimaryGroupingByAmount) { - if (slabs1.isAmountSame(slabs2)) { - compareResult = comparePeriods(slabs1, slabs2); - } else { - compareResult = compareAmounts(slabs1, slabs2); - } - } else { - if (slabs1.isPeriodsSame(slabs2)) { - compareResult = compareAmounts(slabs1, slabs2); - } else { - compareResult = comparePeriods(slabs1, slabs2); - } - } - } - return compareResult; - } - - private int comparePeriods(final InterestRateChartSlabFields slabs1, InterestRateChartSlabFields slabs2) { - int compareResult = 0; - Integer periodFrom1 = slabs1.fromPeriod(); - Integer periodFrom2 = slabs2.fromPeriod(); - if (periodFrom1 != null && periodFrom2 != null) { - compareResult = periodFrom1.compareTo(periodFrom2); - } - return compareResult; - } - - private int compareAmounts(final InterestRateChartSlabFields slabs1, InterestRateChartSlabFields slabs2) { - int compareResult = 0; - BigDecimal amountFrom1 = slabs1.getAmountRangeFrom(); - BigDecimal amountFrom2 = slabs2.getAmountRangeFrom(); - if (amountFrom1 != null && amountFrom2 != null) { - compareResult = amountFrom1.compareTo(amountFrom2); - } - return compareResult; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabFields.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabFields.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabFields.java index b8c00de..334772c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabFields.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChartSlabFields.java @@ -51,23 +51,15 @@ public class InterestRateChartSlabFields { @Column(name = "period_type_enum", nullable = false) private Integer periodType; - @Column(name = "from_period") + @Column(name = "from_period", nullable = false) private Integer fromPeriod; - @Column(name = "to_period") + @Column(name = "to_period", nullable = true) private Integer toPeriod; @Column(name = "amount_range_from", scale = 6, precision = 19) private BigDecimal amountRangeFrom; - public BigDecimal getAmountRangeFrom() { - return this.amountRangeFrom; - } - - public BigDecimal getAmountRangeTo() { - return this.amountRangeTo; - } - @Column(name = "amount_range_to", scale = 6, precision = 19) private BigDecimal amountRangeTo; @@ -92,7 +84,7 @@ public class InterestRateChartSlabFields { final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, final BigDecimal annualInterestRate, final String currencyCode) { this.description = description; - this.periodType = (periodFrequencyType == null || periodFrequencyType.isInvalid()) ? null : periodFrequencyType.getValue(); + this.periodType = (periodFrequencyType == null) ? null : periodFrequencyType.getValue(); this.fromPeriod = fromPeriod; this.toPeriod = toPeriod; this.amountRangeFrom = amountRangeFrom; @@ -191,129 +183,17 @@ public class InterestRateChartSlabFields { return this.toPeriod; } - public boolean isRateChartHasGap(final InterestRateChartSlabFields that, final boolean isPrimaryGroupingByAmount) { - boolean isPeriodSame = isPeriodsSame(that); - boolean isAmountSame = isAmountSame(that); - boolean hasPeriods = this.fromPeriod != null || that.fromPeriod != null; - boolean hasAmounts = this.amountRangeFrom != null || that.amountRangeFrom != null; - if (isPrimaryGroupingByAmount) { - if (isAmountSame) { - if (hasPeriods) { - if (this.toPeriod == null) { return true; } - return isNotProperPeriodStart(that.fromPeriod); - } - } else { - return isNotProperAmountStart(that.amountRangeFrom) || isNotProperPeriodStart(that); - } - } else { - if (isPeriodSame) { - if (hasAmounts) { - if (this.amountRangeTo == null) { return true; } - return isNotProperAmountStart(that.amountRangeFrom); - } - } else { - return isNotProperPeriodStart(that.fromPeriod) || isNotProperAmountStart(that); - } - } - return false; - } - - public boolean isValidChart(boolean isPrimaryGroupingByAmount) { - return (!isPrimaryGroupingByAmount && this.fromPeriod != null) || (isPrimaryGroupingByAmount && this.amountRangeFrom != null); - } - - public boolean isNotProperChartStart() { - return isNotProperPeriodStart(this) || isNotProperAmountStart(this); - } - - public static boolean isNotProperAmountStart(final InterestRateChartSlabFields interestRateChartSlabFields) { - return interestRateChartSlabFields.amountRangeFrom != null - && (interestRateChartSlabFields.amountRangeFrom.compareTo(BigDecimal.ONE) != 0 && interestRateChartSlabFields.amountRangeFrom - .compareTo(BigDecimal.ZERO) != 0); - } - - private boolean isNotProperAmountStart(final BigDecimal amount) { - return this.amountRangeTo == null || (amount != null && amount.compareTo(this.amountRangeTo.add(BigDecimal.ONE)) != 0); - } - - private boolean isNotProperPeriodStart(final Integer period) { - return this.toPeriod == null || (period != null && period.compareTo(this.toPeriod + 1) != 0); - } - - public static boolean isNotProperPeriodStart(InterestRateChartSlabFields interestRateChartSlabFields) { - return interestRateChartSlabFields.fromPeriod != null - && !(interestRateChartSlabFields.fromPeriod.equals(1) || interestRateChartSlabFields.fromPeriod.equals(0)); - } - - public boolean isNotProperPriodEnd() { - return !(this.toPeriod == null && this.amountRangeTo == null); - - } - - public boolean isRateChartOverlapping(final InterestRateChartSlabFields that, final boolean isPrimaryGroupingByAmount) { - boolean isPeriodOverLapping = isPeriodOverlapping(that); - boolean isAmountOverLapping = isAmountOverlapping(that); - boolean isPeriodSame = isPeriodsSame(that); - boolean isAmountSame = isAmountSame(that); - boolean isOverlapping = false; - if (isPrimaryGroupingByAmount) { - isOverlapping = (isAmountOverLapping && !isAmountSame) || (isPeriodOverLapping && isAmountSame); - } else { - isOverlapping = (isPeriodOverLapping && !isPeriodSame) || (isAmountOverLapping && isPeriodSame); + public boolean isPeriodOverlapping(final InterestRateChartSlabFields that) { + if (that.toPeriod == null) { + if (this.toPeriod == null) { return true; } + return that.fromPeriod <= this.toPeriod; } - - return isOverlapping; - } - - private boolean isPeriodOverlapping(final InterestRateChartSlabFields that) { - if (isIntegerSame(that.toPeriod, this.toPeriod)) { - return true; - } else if (isIntegerSame(that.fromPeriod, this.fromPeriod)) { - return true; - } else if (this.toPeriod == null) { - return true; - } else if (that.toPeriod == null) { return that.fromPeriod <= this.toPeriod; } return this.fromPeriod <= that.toPeriod && that.fromPeriod <= this.toPeriod; } - private boolean isAmountOverlapping(final InterestRateChartSlabFields that) { - if (isBigDecimalSame(that.amountRangeFrom, this.amountRangeFrom)) { - return true; - } else if (isBigDecimalSame(that.amountRangeTo, this.amountRangeTo)) { - return true; - } else if (this.amountRangeTo == null) { - return true; - } else if (that.amountRangeTo == null) { return that.amountRangeFrom.compareTo(this.amountRangeTo) < 1; } - return this.amountRangeFrom.compareTo(that.amountRangeTo) < 1 && that.amountRangeFrom.compareTo(this.amountRangeTo) < 1; - } - - public boolean isAmountSame(final InterestRateChartSlabFields that) { - return isBigDecimalSame(this.amountRangeFrom, that.amountRangeFrom) && isBigDecimalSame(this.amountRangeTo, that.amountRangeTo); - } - - public boolean isPeriodsSame(final InterestRateChartSlabFields that) { - return isIntegerSame(this.fromPeriod, that.fromPeriod) && isIntegerSame(this.toPeriod, that.toPeriod); - } - - public boolean isIntegerSame(final Integer obj1, final Integer obj2) { - if (obj1 == null || obj2 == null) { - if (obj1 == obj2) { return true; } - return false; - } - return obj1.equals(obj2); - } - - public boolean isBigDecimalSame(final BigDecimal obj1, final BigDecimal obj2) { - if (obj1 == null || obj2 == null) { - if (obj1 == obj2) { return true; } - return false; - } - return obj1.compareTo(obj2) == 0; - } - public boolean isBetweenPeriod(final LocalDate periodStartDate, final LocalDate periodEndDate) { final Integer compare = depositPeriod(periodStartDate, periodEndDate); - return isPeriodBetween(compare); + return (compare < this.fromPeriod || (this.toPeriod != null && compare > this.toPeriod)) ? false : true; } public boolean isAmountRangeProvided() { @@ -353,16 +233,8 @@ public class InterestRateChartSlabFields { returnValue = depositAmount.compareTo(amountRangeFrom) >= 0 && depositAmount.compareTo(amountRangeTo) <= 0; } else if (amountRangeFrom != null) { returnValue = depositAmount.compareTo(amountRangeFrom) >= 0; - } - return returnValue; - } - - public boolean isPeriodBetween(final Integer periods) { - boolean returnValue = true; - if (fromPeriod != null && toPeriod != null) { - returnValue = periods.compareTo(fromPeriod) >= 0 && periods.compareTo(toPeriod) <= 0; - } else if (fromPeriod != null) { - returnValue = periods.compareTo(fromPeriod) >= 0; + } else if (amountRangeTo != null) { + returnValue = depositAmount.compareTo(amountRangeTo) <= 0; } return returnValue; } http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartAssembler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartAssembler.java index a7f29e3..a2a65db 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartAssembler.java @@ -22,7 +22,6 @@ import static org.apache.fineract.portfolio.interestratechart.InterestRateChartA import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.descriptionParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.endDateParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.fromDateParamName; -import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.isPrimaryGroupingByAmountParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartApiConstants.nameParamName; import static org.apache.fineract.portfolio.interestratechart.InterestRateChartSlabApiConstants.currencyCodeParamName; @@ -66,38 +65,33 @@ public class InterestRateChartAssembler { * request */ public InterestRateChart assembleFrom(final JsonCommand command) { + + final JsonElement element = command.parsedJson(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); + @SuppressWarnings("unused") final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(INTERESTRATE_CHART_RESOURCE_NAME); - final JsonElement element = command.parsedJson(); final String currencyCode = this.fromApiJsonHelper.extractStringNamed(currencyCodeParamName, element); - final InterestRateChart newChart = this.assembleFrom(element, currencyCode, baseDataValidator); + final InterestRateChart newChart = this.assembleFrom(element, currencyCode); + throwExceptionIfValidationWarningsExist(dataValidationErrors); return newChart; } - private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) { - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } - } - - public InterestRateChart assembleFrom(final JsonElement element, final String currencyCode, final DataValidatorBuilder baseDataValidator) { + public InterestRateChart assembleFrom(final JsonElement element, final String currencyCode) { final String name = this.fromApiJsonHelper.extractStringNamed(nameParamName, element); final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed(fromDateParamName, element); final LocalDate toDate = this.fromApiJsonHelper.extractLocalDateNamed(endDateParamName, element); - Boolean isPrimaryGroupingByAmount = this.fromApiJsonHelper.extractBooleanNamed(isPrimaryGroupingByAmountParamName, element); - if (isPrimaryGroupingByAmount == null) { - isPrimaryGroupingByAmount = false; - } + // assemble chart Slabs - final Collection<InterestRateChartSlab> newChartSlabs = this.chartSlabAssembler.assembleChartSlabsFrom(element, currencyCode); + final Collection<InterestRateChartSlab> newChartSlabs = this.chartSlabAssembler.assembleChartSlabsFrom(element, + currencyCode); - final InterestRateChartFields fields = InterestRateChartFields.createNew(name, description, fromDate, toDate, - isPrimaryGroupingByAmount); + final InterestRateChartFields fields = InterestRateChartFields.createNew(name, description, fromDate, toDate); final InterestRateChart newChart = InterestRateChart.createNew(fields, newChartSlabs); - newChart.validateChartSlabs(baseDataValidator); return newChart; } @@ -106,4 +100,8 @@ public class InterestRateChartAssembler { .findOneWithNotFoundDetection(interestRateChartId); return interestRateChart; } + + private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java index d03e502..86eefad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java @@ -86,21 +86,8 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha @Override public Collection<InterestRateChartData> retrieveAllWithSlabs(Long productId) { this.context.authenticatedUser(); - StringBuilder sql = new StringBuilder(); - sql.append("select "); - sql.append(this.chartExtractor.schema()); - sql.append(" where sp.id = ? order by irc.id, "); - sql.append("CASE "); - sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_from "); - sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_to "); - sql.append("END,"); - sql.append("ircd.from_period, ircd.to_period,"); - sql.append("CASE "); - sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_from "); - sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_to "); - sql.append("END"); - - return this.jdbcTemplate.query(sql.toString(), this.chartExtractor, new Object[] { productId }); + String sql = "select " + this.chartExtractor.schema() + " where sp.id = ? order by irc.id, ircd.id"; + return this.jdbcTemplate.query(sql, this.chartExtractor, new Object[] { productId }); } @Override @@ -190,7 +177,6 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha sqlBuilder .append("irc.id as ircId, irc.name as ircName, irc.description as ircDescription,") .append("irc.from_date as ircFromDate, irc.end_date as ircEndDate, ") - .append("irc.is_primary_grouping_by_amount as isPrimaryGroupingByAmount, ") .append("ircd.id as ircdId, ircd.description as ircdDescription, ircd.period_type_enum ircdPeriodTypeId, ") .append("ircd.from_period as ircdFromPeriod, ircd.to_period as ircdToPeriod, ircd.amount_range_from as ircdAmountRangeFrom, ") .append("ircd.amount_range_to as ircdAmountRangeTo, ircd.annual_interest_rate as ircdAnnualInterestRate, ") @@ -253,7 +239,6 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha sqlBuilder.append("irc.id as ircId, irc.name as ircName, irc.description as ircDescription, ") .append("irc.from_date as ircFromDate, irc.end_date as ircEndDate, ") - .append("irc.is_primary_grouping_by_amount as isPrimaryGroupingByAmount, ") .append("sp.id as savingsProductId, sp.name as savingsProductName ").append("from ") .append("m_interest_rate_chart irc ") .append("left join m_deposit_product_interest_rate_chart dpirc on irc.id=dpirc.interest_rate_chart_id ") @@ -268,11 +253,10 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha final String description = rs.getString("ircDescription"); final LocalDate fromDate = JdbcSupport.getLocalDate(rs, "ircFromDate"); final LocalDate endDate = JdbcSupport.getLocalDate(rs, "ircEndDate"); - final boolean isPrimaryGroupingByAmount = rs.getBoolean("isPrimaryGroupingByAmount"); final Long savingsProductId = JdbcSupport.getLongDefaultToNullIfZero(rs, "savingsProductId"); final String savingsProductName = rs.getString("savingsProductName"); - return InterestRateChartData.instance(id, name, description, fromDate, endDate, isPrimaryGroupingByAmount, savingsProductId, savingsProductName); + return InterestRateChartData.instance(id, name, description, fromDate, endDate, savingsProductId, savingsProductName); } } @@ -315,10 +299,7 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha final Integer fromPeriod = JdbcSupport.getInteger(rs, "ircdFromPeriod"); final Integer toPeriod = JdbcSupport.getInteger(rs, "ircdToPeriod"); final Integer periodTypeId = JdbcSupport.getInteger(rs, "ircdPeriodTypeId"); - EnumOptionData periodType = null; - if (periodTypeId != null) { - periodType = InterestRateChartEnumerations.periodType(periodTypeId); - } + final EnumOptionData periodType = InterestRateChartEnumerations.periodType(periodTypeId); final BigDecimal amountRangeFrom = rs.getBigDecimal("ircdAmountRangeFrom"); final BigDecimal amountRangeTo = rs.getBigDecimal("ircdAmountRangeTo"); final BigDecimal annualInterestRate = rs.getBigDecimal("ircdAnnualInterestRate"); http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/ScheduleGeneratorDTO.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/ScheduleGeneratorDTO.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/ScheduleGeneratorDTO.java index a8f7a35..dde8599 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/ScheduleGeneratorDTO.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/ScheduleGeneratorDTO.java @@ -19,8 +19,6 @@ package org.apache.fineract.portfolio.loanaccount.data; import org.apache.fineract.organisation.monetary.domain.ApplicationCurrency; -import org.apache.fineract.portfolio.calendar.data.CalendarHistoryDataWrapper; -import org.apache.fineract.portfolio.calendar.domain.Calendar; import org.apache.fineract.portfolio.calendar.domain.CalendarInstance; import org.apache.fineract.portfolio.floatingrates.data.FloatingRateDTO; import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleGeneratorFactory; @@ -37,14 +35,11 @@ public class ScheduleGeneratorDTO { LocalDate recalculateFrom; final Long overdurPenaltyWaitPeriod; final FloatingRateDTO floatingRateDTO; - final Calendar calendar; - final CalendarHistoryDataWrapper calendarHistoryDataWrapper; public ScheduleGeneratorDTO(final LoanScheduleGeneratorFactory loanScheduleFactory, final ApplicationCurrency applicationCurrency, final LocalDate calculatedRepaymentsStartingFromDate, final HolidayDetailDTO holidayDetailDTO, final CalendarInstance calendarInstanceForInterestRecalculation, final CalendarInstance compoundingCalendarInstance, - final LocalDate recalculateFrom, final Long overdurPenaltyWaitPeriod, final FloatingRateDTO floatingRateDTO, - final Calendar calendar, final CalendarHistoryDataWrapper calendarHistoryDataWrapper) { + final LocalDate recalculateFrom, final Long overdurPenaltyWaitPeriod, final FloatingRateDTO floatingRateDTO) { this.loanScheduleFactory = loanScheduleFactory; this.applicationCurrency = applicationCurrency; @@ -55,9 +50,6 @@ public class ScheduleGeneratorDTO { this.overdurPenaltyWaitPeriod = overdurPenaltyWaitPeriod; this.holidayDetailDTO = holidayDetailDTO; this.floatingRateDTO = floatingRateDTO; - this.calendar = calendar; - this.calendarHistoryDataWrapper = calendarHistoryDataWrapper; - } public LoanScheduleGeneratorFactory getLoanScheduleFactory() { @@ -107,13 +99,5 @@ public class ScheduleGeneratorDTO { public FloatingRateDTO getFloatingRateDTO() { return this.floatingRateDTO; } - - public Calendar getCalendar(){ - return this.calendar; - } - - public CalendarHistoryDataWrapper getCalendarHistoryDataWrapper(){ - return this.calendarHistoryDataWrapper; - } } http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index db159b9..56fd87c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -71,9 +71,7 @@ import org.apache.fineract.organisation.staff.domain.Staff; import org.apache.fineract.organisation.workingdays.domain.WorkingDays; import org.apache.fineract.organisation.workingdays.service.WorkingDaysUtil; import org.apache.fineract.portfolio.accountdetails.domain.AccountType; -import org.apache.fineract.portfolio.calendar.data.CalendarHistoryDataWrapper; import org.apache.fineract.portfolio.calendar.domain.Calendar; -import org.apache.fineract.portfolio.calendar.domain.CalendarHistory; import org.apache.fineract.portfolio.calendar.domain.CalendarInstance; import org.apache.fineract.portfolio.calendar.service.CalendarUtils; import org.apache.fineract.portfolio.charge.domain.Charge; @@ -125,7 +123,6 @@ import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMe import org.apache.fineract.portfolio.loanproduct.domain.LoanTransactionProcessingStrategy; import org.apache.fineract.portfolio.loanproduct.domain.RecalculationFrequencyType; import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations; -import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail; import org.apache.fineract.useradministration.domain.AppUser; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; @@ -2288,7 +2285,7 @@ public class Loan extends AbstractPersistable<Long> { } public ChangedTransactionDetail disburse(final AppUser currentUser, final JsonCommand command, final Map<String, Object> actualChanges, - final ScheduleGeneratorDTO scheduleGeneratorDTO,final PaymentDetail paymentDetail) { + final ScheduleGeneratorDTO scheduleGeneratorDTO) { final LoanStatus statusEnum = this.loanLifecycleStateMachine.transition(LoanEvent.LOAN_DISBURSED, LoanStatus.fromInt(this.loanStatus)); @@ -2319,7 +2316,7 @@ public class Loan extends AbstractPersistable<Long> { updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement()); updateLoanRepaymentPeriodsDerivedFields(actualDisbursementDate); LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant(); - handleDisbursementTransaction(actualDisbursementDate, createdDate, currentUser,paymentDetail); + handleDisbursementTransaction(actualDisbursementDate, createdDate, currentUser); updateLoanSummaryDerivedFields(); final Money interestApplied = Money.of(getCurrency(), this.summary.getTotalInterestCharged()); @@ -2617,7 +2614,7 @@ public class Loan extends AbstractPersistable<Long> { return interestRate; } - private void handleDisbursementTransaction(final LocalDate disbursedOn, final LocalDateTime createdDate, final AppUser currentUser, final PaymentDetail paymentDetail) { + private void handleDisbursementTransaction(final LocalDate disbursedOn, final LocalDateTime createdDate, final AppUser currentUser) { // add repayment transaction to track incoming money from client to mfi // for (charges due at time of disbursement) @@ -2635,7 +2632,7 @@ public class Loan extends AbstractPersistable<Long> { **/ Money disbursentMoney = Money.zero(getCurrency()); - final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(getOffice(), disbursentMoney, paymentDetail, disbursedOn, + final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(getOffice(), disbursentMoney, null, disbursedOn, null, createdDate, currentUser); final Integer installmentNumber = null; for (final LoanCharge charge : charges()) { @@ -5035,8 +5032,6 @@ public class Loan extends AbstractPersistable<Long> { InterestRecalculationCompoundingMethod compoundingMethod = null; RecalculationFrequencyType compoundingFrequencyType = null; LoanRescheduleStrategyMethod rescheduleStrategyMethod = null; - Calendar calendar = null; - CalendarHistoryDataWrapper calendarHistoryDataWrapper = null; if (this.repaymentScheduleDetail().isInterestRecalculationEnabled()) { restCalendarInstance = scheduleGeneratorDTO.getCalendarInstanceForInterestRecalculation(); compoundingCalendarInstance = scheduleGeneratorDTO.getCompoundingCalendarInstance(); @@ -5044,8 +5039,6 @@ public class Loan extends AbstractPersistable<Long> { compoundingMethod = this.loanInterestRecalculationDetails.getInterestRecalculationCompoundingMethod(); compoundingFrequencyType = this.loanInterestRecalculationDetails.getCompoundingFrequencyType(); rescheduleStrategyMethod = this.loanInterestRecalculationDetails.getRescheduleStrategyMethod(); - calendar = scheduleGeneratorDTO.getCalendar(); - calendarHistoryDataWrapper = scheduleGeneratorDTO.getCalendarHistoryDataWrapper(); } BigDecimal annualNominalInterestRate = this.loanRepaymentScheduleDetail.getAnnualNominalInterestRate(); @@ -5060,7 +5053,7 @@ public class Loan extends AbstractPersistable<Long> { this.maxOutstandingLoanBalance, getInterestChargedFromDate(), this.loanProduct.getPrincipalThresholdForLastInstallment(), this.loanProduct.getInstallmentAmountInMultiplesOf(), recalculationFrequencyType, restCalendarInstance, compoundingMethod, compoundingCalendarInstance, compoundingFrequencyType, this.loanProduct.preCloseInterestCalculationStrategy(), - rescheduleStrategyMethod, calendar, getApprovedPrincipal(), annualNominalInterestRate, loanTermVariations, calendarHistoryDataWrapper); + rescheduleStrategyMethod, getApprovedPrincipal(), annualNominalInterestRate, loanTermVariations); return loanApplicationTerms; } @@ -5276,12 +5269,6 @@ public class Loan extends AbstractPersistable<Long> { final BigDecimal maxOutstandingBalance = getMaxOutstandingLoanBalance(); final List<DisbursementData> disbursementData = getDisbursmentData(); - - CalendarHistoryDataWrapper calendarHistoryDataWrapper = null; - if (loanCalendar != null) { - Set<CalendarHistory> calendarHistory = loanCalendar.getCalendarHistory(); - calendarHistoryDataWrapper = new CalendarHistoryDataWrapper(calendarHistory); - } RecalculationFrequencyType recalculationFrequencyType = null; InterestRecalculationCompoundingMethod compoundingMethod = null; @@ -5303,8 +5290,7 @@ public class Loan extends AbstractPersistable<Long> { maxOutstandingBalance, interestChargedFromDate, this.loanProduct.getPrincipalThresholdForLastInstallment(), this.loanProduct.getInstallmentAmountInMultiplesOf(), recalculationFrequencyType, restCalendarInstance, compoundingMethod, compoundingCalendarInstance, compoundingFrequencyType, this.loanProduct.preCloseInterestCalculationStrategy(), - rescheduleStrategyMethod, loanCalendar, getApprovedPrincipal(), annualNominalInterestRate, loanTermVariations, - calendarHistoryDataWrapper); + rescheduleStrategyMethod, loanCalendar, getApprovedPrincipal(), annualNominalInterestRate, loanTermVariations); } /** http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java index 437e7e6..3206610 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java @@ -19,7 +19,6 @@ package org.apache.fineract.portfolio.loanaccount.domain; import java.math.BigDecimal; -import java.util.Date; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -438,12 +437,6 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { @Override public void recalculateAccruals(Loan loan) { LocalDate accruedTill = loan.getAccruedTill(); - boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnabled(); - Date organisationStartDate = new Date(); - if(isOrganisationDateEnabled){ - organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate(); - } - if (!loan.isPeriodicAccrualAccountingEnabledOnLoanProduct() || !loan.repaymentScheduleDetail().isInterestRecalculationEnabled() || accruedTill == null || loan.isNpa() || !loan.status().isActive()) { return; } Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas = new ArrayList<>(); @@ -461,9 +454,33 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { Set<LoanCharge> loanCharges = loan.charges(); for (LoanRepaymentScheduleInstallment installment : installments) { - if(!isOrganisationDateEnabled || new LocalDate(organisationStartDate).isBefore(installment.getDueDate())){ - generateLoanScheduleAccrualData(accruedTill, loanScheduleAccrualDatas, loanId, officeId, accrualStartDate, repaymentFrequency, - repayEvery, interestCalculatedFrom, loanProductId, currency, currencyData, loanCharges, installment); + if (!accruedTill.isBefore(installment.getDueDate()) + || (accruedTill.isAfter(installment.getFromDate()) && !accruedTill.isAfter(installment.getDueDate()))) { + BigDecimal dueDateFeeIncome = BigDecimal.ZERO; + BigDecimal dueDatePenaltyIncome = BigDecimal.ZERO; + LocalDate chargesTillDate = installment.getDueDate(); + if (!accruedTill.isAfter(installment.getDueDate())) { + chargesTillDate = accruedTill; + } + + for (final LoanCharge loanCharge : loanCharges) { + if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), chargesTillDate)) { + if (loanCharge.isFeeCharge()) { + dueDateFeeIncome = dueDateFeeIncome.add(loanCharge.amount()); + } else if (loanCharge.isPenaltyCharge()) { + dueDatePenaltyIncome = dueDatePenaltyIncome.add(loanCharge.amount()); + } + } + } + LoanScheduleAccrualData accrualData = new LoanScheduleAccrualData(loanId, officeId, installment.getInstallmentNumber(), + accrualStartDate, repaymentFrequency, repayEvery, installment.getDueDate(), installment.getFromDate(), + installment.getId(), loanProductId, installment.getInterestCharged(currency).getAmount(), installment + .getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount(), + installment.getInterestAccrued(currency).getAmount(), installment.getFeeAccrued(currency).getAmount(), installment + .getPenaltyAccrued(currency).getAmount(), currencyData, interestCalculatedFrom, installment + .getInterestWaived(currency).getAmount()); + loanScheduleAccrualDatas.add(accrualData); + } } @@ -476,41 +493,6 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { } } - private void generateLoanScheduleAccrualData(final LocalDate accruedTill, final Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas, - final Long loanId, Long officeId, final LocalDate accrualStartDate, final PeriodFrequencyType repaymentFrequency, final Integer repayEvery, - final LocalDate interestCalculatedFrom, final Long loanProductId, final MonetaryCurrency currency, final CurrencyData currencyData, - final Set<LoanCharge> loanCharges, final LoanRepaymentScheduleInstallment installment) { - - if (!accruedTill.isBefore(installment.getDueDate()) - || (accruedTill.isAfter(installment.getFromDate()) && !accruedTill.isAfter(installment.getDueDate()))) { - BigDecimal dueDateFeeIncome = BigDecimal.ZERO; - BigDecimal dueDatePenaltyIncome = BigDecimal.ZERO; - LocalDate chargesTillDate = installment.getDueDate(); - if (!accruedTill.isAfter(installment.getDueDate())) { - chargesTillDate = accruedTill; - } - - for (final LoanCharge loanCharge : loanCharges) { - if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), chargesTillDate)) { - if (loanCharge.isFeeCharge()) { - dueDateFeeIncome = dueDateFeeIncome.add(loanCharge.amount()); - } else if (loanCharge.isPenaltyCharge()) { - dueDatePenaltyIncome = dueDatePenaltyIncome.add(loanCharge.amount()); - } - } - } - LoanScheduleAccrualData accrualData = new LoanScheduleAccrualData(loanId, officeId, installment.getInstallmentNumber(), - accrualStartDate, repaymentFrequency, repayEvery, installment.getDueDate(), installment.getFromDate(), - installment.getId(), loanProductId, installment.getInterestCharged(currency).getAmount(), installment - .getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount(), - installment.getInterestAccrued(currency).getAmount(), installment.getFeeAccrued(currency).getAmount(), installment - .getPenaltyAccrued(currency).getAmount(), currencyData, interestCalculatedFrom, installment - .getInterestWaived(currency).getAmount()); - loanScheduleAccrualDatas.add(accrualData); - - } - } - private void updateLoanTransaction(final Long loanTransactionId, final LoanTransaction newLoanTransaction) { final AccountTransferTransaction transferTransaction = this.accountTransferRepository.findByToLoanTransactionId(loanTransactionId); if (transferTransaction != null) { http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java index a23f1e4..0a8ac12 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGenerator.java @@ -18,13 +18,10 @@ */ package org.apache.fineract.portfolio.loanaccount.loanschedule.domain; - import org.apache.fineract.organisation.holiday.service.HolidayUtil; import org.apache.fineract.organisation.workingdays.domain.RepaymentRescheduleType; import org.apache.fineract.organisation.workingdays.service.WorkingDaysUtil; -import org.apache.fineract.portfolio.calendar.data.CalendarHistoryDataWrapper; import org.apache.fineract.portfolio.calendar.domain.Calendar; -import org.apache.fineract.portfolio.calendar.domain.CalendarHistory; import org.apache.fineract.portfolio.calendar.service.CalendarUtils; import org.apache.fineract.portfolio.common.domain.DayOfWeekType; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; @@ -71,25 +68,9 @@ public class DefaultScheduledDateGenerator implements ScheduledDateGenerator { // calendar associated with // the loan, and we should use it in order to calculate next // repayment - - CalendarHistory calendarHistory = null; - CalendarHistoryDataWrapper calendarHistoryDataWrapper = loanApplicationTerms.getCalendarHistoryDataWrapper(); - if(calendarHistoryDataWrapper != null){ - calendarHistory = loanApplicationTerms.getCalendarHistoryDataWrapper().getCalendarHistory(dueRepaymentPeriodDate); - } - - // get the start date from the calendar history - LocalDate seedDate = null; - String reccuringString = null; - if (calendarHistory == null) { - seedDate = currentCalendar.getStartDateLocalDate(); - reccuringString = currentCalendar.getRecurrence(); - } else { - seedDate = calendarHistory.getStartDateLocalDate(); - reccuringString = calendarHistory.getRecurrence(); - } - - dueRepaymentPeriodDate = CalendarUtils.getNewRepaymentMeetingDate(reccuringString, seedDate, lastRepaymentDate.plusDays(1), + LocalDate seedDate = currentCalendar.getStartDateLocalDate(); + String reccuringString = currentCalendar.getRecurrence(); + dueRepaymentPeriodDate = CalendarUtils.getNewRepaymentMeetingDate(reccuringString, seedDate, dueRepaymentPeriodDate, loanApplicationTerms.getRepaymentEvery(), CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType(loanApplicationTerms.getLoanTermPeriodFrequencyType()), holidayDetailDTO.getWorkingDays()); http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java index 68e9d83..c33091c 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java @@ -27,7 +27,6 @@ import org.apache.fineract.organisation.monetary.domain.ApplicationCurrency; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.organisation.monetary.domain.MoneyHelper; -import org.apache.fineract.portfolio.calendar.data.CalendarHistoryDataWrapper; import org.apache.fineract.portfolio.calendar.domain.Calendar; import org.apache.fineract.portfolio.calendar.domain.CalendarInstance; import org.apache.fineract.portfolio.common.domain.DayOfWeekType; @@ -179,8 +178,6 @@ public final class LoanApplicationTerms { private final LocalDate seedDate; - private final CalendarHistoryDataWrapper calendarHistoryDataWrapper; - public static LoanApplicationTerms assembleFrom(final ApplicationCurrency currency, final Integer loanTermFrequency, final PeriodFrequencyType loanTermPeriodFrequencyType, final Integer numberOfRepayments, final Integer repaymentEvery, final PeriodFrequencyType repaymentPeriodFrequencyType, Integer nthDay, DayOfWeekType weekDayType, @@ -201,7 +198,6 @@ public final class LoanApplicationTerms { final LoanRescheduleStrategyMethod rescheduleStrategyMethod = null; final InterestRecalculationCompoundingMethod interestRecalculationCompoundingMethod = null; - final CalendarHistoryDataWrapper calendarHistoryDataWrapper = null; return new LoanApplicationTerms(currency, loanTermFrequency, loanTermPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentPeriodFrequencyType, nthDay, weekDayType, amortizationMethod, interestMethod, interestRatePerPeriod, interestRatePeriodFrequencyType, annualNominalInterestRate, interestCalculationPeriodMethod, @@ -211,7 +207,7 @@ public final class LoanApplicationTerms { graceOnArrearsAgeing, daysInMonthType, daysInYearType, isInterestRecalculationEnabled, rescheduleStrategyMethod, interestRecalculationCompoundingMethod, restCalendarInstance, recalculationFrequencyType, compoundingCalendarInstance, compoundingFrequencyType, principalThresholdForLastInstalment, installmentAmountInMultiplesOf, - preClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations, calendarHistoryDataWrapper); + preClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations); } public static LoanApplicationTerms assembleFrom(final ApplicationCurrency applicationCurrency, final Integer loanTermFrequency, @@ -228,15 +224,13 @@ public final class LoanApplicationTerms { final LoanRescheduleStrategyMethod rescheduleStrategyMethod, BigDecimal approvedAmount, BigDecimal annualNominalInterestRate, List<LoanTermVariationsData> loanTermVariations) { final Calendar loanCalendar = null; - final CalendarHistoryDataWrapper calendarHistoryDataWrapper = null; return assembleFrom(applicationCurrency, loanTermFrequency, loanTermPeriodFrequencyType, nthDay, dayOfWeek, expectedDisbursementDate, repaymentsStartingFromDate, calculatedRepaymentsStartingFromDate, inArrearsTolerance, loanProductRelatedDetail, multiDisburseLoan, emiAmount, disbursementDatas, maxOutstandingBalance, interestChargedFromDate, principalThresholdForLastInstalment, installmentAmountInMultiplesOf, recalculationFrequencyType, restCalendarInstance, compoundingMethod, compoundingCalendarInstance, compoundingFrequencyType, loanPreClosureInterestCalculationStrategy, - rescheduleStrategyMethod, loanCalendar, approvedAmount, annualNominalInterestRate, loanTermVariations, - calendarHistoryDataWrapper); + rescheduleStrategyMethod, loanCalendar, approvedAmount, annualNominalInterestRate, loanTermVariations); } public static LoanApplicationTerms assembleFrom(final ApplicationCurrency applicationCurrency, final Integer loanTermFrequency, @@ -251,8 +245,7 @@ public final class LoanApplicationTerms { final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType, final LoanPreClosureInterestCalculationStrategy loanPreClosureInterestCalculationStrategy, final LoanRescheduleStrategyMethod rescheduleStrategyMethod, final Calendar loanCalendar, BigDecimal approvedAmount, - BigDecimal annualNominalInterestRate, final List<LoanTermVariationsData> loanTermVariations, - final CalendarHistoryDataWrapper calendarHistoryDataWrapper) { + BigDecimal annualNominalInterestRate, final List<LoanTermVariationsData> loanTermVariations) { final Integer numberOfRepayments = loanProductRelatedDetail.getNumberOfRepayments(); final Integer repaymentEvery = loanProductRelatedDetail.getRepayEvery(); @@ -284,7 +277,7 @@ public final class LoanApplicationTerms { loanProductRelatedDetail.getGraceOnDueDate(), daysInMonthType, daysInYearType, isInterestRecalculationEnabled, rescheduleStrategyMethod, compoundingMethod, restCalendarInstance, recalculationFrequencyType, compoundingCalendarInstance, compoundingFrequencyType, principalThresholdForLastInstalment, installmentAmountInMultiplesOf, - loanPreClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations, calendarHistoryDataWrapper); + loanPreClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations); } public static LoanApplicationTerms assembleFrom(final ApplicationCurrency applicationCurrency, final Integer loanTermFrequency, @@ -296,8 +289,8 @@ public final class LoanApplicationTerms { final CalendarInstance restCalendarInstance, final RecalculationFrequencyType recalculationFrequencyType, final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType, final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf, - final LoanPreClosureInterestCalculationStrategy loanPreClosureInterestCalculationStrategy, final Calendar loanCalendar, - BigDecimal approvedAmount, final BigDecimal annualNominalInterestRate, final List<LoanTermVariationsData> loanTermVariations) { + final LoanPreClosureInterestCalculationStrategy loanPreClosureInterestCalculationStrategy, BigDecimal approvedAmount, + final BigDecimal annualNominalInterestRate, final List<LoanTermVariationsData> loanTermVariations) { final Integer numberOfRepayments = loanProductRelatedDetail.getNumberOfRepayments(); final Integer repaymentEvery = loanProductRelatedDetail.getRepayEvery(); @@ -326,8 +319,7 @@ public final class LoanApplicationTerms { rescheduleStrategyMethod = interestRecalculationDetails.getRescheduleStrategyMethod(); interestRecalculationCompoundingMethod = interestRecalculationDetails.getInterestRecalculationCompoundingMethod(); } - final CalendarHistoryDataWrapper calendarHistoryDataWrapper = null; - + final Calendar loanCalendar = null; return new LoanApplicationTerms(applicationCurrency, loanTermFrequency, loanTermPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentPeriodFrequencyType, null, null, amortizationMethod, interestMethod, interestRatePerPeriod, interestRatePeriodFrequencyType, annualNominalInterestRate, interestCalculationPeriodMethod, @@ -337,7 +329,7 @@ public final class LoanApplicationTerms { loanProductRelatedDetail.getGraceOnDueDate(), daysInMonthType, daysInYearType, isInterestRecalculationEnabled, rescheduleStrategyMethod, interestRecalculationCompoundingMethod, restCalendarInstance, recalculationFrequencyType, compoundingCalendarInstance, compoundingFrequencyType, principalThresholdForLastInstalment, installmentAmountInMultiplesOf, - loanPreClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations, calendarHistoryDataWrapper); + loanPreClosureInterestCalculationStrategy, loanCalendar, approvedAmount, loanTermVariations); } public static LoanApplicationTerms assembleFrom(final LoanApplicationTerms applicationTerms, @@ -359,7 +351,7 @@ public final class LoanApplicationTerms { applicationTerms.compoundingCalendarInstance, applicationTerms.compoundingFrequencyType, applicationTerms.principalThresholdForLastInstalment, applicationTerms.installmentAmountInMultiplesOf, applicationTerms.preClosureInterestCalculationStrategy, applicationTerms.loanCalendar, - applicationTerms.approvedPrincipal.getAmount(), loanTermVariations, applicationTerms.calendarHistoryDataWrapper); + applicationTerms.approvedPrincipal.getAmount(), loanTermVariations); } private LoanApplicationTerms(final ApplicationCurrency currency, final Integer loanTermFrequency, @@ -380,8 +372,7 @@ public final class LoanApplicationTerms { final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType, final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf, final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar, - BigDecimal approvedAmount, List<LoanTermVariationsData> loanTermVariations, - final CalendarHistoryDataWrapper calendarHistoryDataWrapper) { + BigDecimal approvedAmount, List<LoanTermVariationsData> loanTermVariations) { this.currency = currency; this.loanTermFrequency = loanTermFrequency; this.loanTermPeriodFrequencyType = loanTermPeriodFrequencyType; @@ -439,7 +430,6 @@ public final class LoanApplicationTerms { } else { this.seedDate = this.calculatedRepaymentsStartingFromDate; } - this.calendarHistoryDataWrapper = calendarHistoryDataWrapper; } public Money adjustPrincipalIfLastRepaymentPeriod(final Money principalForPeriod, final Money totalCumulativePrincipalToDate, @@ -711,13 +701,8 @@ public final class LoanApplicationTerms { case INVALID: break; case SAME_AS_REPAYMENT_PERIOD: - if (this.allowPartialPeriodInterestCalcualtion) { - LocalDate startDate = getExpectedDisbursementDate(); - if (getInterestChargedFromDate() != null) { - startDate = getInterestChargedFromLocalDate(); - } - periodsInLoanTerm = calculatePeriodsBetweenDates(startDate, this.loanEndDate); - } + LocalDate startDate = getExpectedDisbursementDate(); + periodsInLoanTerm = calculatePeriodsBetweenDates(startDate, this.loanEndDate); break; } @@ -1437,8 +1422,4 @@ public final class LoanApplicationTerms { return this.seedDate; } - public CalendarHistoryDataWrapper getCalendarHistoryDataWrapper() { - return this.calendarHistoryDataWrapper; - } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java index 3c284ee..f6db0d2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java @@ -540,10 +540,8 @@ public class LoanScheduleAssembler { validateDisbursementDateIsOnNonWorkingDay(loanApplicationTerms.getExpectedDisbursementDate(), workingDays); validateDisbursementDateIsOnHoliday(loanApplicationTerms.getExpectedDisbursementDate(), isHolidayEnabled, holidays); - - Set<LoanDisbursementDetails> loanDisbursementDetails = this.loanUtilService.fetchDisbursementData(element.getAsJsonObject()); - return assembleLoanScheduleFrom(loanApplicationTerms, isHolidayEnabled, holidays, workingDays, element, loanDisbursementDetails); + return assembleLoanScheduleFrom(loanApplicationTerms, isHolidayEnabled, holidays, workingDays, element, null); } public LoanScheduleModel assembleLoanScheduleFrom(final LoanApplicationTerms loanApplicationTerms, final boolean isHolidayEnabled, http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/5ed50615/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index 869dd91..e859b0d 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -508,7 +508,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa LoanChargeData chargeData = new LoanChargeData(charge.getId(), charge.getDueLocalDate(), charge.amountOrPercentage()); chargesMap.put(charge.getId(), chargeData); } - Set<LoanDisbursementDetails> disbursementDetails = this.loanUtilService.fetchDisbursementData(command.parsedJson() + Set<LoanDisbursementDetails> disbursementDetails = this.loanAssembler.fetchDisbursementData(command.parsedJson() .getAsJsonObject()); /**