FINERACT-1760: Enhanced external id support for loan transactions

This commit is contained in:
Adam Saghy
2022-11-26 14:39:36 +01:00
parent 3f0872d1ec
commit a370875ce8
4 changed files with 183 additions and 25 deletions
@@ -91,7 +91,7 @@ public class LoanTransactionData {
private List<LoanRepaymentScheduleInstallmentData> loanRepaymentScheduleInstallments;
// Reverse Data
private String reversalExternalId;
private final ExternalId reversalExternalId;
private LocalDate reversedOnDate;
private List<LoanTransactionRelationData> transactionRelations;
@@ -126,7 +126,7 @@ public class LoanTransactionData {
this.penaltyChargesPortion = null;
this.overpaymentPortion = null;
this.unrecognizedIncomePortion = null;
this.externalId = null;
this.externalId = ExternalId.empty();
this.transfer = null;
this.fixedEmiAmount = null;
this.outstandingLoanBalance = null;
@@ -135,6 +135,7 @@ public class LoanTransactionData {
this.possibleNextRepaymentDate = null;
this.paymentTypeOptions = null;
this.writeOffReasonOptions = null;
this.reversalExternalId = ExternalId.empty();
}
public static LoanTransactionData importInstance(BigDecimal repaymentAmount, LocalDate repaymentDate, Long repaymentTypeId,
@@ -177,7 +178,7 @@ public class LoanTransactionData {
this.penaltyChargesPortion = null;
this.overpaymentPortion = null;
this.unrecognizedIncomePortion = null;
this.externalId = null;
this.externalId = ExternalId.empty();
this.transfer = null;
this.fixedEmiAmount = null;
this.outstandingLoanBalance = null;
@@ -186,6 +187,7 @@ public class LoanTransactionData {
this.possibleNextRepaymentDate = null;
this.paymentTypeOptions = null;
this.writeOffReasonOptions = null;
this.reversalExternalId = ExternalId.empty();
}
public void setNumberOfRepayments(Integer numberOfRepayments) {
@@ -229,8 +231,8 @@ public class LoanTransactionData {
boolean manuallyReversed, Long loanId, String externalLoanId) {
this(id, externalLoanId, officeId, officeName, transactionType, paymentDetailData, currency, date, amount, netDisbursalAmount,
principalPortion, interestPortion, feeChargesPortion, penaltyChargesPortion, overpaymentPortion, unrecognizedIncomePortion,
paymentTypeOptions, externalId, transfer, fixedEmiAmount, outstandingLoanBalance, null, manuallyReversed, null, null,
loanId);
paymentTypeOptions, externalId, transfer, fixedEmiAmount, outstandingLoanBalance, null, manuallyReversed,
ExternalId.empty(), null, loanId);
}
public LoanTransactionData(final Long id, final Long officeId, final String officeName, final LoanTransactionEnumData transactionType,
@@ -239,7 +241,7 @@ public class LoanTransactionData {
final BigDecimal feeChargesPortion, final BigDecimal penaltyChargesPortion, final BigDecimal overpaymentPortion,
final BigDecimal unrecognizedIncomePortion, final ExternalId externalId, final AccountTransferData transfer,
BigDecimal fixedEmiAmount, BigDecimal outstandingLoanBalance, LocalDate submittedOnDate, final boolean manuallyReversed,
final String reversalExternalId, final LocalDate reversedOnDate, Long loanId, String externalLoanId) {
final ExternalId reversalExternalId, final LocalDate reversedOnDate, Long loanId, String externalLoanId) {
this(id, externalLoanId, officeId, officeName, transactionType, paymentDetailData, currency, date, amount, netDisbursalAmount,
principalPortion, interestPortion, feeChargesPortion, penaltyChargesPortion, overpaymentPortion, unrecognizedIncomePortion,
null, externalId, transfer, fixedEmiAmount, outstandingLoanBalance, submittedOnDate, manuallyReversed, reversalExternalId,
@@ -253,7 +255,7 @@ public class LoanTransactionData {
final BigDecimal overpaymentPortion, final BigDecimal unrecognizedIncomePortion,
final Collection<PaymentTypeData> paymentTypeOptions, final ExternalId externalId, final AccountTransferData transfer,
final BigDecimal fixedEmiAmount, BigDecimal outstandingLoanBalance, final LocalDate submittedOnDate,
final boolean manuallyReversed, final String reversalExternalId, final LocalDate reversedOnDate, Long loanId) {
final boolean manuallyReversed, final ExternalId reversalExternalId, final LocalDate reversedOnDate, Long loanId) {
this.id = id;
this.loanId = loanId;
this.externalLoanId = externalLoanId;
@@ -286,10 +288,10 @@ public class LoanTransactionData {
public LoanTransactionData(Long id, LoanTransactionEnumData transactionType, LocalDate date, BigDecimal totalAmount,
BigDecimal netDisbursalAmount, BigDecimal principalPortion, BigDecimal interestPortion, BigDecimal feeChargesPortion,
BigDecimal penaltyChargesPortion, BigDecimal overpaymentPortion, BigDecimal unrecognizedIncomePortion,
BigDecimal outstandingLoanBalance, final boolean manuallyReversed, Long loanId, String externalLoanId) {
BigDecimal outstandingLoanBalance, final boolean manuallyReversed, ExternalId externalId, Long loanId, String externalLoanId) {
this(id, externalLoanId, null, null, transactionType, null, null, date, totalAmount, netDisbursalAmount, principalPortion,
interestPortion, feeChargesPortion, penaltyChargesPortion, overpaymentPortion, unrecognizedIncomePortion, null, null, null,
null, outstandingLoanBalance, null, manuallyReversed, null, null, loanId);
interestPortion, feeChargesPortion, penaltyChargesPortion, overpaymentPortion, unrecognizedIncomePortion, null, externalId,
null, null, outstandingLoanBalance, null, manuallyReversed, ExternalId.empty(), null, loanId);
}
public static LoanTransactionData loanTransactionDataForDisbursalTemplate(final LoanTransactionEnumData transactionType,
@@ -355,6 +357,7 @@ public class LoanTransactionData {
this.submittedOnDate = submittedOnDate;
this.manuallyReversed = manuallyReversed;
this.possibleNextRepaymentDate = possibleNextRepaymentDate;
this.reversalExternalId = ExternalId.empty();
}
public boolean isNotDisbursement() {
@@ -44,6 +44,7 @@ import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
@@ -459,7 +460,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
loanRepaymentScheduleInstallment.getInterestOutstanding(currency).getAmount(),
loanRepaymentScheduleInstallment.getFeeChargesOutstanding(currency).getAmount().subtract(adjustedChargeAmount),
loanRepaymentScheduleInstallment.getPenaltyChargesOutstanding(currency).getAmount(), null, unrecognizedIncomePortion,
paymentOptions, null, null, null, outstandingLoanBalance, false, loanId, loan.getExternalId());
paymentOptions, ExternalId.empty(), null, null, outstandingLoanBalance, false, loanId, loan.getExternalId());
}
private BigDecimal adjustPrepayInstallmentCharge(Loan loan, final LocalDate onDate) {
@@ -496,7 +497,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final BigDecimal outstandingLoanBalance = null;
final BigDecimal unrecognizedIncomePortion = null;
return new LoanTransactionData(null, null, null, transactionType, null, currencyData, waiveOfInterest.getTransactionDate(), amount,
loan.getNetDisbursalAmount(), null, null, null, null, null, null, null, null, outstandingLoanBalance,
loan.getNetDisbursalAmount(), null, null, null, null, null, ExternalId.empty(), null, null, outstandingLoanBalance,
unrecognizedIncomePortion, false, loanId, loan.getExternalId());
}
@@ -508,7 +509,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final LoanTransactionEnumData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WRITEOFF);
final BigDecimal unrecognizedIncomePortion = null;
return new LoanTransactionData(null, null, null, transactionType, null, null, DateUtils.getBusinessLocalDate(), null, null, null,
null, null, null, null, null, null, null, outstandingLoanBalance, unrecognizedIncomePortion, false, null, null);
null, null, null, null, ExternalId.empty(), null, null, outstandingLoanBalance, unrecognizedIncomePortion, false, null,
null);
}
@@ -1374,8 +1376,9 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final BigDecimal unrecognizedIncomePortion = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "unrecognizedIncome");
final BigDecimal outstandingLoanBalance = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "outstandingLoanBalance");
final String externalIdStr = rs.getString("externalId");
final ExternalId externalId = StringUtils.isBlank(externalIdStr) ? ExternalId.empty() : new ExternalId(externalIdStr);
final String reversalExternalId = rs.getString("reversalExternalId");
final ExternalId externalId = ExternalIdFactory.produce(externalIdStr);
final String reversalExternalIdStr = rs.getString("reversalExternalId");
final ExternalId reversalExternalId = ExternalIdFactory.produce(reversalExternalIdStr);
final LocalDate reversedOnDate = JdbcSupport.getLocalDate(rs, "reversedOnDate");
final BigDecimal netDisbursalAmount = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "netDisbursalAmount");
@@ -1873,8 +1876,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
BigDecimal outstandingLoanBalance = null;
final BigDecimal unrecognizedIncomePortion = null;
return new LoanTransactionData(null, null, null, transactionType, null, null, null, loan.getTotalWrittenOff(),
loan.getNetDisbursalAmount(), null, null, null, null, null, unrecognizedIncomePortion, paymentOptions, null, null, null,
outstandingLoanBalance, false, loanId, loan.getExternalId());
loan.getNetDisbursalAmount(), null, null, null, null, null, unrecognizedIncomePortion, paymentOptions, ExternalId.empty(),
null, null, outstandingLoanBalance, false, loanId, loan.getExternalId());
}
@@ -1887,8 +1890,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final List<CodeValueData> writeOffReasonOptions = new ArrayList<>(
this.codeValueReadPlatformService.retrieveCodeValuesByCode(LoanApiConstants.WRITEOFFREASONS));
LoanTransactionData loanTransactionData = new LoanTransactionData(null, null, null, transactionType, null, loan.getCurrency(),
DateUtils.getBusinessLocalDate(), totalOutstanding, loan.getNetDisbursalAmount(), null, null, null, null, null, null, null,
null, null, null, false, loanId, loan.getExternalId());
DateUtils.getBusinessLocalDate(), totalOutstanding, loan.getNetDisbursalAmount(), null, null, null, null, null,
ExternalId.empty(), null, null, null, null, false, loanId, loan.getExternalId());
loanTransactionData.setWriteOffReasonOptions(writeOffReasonOptions);
return loanTransactionData;
}
@@ -2018,8 +2021,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
+ ", tr.amount as total, tr.principal_portion_derived as principal, tr.interest_portion_derived as interest, "
+ " tr.fee_charges_portion_derived as fees, tr.penalty_charges_portion_derived as penalties, "
+ " tr.overpayment_portion_derived as overpayment, tr.outstanding_loan_balance_derived as outstandingLoanBalance, "
+ " tr.unrecognized_income_portion as unrecognizedIncome, tr.loan_id as loanId, l.external_id as externalLoanId from m_loan_transaction tr "
+ " left join m_loan l on tr.loan_id = l.id";
+ " tr.unrecognized_income_portion as unrecognizedIncome, tr.loan_id as loanId, l.external_id as externalLoanId, "
+ " tr.external_id as externalId from m_loan_transaction tr " + " left join m_loan l on tr.loan_id = l.id";
}
@Override
@@ -2040,10 +2043,12 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final BigDecimal overPaymentPortion = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "overpayment");
final BigDecimal unrecognizedIncomePortion = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "unrecognizedIncome");
final BigDecimal outstandingLoanBalance = JdbcSupport.getBigDecimalDefaultToZeroIfNull(rs, "outstandingLoanBalance");
final String externalIdStr = rs.getString("externalId");
final ExternalId externalId = ExternalIdFactory.produce(externalIdStr);
return new LoanTransactionData(id, transactionType, date, totalAmount, null, principalPortion, interestPortion,
feeChargesPortion, penaltyChargesPortion, overPaymentPortion, unrecognizedIncomePortion, outstandingLoanBalance, false,
loanId, externalLoanId);
externalId, loanId, externalLoanId);
}
}
@@ -2283,7 +2288,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
loanRepaymentScheduleInstallment.getInterestOutstanding(currency).getAmount(),
loanRepaymentScheduleInstallment.getFeeChargesOutstanding(currency).getAmount(),
loanRepaymentScheduleInstallment.getPenaltyChargesOutstanding(currency).getAmount(), null, unrecognizedIncomePortion,
paymentTypeOptions, null, null, null, outstandingLoanBalance, isReversed, loanId, loan.getExternalId());
paymentTypeOptions, ExternalId.empty(), null, null, outstandingLoanBalance, isReversed, loanId, loan.getExternalId());
}
private static final class CurrencyMapper implements RowMapper<CurrencyData> {