FINERACT-2098: Currency data needed in loan transaction for UI

This commit is contained in:
Jose Alberto Hernandez
2024-07-03 09:54:28 +02:00
committed by Adam Saghy
parent b482fbd447
commit f17a0965db
6 changed files with 68 additions and 19 deletions
@@ -76,6 +76,29 @@ final class LoanTransactionsApiResourceSwagger {
@Schema(example = "[2009, 8, 1]")
public LocalDate date;
public GetLoansTotal total;
@Schema(example = "200.000000")
public Double amount;
public GetLoanCurrency currency;
}
public static final class GetLoanCurrency {
private GetLoanCurrency() {}
@Schema(example = "UGX")
public String code;
@Schema(example = "Uganda Shilling")
public String name;
@Schema(example = "2")
public Integer decimalPlaces;
@Schema(example = "USh")
public String displaySymbol;
@Schema(example = "currency.UGX")
public String nameCode;
@Schema(example = "Uganda Shilling (USh)")
public String displayLabel;
}
@Schema(description = "GetLoansLoanIdTransactionsTransactionIdResponse")
@@ -20,10 +20,13 @@ package org.apache.fineract.portfolio.loanaccount.data;
import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Getter;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
/**
* Immutable data object representing a loan transaction.
*/
@Getter
public class LoanApprovalData {
private final LocalDate approvalDate;
@@ -36,6 +39,7 @@ public class LoanApprovalData {
private String dateFormat;
private String locale;
private transient Integer rowIndex;
private CurrencyData currency;
public static LoanApprovalData importInstance(LocalDate approvedOnDate, Integer rowIndex, String locale, String dateFormat) {
return new LoanApprovalData(approvedOnDate, rowIndex, locale, dateFormat);
@@ -52,22 +56,12 @@ public class LoanApprovalData {
this.netDisbursalAmount = null;
}
public LoanApprovalData(final BigDecimal approvalAmount, final LocalDate approvalDate, final BigDecimal netDisbursalAmount) {
public LoanApprovalData(final BigDecimal approvalAmount, final LocalDate approvalDate, final BigDecimal netDisbursalAmount,
final CurrencyData currency) {
this.approvalDate = approvalDate;
this.approvalAmount = approvalAmount;
this.netDisbursalAmount = netDisbursalAmount;
}
public LocalDate getApprovalDate() {
return this.approvalDate;
}
public BigDecimal getApprovalAmount() {
return this.approvalAmount;
}
public BigDecimal getNetDisbursalAmount() {
return this.netDisbursalAmount;
this.currency = currency;
}
}
@@ -300,14 +300,13 @@ public class LoanTransactionData {
public static LoanTransactionData loanTransactionDataForDisbursalTemplate(final LoanTransactionEnumData transactionType,
final LocalDate expectedDisbursedOnLocalDateForTemplate, final BigDecimal disburseAmountForTemplate,
final BigDecimal netDisbursalAmount, final Collection<PaymentTypeData> paymentOptions, final BigDecimal retriveLastEmiAmount,
final LocalDate possibleNextRepaymentDate) {
final LocalDate possibleNextRepaymentDate, final CurrencyData currency) {
final Long id = null;
final Long loanId = null;
final ExternalId externalLoanId = ExternalId.empty();
final Long officeId = null;
final String officeName = null;
final PaymentDetailData paymentDetailData = null;
final CurrencyData currency = null;
final BigDecimal unrecognizedIncomePortion = null;
final BigDecimal principalPortion = null;
final BigDecimal interestPortion = null;
@@ -44,6 +44,26 @@ final class LoansApiResourceSwagger {
public Double approvalAmount;
@Schema(example = "200.000000")
public Double netDisbursalAmount;
public GetLoanCurrency currency;
}
public static final class GetLoanCurrency {
private GetLoanCurrency() {}
@Schema(example = "UGX")
public String code;
@Schema(example = "Uganda Shilling")
public String name;
@Schema(example = "2")
public Integer decimalPlaces;
@Schema(example = "USh")
public String displaySymbol;
@Schema(example = "currency.UGX")
public String nameCode;
@Schema(example = "Uganda Shilling (USh)")
public String displayLabel;
}
@Schema(description = "GetLoansTemplateResponse")
@@ -539,7 +539,9 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
@Override
public LoanApprovalData retrieveApprovalTemplate(final Long loanId) {
final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
return new LoanApprovalData(loan.getProposedPrincipal(), DateUtils.getBusinessLocalDate(), loan.getNetDisbursalAmount());
final ApplicationCurrency appCurrency = applicationCurrencyRepository.findOneWithNotFoundDetection(loan.getCurrency());
return new LoanApprovalData(loan.getProposedPrincipal(), DateUtils.getBusinessLocalDate(), loan.getNetDisbursalAmount(),
appCurrency.toData());
}
@Override
@@ -550,11 +552,10 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
if (paymentDetailsRequired) {
paymentOptions = this.paymentTypeReadPlatformService.retrieveAllPaymentTypes();
}
final ApplicationCurrency appCurrency = applicationCurrencyRepository.findOneWithNotFoundDetection(loan.getCurrency());
return LoanTransactionData.loanTransactionDataForDisbursalTemplate(transactionType,
loan.getExpectedDisbursedOnLocalDateForTemplate(), loan.getDisburseAmountForTemplate(), loan.getNetDisbursalAmount(),
paymentOptions, loan.retriveLastEmiAmount(), loan.getNextPossibleRepaymentDateForRescheduling());
paymentOptions, loan.retriveLastEmiAmount(), loan.getNextPossibleRepaymentDateForRescheduling(), appCurrency.toData());
}
@Override
@@ -45,6 +45,7 @@ import org.apache.fineract.client.models.GetLoansApprovalTemplateResponse;
import org.apache.fineract.client.models.GetLoansLoanIdChargesChargeIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdChargesTemplateResponse;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
import org.apache.fineract.client.models.PostClientsResponse;
import org.apache.fineract.client.models.PostDelinquencyBucketResponse;
@@ -900,12 +901,23 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
assertEquals(actualDate, loanApprovalResult.getApprovalDate());
assertEquals(1000.0, loanApprovalResult.getApprovalAmount());
assertEquals(1000.0, loanApprovalResult.getNetDisbursalAmount());
assertNotNull(loanApprovalResult.getCurrency());
assertNotNull(loanApprovalResult.getCurrency().getCode());
assertEquals("USD", loanApprovalResult.getCurrency().getCode());
GetLoansLoanIdResponse loanDetailsResult = this.loanTransactionHelper.getLoanDetails(loanExternalIdStr);
assertEquals(loanExternalIdStr, loanDetailsResult.getExternalId());
this.loanTransactionHelper.approveLoan("02 September 2022", loanId);
String txnExternalIdStr = UUID.randomUUID().toString();
GetLoansLoanIdTransactionsTemplateResponse disburseTemplate = this.loanTransactionHelper
.retrieveTransactionTemplate(loanExternalIdStr, "disburse", null, null, null);
assertEquals(1000.0, disburseTemplate.getAmount());
assertNotNull(disburseTemplate.getCurrency());
assertNotNull(disburseTemplate.getCurrency().getCode());
assertEquals("USD", disburseTemplate.getCurrency().getCode());
final HashMap disbursedLoanResult = this.loanTransactionHelper.disburseLoan("03 September 2022", loanId, "1000",
txnExternalIdStr);