Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -30,6 +30,7 @@
import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdRequest;
import org.apache.fineract.test.data.workingcapitalproduct.DefaultWorkingCapitalLoanProduct;
import org.apache.fineract.test.data.workingcapitalproduct.WorkingCapitalLoanProductResolver;
import org.apache.fineract.test.helper.BusinessDateHelper;
import org.apache.fineract.test.helper.Utils;
import org.springframework.stereotype.Component;

Expand All @@ -38,6 +39,7 @@
public class WorkingCapitalLoanRequestFactory {

private final WorkingCapitalLoanProductResolver workingCapitalLoanProductResolver;
private final BusinessDateHelper businessDateHelper;

public static final String DATE_FORMAT = "dd MMMM yyyy";
public static final String DEFAULT_LOCALE = "en";
Expand Down Expand Up @@ -135,8 +137,12 @@ public PutWorkingCapitalLoansLoanIdDiscountRequest defaultWorkingCapitalLoanUpda
}

public PutWorkingCapitalLoansLoanIdRateRequest defaultWorkingCapitalLoanUpdateRateRequest() {
// effectiveDate is mandatory; defaulted to the business date so a scenario that does not care about the date
// reads as "change the rate now", and one that does simply overrides it.
return new PutWorkingCapitalLoansLoanIdRateRequest() //
.periodPaymentRate(DEFAULT_PAYMENT_RATE) //
.locale(DEFAULT_LOCALE); //
.effectiveDate(FORMATTER.format(businessDateHelper.getBusinessLocalDate())) //
.locale(DEFAULT_LOCALE) //
.dateFormat(DATE_FORMAT); //
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.apache.fineract.client.feign.util.FeignCalls.ok;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -69,6 +70,14 @@ public BusinessDateUpdateRequest defaultBusinessDateRequest() {
.locale(DEFAULT_LOCALE);
}

/**
* The business date as a date, for requests that have to state one. {@link #getBusinessDate()} returns the whole
* response rendered as a string, which is only good for logging.
*/
public LocalDate getBusinessLocalDate() {
return ok(() -> fineractClient.businessDateManagement().getBusinessDate(BUSINESS_DATE, Map.of())).getDate();
}

public String getBusinessDate() {
log.debug("Getting business date (using Feign)");
BusinessDateResponse response = ok(() -> fineractClient.businessDateManagement().getBusinessDate(BUSINESS_DATE, Map.of()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ public void verifyRetrievedPaymentDetailsByPaymentNo(final DataTable dataTable)
assertNullableDecimal(assertions, p + "expectedDiscountFeeBalance", actual.getExpectedDiscountFeeBalance(),
expected.get("expectedDiscountFeeBalance"));
}
if (expected.containsKey("actualPaymentAmount")) {
assertNullableDecimal(assertions, p + "actualPaymentAmount", actual.getActualPaymentAmount(),
expected.get("actualPaymentAmount"));
}
if (expected.containsKey("actualBalance")) {
assertNullableDecimal(assertions, p + "actualBalance", actual.getActualBalance(), expected.get("actualBalance"));
}
if (expected.containsKey("actualAmortizationAmount")) {
assertNullableDecimal(assertions, p + "actualAmortizationAmount", actual.getActualAmortizationAmount(),
expected.get("actualAmortizationAmount"));
}
if (expected.containsKey("actualDiscountFeeBalance")) {
assertNullableDecimal(assertions, p + "actualDiscountFeeBalance", actual.getActualDiscountFeeBalance(),
expected.get("actualDiscountFeeBalance"));
}
}

assertions.assertAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,31 @@ public void adminAddWorkingCapitalPeriodPaymentRate(String periodPaymentRate) {
checkWorkingCapitalPeriodPaymentRate(loanId, periodPaymentRate);
}

@When("Admin update Working Capital period payment rate with {string} value effective from {string}")
public void adminAddWorkingCapitalPeriodPaymentRateEffectiveFrom(final String periodPaymentRate, final String effectiveDate) {
final PostWorkingCapitalLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.getLoanId();

PutWorkingCapitalLoansLoanIdRateRequest rateChangeRequest = workingCapitalLoanRequestFactory
.defaultWorkingCapitalLoanUpdateRateRequest().periodPaymentRate(new BigDecimal(periodPaymentRate))
.effectiveDate(effectiveDate);

final CommandProcessingResult rateChangeResponse = ok(
() -> fineractClient.workingCapitalLoans().updateWorkingCapitalLoanRateById(loanId, rateChangeRequest));

testContext().set(TestContextKey.WORKING_CAPITAL_LOAN_RATE_CHANGE_ID, rateChangeResponse.getResourceId());
assertThat(rateChangeResponse.getChanges()).isNotNull();
// Deliberately no assertion on the loan's rate here: a future-dated change does not move it, and a backdated
// one
// moves it only when nothing later supersedes it. Assert that separately where the expected value is known.
}

@Then("Working Capital Loan period payment rate is {string}")
public void workingCapitalLoanPeriodPaymentRateIs(final String periodPaymentRate) {
final PostWorkingCapitalLoansResponse loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
checkWorkingCapitalPeriodPaymentRate(loanResponse.getLoanId(), periodPaymentRate);
}

@When("Admin update Working Capital period payment rate with {string} value by externalId")
public void adminAddWorkingCapitalPeriodPaymentRateByExternalId(String periodPaymentRate) {
final Long loanId = getCreatedLoanId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ Feature: WorkingCapitalAmortizationSchedule

@TestRailId:C78826
Scenario: Generate and retrieve a projected amortization schedule with 200 payments with update period payment rate in a middle of loan lifecycle - UC2
When Admin sets the business date to "01 January 2026"
When Admin sets the business date to "01 January 2019"
And Admin creates a client with random data
And Admin creates a working capital loan with the following data:
| LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPaymentVolume | periodPaymentRate | discount |
| WCLP | 01 January 2026 | 01 January 2026 | 100 | 100 | 18 | 0 |
Then Admin successfully approves the working capital loan on "01 January 2026" with "100" amount and expected disbursement date on "01 January 2026"
Then Admin successfully disburse the Working Capital loan on "01 January 2026" with "100" EUR transaction amount
| WCLP | 01 January 2019 | 01 January 2019 | 9000 | 100000 | 18 | |
Then Admin successfully approves the working capital loan on "01 January 2019" with "9000" amount and expected disbursement date on "01 January 2019"
Then Admin successfully disburse the Working Capital loan on "01 January 2019" with "9000" EUR transaction amount
Then Working Capital loan status will be "ACTIVE"
When Admin generates a projected amortization schedule with discountFeeAmount 1000.0, netDisbursementAmount 9000.0, totalPaymentVolume 100000.0, periodPaymentRate 18, npvDayCount 360, expectedDisbursementDate "2019-01-01"
Then Admin successfully add discount with "1000" amount on Working Capital loan account
And Admin retrieves the projected amortization schedule
Then The retrieved amortization schedule has the following summary fields:
| discountFeeAmount | netDisbursementAmount | totalPaymentVolume | periodPaymentRate | npvDayCount | expectedPaymentAmount | originalPaymentNumber |
Expand Down Expand Up @@ -436,7 +436,7 @@ Feature: WorkingCapitalAmortizationSchedule
| 198 | 2019-07-18 | 50.00 | 99.84 | 0.16 | | | 0.17 | | |
| 199 | 2019-07-19 | 50.00 | 49.95 | 0.11 | | | 0.06 | | |
| 200 | 2019-07-20 | 50.00 | 0.00 | 0.06 | | | 0.00 | | |
When Admin sets the business date to "25 January 2026"
When Admin sets the business date to "25 January 2019"
And Admin runs inline COB job for Working Capital Loan by loanId
And Admin update Working Capital period payment rate with "17" value
And Admin retrieves the projected amortization schedule
Expand Down Expand Up @@ -682,19 +682,19 @@ Feature: WorkingCapitalAmortizationSchedule
| 212 | 2019-08-01 | 36.58 | 0.00 | 0.00 | 0.00 |

Scenario: Generate a projected amortization schedule matching reference - UC4
When Admin sets the business date to "01 January 2026"
When Admin sets the business date to "01 January 2019"
And Admin creates a client with random data
And Admin creates a working capital loan with the following data:
| LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPaymentVolume | periodPaymentRate | discount |
| WCLP | 01 January 2026 | 01 January 2026 | 100 | 100 | 18 | 0 |
Then Admin successfully approves the working capital loan on "01 January 2026" with "100" amount and expected disbursement date on "01 January 2026"
Then Admin successfully disburse the Working Capital loan on "01 January 2026" with "100" EUR transaction amount
| WCLP | 01 January 2019 | 01 January 2019 | 9000 | 100000 | 18 | |
Then Admin successfully approves the working capital loan on "01 January 2019" with "9000" amount and expected disbursement date on "01 January 2019"
Then Admin successfully disburse the Working Capital loan on "01 January 2019" with "9000" EUR transaction amount
Then Working Capital loan status will be "ACTIVE"
When Admin generates a projected amortization schedule with discountFeeAmount 1000.0, netDisbursementAmount 9000.0, totalPaymentVolume 100000.0, periodPaymentRate 18, npvDayCount 360, expectedDisbursementDate "2019-01-01"
When Admin sets the business date to "25 January 2026"
Then Admin successfully add discount with "1000" amount on Working Capital loan account
When Admin sets the business date to "25 January 2019"
And Admin runs inline COB job for Working Capital Loan by loanId
And Admin update Working Capital period payment rate with "17" value
When Admin sets the business date to "01 February 2026"
When Admin sets the business date to "01 February 2019"
And Admin runs inline COB job for Working Capital Loan by loanId
And Admin update Working Capital period payment rate with "20" value
And Admin retrieves the projected amortization schedule
Expand Down
Loading
Loading