diff --git a/fineract-current-product/src/main/java/org/apache/fineract/portfolio/currentaccount/domain/CurrentAccountRepository.java b/fineract-current-product/src/main/java/org/apache/fineract/portfolio/currentaccount/domain/CurrentAccountRepository.java index 4c5617f97..944afff22 100644 --- a/fineract-current-product/src/main/java/org/apache/fineract/portfolio/currentaccount/domain/CurrentAccountRepository.java +++ b/fineract-current-product/src/main/java/org/apache/fineract/portfolio/currentaccount/domain/CurrentAccountRepository.java @@ -38,6 +38,12 @@ public interface CurrentAccountRepository extends JpaRepository findActiveByClientId(@Param("clientId") Long clientId); - @Query("SELECT COUNT(ca) FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.productId = :productId AND ca.statusEnum != 600") + // statusEnum != 600 (CLOSED) let a client re-apply for the same product only once every prior + // account on it was closed -- but 400 (WITHDRAWN) and 500 (REJECTED), see CurrentAccount.withdraw() + // /.reject(), are equally terminal and were still being counted as "still has one", blocking a + // fresh application the client should have been free to make. 100/200/300 (submitted, approved, + // active) are the only statuses a second application on the same product should actually collide + // with. + @Query("SELECT COUNT(ca) FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.productId = :productId AND ca.statusEnum IN (100, 200, 300)") long countActiveByClientAndProduct(@Param("clientId") Long clientId, @Param("productId") Long productId); }