Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
import org.apache.fineract.client.models.GetUsersUserIdResponse;
import org.apache.fineract.client.models.LoanTransactionData;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest;
Expand Down Expand Up @@ -631,10 +631,10 @@ public void adjustNthRepayment(String nthItemStr, String transactionDate, String

public Double getLoanTransactionAmountToPayOff(PostLoansResponse loanResponse, String transactionDate) {
long loanId1 = loanResponse.getLoanId();
GetLoansLoanIdTransactionsTemplateResponse response = ok(
LoanTransactionData response = ok(
() -> fineractClient.loanTransactions().retrieveTemplateLoanTransaction(loanId1, Map.<String, Object>of("command",
"prepayLoan", "dateFormat", DATE_FORMAT, "transactionDate", transactionDate, "locale", DEFAULT_LOCALE)));
return response.getAmount();
return response.getAmount() != null ? response.getAmount().doubleValue() : null;
}

@When("Loan Pay-off is made on {string}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class LoanTransactionsApiResource {
+ "\n" + "loans/1/transactions/template?command=charge-off" + "\n" + "loans/1/transactions/template?command=downPayment" + "\n"
+ "loans/1/transactions/template?command=interest-refund")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanTransactionsApiResourceSwagger.GetLoansLoanIdTransactionsTemplateResponse.class))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanTransactionData.class))) })
public String retrieveTransactionTemplate(@PathParam("loanId") @Parameter(description = "loanId", required = true) final Long loanId,
@QueryParam("command") @Parameter(description = "command") final String commandParam, @Context final UriInfo uriInfo,
@QueryParam("dateFormat") @Parameter(description = "dateFormat") final String rawDateFormat,
Expand Down Expand Up @@ -162,7 +162,7 @@ public String retrieveTransactionTemplate(@PathParam("loanId") @Parameter(descri
+ "\n" + "loans/1/transactions/template?command=charge-off" + "\n" + "loans/1/transactions/template?command=downPayment" + "\n"
+ "loans/1/transactions/template?command=interest-refund")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanTransactionsApiResourceSwagger.GetLoansLoanIdTransactionsTemplateResponse.class))) })
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanTransactionData.class))) })
public String retrieveTransactionTemplate(
@PathParam("loanExternalId") @Parameter(description = "loanExternalId", required = true) final String loanExternalId,
@QueryParam("command") @Parameter(description = "command") final String commandParam, @Context final UriInfo uriInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private PostSavingsCharges() {}
public String locale;
@Schema(example = "5.0")
public Double nominalAnnualInterestRate;
@Schema(example = "10000.0")
public BigDecimal minRequiredOpeningBalance;
@Schema(example = "1")
public Integer interestCompoundingPeriodType;
@Schema(example = "4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public void testBuildRequestFromQueryParametersTypeConversion(String fieldName,
// then
assertThat(result).isNotNull();
Object actualValue = getFieldValue(result, fieldName);
if (expectedValue instanceof BigDecimal) {
assertThat((BigDecimal) actualValue).isEqualByComparingTo((BigDecimal) expectedValue);
if (expectedValue instanceof BigDecimal expectedValueAsBigDecimal) {
assertThat((BigDecimal) actualValue).isEqualByComparingTo(expectedValueAsBigDecimal);
} else {
assertThat(actualValue).isEqualTo(expectedValue);
}
Expand Down Expand Up @@ -240,22 +240,15 @@ public void testBuildRequestFromQueryParametersWithClassWithoutBuilder() {
}

private Object getFieldValue(TestRequest request, String fieldName) {
switch (fieldName) {
case "stringField":
return request.getStringField();
case "integerField":
return request.getIntegerField();
case "longField":
return request.getLongField();
case "bigDecimalField":
return request.getBigDecimalField();
case "doubleField":
return request.getDoubleField();
case "booleanField":
return request.getBooleanField();
default:
return null;
}
return switch (fieldName) {
case "stringField" -> request.getStringField();
case "integerField" -> request.getIntegerField();
case "longField" -> request.getLongField();
case "bigDecimalField" -> request.getBigDecimalField();
case "doubleField" -> request.getDoubleField();
case "booleanField" -> request.getBooleanField();
default -> null;
};
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public void testGetLastUserTransaction() {
when(loanTransaction4.isNotReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction4.isAccrual()).thenReturn(Boolean.FALSE);
when(loanTransaction4.isAccrualAdjustment()).thenReturn(Boolean.TRUE);
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction, loanTransaction2, loanTransaction3));
ReflectionTestUtils.setField(loan, "loanTransactions",
List.of(loanTransaction, loanTransaction2, loanTransaction3, loanTransaction4));
final LoanTransaction userTransaction = loan.getLastUserTransaction();
assertNotNull(userTransaction);
assertEquals(loanTransaction2, userTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
import org.apache.fineract.client.models.LoanProduct;
import org.apache.fineract.client.models.LoanTransactionData;
import org.apache.fineract.client.models.PaymentAllocationOrder;
import org.apache.fineract.client.models.PostClientsResponse;
import org.apache.fineract.client.models.PostCreateRescheduleLoansRequest;
Expand Down Expand Up @@ -278,8 +278,8 @@ public void uc2() {
assertTrue(loanDetails.getStatus().getOverpaid());

// Loan Repayment (after) Overpaid
GetLoansLoanIdTransactionsTemplateResponse transactionAfter = loanTransactionHelper
.retrieveTransactionTemplate(loanResponse.getLoanId(), "repayment", DATETIME_PATTERN, "15 February 2023", LOCALE);
LoanTransactionData transactionAfter = loanTransactionHelper.retrieveTransactionTemplate(loanResponse.getLoanId(), "repayment",
DATETIME_PATTERN, "15 February 2023", LOCALE);
assertNotNull(transactionAfter);
});
}
Expand Down Expand Up @@ -350,8 +350,8 @@ public void uc3() {
assertTrue(loanDetails.getStatus().getOverpaid());

// Loan Repayment (after) Overpaid
GetLoansLoanIdTransactionsTemplateResponse transactionAfter = loanTransactionHelper
.retrieveTransactionTemplate(loanResponse.getLoanId(), "repayment", DATETIME_PATTERN, "15 February 2023", LOCALE);
LoanTransactionData transactionAfter = loanTransactionHelper.retrieveTransactionTemplate(loanResponse.getLoanId(), "repayment",
DATETIME_PATTERN, "15 February 2023", LOCALE);
assertNotNull(transactionAfter);
});
}
Expand Down Expand Up @@ -487,14 +487,14 @@ public void repaymentTemplateReturnsNextUnpaidInstallmentAmount() {
// Repayment template must point to installment 3 (next unpaid), not installment 2 (fully paid)
// Before the fix, this would return 0.0 because the query always picked the lowest installment
// number with outstanding balance, which after partial repayment could be a fully satisfied one
final GetLoansLoanIdTransactionsTemplateResponse transactionTemplate = loanTransactionHelper
.retrieveTransactionTemplate(loanResponse.getLoanId(), "repayment", DATETIME_PATTERN, "16 January 2023", LOCALE);
final LoanTransactionData transactionTemplate = loanTransactionHelper.retrieveTransactionTemplate(loanResponse.getLoanId(),
"repayment", DATETIME_PATTERN, "16 January 2023", LOCALE);
assertNotNull(transactionTemplate);
assertEquals(125.0, transactionTemplate.getAmount());
assertEquals(125.0, transactionTemplate.getPrincipalPortion());
assertEquals(0.0, transactionTemplate.getInterestPortion());
assertEquals(0.0, transactionTemplate.getFeeChargesPortion());
assertEquals(0.0, transactionTemplate.getPenaltyChargesPortion());
assertEquals(125.0, transactionTemplate.getAmount().doubleValue());
assertEquals(125.0, transactionTemplate.getPrincipalPortion().doubleValue());
assertEquals(0.0, transactionTemplate.getInterestPortion().doubleValue());
assertEquals(0.0, transactionTemplate.getFeeChargesPortion().doubleValue());
assertEquals(0.0, transactionTemplate.getPenaltyChargesPortion().doubleValue());
});
}

