adamsaghy commented on code in PR #5180:
URL: https://github.com/apache/fineract/pull/5180#discussion_r2577232343


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionData.java:
##########
@@ -124,6 +124,11 @@ public class LoanTransactionData implements Serializable {
     private Collection<CodeValueData> reAmortizationReasonOptions = null;
     private Collection<StringEnumOptionData> 
reAmortizationInterestHandlingOptions = null;
 
+    private Integer numberOfFutureInstallments;

Review Comment:
   Current business date is missing.



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java:
##########
@@ -1728,16 +1729,57 @@ public LoanTransactionData 
retrieveLoanWriteoffTemplate(final Long loanId) {
 
     @Override
     public LoanTransactionData retrieveLoanReAgeTemplate(final Long loanId) {
-        final LoanAccountData loan = this.retrieveOne(loanId);
+        final Loan loan = 
this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
         final LoanTransactionEnumData transactionType = 
LoanEnumerations.transactionType(LoanTransactionType.REAGE);
         final BigDecimal totalOutstanding = loan.getSummary() != null ? 
loan.getSummary().getTotalOutstanding() : null;
         final List<CodeValueData> reAgeReasonOptions = new ArrayList<>(
                 
codeValueReadPlatformService.retrieveCodeValuesByCode(LoanApiConstants.REAGE_REASONS));
-        return 
LoanTransactionData.builder().type(transactionType).currency(loan.getCurrency()).date(DateUtils.getBusinessLocalDate())
-                
.amount(totalOutstanding).netDisbursalAmount(loan.getNetDisbursalAmount()).loanId(loanId)
-                
.externalLoanId(loan.getExternalId()).periodFrequencyOptions(CommonEnumerations.BASIC_PERIOD_FREQUENCY_TYPES)
-                .reAgeReasonOptions(reAgeReasonOptions)
-                
.reAgeInterestHandlingOptions(LoanReAgeInterestHandlingType.getValuesAsEnumOptionDataList()).build();
+
+        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+        final List<LoanRepaymentScheduleInstallment> installments = 
loan.getRepaymentScheduleInstallments();
+
+        int futureInstallmentCount = 0;
+        int pastInstallmentCount = 0;
+        LocalDate nextInstallmentDueDate = null;
+
+        for (LoanRepaymentScheduleInstallment installment : installments) {
+            LocalDate dueDate = installment.getDueDate();
+            if (DateUtils.isAfter(dueDate, businessDate)) {
+                futureInstallmentCount++;
+                if (nextInstallmentDueDate == null || 
DateUtils.isBefore(dueDate, nextInstallmentDueDate)) {
+                    nextInstallmentDueDate = dueDate;
+                }
+            } else {
+                pastInstallmentCount++;
+            }
+        }
+
+        final PeriodFrequencyType frequencyType = 
loan.getLoanRepaymentScheduleDetail().getRepaymentPeriodFrequencyType();
+        final LocalDate calculatedStartDate = 
calculateReAgeStartDate(businessDate, frequencyType);
+
+        final CurrencyData currencyData = new 
CurrencyData(loan.getCurrencyCode(), null, 
loan.getCurrency().getDigitsAfterDecimal(),
+                loan.getCurrency().getInMultiplesOf(), null, null);
+
+        return 
LoanTransactionData.builder().type(transactionType).currency(currencyData).date(businessDate).amount(totalOutstanding)
+                
.netDisbursalAmount(loan.getNetDisbursalAmount()).loanId(loanId).externalLoanId(loan.getExternalId())
+                
.periodFrequencyOptions(CommonEnumerations.BASIC_PERIOD_FREQUENCY_TYPES).reAgeReasonOptions(reAgeReasonOptions)
+                
.reAgeInterestHandlingOptions(LoanReAgeInterestHandlingType.getValuesAsEnumOptionDataList())
+                
.numberOfFutureInstallments(futureInstallmentCount).numberOfPastInstallments(pastInstallmentCount)
+                
.nextInstallmentDueDate(nextInstallmentDueDate).calculatedStartDate(calculatedStartDate).build();
+    }
+
+    private LocalDate calculateReAgeStartDate(LocalDate businessDate, 
PeriodFrequencyType frequencyType) {
+        if (frequencyType == null) {
+            return null;
+        }
+        // Per PS-2795: calculated start date = current date + 1 unit of 
original frequency type
+        return switch (frequencyType) {
+            case DAYS -> businessDate.plusDays(1);

Review Comment:
   Hardcoded 1 is incorrect. The frequency number should be used!



-- 
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]

Reply via email to