in component-test/src/main/java/org/apache/fineract/cn/portfolio/TestAccountingInteractionInLoanWorkflow.java [429:489]
public void workflowWithOneLateRepayment() throws InterruptedException {
final LocalDateTime today = midnightToday();
step1CreateProduct();
step2CreateCase();
step3OpenCase(today);
step4ApproveCase(today);
final List<PlannedPayment> plannedPayments = individualLending.getPaymentScheduleForCaseStream(
product.getIdentifier(),
customerCase.getIdentifier(),
null)
.collect(Collectors.toList());
step5Disburse(
BigDecimal.valueOf(2_000_00, MINOR_CURRENCY_UNIT_DIGITS),
today,
UPPER_RANGE_DISBURSEMENT_FEE_ID,
BigDecimal.valueOf(20_00, MINOR_CURRENCY_UNIT_DIGITS),
BigDecimal.ZERO,
AccountingFixture.CUSTOMERS_DEPOSIT_ACCOUNT);
int week = 0;
final int weekOfLateRepayment = 3;
while (expectedCurrentPrincipal.compareTo(BigDecimal.ZERO) > 0) {
logger.info("Simulating week {}. Expected current balance {}.", week, expectedCurrentPrincipal);
if (week == weekOfLateRepayment) {
final BigDecimal lateFee = BigDecimal.valueOf(15_36, MINOR_CURRENCY_UNIT_DIGITS); //??? TODO: check the late fee value.
step6CalculateInterestAndCheckForLatenessForRangeOfDays(
today,
(week * 7) + 1,
(week + 1) * 7 + 2,
7,
lateFee);
final BigDecimal nextRepaymentAmount = findNextRepaymentAmount(today.plusDays((week + 1) * 7 + 2));
step7PaybackPartialAmount(
nextRepaymentAmount,
today.plusDays((week + 1) * 7 + 2),
lateFee,
nextRepaymentAmount,
AccountingFixture.CUSTOMERS_DEPOSIT_ACCOUNT);
}
else {
step6CalculateInterestAndCheckForLatenessForWeek(today, week);
final BigDecimal nextRepaymentAmount = findNextRepaymentAmount(today.plusDays((week + 1) * 7));
final Payment payment = step7PaybackPartialAmount(
nextRepaymentAmount,
today.plusDays((week + 1) * 7),
BigDecimal.ZERO,
nextRepaymentAmount,
AccountingFixture.CUSTOMERS_DEPOSIT_ACCOUNT);
final BigDecimal interestAccrual = payment.getBalanceAdjustments().remove(AccountDesignators.INTEREST_ACCRUAL); //Don't compare these with planned payment.
final BigDecimal customerLoanInterest = payment.getBalanceAdjustments().remove(AccountDesignators.CUSTOMER_LOAN_INTEREST);
Assert.assertEquals(interestAccrual.negate(), customerLoanInterest);
//Assert.assertEquals(plannedPayments.get(week+1).getPayment(), payment);
}
week++;
}
step8Close(DateConverter.fromIsoString(plannedPayments.get(plannedPayments.size()-1).getPayment().getDate()));
}