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


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java:
##########
@@ -2394,4 +2405,44 @@ private void validatePartialPeriodSupport(final Integer 
interestCalculationPerio
 
         }
     }
+
+    public void fixedLengthValidations(final String 
transactionProcessingStrategyCode, final LoanApplicationTerms 
loanApplicationTerms,
+            final JsonElement element, final DataValidatorBuilder 
baseDataValidator) {
+        fixedLengthValidations(transactionProcessingStrategyCode, 
loanApplicationTerms.getAnnualNominalInterestRate(),
+                loanApplicationTerms.getNumberOfRepayments(), element, 
baseDataValidator);
+    }
+
+    public void fixedLengthValidations(final String 
transactionProcessingStrategyCode, final BigDecimal interestRatePerPeriod,
+            final Integer numberOfRepayments, final JsonElement element, final 
DataValidatorBuilder baseDataValidator) {
+        if 
(this.fromApiJsonHelper.parameterExists(LoanProductConstants.FIXED_LENGTH, 
element)) {
+            final JsonObject topLevelJsonElement = element.getAsJsonObject();
+            final Locale locale = 
this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
+            final Integer fixedLength = 
this.fromApiJsonHelper.extractIntegerNamed(LoanProductConstants.FIXED_LENGTH, 
element, locale);
+            
baseDataValidator.reset().parameter(LoanProductConstants.FIXED_LENGTH).value(fixedLength).ignoreIfNull()
+                    .integerGreaterThanZero();
+
+            if (fixedLength != null) {
+                if 
(!AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
+                        .equals(transactionProcessingStrategyCode)) {
+                    final String errorMsg = "Fixed Length configuration is 
only allowed with "
+                            + 
AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
 + " stratefy";
+                    throw new 
GeneralPlatformDomainRuleException("error.msg.fixed.length.only.supported.for.advanced.payment.allocation",
+                            errorMsg, 
AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY);
+                }
+
+                if (interestRatePerPeriod.compareTo(BigDecimal.ZERO) > 0) {
+                    final String errorMsg = "Fixed Length configuration is 
only allowed for zero interest products";
+                    throw new 
GeneralPlatformDomainRuleException("error.msg.fixed.length.only.supported.for.zero.interest",
 errorMsg,
+                            interestRatePerPeriod);
+                }
+
+                if (fixedLength != null && 
numberOfRepayments.compareTo(fixedLength) > 0) {

Review Comment:
   This is incorrect...
   Example which should work:
   - number of repayments: 3
   - Repay every: 15 DAYS
   - Fixed term length: 40 days



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