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


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final 
JsonCommand command, final Lon
         });
     }
 
+    private static final List<String> 
BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+            .of(new String[] { "transactionDate", "dateFormat", "locale", 
"transactionAmount", "paymentTypeId", "note", "externalId" });
+
+    @Override
+    public void validateBuyDownFee(JsonCommand command, Long loanId) {
+        final String json = command.json();
+        final Type typeOfMap = new TypeToken<Map<String, Object>>() 
{}.getType();
+        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, 
BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+        final DataValidatorBuilder baseDataValidator = new 
DataValidatorBuilder(dataValidationErrors)
+                .resource("loan.transaction.buyDownFee");
+
+        final JsonElement element = this.fromApiJsonHelper.parse(json);
+        final Loan loan = 
this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+        // Validate buy down fee is enabled on loan product
+        if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {
+            
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("buy.down.fee.not.enabled",
+                    "Buy down fee is not enabled for this loan product");
+        }
+
+        // Basic validation
+        validateBuyDownFeeEligibility(loan);
+
+        final LocalDate transactionDate = 
this.fromApiJsonHelper.extractLocalDateNamed("transactionDate", element);
+        
baseDataValidator.reset().parameter("transactionDate").value(transactionDate).notNull();
+
+        // Validate transaction date is on or after first disbursement
+        if (transactionDate != null) {
+            final LocalDate firstDisbursementDate = loan.getDisbursementDate();
+            if (firstDisbursementDate != null && 
transactionDate.isBefore(firstDisbursementDate)) {
+                
baseDataValidator.reset().parameter("transactionDate").failWithCode("cannot.be.before.first.disbursement.date");
+            }
+        }
+
+        final BigDecimal transactionAmount = 
this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("transactionAmount", 
element);
+        
baseDataValidator.reset().parameter("transactionAmount").value(transactionAmount).notNull().positiveAmount();
+
+        throwExceptionIfValidationWarningsExist(dataValidationErrors);
+    }
+
+    public void validateBuyDownFeeEligibility(Loan loan) {
+        if 
(!loan.getLoanProduct().getLoanProductRelatedDetail().isEnableBuyDownFee()) {

Review Comment:
   We should validate against the loan, not the loan product:
   `loan.getLoanProductRelatedDetail()...`
   
   Please do the same for all the below!



##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final 
JsonCommand command, final Lon
         });
     }
 
+    private static final List<String> 
BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+            .of(new String[] { "transactionDate", "dateFormat", "locale", 
"transactionAmount", "paymentTypeId", "note", "externalId" });
+
+    @Override
+    public void validateBuyDownFee(JsonCommand command, Long loanId) {
+        final String json = command.json();
+        final Type typeOfMap = new TypeToken<Map<String, Object>>() 
{}.getType();
+        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, 
BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+        final DataValidatorBuilder baseDataValidator = new 
DataValidatorBuilder(dataValidationErrors)
+                .resource("loan.transaction.buyDownFee");
+
+        final JsonElement element = this.fromApiJsonHelper.parse(json);
+        final Loan loan = 
this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+        // Validate buy down fee is enabled on loan product
+        if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {

Review Comment:
   We should validate against the loan, not the loan product:
   `loan.getLoanProductRelatedDetail()...`
   
   Please do the same for all the below!



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