Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 516160bf4 -> cb28f2a01


#261 validation added on disabling gl account


Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/94a4bf57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/94a4bf57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/94a4bf57

Branch: refs/heads/develop
Commit: 94a4bf570a64bb016196cb3e954afa572cfbe0a4
Parents: 8baf9f4
Author: nazeer1100126 <[email protected]>
Authored: Fri Apr 21 15:26:19 2017 +0530
Committer: nazeer1100126 <[email protected]>
Committed: Fri Apr 21 15:26:19 2017 +0530

----------------------------------------------------------------------
 .../exception/GLAccountDisableException.java    | 35 ++++++++++++++++++++
 ...ntWritePlatformServiceJpaRepositoryImpl.java | 25 ++++++++++++--
 2 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/94a4bf57/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/exception/GLAccountDisableException.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/exception/GLAccountDisableException.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/exception/GLAccountDisableException.java
new file mode 100644
index 0000000..5ad0658
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/exception/GLAccountDisableException.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.accounting.glaccount.exception;
+
+import 
org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
+
+/**
+ * 
+ * when gl account is attached with any product(loan/saving) then we can not
+ * disable the gl account
+ */
+public class GLAccountDisableException extends
+               AbstractPlatformDomainRuleException {
+
+       public GLAccountDisableException() {
+               super("error.msg.glaccount.attached.to.product",
+                               "General Ledger Account is already attached to 
product.");
+       }
+}

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/94a4bf57/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java
index 4597c6a..2135efd 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java
@@ -27,6 +27,7 @@ import 
org.apache.fineract.accounting.glaccount.command.GLAccountCommand;
 import org.apache.fineract.accounting.glaccount.domain.GLAccount;
 import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
 import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
+import 
org.apache.fineract.accounting.glaccount.exception.GLAccountDisableException;
 import 
org.apache.fineract.accounting.glaccount.exception.GLAccountDuplicateException;
 import 
org.apache.fineract.accounting.glaccount.exception.GLAccountInvalidDeleteException;
 import 
org.apache.fineract.accounting.glaccount.exception.GLAccountInvalidParentException;
@@ -44,10 +45,12 @@ import 
org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
 import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
 import 
org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -60,15 +63,17 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl 
implements GLAccount
     private final JournalEntryRepository glJournalEntryRepository;
     private final GLAccountCommandFromApiJsonDeserializer 
fromApiJsonDeserializer;
     private final CodeValueRepositoryWrapper codeValueRepositoryWrapper;
+    private final JdbcTemplate jdbcTemplate;
 
     @Autowired
     public GLAccountWritePlatformServiceJpaRepositoryImpl(final 
GLAccountRepository glAccountRepository,
             final JournalEntryRepository glJournalEntryRepository, final 
GLAccountCommandFromApiJsonDeserializer fromApiJsonDeserializer,
-            final CodeValueRepositoryWrapper codeValueRepositoryWrapper) {
+            final CodeValueRepositoryWrapper codeValueRepositoryWrapper, final 
RoutingDataSource dataSource) {
         this.glAccountRepository = glAccountRepository;
         this.glJournalEntryRepository = glJournalEntryRepository;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.codeValueRepositoryWrapper = codeValueRepositoryWrapper;
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
     }
 
     @Transactional
@@ -115,7 +120,13 @@ public class 
GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
         try {
             final GLAccountCommand accountCommand = 
this.fromApiJsonDeserializer.commandFromApiJson(command.json());
             accountCommand.validateForUpdate();
-
+                       if 
(command.hasParameter(GLAccountJsonInputParams.DISABLED
+                                       .getValue())
+                                       && command
+                                                       
.booleanPrimitiveValueOfParameterNamed(GLAccountJsonInputParams.DISABLED
+                                                                       
.getValue())) {
+                               validateForAttachedProduct(glAccountId);
+                       }
             final Long parentId = 
command.longValueOfParameterNamed(GLAccountJsonInputParams.PARENT_ID.getValue());
             if (glAccountId.equals(parentId)) { throw new 
InvalidParentGLAccountHeadException(glAccountId, parentId); }
             // is the glAccount valid
@@ -165,7 +176,15 @@ public class 
GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
         }
     }
 
-    @Transactional
+    private void validateForAttachedProduct(Long glAccountId) {
+               String sql = "select count(*) from acc_product_mapping acc 
where acc.gl_account_id = "+glAccountId;
+               int count = this.jdbcTemplate.queryForObject(sql, 
Integer.class);
+               if(count>0){
+                       throw new GLAccountDisableException();
+               }
+       }
+
+       @Transactional
     @Override
     public CommandProcessingResult deleteGLAccount(final Long glAccountId) {
         final GLAccount glAccount = 
this.glAccountRepository.findOne(glAccountId);

Reply via email to