some fixes around transactions returned for loan account screens.
This commit is contained in:
@@ -30,7 +30,7 @@ import org.mifosng.platform.api.data.LoanPermissionData;
|
||||
import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
|
||||
import org.mifosng.platform.api.data.LoanSchedule;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionDataDTO;
|
||||
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
|
||||
import org.mifosng.platform.api.data.NewLoanData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||
@@ -99,7 +99,7 @@ public class LoansApiResource {
|
||||
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService
|
||||
.retrieveLoanAccountDetails(loanId);
|
||||
|
||||
Collection<LoanTransactionDataDTO> loanRepayments = this.loanReadPlatformService
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments = this.loanReadPlatformService
|
||||
.retrieveLoanPayments(loanId);
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule = this.loanReadPlatformService
|
||||
.retrieveRepaymentSchedule(loanId);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class LoanAccountData {
|
||||
|
||||
private LoanAccountSummaryData summary;
|
||||
private Collection<LoanRepaymentPeriodData> repaymentSchedule;
|
||||
private Collection<LoanTransactionDataDTO> loanRepayments;
|
||||
private Collection<LoanRepaymentTransactionData> loanRepayments;
|
||||
|
||||
private LoanPermissionData permissions;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class LoanAccountData {
|
||||
public LoanAccountData(LoanBasicDetailsData basicDetails,
|
||||
LoanAccountSummaryData summary,
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
||||
Collection<LoanTransactionDataDTO> loanRepayments,
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments,
|
||||
LoanPermissionData permissions) {
|
||||
this.summary = summary;
|
||||
this.repaymentSchedule = repaymentSchedule;
|
||||
@@ -150,12 +150,12 @@ public class LoanAccountData {
|
||||
this.repaymentSchedule = repaymentSchedule;
|
||||
}
|
||||
|
||||
public Collection<LoanTransactionDataDTO> getLoanRepayments() {
|
||||
public Collection<LoanRepaymentTransactionData> getLoanRepayments() {
|
||||
return loanRepayments;
|
||||
}
|
||||
|
||||
public void setLoanRepayments(
|
||||
Collection<LoanTransactionDataDTO> loanRepayments) {
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments) {
|
||||
this.loanRepayments = loanRepayments;
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -2,18 +2,21 @@ package org.mifosng.platform.api.data;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
public class LoanTransactionDataDTO {
|
||||
/**
|
||||
* This data object replaces {@link LoanTransactionData}.
|
||||
*/
|
||||
public class LoanRepaymentTransactionData {
|
||||
|
||||
private Long id;
|
||||
private EnumOptionData transactionType;
|
||||
private LocalDate date;
|
||||
private MoneyData total;
|
||||
|
||||
public LoanTransactionDataDTO() {
|
||||
public LoanRepaymentTransactionData() {
|
||||
//
|
||||
}
|
||||
|
||||
public LoanTransactionDataDTO(Long id, EnumOptionData transactionType,
|
||||
public LoanRepaymentTransactionData(Long id, EnumOptionData transactionType,
|
||||
final LocalDate date, final MoneyData total) {
|
||||
this.id = id;
|
||||
this.transactionType = transactionType;
|
||||
@@ -3,6 +3,10 @@ package org.mifosng.platform.api.data;
|
||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* TODO - KW - Think this is deprecated now.
|
||||
*/
|
||||
@Deprecated
|
||||
@JsonFilter("loanRepaymentFilter")
|
||||
public class LoanTransactionData {
|
||||
|
||||
|
||||
@@ -413,15 +413,31 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
}
|
||||
}
|
||||
|
||||
public void makeRepayment(final LoanTransaction loanTransaction,
|
||||
LoanLifecycleStateMachine loanLifecycleStateMachine) {
|
||||
this.loanStatus = loanLifecycleStateMachine.transition(
|
||||
LoanEvent.LOAN_REPAYMENT, this.loanStatus);
|
||||
public void makeRepayment(final LoanTransaction loanTransaction, final LoanLifecycleStateMachine loanLifecycleStateMachine) {
|
||||
this.loanStatus = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REPAYMENT, this.loanStatus);
|
||||
loanTransaction.updateLoan(this);
|
||||
this.loanTransactions.add(loanTransaction);
|
||||
|
||||
deriveLoanRepaymentScheduleCompletedData();
|
||||
|
||||
|
||||
// Money totalRepaidOrWaived = Money.zero(this.loanRepaymentScheduleDetail.getPrincipal().getCurrency());
|
||||
// MonetaryCurrency currency = totalRepaidOrWaived.getCurrency();
|
||||
//
|
||||
// int repaymentIndex = 0;
|
||||
//
|
||||
// for (LoanTransaction transaction : this.loanTransactions) {
|
||||
// if (transaction.isRepayment() || transaction.isWaiver()) {
|
||||
// totalRepaidOrWaived = totalRepaidOrWaived.plus(transaction.getAmount());
|
||||
//
|
||||
// LoanRepaymentScheduleInstallment currentInstallment = this.repaymentScheduleInstallments.get(repaymentIndex);
|
||||
// if (currentInstallment.unpaid()) {
|
||||
// currentInstallment.payOffWith(transaction, currency);
|
||||
// } else {
|
||||
// repaymentIndex++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (loanTransaction.isNotRepayment()) {
|
||||
final String errorMessage = "A transaction of type repayment was expected but not received.";
|
||||
throw new InvalidLoanTransactionTypeException("transaction",
|
||||
@@ -466,23 +482,18 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
Money totalRepaidOrWaivedAgainstLoan = calculateTotalPaidOrWaived();
|
||||
|
||||
Money remainingToPayoffAgainstLoanSchedule = totalRepaidOrWaivedAgainstLoan;
|
||||
Money totalOverpaid = Money.zero(totalRepaidOrWaivedAgainstLoan
|
||||
.getCurrency());
|
||||
Money totalOverpaid = Money.zero(totalRepaidOrWaivedAgainstLoan.getCurrency());
|
||||
int repaymentInstallmentIndex = 0;
|
||||
while (remainingToPayoffAgainstLoanSchedule.isGreaterThanZero()) {
|
||||
|
||||
if (repaymentInstallmentIndex == this.repaymentScheduleInstallments
|
||||
.size()) {
|
||||
if (repaymentInstallmentIndex == this.repaymentScheduleInstallments.size()) {
|
||||
totalOverpaid = remainingToPayoffAgainstLoanSchedule;
|
||||
|
||||
// to exit while loop
|
||||
remainingToPayoffAgainstLoanSchedule = remainingToPayoffAgainstLoanSchedule
|
||||
.minus(totalOverpaid);
|
||||
remainingToPayoffAgainstLoanSchedule = remainingToPayoffAgainstLoanSchedule.minus(totalOverpaid);
|
||||
} else {
|
||||
LoanRepaymentScheduleInstallment scheduledRepaymentInstallment = this.repaymentScheduleInstallments
|
||||
.get(repaymentInstallmentIndex);
|
||||
remainingToPayoffAgainstLoanSchedule = scheduledRepaymentInstallment
|
||||
.updateDerivedComponents(remainingToPayoffAgainstLoanSchedule);
|
||||
LoanRepaymentScheduleInstallment scheduledRepaymentInstallment = this.repaymentScheduleInstallments.get(repaymentInstallmentIndex);
|
||||
remainingToPayoffAgainstLoanSchedule = scheduledRepaymentInstallment.updateDerivedComponents(remainingToPayoffAgainstLoanSchedule);
|
||||
repaymentInstallmentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -151,4 +151,18 @@ public class LoanRepaymentScheduleInstallment extends AbstractAuditableCustom<Ap
|
||||
private Money getTotalCompleted(MonetaryCurrency currency) {
|
||||
return getPrincipalCompleted(currency).plus(getInterestCompleted(currency));
|
||||
}
|
||||
|
||||
// public void payOffWith(final LoanTransaction transaction, final MonetaryCurrency currency) {
|
||||
// Money transactionAmountRemaining = Money.of(currency, transaction.getAmount());
|
||||
//
|
||||
// Money interestDue = getInterest(currency);
|
||||
// if (transactionAmountRemaining.isGreaterThanOrEqualTo(interestDue)) {
|
||||
// this.interestCompleted = interestDue.getAmount();
|
||||
// transactionAmountRemaining = transactionAmountRemaining.minus(interestDue);
|
||||
// } else {
|
||||
// this.interestCompleted = transactionAmountRemaining.getAmount();
|
||||
// }
|
||||
//
|
||||
// Money principalDue = getPrincipal(currency);
|
||||
// }
|
||||
}
|
||||
+3
-3
@@ -7,7 +7,7 @@ import org.mifosng.platform.api.data.LoanBasicDetailsData;
|
||||
import org.mifosng.platform.api.data.LoanPermissionData;
|
||||
import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionDataDTO;
|
||||
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
|
||||
import org.mifosng.platform.api.data.MoneyData;
|
||||
import org.mifosng.platform.api.data.NewLoanData;
|
||||
|
||||
@@ -17,11 +17,11 @@ public interface LoanReadPlatformService {
|
||||
|
||||
Collection<LoanRepaymentPeriodData> retrieveRepaymentSchedule(Long loanId);
|
||||
|
||||
Collection<LoanTransactionDataDTO> retrieveLoanPayments(Long loanId);
|
||||
Collection<LoanRepaymentTransactionData> retrieveLoanPayments(Long loanId);
|
||||
|
||||
LoanAccountSummaryData retrieveSummary(MoneyData principal,
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
||||
Collection<LoanTransactionDataDTO> loanRepayments);
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments);
|
||||
|
||||
LoanPermissionData retrieveLoanPermissions(
|
||||
LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed,
|
||||
|
||||
+9
-9
@@ -17,7 +17,7 @@ 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.LoanTransactionData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionDataDTO;
|
||||
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
|
||||
import org.mifosng.platform.api.data.MoneyData;
|
||||
import org.mifosng.platform.api.data.NewLoanData;
|
||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||
@@ -110,7 +110,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
@Override
|
||||
public LoanAccountSummaryData retrieveSummary(MoneyData principal,
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
||||
Collection<LoanTransactionDataDTO> loanRepayments) {
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments) {
|
||||
|
||||
CurrencyData currencyData = new CurrencyData(
|
||||
principal.getCurrencyCode(), principal.getDefaultName(),
|
||||
@@ -157,7 +157,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
Long waiverType = (long) 4;
|
||||
for (LoanTransactionDataDTO loanRepayment : loanRepayments) {
|
||||
for (LoanRepaymentTransactionData loanRepayment : loanRepayments) {
|
||||
Long transactionType = loanRepayment.getTransactionType().getId();
|
||||
if (transactionType.equals(waiverType)) {
|
||||
totalWaived = totalWaived.add(loanRepayment.getTotal()
|
||||
@@ -179,17 +179,17 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LoanTransactionDataDTO> retrieveLoanPayments(Long loanId) {
|
||||
public Collection<LoanRepaymentTransactionData> retrieveLoanPayments(Long loanId) {
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
LoanPaymentsMapper rm = new LoanPaymentsMapper();
|
||||
|
||||
// retrieve all loan transactions that are not invalid (0) and not
|
||||
// disbursements (1)
|
||||
// disbursements (1) and have not been 'contra'ed by another transaction
|
||||
String sql = "select "
|
||||
+ rm.LoanPaymentsSchema()
|
||||
+ " where tr.loan_id = ? and tr.transaction_type_enum not in (0, 1) order by tr.transaction_date";
|
||||
+ " where tr.loan_id = ? and tr.transaction_type_enum not in (0, 1) and tr.contra_id is null order by tr.transaction_date ASC";
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { loanId });
|
||||
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
@@ -581,7 +581,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
private static final class LoanPaymentsMapper implements
|
||||
RowMapper<LoanTransactionDataDTO> {
|
||||
RowMapper<LoanRepaymentTransactionData> {
|
||||
|
||||
public String LoanPaymentsSchema() {
|
||||
|
||||
@@ -593,7 +593,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoanTransactionDataDTO mapRow(final ResultSet rs,
|
||||
public LoanRepaymentTransactionData mapRow(final ResultSet rs,
|
||||
final int rowNum) throws SQLException {
|
||||
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
@@ -616,7 +616,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
BigDecimal totalBD = rs.getBigDecimal("total");
|
||||
MoneyData total = MoneyData.of(currencyData, totalBD);
|
||||
|
||||
return new LoanTransactionDataDTO(id, transactionType, date, total);
|
||||
return new LoanRepaymentTransactionData(id, transactionType, date, total);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user