fix update loan product transaction strategy field and align new loan application with implementation of modify loan application work from mifosx-32.

This commit is contained in:
Keith Woodlock
2012-09-07 15:32:17 +01:00
parent c686d0d628
commit 61b49d0b4c
10 changed files with 233 additions and 209 deletions
@@ -23,9 +23,9 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.platform.api.commands.LoanApplicationCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.LoanApplicationCommand;
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.api.data.ChargeData;
import org.mifosng.platform.api.data.EntityIdentifier;
@@ -40,7 +40,6 @@ import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
import org.mifosng.platform.api.data.LoanSchedule;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.data.TransactionProcessingStrategyData;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
@@ -98,8 +97,23 @@ public class LoansApiResource {
@QueryParam("productId") final Long productId,
@Context final UriInfo uriInfo) {
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("clientId", "clientName", "productId", "productName",
"selectedProduct", "expectedDisbursementDate", "allowedProducts"));
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "externalId", "clientId", "clientName", "fundId", "fundName",
"loanProductId", "loanProductName", "loanProductDescription",
"currency", "principal",
"inArrearsTolerance", "numberOfRepayments",
"repaymentEvery", "interestRatePerPeriod",
"annualInterestRate", "repaymentFrequencyType",
"interestRateFrequencyType", "amortizationType",
"interestType", "interestCalculationPeriodType",
"submittedOnDate", "approvedOnDate",
"expectedDisbursementDate", "actualDisbursementDate",
"expectedFirstRepaymentOnDate", "interestChargedFromDate",
"closedOnDate", "expectedMaturityDate",
"status",
"lifeCycleStatusDate", "summary", "repaymentSchedule",
"loanRepayments", "permissions", "convenienceData", "charges")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
if (responseParameters.isEmpty()) {
@@ -107,9 +121,32 @@ public class LoansApiResource {
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
NewLoanData workflowData = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
responseParameters.addAll(Arrays.asList("productOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions",
"repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "transactionProcessingStrategyOptions", "chargeOptions"));
// tempate related
Collection<LoanProductLookup> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
Collection<EnumOptionData>loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
Collection<EnumOptionData>repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
Collection<EnumOptionData>interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
Collection<EnumOptionData>amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
Collection<EnumOptionData>interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
Collection<EnumOptionData>interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
final boolean convenienceDataRequired = false;
Collection<ChargeData> charges = null;
final LoanAccountData newLoanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, null, null, null, null, charges,
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
transactionProcessingStrategyOptions, interestRateFrequencyTypeOptions,
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions);
return this.apiJsonSerializerService.serializeNewLoanDataToJson(prettyPrint, responseParameters, workflowData);
return this.apiJsonSerializerService.serialzieLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount);
}
@GET
@@ -145,6 +182,7 @@ public class LoansApiResource {
LoanPermissionData permissions = null;
Collection<ChargeData> charges = null;
boolean convenienceDataRequired = false;
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
if (!associationParameters.isEmpty()) {
if (associationParameters.contains("all")) {
@@ -160,7 +198,8 @@ public class LoansApiResource {
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getCurrency(), loanBasicDetails.getInArrearsTolerance());
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepayments.size());
convenienceDataRequired = true;
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
}
@@ -193,7 +232,7 @@ public class LoansApiResource {
transactionProcessingStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
}
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, permissions, charges,
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, summary, repaymentSchedule, loanRepayments, permissions, charges,
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
transactionProcessingStrategyOptions, interestRateFrequencyTypeOptions,
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions);
@@ -67,9 +67,10 @@ public class LoanAccountData {
private final LoanPermissionData permissions;
private final LoanConvenienceData convenienceData;
public LoanAccountData(
final LoanBasicDetailsData basicDetails,
final boolean convenienceDataRequired,
final LoanAccountSummaryData summary,
final Collection<LoanRepaymentPeriodData> repaymentSchedule,
final Collection<LoanRepaymentTransactionData> loanRepayments,
@@ -99,22 +100,26 @@ public class LoanAccountData {
this.interestCalculationPeriodTypeOptions = interestCalculationPeriodTypeOptions;
this.fundOptions = fundOptions;
int maxSubmittedOnOffsetFromToday = basicDetails
.getMaxSubmittedOnOffsetFromToday();
int maxApprovedOnOffsetFromToday = basicDetails
.getMaxApprovedOnOffsetFromToday();
int maxDisbursedOnOffsetFromToday = basicDetails
.getMaxDisbursedOnOffsetFromToday();
int expectedLoanTermInDays = basicDetails.getLoanTermInDays();
int expectedLoanTermInMonths = basicDetails.getLoanTermInMonths();
int actualLoanTermInDays = basicDetails.getActualLoanTermInDays();
int actualLoanTermInMonths = basicDetails.getActualLoanTermInMonths();
this.convenienceData = new LoanConvenienceData(
maxSubmittedOnOffsetFromToday, maxApprovedOnOffsetFromToday,
maxDisbursedOnOffsetFromToday, expectedLoanTermInDays,
actualLoanTermInDays, expectedLoanTermInMonths,
actualLoanTermInMonths);
if (convenienceDataRequired) {
int maxSubmittedOnOffsetFromToday = basicDetails
.getMaxSubmittedOnOffsetFromToday();
int maxApprovedOnOffsetFromToday = basicDetails
.getMaxApprovedOnOffsetFromToday();
int maxDisbursedOnOffsetFromToday = basicDetails
.getMaxDisbursedOnOffsetFromToday();
int expectedLoanTermInDays = basicDetails.getLoanTermInDays();
int expectedLoanTermInMonths = basicDetails.getLoanTermInMonths();
int actualLoanTermInDays = basicDetails.getActualLoanTermInDays();
int actualLoanTermInMonths = basicDetails.getActualLoanTermInMonths();
this.convenienceData = new LoanConvenienceData(
maxSubmittedOnOffsetFromToday, maxApprovedOnOffsetFromToday,
maxDisbursedOnOffsetFromToday, expectedLoanTermInDays,
actualLoanTermInDays, expectedLoanTermInMonths,
actualLoanTermInMonths);
} else {
this.convenienceData = null;
}
this.id = basicDetails.getId();
this.externalId = basicDetails.getExternalId();
@@ -133,7 +138,7 @@ public class LoanAccountData {
this.actualDisbursementDate = basicDetails.getActualDisbursementDate();
this.closedOnDate = basicDetails.getClosedOnDate();
this.expectedMaturityDate = basicDetails.getExpectedMaturityDate();
this.repaymentsStartingFromDate = basicDetails.getExpectedFirstRepaymentOnDate();
this.repaymentsStartingFromDate = basicDetails.getRepaymentsStartingFromDate();
this.interestChargedFromDate = basicDetails.getInterestChargedFromDate();
this.currency = basicDetails.getCurrency();
@@ -7,6 +7,9 @@ import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Months;
/**
* Immutable data object for core details of loan to be combined with {@link LoanAccountData} usage.
*/
public class LoanBasicDetailsData {
private final Long id;
@@ -16,38 +19,156 @@ public class LoanBasicDetailsData {
private final Long loanProductId;
private final String loanProductName;
private final String loanProductDescription;
private final EnumOptionData status;
private final Long fundId;
private final String fundName;
private final EnumOptionData status;
private final CurrencyData currency;
private final BigDecimal principal;
private final BigDecimal inArrearsTolerance;
private final Integer termFrequency;
private final EnumOptionData termPeriodFrequencyType;
private final Integer numberOfRepayments;
private final Integer repaymentEvery;
private final EnumOptionData repaymentFrequencyType;
private final Integer transactionStrategyId;
private final EnumOptionData amortizationType;
private final BigDecimal interestRatePerPeriod;
private final EnumOptionData interestRateFrequencyType;
private final BigDecimal annualInterestRate;
private final EnumOptionData interestType;
private final EnumOptionData interestCalculationPeriodType;
private final LocalDate submittedOnDate;
private final LocalDate approvedOnDate;
private final LocalDate expectedDisbursementDate;
private final LocalDate actualDisbursementDate;
private final LocalDate expectedFirstRepaymentOnDate;
private final LocalDate repaymentsStartingFromDate;
private final LocalDate interestChargedFromDate;
private final LocalDate closedOnDate;
private final LocalDate expectedMaturityDate;
private final CurrencyData currency;
private final BigDecimal principal;
private final BigDecimal inArrearsTolerance;
private final Integer termFrequency;
private final EnumOptionData termPeriodFrequencyType;
private final Integer numberOfRepayments;
private final Integer repaymentEvery;
private final Integer transactionStrategyId;
private final BigDecimal interestRatePerPeriod;
private final BigDecimal annualInterestRate;
private final EnumOptionData repaymentFrequencyType;
private final EnumOptionData interestRateFrequencyType;
private final EnumOptionData amortizationType;
private final EnumOptionData interestType;
private final EnumOptionData interestCalculationPeriodType;
private final LocalDate lifeCycleStatusDate;
public static LoanBasicDetailsData populateForNewLoanCreation(final Long clientId, final String clientName, final LocalDate expectedDisbursementDate) {
return new LoanBasicDetailsData(clientId, clientName, expectedDisbursementDate);
}
public static LoanBasicDetailsData populateForNewLoanCreation(final LoanBasicDetailsData loanAccount, final LoanProductData product) {
final Integer termFrequency = product.getNumberOfRepayments() * product.getRepaymentEvery();
final EnumOptionData termPeriodFrequencyType = product.getRepaymentFrequencyType();
return new LoanBasicDetailsData(
loanAccount.clientId, loanAccount.clientName,
product.getId(), product.getName(), product.getDescription(), product.getFundId(), product.getFundName(),
product.getCurrency(), product.getPrincipal(), product.getInArrearsTolerance(),
termFrequency, termPeriodFrequencyType, product.getNumberOfRepayments(), product.getRepaymentEvery(), product.getRepaymentFrequencyType(),
product.getTransactionProcessingStrategyId(), product.getAmortizationType(),
product.getInterestRatePerPeriod(), product.getInterestRateFrequencyType(), product.getInterestType(), product.getInterestCalculationPeriodType(),
loanAccount.expectedDisbursementDate);
}
private LoanBasicDetailsData(
final Long clientId, final String clientName,
final Long productId, final String productName, final String productDescription, final Long fundId, final String fundName,
final CurrencyData currency, final BigDecimal principal, final BigDecimal inArrearsTolerance,
final Integer termFrequency,
final EnumOptionData termPeriodFrequencyType,
final Integer numberOfRepayments,
final Integer repaymentEvery,
final EnumOptionData repaymentFrequencyType,
final Long transactionStrategyId,
final EnumOptionData amortizationType,
final BigDecimal interestRatePerPeriod,
final EnumOptionData interestRateFrequencyType,
final EnumOptionData interestType,
final EnumOptionData interestCalculationPeriodType,
final LocalDate expectedDisbursementDate) {
this.id = null;
this.externalId = null;
this.clientId = clientId;
this.clientName = clientName;
this.loanProductId = productId;
this.loanProductName = productName;
this.loanProductDescription= productDescription;
this.status = null;
this.fundId = fundId;
this.fundName = fundName;
this.currency = currency;
this.principal = principal;
this.inArrearsTolerance = inArrearsTolerance;
this.termFrequency = termFrequency;
this.termPeriodFrequencyType = termPeriodFrequencyType;
this.numberOfRepayments = numberOfRepayments;
this.repaymentEvery = repaymentEvery;
this.repaymentFrequencyType = repaymentFrequencyType;
// FIXME - kw - settle on using either long or integer for this throughout product and account fields for loan.
if (transactionStrategyId != null) {
this.transactionStrategyId = transactionStrategyId.intValue();
} else {
this.transactionStrategyId = null;
}
this.amortizationType = amortizationType;
this.interestRatePerPeriod = interestRatePerPeriod;
this.annualInterestRate = null;
this.interestRateFrequencyType = interestRateFrequencyType;
this.interestType = interestType;
this.interestCalculationPeriodType = interestCalculationPeriodType;
this.submittedOnDate = null;
this.approvedOnDate = null;
this.expectedDisbursementDate = expectedDisbursementDate;
this.actualDisbursementDate = null;
this.closedOnDate = null;
this.expectedMaturityDate = null;
this.repaymentsStartingFromDate = null;
this.interestChargedFromDate = null;
this.lifeCycleStatusDate = null;
}
private LoanBasicDetailsData(final Long clientId, final String clientName, final LocalDate expectedDisbursementDate) {
this.id = null;
this.externalId = null;
this.clientId = clientId;
this.clientName = clientName;
this.loanProductId = null;
this.loanProductName = null;
this.loanProductDescription= null;
this.status = null;
this.fundId = null;
this.fundName = null;
this.currency = null;
this.principal = null;
this.inArrearsTolerance = null;
this.termFrequency = null;
this.termPeriodFrequencyType = null;
this.numberOfRepayments = null;
this.repaymentEvery = null;
this.transactionStrategyId = null;
this.interestRatePerPeriod = null;
this.annualInterestRate = null;
this.repaymentFrequencyType = null;
this.interestRateFrequencyType = null;
this.amortizationType = null;
this.interestType = null;
this.interestCalculationPeriodType = null;
this.lifeCycleStatusDate = null;
this.submittedOnDate = null;
this.approvedOnDate = null;
this.expectedDisbursementDate = expectedDisbursementDate;
this.actualDisbursementDate = null;
this.closedOnDate = null;
this.expectedMaturityDate = null;
this.repaymentsStartingFromDate = null;
this.interestChargedFromDate = null;
}
public LoanBasicDetailsData(
final Long id,
@@ -63,7 +184,7 @@ public class LoanBasicDetailsData {
final LocalDate expectedDisbursementDate,
final LocalDate actualDisbursementDate,
final LocalDate expectedMaturityDate,
final LocalDate expectedFirstRepaymentOnDate,
final LocalDate repaymentsStartingFromDate,
final LocalDate interestChargedFromDate,
final CurrencyData currency,
final BigDecimal principal,
@@ -97,7 +218,7 @@ public class LoanBasicDetailsData {
this.expectedDisbursementDate = expectedDisbursementDate;
this.actualDisbursementDate = actualDisbursementDate;
this.expectedMaturityDate = expectedMaturityDate;
this.expectedFirstRepaymentOnDate = expectedFirstRepaymentOnDate;
this.repaymentsStartingFromDate = repaymentsStartingFromDate;
this.interestChargedFromDate = interestChargedFromDate;
this.currency = currency;
this.principal = principal;
@@ -270,9 +391,9 @@ public class LoanBasicDetailsData {
public LocalDate getActualDisbursementDate() {
return actualDisbursementDate;
}
public LocalDate getExpectedFirstRepaymentOnDate() {
return expectedFirstRepaymentOnDate;
public LocalDate getRepaymentsStartingFromDate() {
return repaymentsStartingFromDate;
}
public LocalDate getInterestChargedFromDate() {
@@ -1,80 +0,0 @@
package org.mifosng.platform.api.data;
import java.util.ArrayList;
import java.util.List;
import org.joda.time.LocalDate;
public class NewLoanData {
private Long clientId;
private String clientName;
private Long productId;
private String productName;
private LoanProductData selectedProduct;
private LocalDate expectedDisbursementDate;
private List<LoanProductLookup> allowedProducts = new ArrayList<LoanProductLookup>();
public NewLoanData() {
//
}
public Long getClientId() {
return clientId;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public List<LoanProductLookup> getAllowedProducts() {
return allowedProducts;
}
public void setAllowedProducts(List<LoanProductLookup> allowedProducts) {
this.allowedProducts = allowedProducts;
}
public LoanProductData getSelectedProduct() {
return selectedProduct;
}
public void setSelectedProduct(LoanProductData selectedProduct) {
this.selectedProduct = selectedProduct;
}
public LocalDate getExpectedDisbursementDate() {
return expectedDisbursementDate;
}
public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) {
this.expectedDisbursementDate = expectedDisbursementDate;
}
}
@@ -7,8 +7,8 @@ import org.mifosng.platform.api.data.AdditionalFieldsSetData;
import org.mifosng.platform.api.data.AppUserData;
import org.mifosng.platform.api.data.AuthenticatedUserData;
import org.mifosng.platform.api.data.ChargeData;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ConfigurationData;
import org.mifosng.platform.api.data.DepositAccountData;
import org.mifosng.platform.api.data.DepositProductData;
@@ -18,7 +18,6 @@ import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -89,8 +88,6 @@ public interface ApiJsonSerializerService {
String serializeNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, NoteData note);
String serializeNewLoanDataToJson(boolean prettyPrint, Set<String> responseParameters, NewLoanData newLoan);
String serialzieLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData transaction);
@@ -9,8 +9,8 @@ import org.mifosng.platform.api.data.AdditionalFieldsSetData;
import org.mifosng.platform.api.data.AppUserData;
import org.mifosng.platform.api.data.AuthenticatedUserData;
import org.mifosng.platform.api.data.ChargeData;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ConfigurationData;
import org.mifosng.platform.api.data.DepositAccountData;
import org.mifosng.platform.api.data.DepositProductData;
@@ -20,7 +20,6 @@ import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -38,8 +37,7 @@ import com.google.gson.Gson;
* serialize Java object representation into JSON.
*/
@Service
public class GoogleGsonApiJsonSerializerService implements
ApiJsonSerializerService {
public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerService {
private static final Set<String> PERMISSION_DATA_PARAMETERS = new HashSet<String>(
Arrays.asList("id", "name", "description", "code"));
@@ -133,11 +131,6 @@ public class GoogleGsonApiJsonSerializerService implements
"createdOn", "updatedById", "updatedByUsername",
"updatedOn"));
private static final Set<String> NEW_LOAN_DATA_PARAMETERS = new HashSet<String>(
Arrays.asList("clientId", "clientName", "productId", "productName",
"selectedProduct", "expectedDisbursementDate",
"allowedProducts"));
private static final Set<String> LOAN_DATA_PARAMETERS = new HashSet<String>(
Arrays.asList("id", "externalId", "clientId", "clientName", "fundId", "fundName",
"loanProductId", "loanProductName", "loanProductDescription",
@@ -488,16 +481,6 @@ public class GoogleGsonApiJsonSerializerService implements
return helper.serializedJsonFrom(gsonDeserializer, note);
}
@Override
public String serializeNewLoanDataToJson(final boolean prettyPrint,
final Set<String> responseParameters, final NewLoanData newLoan) {
final Gson gsonDeserializer = helper
.createGsonBuilderWithParameterExclusionSerializationStrategy(
NEW_LOAN_DATA_PARAMETERS, prettyPrint,
responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, newLoan);
}
@Override
public String serialzieLoanAccountDataToJson(final boolean prettyPrint,
final Set<String> responseParameters,
@@ -9,7 +9,6 @@ import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
public interface LoanReadPlatformService {
@@ -27,13 +26,11 @@ public interface LoanReadPlatformService {
LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed,
int repaymentAndWaiveCount);
NewLoanData retrieveClientAndProductDetails(Long clientId, Long productId);
LoanBasicDetailsData retrieveClientAndProductDetails(Long clientId, Long productId);
LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
LoanTransactionData retrieveNewLoanWaiverDetails(Long loanId);
LoanTransactionData retrieveLoanTransactionDetails(Long loanId,
Long transactionId);
LoanTransactionData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
}
@@ -3,11 +3,9 @@ package org.mifosng.platform.loan.service;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.data.ChargeData;
import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.CurrencyData;
import org.mifosng.platform.api.data.EnumOptionData;
@@ -15,13 +13,10 @@ import org.mifosng.platform.api.data.LoanAccountSummaryData;
import org.mifosng.platform.api.data.LoanBasicDetailsData;
import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanProductLookup;
import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.MoneyData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.charge.service.ChargeReadPlatformService;
import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.currency.domain.ApplicationCurrency;
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
@@ -55,7 +50,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
private final LoanProductReadPlatformService loanProductReadPlatformService;
private final ClientReadPlatformService clientReadPlatformService;
private final LoanTransactionRepository loanTransactionRepository;
private final ChargeReadPlatformService chargeReadPlatformService;
@Autowired
public LoanReadPlatformServiceImpl(
@@ -65,7 +59,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanProductReadPlatformService loanProductReadPlatformService,
final ClientReadPlatformService clientReadPlatformService,
final ChargeReadPlatformService chargeReadPlatformService,
final TenantAwareRoutingDataSource dataSource) {
this.context = context;
this.loanRepository = loanRepository;
@@ -73,7 +66,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
this.applicationCurrencyRepository = applicationCurrencyRepository;
this.loanProductReadPlatformService = loanProductReadPlatformService;
this.clientReadPlatformService = clientReadPlatformService;
this.chargeReadPlatformService = chargeReadPlatformService;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@@ -234,51 +226,21 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
public NewLoanData retrieveClientAndProductDetails(final Long clientId,
final Long productId) {
public LoanBasicDetailsData retrieveClientAndProductDetails(final Long clientId, final Long productId) {
context.authenticatedUser();
NewLoanData workflowData = new NewLoanData();
Collection<LoanProductLookup> loanProducts = this.loanProductReadPlatformService
.retrieveAllLoanProductsForLookup();
workflowData.setAllowedProducts(new ArrayList<LoanProductLookup>(
loanProducts));
final LocalDate expectedDisbursementDate = new LocalDate();
final ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
LoanBasicDetailsData loanDetails = LoanBasicDetailsData.populateForNewLoanCreation(clientAccount.getId(), clientAccount.getDisplayName(), expectedDisbursementDate);
if (productId != null) {
LoanProductData selectedProduct = findLoanProductById(loanProducts, productId);
workflowData.setProductId(selectedProduct.getId());
workflowData.setProductName(selectedProduct.getName());
workflowData.setSelectedProduct(selectedProduct);
LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId);
loanDetails = LoanBasicDetailsData.populateForNewLoanCreation(loanDetails, selectedProduct);
}
ClientData clientAccount = this.clientReadPlatformService
.retrieveIndividualClient(clientId);
workflowData.setClientId(clientAccount.getId());
workflowData.setClientName(clientAccount.getDisplayName());
workflowData.setExpectedDisbursementDate(new LocalDate());
return workflowData;
}
private LoanProductData findLoanProductById(
Collection<LoanProductLookup> loanProducts, Long productId) {
LoanProductData match = this.loanProductReadPlatformService
.retrieveNewLoanProductDetails();
for (LoanProductLookup loanProductLookup : loanProducts) {
if (loanProductLookup.getId().equals(productId)) {
match = this.loanProductReadPlatformService
.retrieveLoanProduct(loanProductLookup.getId());
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges();
chargeOptions.removeAll(match.getCharges());
match.setChargeOptions(chargeOptions);
break;
}
}
return match;
return loanDetails;
}
@Override
@@ -151,7 +151,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
}
public String loanProductSchema() {
return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, "
return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, "
+ "lp.name as name, lp.description as description, lp.flexible_repayment_schedule as isFlexible, lp.interest_rebate as isInterestRebateAllowed, "
+ "lp.principal_amount as principal, lp.currency_code as currencyCode, lp.currency_digits as currencyDigits, "
+ "lp.nominal_interest_rate_per_period as interestRatePerPeriod, lp.interest_period_frequency_enum as interestRatePerPeriodFreq, "
@@ -141,7 +141,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = null;
if (command.isTransactionProcessingStrategyChanged()) {
findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId());
loanTransactionProcessingStrategy = findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId());
}
final Set<Charge> charges = this.assembleSetOfCharges(command, product.getCurrency().getCode());