allow undo disbursal if only disbursement transactions. refactor loanTransactionData object.
This commit is contained in:
@@ -38,7 +38,7 @@ 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.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.StaffData;
|
||||
import org.mifosng.platform.api.data.TransactionProcessingStrategyData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
@@ -192,7 +192,7 @@ public class LoansApiResource {
|
||||
final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
||||
|
||||
int loanRepaymentsCount = 0;
|
||||
Collection<LoanTransactionNewData> loanRepayments = null;
|
||||
Collection<LoanTransactionData> loanRepayments = null;
|
||||
LoanScheduleData repaymentSchedule = null;
|
||||
LoanPermissionData permissions = null;
|
||||
Collection<LoanChargeData> charges = null;
|
||||
@@ -208,10 +208,9 @@ public class LoansApiResource {
|
||||
}
|
||||
|
||||
if (responseParameters.contains("transactions")) {
|
||||
Collection<LoanTransactionNewData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
|
||||
final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
|
||||
if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
|
||||
loanRepayments = currentLoanRepayments;
|
||||
loanRepaymentsCount = loanRepayments.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +228,7 @@ public class LoansApiResource {
|
||||
boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
|
||||
|
||||
if (responseParameters.contains("permissions")) {
|
||||
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
|
||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount);
|
||||
}
|
||||
convenienceDataRequired = true;
|
||||
@@ -290,6 +290,19 @@ public class LoansApiResource {
|
||||
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
|
||||
}
|
||||
|
||||
private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) {
|
||||
int loanRepaymentsCount = 0;
|
||||
if (!CollectionUtils.isEmpty(loanRepayments)) {
|
||||
for (LoanTransactionData transaction : loanRepayments) {
|
||||
if (transaction.isNotDisbursement()) {
|
||||
// use this to decide if undo disbural should permission should be set to true.
|
||||
loanRepaymentsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return loanRepaymentsCount;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@@ -453,7 +466,7 @@ public class LoansApiResource {
|
||||
}
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
LoanTransactionNewData transactionData = null;
|
||||
LoanTransactionData transactionData = null;
|
||||
if (is(commandParam, "repayment")) {
|
||||
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
|
||||
} else if (is(commandParam, "waiveinterest")) {
|
||||
@@ -485,7 +498,7 @@ public class LoansApiResource {
|
||||
}
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final LoanTransactionNewData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
||||
final LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
||||
|
||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class LoanAccountData {
|
||||
|
||||
// associations
|
||||
private final LoanScheduleData repaymentSchedule;
|
||||
private final Collection<LoanTransactionNewData> transactions;
|
||||
private final Collection<LoanTransactionData> transactions;
|
||||
private final Collection<LoanChargeData> charges;
|
||||
private final LoanPermissionData permissions;
|
||||
private final LoanConvenienceData convenienceData;
|
||||
@@ -79,7 +79,7 @@ public class LoanAccountData {
|
||||
final LoanBasicDetailsData basicDetails,
|
||||
final boolean convenienceDataRequired,
|
||||
final LoanScheduleData repaymentSchedule,
|
||||
final Collection<LoanTransactionNewData> transactions,
|
||||
final Collection<LoanTransactionData> transactions,
|
||||
final LoanPermissionData permissions,
|
||||
final Collection<LoanChargeData> charges,
|
||||
final Collection<LoanProductData> productOptions,
|
||||
|
||||
+6
-3
@@ -7,12 +7,11 @@ import org.joda.time.LocalDate;
|
||||
/**
|
||||
* Immutable data object representing a loan transaction.
|
||||
*/
|
||||
public class LoanTransactionNewData {
|
||||
public class LoanTransactionData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Long id;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private EnumOptionData type;
|
||||
|
||||
private LocalDate date;
|
||||
@@ -23,7 +22,7 @@ public class LoanTransactionNewData {
|
||||
@SuppressWarnings("unused")
|
||||
private BigDecimal amount;
|
||||
|
||||
public LoanTransactionNewData(
|
||||
public LoanTransactionData(
|
||||
final Long id,
|
||||
final EnumOptionData transactionType,
|
||||
final CurrencyData currency,
|
||||
@@ -39,4 +38,8 @@ public class LoanTransactionNewData {
|
||||
public LocalDate dateOf() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public boolean isNotDisbursement() {
|
||||
return type.getId().equals(Integer.valueOf(1));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ 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.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
@@ -103,7 +103,7 @@ public interface ApiJsonSerializerService {
|
||||
|
||||
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
|
||||
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionNewData newTransactionData);
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
|
||||
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ 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.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
@@ -556,7 +556,7 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
@Override
|
||||
public String serializeLoanTransactionDataToJson(final boolean prettyPrint,
|
||||
final Set<String> responseParameters,
|
||||
final LoanTransactionNewData transaction) {
|
||||
final LoanTransactionData transaction) {
|
||||
final Gson gsonDeserializer = helper
|
||||
.createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
LOAN_TRANSACTION_NEW_DATA_PARAMETERS, prettyPrint,
|
||||
|
||||
+3
-3
@@ -2,12 +2,12 @@ package org.mifosng.platform.loan.domain;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.mifosng.platform.api.data.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
|
||||
public class LoanRepaymentDataComparator implements Comparator<LoanTransactionNewData> {
|
||||
public class LoanRepaymentDataComparator implements Comparator<LoanTransactionData> {
|
||||
|
||||
@Override
|
||||
public int compare(final LoanTransactionNewData o1, final LoanTransactionNewData o2) {
|
||||
public int compare(final LoanTransactionData o1, final LoanTransactionData o2) {
|
||||
return o2.dateOf().compareTo(o1.dateOf());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -8,7 +8,7 @@ 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.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
|
||||
public interface LoanReadPlatformService {
|
||||
|
||||
@@ -16,7 +16,7 @@ public interface LoanReadPlatformService {
|
||||
|
||||
LoanScheduleData retrieveRepaymentSchedule(Long loanId, CurrencyData currency, DisbursementData disbursement, BigDecimal totalChargesAtDisbursement, BigDecimal inArrearsTolerance);
|
||||
|
||||
Collection<LoanTransactionNewData> retrieveLoanTransactions(Long loanId);
|
||||
Collection<LoanTransactionData> retrieveLoanTransactions(Long loanId);
|
||||
|
||||
LoanPermissionData retrieveLoanPermissions(
|
||||
LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed,
|
||||
@@ -26,11 +26,11 @@ public interface LoanReadPlatformService {
|
||||
|
||||
LoanBasicDetailsData retrieveGroupAndProductDetails(Long groupId, Long productId);
|
||||
|
||||
LoanTransactionNewData retrieveNewLoanRepaymentDetails(Long loanId);
|
||||
LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
|
||||
|
||||
LoanTransactionNewData retrieveNewLoanWaiveInterestDetails(Long loanId);
|
||||
LoanTransactionData retrieveNewLoanWaiveInterestDetails(Long loanId);
|
||||
|
||||
LoanTransactionNewData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
|
||||
LoanTransactionData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
|
||||
|
||||
LoanTransactionNewData retrieveNewClosureDetails();
|
||||
LoanTransactionData retrieveNewClosureDetails();
|
||||
}
|
||||
+13
-13
@@ -18,7 +18,7 @@ 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.LoanTransactionNewData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||
import org.mifosng.platform.currency.domain.ApplicationCurrency;
|
||||
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
|
||||
@@ -162,7 +162,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LoanTransactionNewData> retrieveLoanTransactions(final Long loanId) {
|
||||
public Collection<LoanTransactionData> retrieveLoanTransactions(final Long loanId) {
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -262,7 +262,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionNewData retrieveNewLoanRepaymentDetails(final Long loanId) {
|
||||
public LoanTransactionData retrieveNewLoanRepaymentDetails(final Long loanId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -287,11 +287,11 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
|
||||
final Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount();
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.REPAYMENT);
|
||||
return new LoanTransactionNewData(null, transactionType, currencyData, earliestUnpaidInstallmentDate, possibleNextRepaymentAmount.getAmount());
|
||||
return new LoanTransactionData(null, transactionType, currencyData, earliestUnpaidInstallmentDate, possibleNextRepaymentAmount.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionNewData retrieveNewLoanWaiveInterestDetails(final Long loanId) {
|
||||
public LoanTransactionData retrieveNewLoanWaiveInterestDetails(final Long loanId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -315,21 +315,21 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST);
|
||||
|
||||
return new LoanTransactionNewData(null, transactionType, currencyData, waiveOfInterest.getTransactionDate(), waiveOfInterest.getAmount());
|
||||
return new LoanTransactionData(null, transactionType, currencyData, waiveOfInterest.getTransactionDate(), waiveOfInterest.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionNewData retrieveNewClosureDetails() {
|
||||
public LoanTransactionData retrieveNewClosureDetails() {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WRITEOFF);
|
||||
|
||||
return new LoanTransactionNewData(null, transactionType, null, new LocalDate(), null);
|
||||
return new LoanTransactionData(null, transactionType, null, new LocalDate(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionNewData retrieveLoanTransactionDetails(
|
||||
public LoanTransactionData retrieveLoanTransactionDetails(
|
||||
final Long loanId, final Long transactionId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
@@ -359,7 +359,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
currency.getDisplaySymbol(), currency.getNameCode());
|
||||
|
||||
final EnumOptionData transactionType = LoanEnumerations.transactionType(transaction.getTypeOf());
|
||||
return new LoanTransactionNewData(transactionId, transactionType, currencyData, transaction.getTransactionDate(), transaction.getAmount());
|
||||
return new LoanTransactionData(transactionId, transactionType, currencyData, transaction.getTransactionDate(), transaction.getAmount());
|
||||
}
|
||||
|
||||
private static final class LoanMapper implements
|
||||
@@ -573,7 +573,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class LoanTransactionsMapper implements RowMapper<LoanTransactionNewData> {
|
||||
private static final class LoanTransactionsMapper implements RowMapper<LoanTransactionData> {
|
||||
|
||||
public String LoanPaymentsSchema() {
|
||||
|
||||
@@ -586,7 +586,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionNewData mapRow(final ResultSet rs,
|
||||
public LoanTransactionData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
@@ -604,7 +604,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
LocalDate date = JdbcSupport.getLocalDate(rs, "date");
|
||||
BigDecimal totalAmount = rs.getBigDecimal("total");
|
||||
|
||||
return new LoanTransactionNewData(id, transactionType, currencyData, date, totalAmount);
|
||||
return new LoanTransactionData(id, transactionType, currencyData, date, totalAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user