You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org> on 2026/03/30 12:00:12 UTC
[PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
oleksii-novikov-onix opened a new pull request, #5718:
URL: https://github.com/apache/fineract/pull/5718
## 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!
- [ ] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
- [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
- [ ] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made.
- [ ] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
- [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
- [ ] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute).
Your assigned reviewer(s) will follow our [guidelines for code reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5718:
URL: https://github.com/apache/fineract/pull/5718#discussion_r3043949669
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDelinquencyRangeScheduleServiceImpl.java:
##########
@@ -175,26 +188,103 @@ private LocalDate calculateToDate(LocalDate fromDate, Integer frequency, Delinqu
};
}
- private BigDecimal calculateExpectedAmount(WorkingCapitalLoan loan, DelinquencyMinimumPaymentPeriodAndRule rule) {
- BigDecimal minimumPayment = rule.getMinimumPayment();
+ private BigDecimal calculateExpectedAmount(final WorkingCapitalLoan loan, final DelinquencyMinimumPaymentPeriodAndRule rule,
+ final WorkingCapitalLoanDelinquencyAction rescheduleOverride) {
+ final BigDecimal principal = loan.getApprovedPrincipal();
+ if (principal == null) {
+ return BigDecimal.ZERO;
+ }
+ if (rescheduleOverride != null) {
+ return MathUtil.percentageOf(principal, rescheduleOverride.getMinimumPayment(), MathContext.DECIMAL128);
Review Comment:
Expected amount should be Money, We cannot have more precision than the relevant currency allows!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5718:
URL: https://github.com/apache/fineract/pull/5718#discussion_r3044256004
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDelinquencyRangeScheduleServiceImpl.java:
##########
@@ -175,26 +188,103 @@ private LocalDate calculateToDate(LocalDate fromDate, Integer frequency, Delinqu
};
}
- private BigDecimal calculateExpectedAmount(WorkingCapitalLoan loan, DelinquencyMinimumPaymentPeriodAndRule rule) {
- BigDecimal minimumPayment = rule.getMinimumPayment();
+ private BigDecimal calculateExpectedAmount(final WorkingCapitalLoan loan, final DelinquencyMinimumPaymentPeriodAndRule rule,
+ final WorkingCapitalLoanDelinquencyAction rescheduleOverride) {
+ final BigDecimal principal = loan.getApprovedPrincipal();
+ if (principal == null) {
+ return BigDecimal.ZERO;
+ }
+ if (rescheduleOverride != null) {
+ return MathUtil.percentageOf(principal, rescheduleOverride.getMinimumPayment(), MathContext.DECIMAL128);
+ }
+ final BigDecimal minimumPayment = rule.getMinimumPayment();
if (minimumPayment == null) {
return BigDecimal.ZERO;
}
if (DelinquencyMinimumPaymentType.FLAT.equals(rule.getMinimumPaymentType())) {
return minimumPayment;
}
- BigDecimal principal = loan.getApprovedPrincipal();
- if (principal == null) {
- return BigDecimal.ZERO;
- }
BigDecimal discount = loan.getLoanProductRelatedDetails() != null ? loan.getLoanProductRelatedDetails().getDiscount() : null;
BigDecimal base = discount != null ? principal.add(discount) : principal;
return MathUtil.percentageOf(base, minimumPayment, MathContext.DECIMAL128);
}
+ private Optional<WorkingCapitalLoanDelinquencyAction> findLatestRescheduleAction(final Long loanId) {
+ return actionRepository.findTopByWorkingCapitalLoanIdAndActionOrderByIdDesc(loanId, DelinquencyAction.RESCHEDULE);
+ }
+
+ @Override
+ public void rescheduleMinimumPayment(final WorkingCapitalLoan loan, final WorkingCapitalLoanDelinquencyAction rescheduleAction) {
+ final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+ final BigDecimal newExpectedAmount = calculateExpectedAmount(loan, null, rescheduleAction);
+ final Integer newFrequency = rescheduleAction.getFrequency();
+ final DelinquencyFrequencyType newFreqType = rescheduleAction.getFrequencyType();
+
+ final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = repository.findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+
+ WorkingCapitalLoanDelinquencyRangeSchedule currentPeriod = null;
+ final List<WorkingCapitalLoanDelinquencyRangeSchedule> futurePeriods = new ArrayList<>();
+
+ for (final WorkingCapitalLoanDelinquencyRangeSchedule period : periods) {
+ if (period.getMinPaymentCriteriaMet() != null) {
+ continue;
+ }
+ final boolean isCurrent = !period.getFromDate().isAfter(businessDate) && !period.getToDate().isBefore(businessDate);
+ final boolean isFuture = period.getFromDate().isAfter(businessDate);
+
+ if (isCurrent) {
+ currentPeriod = period;
+ period.setExpectedAmount(newExpectedAmount);
+ period.setOutstandingAmount(newExpectedAmount.subtract(period.getPaidAmount()).max(BigDecimal.ZERO));
+ } else if (isFuture) {
+ futurePeriods.add(period);
+ }
+ }
+
+ repository.deleteAll(futurePeriods);
Review Comment:
We should rather update existing once, not delete and recreate...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5718:
URL: https://github.com/apache/fineract/pull/5718#discussion_r3044292157
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/domain/WorkingCapitalLoanDelinquencyAction.java:
##########
@@ -51,7 +53,17 @@ public class WorkingCapitalLoanDelinquencyAction extends AbstractAuditableWithUT
@Column(name = "start_date", nullable = false)
private LocalDate startDate;
- @Column(name = "end_date", nullable = false)
+ @Column(name = "end_date")
private LocalDate endDate;
+ @Column(name = "minimum_payment", scale = 6, precision = 19)
+ private BigDecimal minimumPayment;
Review Comment:
We should allow to change the `DelinquencyMinimumPaymentType` as well if we are already allow to change the `DelinquencyFrequencyType`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5718:
URL: https://github.com/apache/fineract/pull/5718#discussion_r3044265477
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDelinquencyRangeScheduleServiceImpl.java:
##########
@@ -175,26 +188,103 @@ private LocalDate calculateToDate(LocalDate fromDate, Integer frequency, Delinqu
};
}
- private BigDecimal calculateExpectedAmount(WorkingCapitalLoan loan, DelinquencyMinimumPaymentPeriodAndRule rule) {
- BigDecimal minimumPayment = rule.getMinimumPayment();
+ private BigDecimal calculateExpectedAmount(final WorkingCapitalLoan loan, final DelinquencyMinimumPaymentPeriodAndRule rule,
+ final WorkingCapitalLoanDelinquencyAction rescheduleOverride) {
+ final BigDecimal principal = loan.getApprovedPrincipal();
+ if (principal == null) {
+ return BigDecimal.ZERO;
+ }
+ if (rescheduleOverride != null) {
+ return MathUtil.percentageOf(principal, rescheduleOverride.getMinimumPayment(), MathContext.DECIMAL128);
+ }
+ final BigDecimal minimumPayment = rule.getMinimumPayment();
if (minimumPayment == null) {
return BigDecimal.ZERO;
}
if (DelinquencyMinimumPaymentType.FLAT.equals(rule.getMinimumPaymentType())) {
return minimumPayment;
}
- BigDecimal principal = loan.getApprovedPrincipal();
- if (principal == null) {
- return BigDecimal.ZERO;
- }
BigDecimal discount = loan.getLoanProductRelatedDetails() != null ? loan.getLoanProductRelatedDetails().getDiscount() : null;
BigDecimal base = discount != null ? principal.add(discount) : principal;
return MathUtil.percentageOf(base, minimumPayment, MathContext.DECIMAL128);
}
+ private Optional<WorkingCapitalLoanDelinquencyAction> findLatestRescheduleAction(final Long loanId) {
+ return actionRepository.findTopByWorkingCapitalLoanIdAndActionOrderByIdDesc(loanId, DelinquencyAction.RESCHEDULE);
+ }
+
+ @Override
+ public void rescheduleMinimumPayment(final WorkingCapitalLoan loan, final WorkingCapitalLoanDelinquencyAction rescheduleAction) {
+ final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+ final BigDecimal newExpectedAmount = calculateExpectedAmount(loan, null, rescheduleAction);
+ final Integer newFrequency = rescheduleAction.getFrequency();
+ final DelinquencyFrequencyType newFreqType = rescheduleAction.getFrequencyType();
+
+ final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = repository.findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+
+ WorkingCapitalLoanDelinquencyRangeSchedule currentPeriod = null;
+ final List<WorkingCapitalLoanDelinquencyRangeSchedule> futurePeriods = new ArrayList<>();
+
+ for (final WorkingCapitalLoanDelinquencyRangeSchedule period : periods) {
+ if (period.getMinPaymentCriteriaMet() != null) {
+ continue;
+ }
+ final boolean isCurrent = !period.getFromDate().isAfter(businessDate) && !period.getToDate().isBefore(businessDate);
+ final boolean isFuture = period.getFromDate().isAfter(businessDate);
+
+ if (isCurrent) {
+ currentPeriod = period;
+ period.setExpectedAmount(newExpectedAmount);
+ period.setOutstandingAmount(newExpectedAmount.subtract(period.getPaidAmount()).max(BigDecimal.ZERO));
+ } else if (isFuture) {
+ futurePeriods.add(period);
+ }
+ }
+
+ repository.deleteAll(futurePeriods);
+ repository.flush();
+
+ if (currentPeriod != null) {
+ repository.saveAndFlush(currentPeriod);
+ regenerateFuturePeriods(loan, currentPeriod, newExpectedAmount, newFrequency, newFreqType);
+ }
+
+ evaluateExpiredPeriods(loan, businessDate);
+
+ log.debug("Rescheduled delinquency range schedule for WC loan {}: new minimumPayment={}%, frequency={} {}", loan.getId(),
+ rescheduleAction.getMinimumPayment(), newFrequency, newFreqType);
+ }
+
+ private void regenerateFuturePeriods(final WorkingCapitalLoan loan, final WorkingCapitalLoanDelinquencyRangeSchedule currentPeriod,
+ final BigDecimal expectedAmount, final Integer frequency, final DelinquencyFrequencyType frequencyType) {
+ final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+ int periodNumber = currentPeriod.getPeriodNumber();
+ LocalDate fromDate = currentPeriod.getToDate().plusDays(1);
+
+ while (!fromDate.isAfter(businessDate)) {
+ final LocalDate toDate = calculateToDate(fromDate, frequency, frequencyType);
+ periodNumber++;
+
+ final WorkingCapitalLoanDelinquencyRangeSchedule period = new WorkingCapitalLoanDelinquencyRangeSchedule();
Review Comment:
We should introduce versioning to avoid concurrent modifications.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #5718:
URL: https://github.com/apache/fineract/pull/5718#issuecomment-4205689680
@oleksii-novikov-onix Please rebase
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #5718:
URL: https://github.com/apache/fineract/pull/5718#issuecomment-4212570301
@oleksii-novikov-onix Please rebase
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2455: WC delinquency RESCHEDULE action to change minimum payment amount and frequency [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #5718:
URL: https://github.com/apache/fineract/pull/5718
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org