Expand Down Expand Up @@ -5933,22 +5933,22 @@ public void uc153() {
.externalId(transactionExternalId).chargeOffReasonId((long) chargeOffReasonId));

// Loan Prepayment (before) Charge-Off transaction - With Interest Recalculation
GetLoansLoanIdTransactionsTemplateResponse transactionBefore = loanTransactionHelper
.retrieveTransactionTemplate(createdLoanId.get(), "prepayLoan", "dd MMMM yyyy", "15 February 2024", "en");
assertEquals(88.88, transactionBefore.getAmount());
assertEquals(86.11, transactionBefore.getPrincipalPortion());
assertEquals(2.77, transactionBefore.getInterestPortion());
assertEquals(0.00, transactionBefore.getFeeChargesPortion());
assertEquals(0.00, transactionBefore.getPenaltyChargesPortion());
LoanTransactionData transactionBefore = loanTransactionHelper.retrieveTransactionTemplate(createdLoanId.get(), "prepayLoan",
"dd MMMM yyyy", "15 February 2024", "en");
assertEquals(88.88, transactionBefore.getAmount().doubleValue());
assertEquals(86.11, transactionBefore.getPrincipalPortion().doubleValue());
assertEquals(2.77, transactionBefore.getInterestPortion().doubleValue());
assertEquals(0.00, transactionBefore.getFeeChargesPortion().doubleValue());
assertEquals(0.00, transactionBefore.getPenaltyChargesPortion().doubleValue());

