adamsaghy commented on code in PR #5294:
URL: https://github.com/apache/fineract/pull/5294#discussion_r2682192622
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -134,12 +137,111 @@ 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 =
buildLoanApplicationTerms(loanProductRelatedDetail,
firstDisbursedPeriodStartDate,
+ disbursedAmount, mc);
+
+ final ProgressiveLoanInterestScheduleModel
temporaryReAgedScheduleModel =
generateTemporaryScheduleModelWithParticularDisbursementDate(
+ loanApplicationTerms, mc, firstDisbursedPeriodStartDate,
disbursementDate);
+
+ mergeNewInterestScheduleModelWithExistingOne(scheduleModel,
temporaryReAgedScheduleModel, operation);
+ }
+
+ private LoanApplicationTerms buildLoanApplicationTerms(final
ILoanConfigurationDetails loanProductRelatedDetail,
Review Comment:
Use `ToBuilder` instead and update the 3 fields that are different on it and
let the Lombok handle the rest.
--
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]