dont return loanRepayments if none exist.
This commit is contained in:
@@ -57,6 +57,7 @@ import org.mifosng.platform.staff.service.StaffReadPlatformService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Path("/loans")
|
@Path("/loans")
|
||||||
@Component
|
@Component
|
||||||
@@ -204,6 +205,7 @@ public class LoansApiResource {
|
|||||||
|
|
||||||
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
||||||
|
|
||||||
|
int loanRepaymentsCount = 0;
|
||||||
Collection<LoanRepaymentTransactionData> loanRepayments = null;
|
Collection<LoanRepaymentTransactionData> loanRepayments = null;
|
||||||
Collection<LoanRepaymentPeriodData> repaymentSchedule = null;
|
Collection<LoanRepaymentPeriodData> repaymentSchedule = null;
|
||||||
LoanAccountSummaryData summary = null;
|
LoanAccountSummaryData summary = null;
|
||||||
@@ -219,13 +221,17 @@ public class LoansApiResource {
|
|||||||
responseParameters.addAll(associationParameters);
|
responseParameters.addAll(associationParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
loanRepayments = this.loanReadPlatformService.retrieveLoanPayments(loanId);
|
Collection<LoanRepaymentTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanPayments(loanId);
|
||||||
|
if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
|
||||||
|
loanRepayments = currentLoanRepayments;
|
||||||
|
loanRepaymentsCount = loanRepayments.size();
|
||||||
|
}
|
||||||
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId);
|
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId);
|
||||||
|
|
||||||
summary = this.loanReadPlatformService.retrieveSummary(loanBasicDetails.getCurrency(), repaymentSchedule, loanRepayments);
|
summary = this.loanReadPlatformService.retrieveSummary(loanBasicDetails.getCurrency(), repaymentSchedule, loanRepayments);
|
||||||
|
|
||||||
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getCurrency(), loanBasicDetails.getInArrearsTolerance());
|
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getCurrency(), loanBasicDetails.getInArrearsTolerance());
|
||||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepayments.size());
|
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount);
|
||||||
convenienceDataRequired = true;
|
convenienceDataRequired = true;
|
||||||
|
|
||||||
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
|
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
|
||||||
|
|||||||
+8
-6
@@ -148,12 +148,14 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
|||||||
// sum up all repayment transactions
|
// sum up all repayment transactions
|
||||||
Long waiverType = (long) 4;
|
Long waiverType = (long) 4;
|
||||||
MoneyData totalRepaymentAmount = MoneyData.of(currencyData, BigDecimal.ZERO);
|
MoneyData totalRepaymentAmount = MoneyData.of(currencyData, BigDecimal.ZERO);
|
||||||
for (LoanRepaymentTransactionData loanRepayment : loanRepayments) {
|
if (loanRepayments != null) {
|
||||||
Long transactionType = loanRepayment.getTransactionType().getId();
|
for (LoanRepaymentTransactionData loanRepayment : loanRepayments) {
|
||||||
if (transactionType.equals(waiverType)) {
|
Long transactionType = loanRepayment.getTransactionType().getId();
|
||||||
// skip
|
if (transactionType.equals(waiverType)) {
|
||||||
} else {
|
// skip
|
||||||
totalRepaymentAmount = totalRepaymentAmount.plus(loanRepayment.getTotal());
|
} else {
|
||||||
|
totalRepaymentAmount = totalRepaymentAmount.plus(loanRepayment.getTotal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user