MIFOSX-379: check for invalid currencies when submitting new loan application.
This commit is contained in:
+4
-33
@@ -88,21 +88,10 @@ public class LoanCharge extends AbstractPersistable<Long> {
|
||||
public static LoanCharge createNewFromJson(final Loan loan, final Charge chargeDefinition, final JsonCommand command) {
|
||||
|
||||
final BigDecimal amount = command.bigDecimalValueOfParameterNamed("amount");
|
||||
// final Integer chargeTimeType =
|
||||
// command.integerValueOfParameterNamed("chargeTimeType");
|
||||
// final Integer chargeCalculationType =
|
||||
// command.integerValueOfParameterNamed("chargeCalculationType");
|
||||
final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate");
|
||||
|
||||
ChargeTimeType chargeTime = null;
|
||||
// if (chargeTimeType != null) {
|
||||
// chargeTime = ChargeTimeType.fromInt(chargeTimeType);
|
||||
// }
|
||||
ChargeCalculationType chargeCalculation = null;
|
||||
// if (chargeCalculationType != null) {
|
||||
// chargeCalculation =
|
||||
// ChargeCalculationType.fromInt(chargeCalculationType);
|
||||
// }
|
||||
|
||||
return new LoanCharge(loan, chargeDefinition, loan.getPrincpal().getAmount(), amount, chargeTime, chargeCalculation, dueDate);
|
||||
}
|
||||
@@ -286,28 +275,6 @@ public class LoanCharge extends AbstractPersistable<Long> {
|
||||
final String dateFormatAsInput = command.dateFormat();
|
||||
final String localeAsInput = command.locale();
|
||||
|
||||
// final String chargeTimeParamName = "chargeTime";
|
||||
// if (command.isChangeInIntegerParameterNamed(chargeTimeParamName,
|
||||
// this.chargeTime)) {
|
||||
// final Integer newValue =
|
||||
// command.integerValueOfParameterNamed(chargeTimeParamName);
|
||||
// actualChanges.put(chargeTimeParamName, newValue);
|
||||
// actualChanges.put("locale", localeAsInput);
|
||||
// this.chargeTime = ChargeTimeType.fromInt(newValue).getValue();
|
||||
// }
|
||||
//
|
||||
// final String chargeCalculationParamName = "chargeCalculation";
|
||||
// if
|
||||
// (command.isChangeInIntegerParameterNamed(chargeCalculationParamName,
|
||||
// this.chargeCalculation)) {
|
||||
// final Integer newValue =
|
||||
// command.integerValueOfParameterNamed(chargeCalculationParamName);
|
||||
// actualChanges.put(chargeCalculationParamName, newValue);
|
||||
// actualChanges.put("locale", localeAsInput);
|
||||
// this.chargeCalculation =
|
||||
// ChargeCalculationType.fromInt(newValue).getValue();
|
||||
// }
|
||||
|
||||
final String dueDateParamName = "dueDate";
|
||||
if (command.isChangeInLocalDateParameterNamed(dueDateParamName, getDueLocalDate())) {
|
||||
final String valueAsInput = command.stringValueOfParameterNamed(dueDateParamName);
|
||||
@@ -511,6 +478,10 @@ public class LoanCharge extends AbstractPersistable<Long> {
|
||||
return this.charge.getName();
|
||||
}
|
||||
|
||||
public String currencyCode() {
|
||||
return this.charge.getCurrencyCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) { return false; }
|
||||
|
||||
+7
@@ -45,6 +45,7 @@ import org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanSchedule
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProduct;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRepository;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanTransactionProcessingStrategy;
|
||||
import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException;
|
||||
import org.mifosplatform.portfolio.loanproduct.exception.LoanProductNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -123,6 +124,12 @@ public class LoanAssembler {
|
||||
}
|
||||
final Set<LoanCollateral> collateral = this.loanCollateralAssembler.fromParsedJson(element);
|
||||
final Set<LoanCharge> loanCharges = this.loanChargeAssembler.fromParsedJson(element);
|
||||
for (LoanCharge loanCharge : loanCharges) {
|
||||
if (!loanProduct.hasCurrencyCodeOf(loanCharge.currencyCode())) {
|
||||
final String errorMessage = "Charge and Loan must have the same currency.";
|
||||
throw new InvalidCurrencyException("loanCharge", "attach.to.loan", errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
final BigDecimal inArrearsTolerance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("inArrearsTolerance", element);
|
||||
final LoanSchedule loanSchedule = this.loanScheduleAssembler.fromJson(element, inArrearsTolerance);
|
||||
|
||||
+4
@@ -165,6 +165,10 @@ public class LoanProduct extends AbstractPersistable<Long> {
|
||||
this.transactionProcessingStrategy = strategy;
|
||||
}
|
||||
|
||||
public boolean hasCurrencyCodeOf(final String currencyCode) {
|
||||
return this.loanProductRelatedDetail.hasCurrencyCodeOf(currencyCode);
|
||||
}
|
||||
|
||||
public boolean update(final List<Charge> newProductCharges) {
|
||||
if (newProductCharges == null) return false;
|
||||
|
||||
|
||||
+4
@@ -297,4 +297,8 @@ public class LoanProductRelatedDetail implements LoanProductMinimumRepaymentSche
|
||||
private void updateInterestRateDerivedFields(final AprCalculator aprCalculator) {
|
||||
this.annualNominalInterestRate = aprCalculator.calculateFrom(this.interestPeriodFrequencyType, this.nominalInterestRatePerPeriod);
|
||||
}
|
||||
|
||||
public boolean hasCurrencyCodeOf(final String currencyCode) {
|
||||
return this.currency.getCode().equalsIgnoreCase(currencyCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user