wip loan schedule data
This commit is contained in:
@@ -29,6 +29,7 @@ import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
|||||||
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
||||||
import org.mifosng.platform.api.data.LoanSchedule;
|
import org.mifosng.platform.api.data.LoanSchedule;
|
||||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||||
|
import org.mifosng.platform.api.data.LoanTransactionDatajpw;
|
||||||
import org.mifosng.platform.api.data.NewLoanData;
|
import org.mifosng.platform.api.data.NewLoanData;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||||
@@ -100,8 +101,9 @@ public class LoansApiResource {
|
|||||||
|
|
||||||
LoanAccountSummaryData summary = this.loanReadPlatformService.retrieveSummary(loanBasicDetails.getPrincipal(), repaymentSchedule);
|
LoanAccountSummaryData summary = this.loanReadPlatformService.retrieveSummary(loanBasicDetails.getPrincipal(), repaymentSchedule);
|
||||||
|
|
||||||
|
Collection<LoanTransactionDatajpw> loanRepayments = this.loanReadPlatformService.retrieveLoanPayments(loanId);
|
||||||
|
|
||||||
LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, null, null );
|
LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, null );
|
||||||
|
|
||||||
String selectedFields = "";
|
String selectedFields = "";
|
||||||
String associatedFields = "summary,repaymentSchedule,loanRepayments,permissions,convenienceData";
|
String associatedFields = "summary,repaymentSchedule,loanRepayments,permissions,convenienceData";
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.mifosng.platform.api.data;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
@@ -46,7 +45,7 @@ public class LoanAccountData {
|
|||||||
|
|
||||||
private LoanAccountSummaryData summary;
|
private LoanAccountSummaryData summary;
|
||||||
private Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule;
|
private Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule;
|
||||||
private List<LoanTransactionData> loanRepayments;
|
private Collection<LoanTransactionDatajpw> loanRepayments;
|
||||||
|
|
||||||
private LoanPermissionData permissions;
|
private LoanPermissionData permissions;
|
||||||
|
|
||||||
@@ -59,7 +58,7 @@ public class LoanAccountData {
|
|||||||
public LoanAccountData(LoanBasicDetailsData basicDetails,
|
public LoanAccountData(LoanBasicDetailsData basicDetails,
|
||||||
LoanAccountSummaryData summary,
|
LoanAccountSummaryData summary,
|
||||||
Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule,
|
Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule,
|
||||||
List<LoanTransactionData> loanRepayments,
|
Collection<LoanTransactionDatajpw> loanRepayments,
|
||||||
LoanPermissionData permissions) {
|
LoanPermissionData permissions) {
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
this.repaymentSchedule = repaymentSchedule;
|
this.repaymentSchedule = repaymentSchedule;
|
||||||
@@ -146,15 +145,17 @@ public class LoanAccountData {
|
|||||||
return repaymentSchedule;
|
return repaymentSchedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepaymentSchedule(Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule) {
|
public void setRepaymentSchedule(
|
||||||
|
Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule) {
|
||||||
this.repaymentSchedule = repaymentSchedule;
|
this.repaymentSchedule = repaymentSchedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LoanTransactionData> getLoanRepayments() {
|
public Collection<LoanTransactionDatajpw> getLoanRepayments() {
|
||||||
return loanRepayments;
|
return loanRepayments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoanRepayments(List<LoanTransactionData> loanRepayments) {
|
public void setLoanRepayments(
|
||||||
|
Collection<LoanTransactionDatajpw> loanRepayments) {
|
||||||
this.loanRepayments = loanRepayments;
|
this.loanRepayments = loanRepayments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
package org.mifosng.platform.api.data;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
public class LoanTransactionDatajpw {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private EnumOptionData transactionType;
|
||||||
|
private LocalDate date;
|
||||||
|
private MoneyData total;
|
||||||
|
|
||||||
|
public LoanTransactionDatajpw() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoanTransactionDatajpw(Long id, EnumOptionData transactionType,
|
||||||
|
final LocalDate date, final MoneyData total) {
|
||||||
|
this.id = id;
|
||||||
|
this.transactionType = transactionType;
|
||||||
|
this.date = date;
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(MoneyData total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
@@ -7,6 +7,7 @@ import org.mifosng.platform.api.data.LoanAccountSummaryData;
|
|||||||
import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
||||||
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
||||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||||
|
import org.mifosng.platform.api.data.LoanTransactionDatajpw;
|
||||||
import org.mifosng.platform.api.data.MoneyData;
|
import org.mifosng.platform.api.data.MoneyData;
|
||||||
import org.mifosng.platform.api.data.NewLoanData;
|
import org.mifosng.platform.api.data.NewLoanData;
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ public interface LoanReadPlatformService {
|
|||||||
LoanAccountSummaryData retrieveSummary(MoneyData principal,
|
LoanAccountSummaryData retrieveSummary(MoneyData principal,
|
||||||
Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule);
|
Collection<LoanRepaymentPeriodDatajpw> repaymentSchedule);
|
||||||
|
|
||||||
|
Collection<LoanTransactionDatajpw> retrieveLoanPayments(Long loanId);
|
||||||
|
|
||||||
NewLoanData retrieveClientAndProductDetails(Long clientId, Long productId);
|
NewLoanData retrieveClientAndProductDetails(Long clientId, Long productId);
|
||||||
|
|
||||||
LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
|
LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
|
||||||
|
|||||||
+77
-13
@@ -8,7 +8,6 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosng.platform.ReadExtraDataAndReportingServiceImpl;
|
|
||||||
import org.mifosng.platform.api.data.ClientData;
|
import org.mifosng.platform.api.data.ClientData;
|
||||||
import org.mifosng.platform.api.data.CurrencyData;
|
import org.mifosng.platform.api.data.CurrencyData;
|
||||||
import org.mifosng.platform.api.data.EnumOptionData;
|
import org.mifosng.platform.api.data.EnumOptionData;
|
||||||
@@ -20,6 +19,7 @@ import org.mifosng.platform.api.data.LoanProductLookup;
|
|||||||
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
import org.mifosng.platform.api.data.LoanRepaymentPeriodDatajpw;
|
||||||
import org.mifosng.platform.api.data.LoanRepaymentScheduleData;
|
import org.mifosng.platform.api.data.LoanRepaymentScheduleData;
|
||||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||||
|
import org.mifosng.platform.api.data.LoanTransactionDatajpw;
|
||||||
import org.mifosng.platform.api.data.MoneyData;
|
import org.mifosng.platform.api.data.MoneyData;
|
||||||
import org.mifosng.platform.api.data.NewLoanData;
|
import org.mifosng.platform.api.data.NewLoanData;
|
||||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||||
@@ -32,7 +32,6 @@ import org.mifosng.platform.exceptions.LoanTransactionNotFoundException;
|
|||||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||||
import org.mifosng.platform.loan.domain.Loan;
|
import org.mifosng.platform.loan.domain.Loan;
|
||||||
import org.mifosng.platform.loan.domain.LoanRepaymentScheduleInstallment;
|
|
||||||
import org.mifosng.platform.loan.domain.LoanRepository;
|
import org.mifosng.platform.loan.domain.LoanRepository;
|
||||||
import org.mifosng.platform.loan.domain.LoanTransaction;
|
import org.mifosng.platform.loan.domain.LoanTransaction;
|
||||||
import org.mifosng.platform.loan.domain.LoanTransactionRepository;
|
import org.mifosng.platform.loan.domain.LoanTransactionRepository;
|
||||||
@@ -135,20 +134,26 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
|||||||
BigDecimal totalInArrears = BigDecimal.ZERO;
|
BigDecimal totalInArrears = BigDecimal.ZERO;
|
||||||
BigDecimal totalWaived = BigDecimal.ZERO;
|
BigDecimal totalWaived = BigDecimal.ZERO;
|
||||||
|
|
||||||
logger.info("reading");
|
|
||||||
for (LoanRepaymentPeriodDatajpw installment : repaymentSchedule) {
|
for (LoanRepaymentPeriodDatajpw installment : repaymentSchedule) {
|
||||||
logger.info("reading: " + installment.getPrincipal().getAmount());
|
originalPrincipal = originalPrincipal.add(installment
|
||||||
originalPrincipal.add(installment.getPrincipal().getAmount());
|
.getPrincipal().getAmount());
|
||||||
principalPaid.add(installment.getPrincipalPaid().getAmount());
|
principalPaid = principalPaid.add(installment.getPrincipalPaid()
|
||||||
principalOutstanding.add(installment.getPrincipalOutstanding().getAmount());
|
.getAmount());
|
||||||
|
principalOutstanding = principalOutstanding.add(installment
|
||||||
|
.getPrincipalOutstanding().getAmount());
|
||||||
|
|
||||||
originalInterest.add(installment.getInterest().getAmount());
|
originalInterest = originalInterest.add(installment.getInterest()
|
||||||
interestPaid.add(installment.getInterestPaid().getAmount());
|
.getAmount());
|
||||||
interestOutstanding.add(installment.getInterestOutstanding().getAmount());
|
interestPaid = interestPaid.add(installment.getInterestPaid()
|
||||||
|
.getAmount());
|
||||||
|
interestOutstanding = interestOutstanding.add(installment
|
||||||
|
.getInterestOutstanding().getAmount());
|
||||||
|
|
||||||
originalTotal.add(installment.getTotal().getAmount());
|
originalTotal = originalTotal.add(installment.getTotal()
|
||||||
totalPaid.add(installment.getTotalPaid().getAmount());
|
.getAmount());
|
||||||
totalOutstanding.add(installment.getTotalOutstanding().getAmount());
|
totalPaid = totalPaid.add(installment.getTotalPaid().getAmount());
|
||||||
|
totalOutstanding = totalOutstanding.add(installment
|
||||||
|
.getTotalOutstanding().getAmount());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +172,25 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
|||||||
currencyData, totalWaived));
|
currencyData, totalWaived));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<LoanTransactionDatajpw> retrieveLoanPayments(Long loanId) {
|
||||||
|
try {
|
||||||
|
context.authenticatedUser();
|
||||||
|
|
||||||
|
LoanPaymentsMapper rm = new LoanPaymentsMapper();
|
||||||
|
|
||||||
|
// retrieve all loan transactions that are not invalid (0) and not
|
||||||
|
// disbursements (1)
|
||||||
|
String sql = "select "
|
||||||
|
+ rm.LoanPaymentsSchema()
|
||||||
|
+ " where tr.loan_id = ? and tr.transaction_type_enum not in (0, 1) order by tr.transaction_date";
|
||||||
|
return this.jdbcTemplate.query(sql, rm, new Object[] { loanId });
|
||||||
|
|
||||||
|
} catch (EmptyResultDataAccessException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LoanAccountData convertToData(LoanBasicDetailsData loanBasic) {
|
public LoanAccountData convertToData(LoanBasicDetailsData loanBasic) {
|
||||||
|
|
||||||
MoneyData princ = loanBasic.getPrincipal();
|
MoneyData princ = loanBasic.getPrincipal();
|
||||||
@@ -608,4 +632,44 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class LoanPaymentsMapper implements
|
||||||
|
RowMapper<LoanTransactionDatajpw> {
|
||||||
|
|
||||||
|
public String LoanPaymentsSchema() {
|
||||||
|
|
||||||
|
return " tr.id as id, tr.transaction_type_enum as transactionType, tr.transaction_date as `date`, tr.amount as total, "
|
||||||
|
+ " l.currency_code as currencyCode, l.currency_digits as currencyDigits, rc.`name` as currencyName, rc.display_symbol as currencyDisplaySymbol, rc.internationalized_name_code as currencyNameCode "
|
||||||
|
+ " from portfolio_loan l "
|
||||||
|
+ " join portfolio_loan_transaction tr on tr.loan_id = l.id"
|
||||||
|
+ " join ref_currency rc on rc.`code` = l.currency_code ";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoanTransactionDatajpw mapRow(final ResultSet rs,
|
||||||
|
final int rowNum) throws SQLException {
|
||||||
|
|
||||||
|
String currencyCode = rs.getString("currencyCode");
|
||||||
|
String currencyName = rs.getString("currencyName");
|
||||||
|
String currencyNameCode = rs.getString("currencyNameCode");
|
||||||
|
String currencyDisplaySymbol = rs
|
||||||
|
.getString("currencyDisplaySymbol");
|
||||||
|
Integer currencyDigits = JdbcSupport.getInteger(rs,
|
||||||
|
"currencyDigits");
|
||||||
|
CurrencyData currencyData = new CurrencyData(currencyCode,
|
||||||
|
currencyName, currencyDigits, currencyDisplaySymbol,
|
||||||
|
currencyNameCode);
|
||||||
|
|
||||||
|
Long id = rs.getLong("id");
|
||||||
|
int transactionTypeInt = JdbcSupport.getInteger(rs,
|
||||||
|
"transactionType");
|
||||||
|
EnumOptionData transactionType = LoanEnumerations
|
||||||
|
.transactionType(transactionTypeInt);
|
||||||
|
LocalDate date = JdbcSupport.getLocalDate(rs, "date");
|
||||||
|
BigDecimal totalBD = rs.getBigDecimal("total");
|
||||||
|
MoneyData total = MoneyData.of(currencyData, totalBD);
|
||||||
|
|
||||||
|
return new LoanTransactionDatajpw(id, transactionType, date, total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user