FINERACT-2455: Add WC near-breach evaluation business step#5849
FINERACT-2455: Add WC near-breach evaluation business step#5849oleksii-novikov-onix wants to merge 2 commits into
Conversation
galovics
left a comment
There was a problem hiding this comment.
I'm not convinced CREDIT_BALANCE_REFUND should be in REDUCING_TRANSACTION_TYPES here.
A CREDIT_BALANCE_REFUND is the bank returning an overpayment to the borrower - money leaving the loan, not an inbound payment. Summing it in paidInWindow would make the borrower appear to have paid more than they actually did, and could suppress a near-breach trigger that should have fired. None of the e2e scenarios exercise this path, so a bug here would go undetected.
Wouldn't it make more sense to only count REPAYMENT and GOODWILL_CREDIT? (And worth a double-check on GOODWILL_CREDIT too - that's a bank-side write-off, not a borrower payment, though at least it goes the right direction.)
a743639 to
9ca4f57
Compare
|
@galovics Thanks, I removed CREDIT_BALANCE_REFUND |
9ca4f57 to
55cc88c
Compare
55cc88c to
ff9bfb2
Compare
ff9bfb2 to
0546770
Compare
| final BigDecimal requiredCumulative = thresholdFraction.multiply(BigDecimal.valueOf(index + 1L), MoneyHelper.getMathContext()) | ||
| .multiply(period.getMinPaymentAmount(), MoneyHelper.getMathContext()); |
There was a problem hiding this comment.
We can extract this calculation into a method for better readability + please use Money object for appropriate rounding and number of digist after decimal point.
| anyPassed = true; | ||
| final BigDecimal requiredCumulative = thresholdFraction.multiply(BigDecimal.valueOf(index + 1L), MoneyHelper.getMathContext()) | ||
| .multiply(period.getMinPaymentAmount(), MoneyHelper.getMathContext()); | ||
| final BigDecimal paidCumulative = transactionRepository.sumPaymentsInWindow(loanId, period.getFromDate(), evalDate, |
There was a problem hiding this comment.
Please use Money object for appropriate rounding and number of digist after decimal point.
| final boolean isDisbursed = input.getDisbursementDetails().stream() | ||
| .map(WorkingCapitalLoanDisbursementDetails::getActualDisbursementDate).anyMatch(Objects::nonNull); | ||
| if (!isDisbursed) { | ||
| log.debug("Skipping near breach evaluation for WC loan {} - not yet disbursed", input.getId()); | ||
| return input; | ||
| } |
There was a problem hiding this comment.
Please use the WorkingCapitalLoan.loanStatus instead.
| private final WorkingCapitalLoanNearBreachEvaluationService nearBreachEvaluationService; | ||
|
|
||
| @Override | ||
| public WorkingCapitalLoan execute(final WorkingCapitalLoan input) { |
There was a problem hiding this comment.
I would rename input field to something more relevant, like: "loan".
| } | ||
|
|
||
| final LocalDate businessDate = DateUtils.getBusinessLocalDate(); | ||
| nearBreachEvaluationService.evaluateNearBreach(input, businessDate.plusDays(1L)); |
There was a problem hiding this comment.
why to increase the date by 1? COB date is the date on we evaluate the near-breach, am i missing something?
| AND t.reversed = false | ||
| AND t.transactionType IN :reducingTypes | ||
| """) | ||
| BigDecimal sumPaymentsInWindow(@Param("loanId") Long loanId, @Param("fromDate") LocalDate fromDate, @Param("toDate") LocalDate toDate, |
There was a problem hiding this comment.
We dont need this. Paid amount is available on the breach schedule already.
| @Override | ||
| public void evaluateBreachAndNearBreach(final WorkingCapitalLoan loan, final LocalDate businessDate) { | ||
| public void evaluateBreach(final WorkingCapitalLoan loan, final LocalDate businessDate) { | ||
| final List<WorkingCapitalLoanBreachSchedule> allPeriods = repository.findByLoanIdOrderByPeriodNumberAsc(loan.getId()); |
There was a problem hiding this comment.
I dont think we need all periods. Fetch only the (one) relevant by business date, please
0546770 to
eef3043
Compare
eef3043 to
406aa0e
Compare
406aa0e to
2801210
Compare
Description
Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
Your assigned reviewer(s) will follow our guidelines for code reviews.