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


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java:
##########
@@ -1573,21 +1576,36 @@ public void 
validateAccountBalanceDoesNotBecomeNegative(final String transaction
                         throw new 
PlatformApiDataValidationException(dataValidationErrors);
                     }
                 }
-
             }
             lastSavingsDate = transaction.transactionLocalDate();
-
         }
 
-        BigDecimal withdrawalFee = null;
-        BigDecimal transactionAmount = null;
         if (isOverdraft()) {
             if (runningBalance.minus(minRequiredBalance).isLessThanZero()) {
-                throw new 
InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), 
withdrawalFee, transactionAmount);
+                overdraftLimitExceededException("transactionAmount", 
getAccountBalance(), transactionAmount);
+            }
+        }
+    }
+
+    public void validateAccountBalanceDoesNotViolateOverdraft(final 
List<SavingsAccountTransaction> savingsAccountTransaction,
+            final BigDecimal amountPaid) {
+        if (savingsAccountTransaction != null) {
+            SavingsAccountTransaction savingsAccountTransactionFirst = 
savingsAccountTransaction.get(0);

Review Comment:
   @rrpawar96 Yeah... i should have read more carefully the story about this 
change :)
   Seems you're right, you need to find the very last transaction of that 
particular day (pay charge transaction date) and based on the running balance 
of that transaction decide whether it is violating the overdraft rule or not.
   
   To do that, I would recommend this:
   `Optional<SavingsAccount> 
findFirstBySavingsAccountAndReversedFalseAndDateOfLessThanEqualOrderByDateOfDescIdDesc();`
   
   But this one is pretty complex, so maybe Pagination would be just fine as 
well:
   `
   
   @Query("select sat from SavingsAccountTransaction sat where 
sat.savingsAccount.id = :savingsId and sat.dateOf <= :transactionDate and 
sat.reversed=false ORDER BY sat.dateOf DESC, sat.id DESC")
        List<SavingsAccountTransaction> 
retrieveRunningBalanceBySavingsAccountIdAndDate(@Param("savingsId") Long 
savingsId,
                @Param("transactionDate") LocalDate transactionDate, 
PageRequest.of(0, 1));`



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