From b7f72b2943e69cce69810696b0b5f5791f0517e5 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Wed, 10 Apr 2013 20:48:48 +0100 Subject: [PATCH] MIFOSX-292: ensure correct decimal places value for currency is returned. --- .../loanproduct/data/LoanProductData.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java index 657a3240c..173149150 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/data/LoanProductData.java @@ -37,8 +37,8 @@ public class LoanProductData { // terms private final CurrencyData currency; private final BigDecimal principal; - private BigDecimal minPrincipal; - private BigDecimal maxPrincipal; + private final BigDecimal minPrincipal; + private final BigDecimal maxPrincipal; private final Integer numberOfRepayments; private final Integer minNumberOfRepayments; private final Integer maxNumberOfRepayments; @@ -109,12 +109,13 @@ public class LoanProductData { final Collection charges = null; final EnumOptionData accountingType = null; - return new LoanProductData(id, name, description, currency, principal, minPrincipal, maxPrincipal, tolerance, numberOfRepayments, minNumberOfRepayments, maxNumberOfRepayments, repaymentEvery, - interestRatePerPeriod, minInterestRatePerPeriod, maxInterestRatePerPeriod, annualInterestRate, repaymentFrequencyType, interestRateFrequencyType, amortizationType, + return new LoanProductData(id, name, description, currency, principal, minPrincipal, maxPrincipal, tolerance, numberOfRepayments, + minNumberOfRepayments, maxNumberOfRepayments, repaymentEvery, interestRatePerPeriod, minInterestRatePerPeriod, + maxInterestRatePerPeriod, annualInterestRate, repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId, fundName, transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType); } - + public static LoanProductData lookupWithCurrency(final Long id, final String name, final CurrencyData currency) { final String description = null; final BigDecimal principal = null; @@ -141,17 +142,18 @@ public class LoanProductData { final Collection charges = null; final EnumOptionData accountingType = null; - return new LoanProductData(id, name, description, currency, principal, minPrincipal, maxPrincipal, tolerance, numberOfRepayments, minNumberOfRepayments, maxNumberOfRepayments, repaymentEvery, - interestRatePerPeriod, minInterestRatePerPeriod, maxInterestRatePerPeriod, annualInterestRate, repaymentFrequencyType, interestRateFrequencyType, amortizationType, + return new LoanProductData(id, name, description, currency, principal, minPrincipal, maxPrincipal, tolerance, numberOfRepayments, + minNumberOfRepayments, maxNumberOfRepayments, repaymentEvery, interestRatePerPeriod, minInterestRatePerPeriod, + maxInterestRatePerPeriod, annualInterestRate, repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId, fundName, transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType); - } + } public static LoanProductData sensibleDefaultsForNewLoanProductCreation() { final Long id = null; final String name = null; final String description = null; - final CurrencyData currency = CurrencyData.blank(); + final CurrencyData currency = null; final BigDecimal principal = null; final BigDecimal minPrincipal = null; final BigDecimal maxPrincipal = null; @@ -202,11 +204,19 @@ public class LoanProductData { final EnumOptionData interestCalculationPeriodType, final Long fundId, final String fundName, final Long transactionProcessingStrategyId, final String transactionProcessingStrategyName, final Collection charges, final EnumOptionData accountingType) { - + this.id = id; this.name = name; this.description = description; - this.currency = currency; + if (currency == null) { + if (this.currencyOptions != null && this.currencyOptions.size() == 1) { + this.currency = new ArrayList(this.currencyOptions).get(0); + } else { + this.currency = CurrencyData.blank(); + } + } else { + this.currency = currency; + } this.principal = principal; this.minPrincipal = minPrincipal; this.maxPrincipal = maxPrincipal; @@ -282,17 +292,13 @@ public class LoanProductData { this.chargeOptions = chargeOptions; this.currencyOptions = currencyOptions; - if (this.currencyOptions != null && this.currencyOptions.size() == 1) { - this.currency = new ArrayList(this.currencyOptions).get(0); - } else { - this.currency = productData.currency; - } + this.currency = productData.currency; this.fundOptions = fundOptions; this.transactionProcessingStrategyOptions = transactionStrategyOptions; if (this.transactionProcessingStrategyOptions != null && this.transactionProcessingStrategyOptions.size() == 1) { final List listOfOptions = new ArrayList( this.transactionProcessingStrategyOptions); - + this.transactionProcessingStrategyId = listOfOptions.get(0).id(); this.transactionProcessingStrategyName = listOfOptions.get(0).name(); } else { @@ -379,7 +385,7 @@ public class LoanProductData { public BigDecimal getMinPrincipal() { return this.minPrincipal; } - + public BigDecimal getMaxPrincipal() { return this.maxPrincipal; } @@ -451,8 +457,9 @@ public class LoanProductData { public Collection getChargeOptions() { return chargeOptions; } + @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { LoanProductData loanProductData = (LoanProductData) obj; return loanProductData.id.equals(this.id); }