Skip to content

Commit

Permalink
FINERACT-1958: Rework down-payment calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Sep 22, 2023
1 parent 0927c8e commit fecc391
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public final class LoanApplicationTerms {
private RepaymentStartDateType repaymentStartDateType;
private LocalDate submittedOnDate;
private boolean isScheduleExtensionForDownPaymentDisabled;
private Money disbursedPrincipal;

public static LoanApplicationTerms assembleFrom(final ApplicationCurrency currency, final Integer loanTermFrequency,
final PeriodFrequencyType loanTermPeriodFrequencyType, final Integer numberOfRepayments, final Integer repaymentEvery,
Expand Down Expand Up @@ -379,6 +380,7 @@ private LoanApplicationTerms(final ApplicationCurrency currency, final Integer l
this.allowPartialPeriodInterestCalcualtion = allowPartialPeriodInterestCalcualtion;

this.principal = principal;
this.disbursedPrincipal = principal;
this.expectedDisbursementDate = expectedDisbursementDate;
this.repaymentsStartingFromDate = repaymentsStartingFromDate;
this.calculatedRepaymentsStartingFromDate = calculatedRepaymentsStartingFromDate;
Expand Down Expand Up @@ -680,7 +682,7 @@ private Money calculateTotalFlatInterestDueWithoutGrace(final PaymentPeriodsInOn
switch (this.interestMethod) {
case FLAT:
final BigDecimal interestRateForLoanTerm = calculateFlatInterestRateForLoanTerm(calculator, mc);
totalInterestDue = this.principal.minus(totalPrincipalAccountedForInterestCalcualtion)
totalInterestDue = this.disbursedPrincipal.minus(totalPrincipalAccountedForInterestCalcualtion)
.multiplyRetainScale(interestRateForLoanTerm, mc.getRoundingMode());

break;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void uc1() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -179,7 +179,7 @@ public void uc2() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -251,7 +251,7 @@ public void uc3() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -324,7 +324,7 @@ public void uc4() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -416,7 +416,7 @@ public void uc5() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -505,7 +505,7 @@ public void uc7() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -592,7 +592,7 @@ public void uc8() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -683,7 +683,7 @@ public void uc9() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -757,7 +757,7 @@ public void uc10() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -845,7 +845,7 @@ public void uc11() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -910,7 +910,7 @@ public void uc12() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -984,7 +984,7 @@ public void uc13() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public void uc14() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1162,7 +1162,7 @@ public void uc15() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1249,7 +1249,7 @@ public void uc17a() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1310,7 +1310,7 @@ public void uc17b() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1371,7 +1371,7 @@ public void uc17c() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1432,7 +1432,7 @@ public void uc18() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.20").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1531,7 +1531,7 @@ public void uc24() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.20").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down Expand Up @@ -1650,7 +1650,7 @@ public void uc25() {
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName())
.date("2023.02.20").dateFormat("yyyy.MM.dd").locale("en"));

final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 60, 15, 4, 0,
final PostLoansResponse loanResponse = applyForLoanApplication(client.getClientId(), commonLoanProductId, 500L, 45, 15, 3, 0,
"01 January 2023", "01 January 2023");

loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
import org.apache.http.HttpStatus;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -121,6 +122,11 @@ public void setup() {
GlobalConfigurationHelper.updateIsAutomaticExternalIdGenerationEnabled(this.requestSpec, this.responseSpec, true);
}

@AfterEach
public void postActions() {
GlobalConfigurationHelper.updateIsAutomaticExternalIdGenerationEnabled(this.requestSpec, this.responseSpec, false);
}

/**
* Tests for the unimplemented command Strategies by returning 501 status code. For a unknownRequest a statusCode
* 501 is returned back with response.
Expand Down
Loading

0 comments on commit fecc391

Please sign in to comment.