Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-1971: N plus one installment loan reschedule #3651

Conversation

ruchiD
Copy link
Contributor

@ruchiD ruchiD commented Dec 22, 2023

Description

Modifications for N+1 installment for loan reschedule for cumulative loan schedule generator.
Tests

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 https://github.com/apache/fineract/#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 for verifying the changes made.

  • Follow coding conventions at 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

  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

LoanScheduleModelPeriod lastInstallment = periods.get(periods.size() - 1);
// get end date for the schedule from loan charges
LocalDate scheduleDueDate = null;
if (!(BigDecimal.ZERO.compareTo(loanApplicationTerms.getAnnualNominalInterestRate()) < 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please simplify this condition?
Negating whether annual nominal interest rate is higher than 0 is not easy to read.

Also interest rate cannot be negative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However i am not fully sure why does it matter whether there is interest or not...

Copy link
Contributor Author

@ruchiD ruchiD Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Adam, here i tried to mimic the condition we have for add charge scenario in LoanChargeWritePlatformServiceImpl->addCharge, where for n+1 case we are checking whether the loan is interest bearing or not.

final Collection<LoanTermVariationsData> interestRates = loanApplicationTerms.getLoanTermVariations()
.getInterestRateChanges();

LocalDate periodStartDateApplicableForInterest = calculateInterestStartDateForPeriod(loanApplicationTerms,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we need to calculate interest after maturity date. @bharathc27 Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bharathc27 Please comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruchiD As discussed there is not interest calculcation involved for N+1 Installment that is after the maturity date.

N+1 Installment scenario happens only for 2 cases

  1. for charges - here user entered amount will be the installment amount
  2. for Charge-backs- here amounts are inherited from the repayment that charge-back was triggered from.

@adamsaghy cc

@@ -410,6 +410,10 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe
scheduleParams.addTotalCumulativeInterest(totalInterest);
}

// add charges only repayment schedule for charges with due date after maturity date (N+1)
addChargesOnlyRepaymentSchedule(currency, scheduleParams, periods, loanCharges, mc, loanApplicationTerms, transactions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only needed for cumulative loans? What about progressive ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required for progressive ones also, but since interest handling, reschedule, prepayment and related stories for progressive schedule handling are pending i did not changed for progressive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean if a progressive N+1 loan got rescheduled the N+1 charge will disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test and confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsaghy, verified with latest, for progressive loans also N+1 installment vanishes after reschedule.

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please kindly review my comments!

@ruchiD ruchiD marked this pull request as draft January 4, 2024 13:14
@ruchiD ruchiD force-pushed the FINERACT-1971-N-plus-one-installment-loan-reschedule branch from be51f75 to 6bce7e3 Compare January 17, 2024 11:04
@ruchiD ruchiD marked this pull request as ready for review January 17, 2024 11:04
@ruchiD
Copy link
Contributor Author

ruchiD commented Jan 17, 2024

Made changes to Loan Repayment schedule transaction processors for adding N+1 installments, for loan reschedule cases.

@@ -78,6 +79,7 @@ public ChangedTransactionDetail reprocessLoanTransactions(final LocalDate disbur
}
}
}
addChargeOnlyRepaymentInstallmentIfRequired(charges, installments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really understand why we need this here.
I am assuming when we are reprocessing the transactions, the installments list containing all the installments including the N+1... no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsaghy, when reschedule happens N+1 installment is not created/retained for loan installments and hence the issue. When reprocess is called after schedule regeneration we are adding the missing installment if required.

if (!CollectionUtils.isEmpty(charges) && !CollectionUtils.isEmpty(installments)) {
LoanRepaymentScheduleInstallment latestRepaymentScheduleInstalment = installments.get(installments.size() - 1);
LocalDate installmentDueDate = null;
for (final LoanCharge loanCharge : charges) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charges are a set, there is no order how you are iterating through on it, and it can happen multiple charges are after the last installment due date, no?

I would be happier if we were taking the latest charge which was after the maturity date and set that one instead of iterating though on them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Will make this change.

@ruchiD ruchiD force-pushed the FINERACT-1971-N-plus-one-installment-loan-reschedule branch from 6bce7e3 to e90abc9 Compare January 18, 2024 09:49
Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamsaghy adamsaghy merged commit 89c3dc3 into apache:develop Jan 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants