remove deprecate MoneyData class usage forcing tidy up of LoanTransaction usage.
This commit is contained in:
@@ -38,15 +38,15 @@ import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
||||
import org.mifosng.platform.api.data.LoanChargeData;
|
||||
import org.mifosng.platform.api.data.LoanPermissionData;
|
||||
import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.MoneyData;
|
||||
import org.mifosng.platform.api.data.StaffData;
|
||||
import org.mifosng.platform.api.data.TransactionProcessingStrategyData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.charge.service.ChargeReadPlatformService;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.currency.domain.Money;
|
||||
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
|
||||
import org.mifosng.platform.fund.service.FundReadPlatformService;
|
||||
import org.mifosng.platform.loan.service.CalculationPlatformService;
|
||||
@@ -112,6 +112,8 @@ public class LoansApiResource {
|
||||
"status",
|
||||
"lifeCycleStatusDate"));
|
||||
|
||||
final Set<String> typicalTransactionResponseParameters = new HashSet<String>(Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@@ -219,8 +221,11 @@ public class LoansApiResource {
|
||||
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, loanBasicDetails.getCurrency(),
|
||||
singleDisbursement, loanBasicDetails.getTotalDisbursementCharges(), loanBasicDetails.getInArrearsTolerance());
|
||||
|
||||
MoneyData tolerance = MoneyData.of(loanBasicDetails.getCurrency(), loanBasicDetails.getInArrearsTolerance());
|
||||
MoneyData totalOutstandingMoney = MoneyData.of(loanBasicDetails.getCurrency(), repaymentSchedule.totalOutstanding());
|
||||
// FIXME - KW - Waive feature was changed to waive interest at anytime so this permission checking is probably not needed - look into.
|
||||
final MonetaryCurrency currency = new MonetaryCurrency(loanBasicDetails.getCurrency().getCode(), loanBasicDetails.getCurrency().getDecimalPlaces());
|
||||
final Money tolerance = Money.of(currency, loanBasicDetails.getInArrearsTolerance());
|
||||
final Money totalOutstandingMoney = Money.of(currency, repaymentSchedule.totalOutstanding());
|
||||
|
||||
boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
|
||||
|
||||
if (responseParameters.contains("permissions")) {
|
||||
@@ -442,67 +447,28 @@ public class LoansApiResource {
|
||||
@QueryParam("command") final String commandParam,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
LoanTransactionData transactionData = null;
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalTransactionResponseParameters);
|
||||
}
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
LoanTransactionNewData transactionData = null;
|
||||
if (is(commandParam, "repayment")) {
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("id", "transactionType", "date", "principal",
|
||||
"interest", "total", "totalWaived", "overpaid"));
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||
} else if (is(commandParam, "waiveinterest")) {
|
||||
|
||||
final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final LoanTransactionNewData newTransactionData = this.loanReadPlatformService.retrieveNewLoanWaiveInterestDetails(loanId);
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, newTransactionData);
|
||||
transactionData = this.loanReadPlatformService.retrieveNewLoanWaiveInterestDetails(loanId);
|
||||
} else if (is(commandParam, "writeoff")) {
|
||||
final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final LoanTransactionNewData newTransactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, newTransactionData);
|
||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
} else if (is(commandParam, "close-rescheduled")) {
|
||||
final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final LoanTransactionNewData newTransactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, newTransactionData);
|
||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
} else if (is(commandParam, "close")) {
|
||||
final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final LoanTransactionNewData newTransactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, newTransactionData);
|
||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||
} else {
|
||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -513,17 +479,13 @@ public class LoansApiResource {
|
||||
@PathParam("transactionId") final Long transactionId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("id", "transactionType", "date", "principal", "interest", "total", "totalWaived", "overpaid")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
responseParameters.addAll(typicalTransactionResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
||||
final LoanTransactionNewData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
||||
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||
}
|
||||
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
public class LoanTransactionData {
|
||||
|
||||
private Long id;
|
||||
private EnumOptionData transactionType;
|
||||
private LocalDate date;
|
||||
private MoneyData principal;
|
||||
private MoneyData interest;
|
||||
private MoneyData total;
|
||||
private MoneyData totalWaived;
|
||||
private MoneyData overpaid;
|
||||
|
||||
public LoanTransactionData() {
|
||||
//
|
||||
}
|
||||
|
||||
public LoanTransactionData(
|
||||
Long id, EnumOptionData transactionType, final LocalDate date,
|
||||
final MoneyData principal,
|
||||
final MoneyData interest,
|
||||
final MoneyData total, final MoneyData overpaid) {
|
||||
this.id = id;
|
||||
this.transactionType = transactionType;
|
||||
this.date = date;
|
||||
this.principal = principal;
|
||||
this.interest = interest;
|
||||
this.total = total;
|
||||
this.overpaid = overpaid;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public EnumOptionData getTransactionType() {
|
||||
return transactionType;
|
||||
}
|
||||
|
||||
public void setTransactionType(EnumOptionData transactionType) {
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public MoneyData getPrincipal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPrincipal(MoneyData principal) {
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public MoneyData getInterest() {
|
||||
return interest;
|
||||
}
|
||||
|
||||
public void setInterest(MoneyData interest) {
|
||||
this.interest = interest;
|
||||
}
|
||||
|
||||
public MoneyData getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(MoneyData total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public MoneyData getOverpaid() {
|
||||
return overpaid;
|
||||
}
|
||||
|
||||
public void setOverpaid(MoneyData overpaid) {
|
||||
this.overpaid = overpaid;
|
||||
}
|
||||
|
||||
public boolean hasOverpaidComponent() {
|
||||
return this.overpaid.isGreaterThanZero();
|
||||
}
|
||||
|
||||
public MoneyData getTotalWaived() {
|
||||
return totalWaived;
|
||||
}
|
||||
|
||||
public void setTotalWaived(MoneyData totalWaived) {
|
||||
this.totalWaived = totalWaived;
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -15,7 +15,6 @@ public class LoanTransactionNewData {
|
||||
@SuppressWarnings("unused")
|
||||
private EnumOptionData type;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private LocalDate date;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -36,4 +35,8 @@ public class LoanTransactionNewData {
|
||||
this.date = date;
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
public LocalDate dateOf() {
|
||||
return this.date;
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* @deprecated - Want to remove this and its usage around loans in full. In its place we just pass back a {@link BigDecimal} for the amount and a {@link CurrencyData} is also passed back.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MoneyData implements Serializable, Comparable<MoneyData> {
|
||||
|
||||
private String currencyCode;
|
||||
private Integer digitsAfterDecimal;
|
||||
private BigDecimal amount;
|
||||
private String defaultName;
|
||||
private String nameCode;
|
||||
private String displaySymbol;
|
||||
|
||||
public static MoneyData of(final CurrencyData currency, final BigDecimal amount) {
|
||||
return new MoneyData(currency.getCode(), currency.getDecimalPlaces(), currency.getName(), currency.getNameCode(), currency.getDisplaySymbol(), amount);
|
||||
}
|
||||
|
||||
public static MoneyData zero(final CurrencyData currency) {
|
||||
return new MoneyData(currency.getCode(), currency.getDecimalPlaces(), currency.getName(), currency.getNameCode(), currency.getDisplaySymbol(), BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
protected MoneyData() {
|
||||
//
|
||||
}
|
||||
|
||||
private MoneyData(final String currencyCode,
|
||||
final int currencyDigitsAfterDecimal,
|
||||
String defaultName, String nameCode, String displaySymbol,
|
||||
final BigDecimal amount) {
|
||||
this.currencyCode = currencyCode;
|
||||
this.digitsAfterDecimal = currencyDigitsAfterDecimal;
|
||||
this.defaultName = defaultName;
|
||||
this.nameCode = nameCode;
|
||||
this.displaySymbol = displaySymbol;
|
||||
BigDecimal amountStripped = amount.stripTrailingZeros();
|
||||
this.amount = amountStripped.setScale(this.digitsAfterDecimal,
|
||||
RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
public MoneyData plus(final Iterable<? extends MoneyData> moniesToAdd) {
|
||||
BigDecimal total = this.amount;
|
||||
for (MoneyData moneyProvider : moniesToAdd) {
|
||||
MoneyData money = this.checkCurrencyEqual(moneyProvider);
|
||||
total = total.add(money.amount);
|
||||
}
|
||||
return MoneyData.of(currencyData(this), total);
|
||||
}
|
||||
|
||||
public MoneyData plus(final MoneyData moneyToAdd) {
|
||||
MoneyData toAdd = this.checkCurrencyEqual(moneyToAdd);
|
||||
return this.plus(toAdd.getAmount());
|
||||
}
|
||||
|
||||
public MoneyData plus(final BigDecimal amountToAdd) {
|
||||
if (amountToAdd.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return this;
|
||||
}
|
||||
BigDecimal newAmount = this.amount.add(amountToAdd);
|
||||
return MoneyData.of(currencyData(this), newAmount);
|
||||
}
|
||||
|
||||
public MoneyData plus(final double amountToAdd) {
|
||||
if (amountToAdd == 0) {
|
||||
return this;
|
||||
}
|
||||
BigDecimal newAmount = this.amount.add(BigDecimal.valueOf(amountToAdd));
|
||||
return MoneyData.of(currencyData(this), newAmount);
|
||||
}
|
||||
|
||||
private static CurrencyData currencyData(MoneyData moneyData) {
|
||||
String code = moneyData.getCurrencyCode();
|
||||
String name = moneyData.getDefaultName();
|
||||
int decimalPlaces = moneyData.getDigitsAfterDecimal();
|
||||
String displaySymbol = moneyData.getDisplaySymbol();
|
||||
String nameCode = moneyData.getNameCode();
|
||||
return new CurrencyData(code, name, decimalPlaces, displaySymbol, nameCode);
|
||||
}
|
||||
|
||||
private MoneyData checkCurrencyEqual(final MoneyData money) {
|
||||
if (this.isSameCurrency(money) == false) {
|
||||
throw new UnsupportedOperationException("currencies are different.");
|
||||
}
|
||||
return money;
|
||||
}
|
||||
|
||||
public boolean isSameCurrency(final MoneyData money) {
|
||||
return this.currencyCode.equals(money.getCurrencyCode());
|
||||
}
|
||||
|
||||
public String getCurrencyCode() {
|
||||
return this.currencyCode;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public void setCurrencyCode(final String currencyCode) {
|
||||
this.currencyCode = currencyCode;
|
||||
}
|
||||
|
||||
public void setAmount(final BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getDefaultName() {
|
||||
return defaultName;
|
||||
}
|
||||
|
||||
public void setDefaultName(String defaultName) {
|
||||
this.defaultName = defaultName;
|
||||
}
|
||||
|
||||
public String getNameCode() {
|
||||
return nameCode;
|
||||
}
|
||||
|
||||
public void setNameCode(String nameCode) {
|
||||
this.nameCode = nameCode;
|
||||
}
|
||||
|
||||
public String getDisplaySymbol() {
|
||||
return displaySymbol;
|
||||
}
|
||||
|
||||
public void setDisplaySymbol(String displaySymbol) {
|
||||
this.displaySymbol = displaySymbol;
|
||||
}
|
||||
|
||||
public boolean isGreaterThanZero() {
|
||||
return this.isGreaterThan(MoneyData.of(currencyData(this), BigDecimal.ZERO));
|
||||
}
|
||||
|
||||
public boolean isGreaterThan(final MoneyData other) {
|
||||
return this.compareTo(other) > 0;
|
||||
}
|
||||
|
||||
public boolean isZero() {
|
||||
return this.isEqualTo(MoneyData.zero(currencyData(this)));
|
||||
}
|
||||
|
||||
public boolean isEqualTo(final MoneyData other) {
|
||||
return this.compareTo(other) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final MoneyData other) {
|
||||
MoneyData otherMoney = other;
|
||||
if (this.currencyCode.equals(otherMoney.currencyCode) == false) {
|
||||
throw new UnsupportedOperationException(
|
||||
"currencies arent different");
|
||||
}
|
||||
return this.amount.compareTo(otherMoney.amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
MoneyData money = (MoneyData) obj;
|
||||
return money.toString().equals(this.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder().append(this.amount.toPlainString()).toString();
|
||||
}
|
||||
|
||||
public String getDisplaySymbolValue() {
|
||||
return new StringBuilder().append(this.amount.toPlainString()).append(' ').append(this.displaySymbol).toString().trim();
|
||||
}
|
||||
|
||||
public Integer getDigitsAfterDecimal() {
|
||||
return digitsAfterDecimal;
|
||||
}
|
||||
|
||||
public void setDigitsAfterDecimal(Integer digitsAfterDecimal) {
|
||||
this.digitsAfterDecimal = digitsAfterDecimal;
|
||||
}
|
||||
}
|
||||
-3
@@ -24,7 +24,6 @@ import org.mifosng.platform.api.data.GroupData;
|
||||
import org.mifosng.platform.api.data.LoanAccountData;
|
||||
import org.mifosng.platform.api.data.LoanChargeData;
|
||||
import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
@@ -104,8 +103,6 @@ public interface ApiJsonSerializerService {
|
||||
|
||||
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
|
||||
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData transaction);
|
||||
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionNewData newTransactionData);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
|
||||
|
||||
-16
@@ -26,7 +26,6 @@ import org.mifosng.platform.api.data.GroupData;
|
||||
import org.mifosng.platform.api.data.LoanAccountData;
|
||||
import org.mifosng.platform.api.data.LoanChargeData;
|
||||
import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
@@ -184,10 +183,6 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
"repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "repaymentStrategyOptions", "chargeOptions",
|
||||
"loanOfficerId", "loanOfficerName", "loanOfficerOptions", "chargeTemplate"));
|
||||
|
||||
private static final Set<String> LOAN_TRANSACTION_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "transactionType", "date", "principal",
|
||||
"interest", "total", "totalWaived", "overpaid"));
|
||||
|
||||
private static final Set<String> LOAN_TRANSACTION_NEW_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "type", "date", "currency", "amount"));
|
||||
|
||||
@@ -558,17 +553,6 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
return helper.serializedJsonFrom(gsonDeserializer, loanAccount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeLoanTransactionDataToJson(final boolean prettyPrint,
|
||||
final Set<String> responseParameters,
|
||||
final LoanTransactionData transaction) {
|
||||
final Gson gsonDeserializer = helper
|
||||
.createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
LOAN_TRANSACTION_DATA_PARAMETERS, prettyPrint,
|
||||
responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeLoanTransactionDataToJson(final boolean prettyPrint,
|
||||
final Set<String> responseParameters,
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientLookup mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
public ClientLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
Long id = rs.getLong("id");
|
||||
String firstname = rs.getString("firstname");
|
||||
String lastname = rs.getString("lastname");
|
||||
|
||||
+5
-7
@@ -2,14 +2,12 @@ package org.mifosng.platform.loan.domain;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
|
||||
|
||||
public class LoanRepaymentDataComparator implements Comparator<LoanTransactionData> {
|
||||
public class LoanRepaymentDataComparator implements Comparator<LoanTransactionNewData> {
|
||||
|
||||
@Override
|
||||
public int compare(final LoanTransactionData o1, final LoanTransactionData o2) {
|
||||
return o2.getDate().compareTo(o1.getDate());
|
||||
public int compare(final LoanTransactionNewData o1, final LoanTransactionNewData o2) {
|
||||
return o2.dateOf().compareTo(o1.dateOf());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -8,7 +8,6 @@ import org.mifosng.platform.api.data.CurrencyData;
|
||||
import org.mifosng.platform.api.data.DisbursementData;
|
||||
import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
||||
import org.mifosng.platform.api.data.LoanPermissionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
|
||||
public interface LoanReadPlatformService {
|
||||
@@ -27,11 +26,11 @@ public interface LoanReadPlatformService {
|
||||
|
||||
LoanBasicDetailsData retrieveGroupAndProductDetails(Long groupId, Long productId);
|
||||
|
||||
LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
|
||||
LoanTransactionNewData retrieveNewLoanRepaymentDetails(Long loanId);
|
||||
|
||||
LoanTransactionNewData retrieveNewLoanWaiveInterestDetails(Long loanId);
|
||||
|
||||
LoanTransactionData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
|
||||
LoanTransactionNewData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
|
||||
|
||||
LoanTransactionNewData retrieveNewClosureDetails();
|
||||
}
|
||||
+28
-48
@@ -18,12 +18,11 @@ import org.mifosng.platform.api.data.LoanChargeData;
|
||||
import org.mifosng.platform.api.data.LoanPermissionData;
|
||||
import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanSchedulePeriodData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.MoneyData;
|
||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||
import org.mifosng.platform.currency.domain.ApplicationCurrency;
|
||||
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.currency.domain.Money;
|
||||
import org.mifosng.platform.exceptions.CurrencyNotFoundException;
|
||||
import org.mifosng.platform.exceptions.LoanNotFoundException;
|
||||
@@ -142,8 +141,9 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
|
||||
final BigDecimal totalOverdue = wrapper.deriveCumulativeTotalOverdue();
|
||||
|
||||
MoneyData tolerance = MoneyData.of(currency, inArrearsTolerance);
|
||||
MoneyData totalOverdueMoney = MoneyData.of(currency, totalOverdue);
|
||||
final MonetaryCurrency monetaryCurrency = new MonetaryCurrency(currency.getCode(), currency.getDecimalPlaces());
|
||||
final Money tolerance = Money.of(monetaryCurrency, inArrearsTolerance);
|
||||
final Money totalOverdueMoney = Money.of(monetaryCurrency, totalOverdue);
|
||||
boolean isWaiveAllowed = totalOverdueMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOverdueMoney) || tolerance.isEqualTo(totalOverdueMoney));
|
||||
|
||||
BigDecimal totalInArrears = null;
|
||||
@@ -262,7 +262,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionData retrieveNewLoanRepaymentDetails(final Long loanId) {
|
||||
public LoanTransactionNewData retrieveNewLoanRepaymentDetails(final Long loanId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -273,31 +273,21 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
throw new LoanNotFoundException(loanId);
|
||||
}
|
||||
|
||||
final String currencyCode = loan.repaymentScheduleDetail()
|
||||
.getPrincipal().getCurrencyCode();
|
||||
ApplicationCurrency currency = this.applicationCurrencyRepository
|
||||
.findOneByCode(currencyCode);
|
||||
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
|
||||
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
|
||||
if (currency == null) {
|
||||
throw new CurrencyNotFoundException(currencyCode);
|
||||
}
|
||||
|
||||
CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
final CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
currency.getName(), currency.getDecimalPlaces(),
|
||||
currency.getDisplaySymbol(), currency.getNameCode());
|
||||
|
||||
LocalDate earliestUnpaidInstallmentDate = loan
|
||||
.possibleNextRepaymentDate();
|
||||
Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount();
|
||||
MoneyData possibleNextRepayment = MoneyData.of(currencyData,
|
||||
possibleNextRepaymentAmount.getAmount());
|
||||
|
||||
LoanTransactionData newRepaymentDetails = new LoanTransactionData();
|
||||
newRepaymentDetails.setTransactionType(LoanEnumerations
|
||||
.transactionType(LoanTransactionType.REPAYMENT));
|
||||
newRepaymentDetails.setDate(earliestUnpaidInstallmentDate);
|
||||
newRepaymentDetails.setTotal(possibleNextRepayment);
|
||||
|
||||
return newRepaymentDetails;
|
||||
final LocalDate earliestUnpaidInstallmentDate = loan.possibleNextRepaymentDate();
|
||||
|
||||
final Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount();
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.REPAYMENT);
|
||||
return new LoanTransactionNewData(null, transactionType, currencyData, earliestUnpaidInstallmentDate, possibleNextRepaymentAmount.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,23 +296,24 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
context.authenticatedUser();
|
||||
|
||||
// TODO - OPTIMIZE - write simple sql query to fetch back overdue interest that can be waived along with the date of repayment period interest is overdue.
|
||||
Loan loan = this.loanRepository.findOne(loanId);
|
||||
final Loan loan = this.loanRepository.findOne(loanId);
|
||||
if (loan == null) {
|
||||
throw new LoanNotFoundException(loanId);
|
||||
}
|
||||
|
||||
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
|
||||
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
|
||||
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
|
||||
if (currency == null) {
|
||||
throw new CurrencyNotFoundException(currencyCode);
|
||||
}
|
||||
CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
|
||||
final CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
currency.getName(), currency.getDecimalPlaces(),
|
||||
currency.getDisplaySymbol(), currency.getNameCode());
|
||||
|
||||
LoanTransaction waiveOfInterest = loan.deriveDefaultInterestWaiverTransaction();
|
||||
final LoanTransaction waiveOfInterest = loan.deriveDefaultInterestWaiverTransaction();
|
||||
|
||||
EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST);
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST);
|
||||
|
||||
return new LoanTransactionNewData(null, transactionType, currencyData, waiveOfInterest.getTransactionDate(), waiveOfInterest.getAmount());
|
||||
}
|
||||
@@ -338,26 +329,23 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionData retrieveLoanTransactionDetails(
|
||||
public LoanTransactionNewData retrieveLoanTransactionDetails(
|
||||
final Long loanId, final Long transactionId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
Loan loan = this.loanRepository.findOne(loanId);
|
||||
final Loan loan = this.loanRepository.findOne(loanId);
|
||||
if (loan == null) {
|
||||
throw new LoanNotFoundException(loanId);
|
||||
}
|
||||
|
||||
final String currencyCode = loan.repaymentScheduleDetail()
|
||||
.getPrincipal().getCurrencyCode();
|
||||
ApplicationCurrency currency = this.applicationCurrencyRepository
|
||||
.findOneByCode(currencyCode);
|
||||
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
|
||||
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
|
||||
if (currency == null) {
|
||||
throw new CurrencyNotFoundException(currencyCode);
|
||||
}
|
||||
|
||||
LoanTransaction transaction = this.loanTransactionRepository
|
||||
.findOne(transactionId);
|
||||
final LoanTransaction transaction = this.loanTransactionRepository.findOne(transactionId);
|
||||
if (transaction == null) {
|
||||
throw new LoanTransactionNotFoundException(transactionId);
|
||||
}
|
||||
@@ -366,20 +354,12 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
throw new LoanTransactionNotFoundException(transactionId, loanId);
|
||||
}
|
||||
|
||||
CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
final CurrencyData currencyData = new CurrencyData(currency.getCode(),
|
||||
currency.getName(), currency.getDecimalPlaces(),
|
||||
currency.getDisplaySymbol(), currency.getNameCode());
|
||||
MoneyData total = MoneyData.of(currencyData, transaction.getAmount());
|
||||
LocalDate date = transaction.getTransactionDate();
|
||||
|
||||
LoanTransactionData loanRepaymentData = new LoanTransactionData();
|
||||
loanRepaymentData.setTransactionType(LoanEnumerations
|
||||
.transactionType(transaction.getTypeOf()));
|
||||
loanRepaymentData.setId(transactionId);
|
||||
loanRepaymentData.setTotal(total);
|
||||
loanRepaymentData.setDate(date);
|
||||
|
||||
return loanRepaymentData;
|
||||
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(transaction.getTypeOf());
|
||||
return new LoanTransactionNewData(transactionId, transactionType, currencyData, transaction.getTransactionDate(), transaction.getAmount());
|
||||
}
|
||||
|
||||
private static final class LoanMapper implements
|
||||
|
||||
Reference in New Issue
Block a user