budaidev commented on code in PR #5771:
URL: https://github.com/apache/fineract/pull/5771#discussion_r3225215875
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanAmortizationScheduleWriteServiceImpl.java:
##########
@@ -180,21 +183,56 @@ public RepaymentAmortizationData applyRepayment(final
WorkingCapitalLoan loan, f
private BigDecimal sumRunningNpv(final ProjectedAmortizationScheduleModel
model) {
final MathContext mc = MoneyHelper.getMathContext();
BigDecimal result = BigDecimal.ZERO;
- for (ProjectedPayment payment : model.payments()) {
+ for (ProjectedPayment payment : model.projectedPayments()) {
if (payment.paymentNo() > 0 && payment.npvValue() != null &&
payment.npvValue().getAmount() != null) {
result = result.add(payment.npvValue().getAmount(), mc);
}
}
return result;
}
- private MonetaryCurrency resolveCurrency(final WorkingCapitalLoan loan) {
+ @Override
+ public void regenerateAmortizationScheduleOnRateChange(final
WorkingCapitalLoan loan, final BigDecimal newRate) {
+ Validate.notNull(loan, "loan must not be null");
+ Validate.notNull(newRate, "newRate must not be null");
+
+ final MathContext mc = MoneyHelper.getMathContext();
+ final CurrencyData currency = resolveCurrency(loan);
+ final ProjectedAmortizationScheduleModel model =
scheduleRepositoryWrapper.readModel(loan.getId(), mc, currency)
+ .orElseThrow(() -> new IllegalStateException("Projected
amortization schedule is not found for loan " + loan.getId()));
+
+ final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+ final LocalDate loanDisbursementDate =
resolveLoanDisbursementDate(loan);
+ final int splitDayIndex = (int)
ChronoUnit.DAYS.between(loanDisbursementDate, businessDate);
+ final LocalDate modelRateChangeDate =
model.expectedDisbursementDate().plusDays(splitDayIndex);
+
+ model.clearLastRateSegment();
+
+ calculator.applyRateChange(model, newRate, modelRateChangeDate);
+
+ scheduleRepositoryWrapper.writeModel(loan, model);
+ }
+
+ private LocalDate resolveLoanDisbursementDate(final WorkingCapitalLoan
loan) {
+ if (loan.getDisbursementDetails() != null &&
!loan.getDisbursementDetails().isEmpty()) {
+ final WorkingCapitalLoanDisbursementDetails detail =
loan.getDisbursementDetails().getFirst();
+ if (detail.getActualDisbursementDate() != null) {
+ return detail.getActualDisbursementDate();
+ }
+ if (detail.getExpectedDisbursementDate() != null) {
+ return detail.getExpectedDisbursementDate();
Review Comment:
fixed
--
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]