logoutdhaval commented on a change in pull request #2215:
URL: https://github.com/apache/fineract/pull/2215#discussion_r840739741



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/data/SavingsAccountTransactionDataValidator.java
##########
@@ -232,25 +232,68 @@ public SavingsAccountTransaction 
validateHoldAndAssembleForm(final String json,
             
baseDataValidator.reset().parameter(SavingsApiConstants.statusParamName)
                     
.failWithCodeNoParameterAddedToErrorCode(SavingsApiConstants.ERROR_MSG_SAVINGS_ACCOUNT_NOT_ACTIVE);
         }
-        account.holdAmount(amount);
 
-        if (account.getEnforceMinRequiredBalance()) {
-            if (account.getWithdrawableBalance().compareTo(BigDecimal.ZERO) < 
0) {
-                
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient 
balance", account.getId());
+        Boolean isEnforceMinRequiredBalanceEnabled = 
account.getEnforceMinRequiredBalance();
+        Boolean isAccountLienEnabled = account.isLienAllowed();
+        Boolean isOverdraftEnabled = account.isAllowOverdraft();
+
+        Boolean lienAllowed = false;
+        if (this.fromApiJsonHelper.parameterExists(lienAllowedParamName, 
element)) {
+            lienAllowed = 
this.fromApiJsonHelper.extractBooleanNamed(lienAllowedParamName, element);
+            if (lienAllowed) {
+                if (isAccountLienEnabled) {
+                    if (isOverdraftEnabled) {
+                        if 
(account.getOverdraftLimit().compareTo(BigDecimal.ZERO) > 0
+                                && 
account.getMaxAllowedLienLimit().compareTo(BigDecimal.ZERO) > 0) {
+                            if 
(account.getOverdraftLimit().compareTo(account.getMaxAllowedLienLimit()) > 0) {
+                                
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
+                                        
"Overdraft.limit.can.not.be.greater.than.lien.limit", account.getId());
+                            }
+                        }
+                    }
+
+                    if (amount.compareTo(account.getMaxAllowedLienLimit()) > 
0) {
+                        
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("lien.limit.exceeded",
 account.getId());
+                    }
+                } else {
+                    
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("lien.is.not.allowed.in.product.level",
+                            account.getId());
+                }
+            } else {
+                if (isOverdraftEnabled) {
+                    if (amount.compareTo(account.getWithdrawableBalance()) > 0 
&& amount.compareTo(account.getOverdraftLimit()) > 0) {
+                        
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
+                    }
+                }
+                if (isEnforceMinRequiredBalanceEnabled) {
+                    if (amount.compareTo(account.getWithdrawableBalance()) > 
0) {
+                        
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
+                    }
+                }
+                if (!isOverdraftEnabled && 
!isEnforceMinRequiredBalanceEnabled) {
+                    if (amount.compareTo(account.getWithdrawableBalance()) > 
0) {
+                        
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
+                    }
+                }
             }
-        }
-
-        Boolean lien = false;
-
-        if (this.fromApiJsonHelper.parameterExists(lienParamName, element)) {
-            lien = this.fromApiJsonHelper.extractBooleanNamed(lienParamName, 
element);
-            if (!lien) {
-                if 
(account.getWithdrawableBalanceWithoutMinimumBalance().compareTo(BigDecimal.ZERO)
 < 0) {
-                    
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient 
balance", account.getId());
+        } else {
+            if (isOverdraftEnabled) {
+                if (amount.compareTo(account.getWithdrawableBalance()) > 0 && 
amount.compareTo(account.getOverdraftLimit()) > 0) {
+                    
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
+                }
+            }
+            if (isEnforceMinRequiredBalanceEnabled) {
+                if (amount.compareTo(account.getWithdrawableBalance()) > 0) {
+                    
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
+                }
+            }
+            if (!isOverdraftEnabled && !isEnforceMinRequiredBalanceEnabled) {
+                if (amount.compareTo(account.getWithdrawableBalance()) > 0) {
+                    
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("insufficient.balance",
 account.getId());
                 }
             }
         }
-
+        account.holdAmount(amount);

Review comment:
       I am working on enhancement of lien feature and this 
account.holdAmount(amount) was already there. Its position might changed during 
enhancements.




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