Aman-Mittal commented on code in PR #5294:
URL: https://github.com/apache/fineract/pull/5294#discussion_r2675375198
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -134,12 +137,97 @@ private void addDisbursement(final
ProgressiveLoanInterestScheduleModel schedule
scheduleModel.repaymentPeriods().stream().filter(rp ->
!operation.getSubmittedOnDate().isAfter(rp.getFromDate()))
.forEach(rp ->
rp.setTotalDisbursedAmount(rp.getTotalDisbursedAmount().add(operation.getAmount())));
- scheduleModel
-
.changeOutstandingBalanceAndUpdateInterestPeriods(operation.getSubmittedOnDate(),
operation.getAmount(),
- scheduleModel.zero(), scheduleModel.zero())
- .ifPresent((repaymentPeriod) ->
calculateEMIValueAndRateFactors(
- getEffectiveRepaymentDueDate(scheduleModel,
repaymentPeriod, operation.getSubmittedOnDate()), scheduleModel,
- operation));
+ final int numberOfRepayments =
scheduleModel.loanProductRelatedDetail().getNumberOfRepayments();
+ if
(scheduleModel.loanProductRelatedDetail().isAllowFullTermForTranche() &&
numberOfRepayments > 0) {
+ addFullTermTrancheDisbursement(scheduleModel, operation);
+ } else {
+ scheduleModel
+
.changeOutstandingBalanceAndUpdateInterestPeriods(operation.getSubmittedOnDate(),
operation.getAmount(),
+ scheduleModel.zero(), scheduleModel.zero())
+ .ifPresent((repaymentPeriod) ->
calculateEMIValueAndRateFactors(
+ getEffectiveRepaymentDueDate(scheduleModel,
repaymentPeriod, operation.getSubmittedOnDate()), scheduleModel,
+ operation));
+ }
+ }
+
+ private void addFullTermTrancheDisbursement(final
ProgressiveLoanInterestScheduleModel scheduleModel,
+ final EmiChangeOperation operation) {
+ final MathContext mc = scheduleModel.mc();
+ final LocalDate disbursementDate = operation.getSubmittedOnDate();
+ final Money disbursedAmount = operation.getAmount();
+ final ILoanConfigurationDetails loanProductRelatedDetail =
scheduleModel.loanProductRelatedDetail();
+ final Optional<RepaymentPeriod> firstDisbursedPeriod =
scheduleModel.repaymentPeriods().stream()
+ .filter(period ->
isInPeriodFromInclusiveToExclusive(disbursementDate, period.getFromDate(),
period.getDueDate()))
+ .findFirst();
+ final LocalDate firstDisbursedPeriodStartDate =
firstDisbursedPeriod.isPresent() ? firstDisbursedPeriod.get().getFromDate()
+ : scheduleModel.getMaturityDate();
+
+ final LoanApplicationTerms loanApplicationTerms = new
LoanApplicationTerms.Builder()
Review Comment:
I think this LoanAplicationBuilder Logic must be extracted to an new helper
function. So that it is easier to read.
and group this chaining maybe like this
// Loan basics
.currency(...)
.principal(...)
.repaymentsStartingFromDate(...)
// Term & frequency
.loanTermFrequency(...)
.numberOfRepayments(...)
.repaymentEvery(...)
.repaymentPeriodFrequencyType(...)
// Interest configuration
.interestRatePerPeriod(...)
.annualNominalInterestRate(...)
.interestRatePeriodFrequencyType(...)
.interestMethod(...)
// Day count conventions
.daysInMonthType(...)
.daysInYearType(...)
.daysInYearCustomStrategy(...)
// Flags & options
.isDownPaymentEnabled(false)
.allowPartialPeriodInterestCalculation(...)
// Technical
.mc(mc)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]