Merge branch 'FINERACT-261' into develop
This commit is contained in:
+35
@@ -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.");
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user