You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2022/04/01 16:17:27 UTC

[GitHub] [fineract] logoutdhaval commented on a change in pull request #2215: FINERACT-1553: Lien configured at product level

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



##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountTransactionsApiResource.java
##########
@@ -130,6 +135,9 @@ public String retrieveOne(@PathParam("savingsId") final Long savingsId, @PathPar
     @POST
     @Consumes({ MediaType.APPLICATION_JSON })
     @Produces({ MediaType.APPLICATION_JSON })
+    @RequestBody(required = true, content = @Content(schema = @Schema(implementation = SavingsAccountTransactionsApiResourceSwagger.PostSavingsAccountTransactionsRequest.class)))
+    @ApiResponses({

Review comment:
       ![commandParam](https://user-images.githubusercontent.com/100835289/161230264-465426ff-53f5-420c-ad7a-017861d9eefd.png)
   
   Yes, It has command parameter.

##########
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 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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org