// Loan Prepayment (after) Charge-Off transaction - WithOut Interest Recalculation
GetLoansLoanIdTransactionsTemplateResponse transactionAfter = loanTransactionHelper
.retrieveTransactionTemplate(createdLoanId.get(), "prepayLoan", "dd MMMM yyyy", "01 March 2024", "en");
assertEquals(104.67, transactionAfter.getAmount());
assertEquals(86.11, transactionAfter.getPrincipalPortion());
assertEquals(18.56, transactionAfter.getInterestPortion());
assertEquals(0.00, transactionAfter.getFeeChargesPortion());
assertEquals(0.00, transactionAfter.getPenaltyChargesPortion());
LoanTransactionData transactionAfter = loanTransactionHelper.retrieveTransactionTemplate(createdLoanId.get(), "prepayLoan",
"dd MMMM yyyy", "01 March 2024", "en");
assertEquals(104.67, transactionAfter.getAmount().doubleValue());
assertEquals(86.11, transactionAfter.getPrincipalPortion().doubleValue());
assertEquals(18.56, transactionAfter.getInterestPortion().doubleValue());
assertEquals(0.00, transactionAfter.getFeeChargesPortion().doubleValue());
assertEquals(0.00, transactionAfter.getPenaltyChargesPortion().doubleValue());
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdStatus;
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTemplateResponse;
import org.apache.fineract.client.models.JournalEntryTransactionItem;
import org.apache.fineract.client.models.LoanApprovedAmountHistoryData;
import org.apache.fineract.client.models.LoanPointInTimeData;
import org.apache.fineract.client.models.LoanTransactionData;
import org.apache.fineract.client.models.PaymentAllocationOrder;
import org.apache.fineract.client.models.PostChargesResponse;
import org.apache.fineract.client.models.PostLoanProductsRequest;
Expand Down Expand Up @@ -283,14 +283,14 @@ protected void verifyLoanStatus(GetLoansLoanIdResponse loanDetails, Function<Get
Assertions.assertTrue(actualValue);
}

protected GetLoansLoanIdTransactionsTemplateResponse getPrepayAmount(Long loanId, String date) {
protected LoanTransactionData getPrepayAmount(Long loanId, String date) {
return ok(fineractClient().loanTransactions.retrieveTemplateLoanTransaction(loanId, "prepayLoan", DATETIME_PATTERN, date, "en",
null));
}

protected Long verifyPrepayAmountByRepayment(Long loanId, String date) {
GetLoansLoanIdTransactionsTemplateResponse prepayAmount = getPrepayAmount(loanId, date);
Double amountToPrepayLoan = prepayAmount.getAmount();
LoanTransactionData prepayAmount = getPrepayAmount(loanId, date);
Double amountToPrepayLoan = prepayAmount.getAmount() != null ? prepayAmount.getAmount().doubleValue() : null;
Long repaymentId = null;
if (amountToPrepayLoan != null && amountToPrepayLoan > 0) {
PostLoansLoanIdTransactionsResponse repayment = loanTransactionHelper.makeLoanRepayment(loanId, "repayment", date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@Slf4j
@ExtendWith(LoanTestLifecycleExtension.class)
public class BlockTransactionsOnClosedOverpaidLoansTest {

private ResponseSpecification responseSpec;
Expand Down Expand Up @@ -79,7 +82,7 @@ public void testTransactionsOnOverpaidLoan() {
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);

final Integer loanProductID = createLoanProduct();
final Integer loanID = applyForLoanApplication(clientID, loanProductID, "1000", "01 January 2024");
final Integer loanID = createLoanApplication(clientID, loanProductID, "1000", "01 January 2024");

this.loanTransactionHelper.approveLoan("01 January 2024", loanID);
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("01 January 2024", loanID, "1000");
Expand Down Expand Up @@ -116,7 +119,7 @@ public void testTransactionsOnClosedLoan() {

final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
final Integer loanProductID = createLoanProduct();
final Integer loanID = applyForLoanApplication(clientID, loanProductID, "1000", "01 January 2024");
final Integer loanID = createLoanApplication(clientID, loanProductID, "1000", "01 January 2024");

this.loanTransactionHelper.approveLoan("01 January 2024", loanID);
this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("01 January 2024", loanID, "1000");
Expand Down Expand Up @@ -165,7 +168,7 @@ private Integer createLoanProduct() {
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
}

private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, String principal, String submitDate) {
private Integer createLoanApplication(final Integer clientID, final Integer loanProductID, String principal, String submitDate) {
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
.withPrincipal(principal) //
.withLoanTermFrequency("4") //
Expand Down
Loading
Loading