Add multiple credit and debit journalentries with accoutnting rule

This commit is contained in:
mifoscontributer
2013-05-31 18:53:22 +05:30
parent eb082d5ec5
commit b373458f57
7 changed files with 132 additions and 71 deletions
@@ -50,9 +50,10 @@ import org.springframework.stereotype.Component;
public class GLAccountsApiResource { public class GLAccountsApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "parentId", "glCode", private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "parentId", "glCode",
"disabled", "manualEntriesAllowed", "type", "usage", "description", "assetHeaderAccountOptions", "liabilityHeaderAccountOptions", "disabled", "manualEntriesAllowed", "type", "usage", "description", "assetHeaderAccountOptions",
"equityHeaderAccountOptions", "incomeHeaderAccountOptions", "expenseHeaderAccountOptions", "nameDecorated", "tagId", "liabilityHeaderAccountOptions", "equityHeaderAccountOptions", "incomeHeaderAccountOptions", "expenseHeaderAccountOptions",
"allowedAssetsTagOptions", "allowedLiabilitiesTagOptions", "allowedEquityTagOptions", "allowedIncomeTagOptions", "allowedExpensesTagOptions")); "nameDecorated", "tagId", "allowedAssetsTagOptions", "allowedLiabilitiesTagOptions", "allowedEquityTagOptions",
"allowedIncomeTagOptions", "allowedExpensesTagOptions", "creditAccounts", "debitAccounts"));
private final String resourceNameForPermission = "GLACCOUNT"; private final String resourceNameForPermission = "GLACCOUNT";
@@ -68,7 +69,8 @@ public class GLAccountsApiResource {
public GLAccountsApiResource(final PlatformSecurityContext context, final GLAccountReadPlatformService glAccountReadPlatformService, public GLAccountsApiResource(final PlatformSecurityContext context, final GLAccountReadPlatformService glAccountReadPlatformService,
final DefaultToApiJsonSerializer<GLAccountData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final DefaultToApiJsonSerializer<GLAccountData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final AccountingDropdownReadPlatformService dropdownReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService) { final AccountingDropdownReadPlatformService dropdownReadPlatformService,
final CodeValueReadPlatformService codeValueReadPlatformService) {
this.context = context; this.context = context;
this.apiRequestParameterHelper = apiRequestParameterHelper; this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
@@ -82,7 +84,7 @@ public class GLAccountsApiResource {
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveNewAccountDetails(@Context final UriInfo uriInfo, @QueryParam("type") final Integer type) { public String retrieveNewAccountDetails(@Context final UriInfo uriInfo, @QueryParam("type") final Integer type) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
@@ -167,16 +169,26 @@ public class GLAccountsApiResource {
private GLAccountData handleTemplate(final GLAccountData glAccountData) { private GLAccountData handleTemplate(final GLAccountData glAccountData) {
final List<EnumOptionData> accountTypeOptions = this.dropdownReadPlatformService.retrieveGLAccountTypeOptions(); final List<EnumOptionData> accountTypeOptions = this.dropdownReadPlatformService.retrieveGLAccountTypeOptions();
final List<EnumOptionData> usageOptions = this.dropdownReadPlatformService.retrieveGLAccountUsageOptions(); final List<EnumOptionData> usageOptions = this.dropdownReadPlatformService.retrieveGLAccountUsageOptions();
final List<GLAccountData> assetHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService.retrieveAllEnabledHeaderGLAccounts(GLAccountType.ASSET)); final List<GLAccountData> assetHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService
final List<GLAccountData> liabilityHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService.retrieveAllEnabledHeaderGLAccounts(GLAccountType.LIABILITY)); .retrieveAllEnabledHeaderGLAccounts(GLAccountType.ASSET));
final List<GLAccountData> equityHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService.retrieveAllEnabledHeaderGLAccounts(GLAccountType.EQUITY)); final List<GLAccountData> liabilityHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService
final List<GLAccountData> incomeHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService.retrieveAllEnabledHeaderGLAccounts(GLAccountType.INCOME)); .retrieveAllEnabledHeaderGLAccounts(GLAccountType.LIABILITY));
final List<GLAccountData> expenseHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService.retrieveAllEnabledHeaderGLAccounts(GLAccountType.EXPENSE)); final List<GLAccountData> equityHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService
final Collection<CodeValueData> allowedAssetsTagOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode(AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME); .retrieveAllEnabledHeaderGLAccounts(GLAccountType.EQUITY));
final Collection<CodeValueData> allowedLiabilitiesTagOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode(AccountingConstants.LIABILITIES_TAG_OPTION_CODE_NAME); final List<GLAccountData> incomeHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService
final Collection<CodeValueData> allowedEquityTagOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode(AccountingConstants.EQUITY_TAG_OPTION_CODE_NAME); .retrieveAllEnabledHeaderGLAccounts(GLAccountType.INCOME));
final Collection<CodeValueData> allowedIncomeTagOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode(AccountingConstants.INCOME_TAG_OPTION_CODE_NAME); final List<GLAccountData> expenseHeaderAccountOptions = defaultIfEmpty(this.glAccountReadPlatformService
final Collection<CodeValueData> allowedExpensesTagOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode(AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME); .retrieveAllEnabledHeaderGLAccounts(GLAccountType.EXPENSE));
final Collection<CodeValueData> allowedAssetsTagOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME);
final Collection<CodeValueData> allowedLiabilitiesTagOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(AccountingConstants.LIABILITIES_TAG_OPTION_CODE_NAME);
final Collection<CodeValueData> allowedEquityTagOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(AccountingConstants.EQUITY_TAG_OPTION_CODE_NAME);
final Collection<CodeValueData> allowedIncomeTagOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(AccountingConstants.INCOME_TAG_OPTION_CODE_NAME);
final Collection<CodeValueData> allowedExpensesTagOptions = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME);
return new GLAccountData(glAccountData, accountTypeOptions, usageOptions, assetHeaderAccountOptions, liabilityHeaderAccountOptions, return new GLAccountData(glAccountData, accountTypeOptions, usageOptions, assetHeaderAccountOptions, liabilityHeaderAccountOptions,
equityHeaderAccountOptions, incomeHeaderAccountOptions, expenseHeaderAccountOptions, allowedAssetsTagOptions, equityHeaderAccountOptions, incomeHeaderAccountOptions, expenseHeaderAccountOptions, allowedAssetsTagOptions,
@@ -48,6 +48,10 @@ public class GLAccountData {
final Collection<CodeValueData> allowedIncomeTagOptions; final Collection<CodeValueData> allowedIncomeTagOptions;
final Collection<CodeValueData> allowedExpensesTagOptions; final Collection<CodeValueData> allowedExpensesTagOptions;
// for predefined journal entry template
private final List<GLAccountDataForLookup> creditAccounts;
private final List<GLAccountDataForLookup> debitAccounts;
public GLAccountData(final Long id, final String name, final Long parentId, final String glCode, final boolean disabled, public GLAccountData(final Long id, final String name, final Long parentId, final String glCode, final boolean disabled,
final boolean manualEntriesAllowed, final EnumOptionData type, final EnumOptionData usage, final String description, final boolean manualEntriesAllowed, final EnumOptionData type, final EnumOptionData usage, final String description,
final String nameDecorated, final CodeValueData tagId) { final String nameDecorated, final CodeValueData tagId) {
@@ -71,9 +75,11 @@ public class GLAccountData {
this.expenseHeaderAccountOptions = null; this.expenseHeaderAccountOptions = null;
this.allowedAssetsTagOptions = null; this.allowedAssetsTagOptions = null;
this.allowedLiabilitiesTagOptions = null; this.allowedLiabilitiesTagOptions = null;
this.allowedEquityTagOptions=null; this.allowedEquityTagOptions = null;
this.allowedIncomeTagOptions=null; this.allowedIncomeTagOptions = null;
this.allowedExpensesTagOptions=null; this.allowedExpensesTagOptions = null;
this.creditAccounts = null;
this.debitAccounts = null;
} }
public GLAccountData(final GLAccountData accountData, final List<EnumOptionData> accountTypeOptions, public GLAccountData(final GLAccountData accountData, final List<EnumOptionData> accountTypeOptions,
@@ -106,6 +112,8 @@ public class GLAccountData {
this.allowedEquityTagOptions = allowedEquityTagOptions; this.allowedEquityTagOptions = allowedEquityTagOptions;
this.allowedIncomeTagOptions = allowedIncomeTagOptions; this.allowedIncomeTagOptions = allowedIncomeTagOptions;
this.allowedExpensesTagOptions = allowedExpensesTagOptions; this.allowedExpensesTagOptions = allowedExpensesTagOptions;
this.creditAccounts = accountData.creditAccounts;
this.debitAccounts = accountData.debitAccounts;
} }
public static GLAccountData sensibleDefaultsForNewGLAccountCreation(final Integer glAccType) { public static GLAccountData sensibleDefaultsForNewGLAccountCreation(final Integer glAccType) {
@@ -116,10 +124,11 @@ public class GLAccountData {
final boolean disabled = false; final boolean disabled = false;
final boolean manualEntriesAllowed = true; final boolean manualEntriesAllowed = true;
final EnumOptionData type; final EnumOptionData type;
if(glAccType != null && glAccType >= GLAccountType.getMinValue() && glAccType <= GLAccountType.getMaxValue()) if (glAccType != null && glAccType >= GLAccountType.getMinValue() && glAccType <= GLAccountType.getMaxValue()) {
type = AccountingEnumerations.gLAccountType(glAccType); type = AccountingEnumerations.gLAccountType(glAccType);
else } else {
type = AccountingEnumerations.gLAccountType(GLAccountType.ASSET); type = AccountingEnumerations.gLAccountType(GLAccountType.ASSET);
}
final EnumOptionData usage = AccountingEnumerations.gLAccountUsage(GLAccountUsage.DETAIL); final EnumOptionData usage = AccountingEnumerations.gLAccountUsage(GLAccountUsage.DETAIL);
final String description = null; final String description = null;
final String nameDecorated = null; final String nameDecorated = null;
@@ -128,7 +137,7 @@ public class GLAccountData {
} }
public GLAccountData(final Long id, final String name, final String glCode) { public GLAccountData(final Long id, final String name, final String glCode) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.parentId = null; this.parentId = null;
this.glCode = glCode; this.glCode = glCode;
@@ -148,23 +157,23 @@ public class GLAccountData {
this.expenseHeaderAccountOptions = null; this.expenseHeaderAccountOptions = null;
this.allowedAssetsTagOptions = null; this.allowedAssetsTagOptions = null;
this.allowedLiabilitiesTagOptions = null; this.allowedLiabilitiesTagOptions = null;
this.allowedEquityTagOptions=null; this.allowedEquityTagOptions = null;
this.allowedIncomeTagOptions=null; this.allowedIncomeTagOptions = null;
this.allowedExpensesTagOptions=null; this.allowedExpensesTagOptions = null;
} this.creditAccounts = null;
this.debitAccounts = null;
}
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
public String getName() {
return this.name;
}
public String getGlCode() {
return this.glCode;
}
public String getName() {
return this.name;
}
public String getGlCode() {
return this.glCode;
}
} }
@@ -2,14 +2,20 @@ package org.mifosplatform.accounting.glaccount.data;
public class GLAccountDataForLookup { public class GLAccountDataForLookup {
private final Long id; private final Long id;
@SuppressWarnings("unused")
private final String name;
@SuppressWarnings("unused")
private final String glCode;
public GLAccountDataForLookup(final Long id) { public GLAccountDataForLookup(final Long id, final String name, final String glCode) {
this.id = id; this.id = id;
} this.name = name;
this.glCode = glCode;
}
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
} }
@@ -214,13 +214,15 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
private static final class GLAccountDataLookUpMapper implements RowMapper<GLAccountDataForLookup> { private static final class GLAccountDataLookUpMapper implements RowMapper<GLAccountDataForLookup> {
public String schema() { public String schema() {
return " gl.id as id from acc_accounting_rule rule join acc_rule_tags tags on tags.acc_rule_id = rule.id join acc_gl_account gl on gl.tag_id=tags.tag_id"; return " gl.id as id, gl.name as name, gl.gl_code as glCode from acc_accounting_rule rule join acc_rule_tags tags on tags.acc_rule_id = rule.id join acc_gl_account gl on gl.tag_id=tags.tag_id";
} }
@Override @Override
public GLAccountDataForLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { public GLAccountDataForLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = JdbcSupport.getLong(rs, "id"); final Long id = JdbcSupport.getLong(rs, "id");
return new GLAccountDataForLookup(id); final String name = rs.getString("name");
final String glCode = rs.getString("glCode");
return new GLAccountDataForLookup(id, name, glCode);
} }
} }
@@ -53,7 +53,7 @@ public class AccountingRuleApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName",
"accountToDebitId", "accountToCreditId", "name", "description", "systemDefined", "allowedAssetsTagOptions", "accountToDebitId", "accountToCreditId", "name", "description", "systemDefined", "allowedAssetsTagOptions",
"allowedLiabilitiesTagOptions", "allowedEquityTagOptions", "allowedIncomeTagOptions", "allowedExpensesTagOptions", "debitTags", "allowedLiabilitiesTagOptions", "allowedEquityTagOptions", "allowedIncomeTagOptions", "allowedExpensesTagOptions", "debitTags",
"creditTags")); "creditTags", "creditAccounts", "debitAccounts"));
private final String resourceNameForPermission = "ACCOUNTINGRULE"; private final String resourceNameForPermission = "ACCOUNTINGRULE";
@@ -10,6 +10,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.mifosplatform.accounting.glaccount.data.GLAccountData; import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.accounting.glaccount.data.GLAccountDataForLookup;
import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.data.OfficeData;
@@ -40,6 +41,8 @@ public class AccountingRuleData {
private final Collection<CodeValueData> allowedEquityTagOptions; private final Collection<CodeValueData> allowedEquityTagOptions;
private final Collection<CodeValueData> allowedIncomeTagOptions; private final Collection<CodeValueData> allowedIncomeTagOptions;
private final Collection<CodeValueData> allowedExpensesTagOptions; private final Collection<CodeValueData> allowedExpensesTagOptions;
private final List<GLAccountDataForLookup> creditAccounts;
private final List<GLAccountDataForLookup> debitAccounts;
public AccountingRuleData(final AccountingRuleData accountingRuleData, final List<GLAccountData> allowedAccounts, public AccountingRuleData(final AccountingRuleData accountingRuleData, final List<GLAccountData> allowedAccounts,
final List<OfficeData> allowedOffices, final Collection<CodeValueData> allowedAssetsTagOptions, final List<OfficeData> allowedOffices, final Collection<CodeValueData> allowedAssetsTagOptions,
@@ -62,6 +65,8 @@ public class AccountingRuleData {
this.allowedExpensesTagOptions = allowedExpensesTagOptions; this.allowedExpensesTagOptions = allowedExpensesTagOptions;
this.creditTags = accountingRuleData.creditTags; this.creditTags = accountingRuleData.creditTags;
this.debitTags = accountingRuleData.debitTags; this.debitTags = accountingRuleData.debitTags;
this.creditAccounts = accountingRuleData.creditAccounts;
this.debitAccounts = accountingRuleData.debitAccounts;
} }
public AccountingRuleData(final List<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices, public AccountingRuleData(final List<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices,
@@ -85,6 +90,8 @@ public class AccountingRuleData {
this.allowedExpensesTagOptions = allowedExpensesTagOptions; this.allowedExpensesTagOptions = allowedExpensesTagOptions;
this.creditTags = null; this.creditTags = null;
this.debitTags = null; this.debitTags = null;
this.creditAccounts = null;
this.debitAccounts = null;
} }
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final String name, final String description, public AccountingRuleData(final Long id, final Long officeId, final String officeName, final String name, final String description,
@@ -106,10 +113,13 @@ public class AccountingRuleData {
this.allowedExpensesTagOptions = null; this.allowedExpensesTagOptions = null;
this.creditTags = null; this.creditTags = null;
this.debitTags = null; this.debitTags = null;
this.creditAccounts = new ArrayList<GLAccountDataForLookup>();
this.debitAccounts = new ArrayList<GLAccountDataForLookup>();
} }
public AccountingRuleData(final AccountingRuleData accountingRuleData, final List<AccountingTagRuleData> creditTags, public AccountingRuleData(final AccountingRuleData accountingRuleData, final List<AccountingTagRuleData> creditTags,
final List<AccountingTagRuleData> debitTags) { final List<GLAccountDataForLookup> creditAccounts, final List<AccountingTagRuleData> debitTags,
final List<GLAccountDataForLookup> debitAccounts) {
this.id = accountingRuleData.id; this.id = accountingRuleData.id;
this.officeId = accountingRuleData.officeId; this.officeId = accountingRuleData.officeId;
this.officeName = accountingRuleData.officeName; this.officeName = accountingRuleData.officeName;
@@ -126,7 +136,9 @@ public class AccountingRuleData {
this.allowedIncomeTagOptions = accountingRuleData.allowedIncomeTagOptions; this.allowedIncomeTagOptions = accountingRuleData.allowedIncomeTagOptions;
this.allowedExpensesTagOptions = accountingRuleData.allowedExpensesTagOptions; this.allowedExpensesTagOptions = accountingRuleData.allowedExpensesTagOptions;
this.creditTags = creditTags; this.creditTags = creditTags;
this.creditAccounts = creditAccounts;
this.debitTags = debitTags; this.debitTags = debitTags;
this.debitAccounts = debitAccounts;
} }
public GLAccountData getDebitAccountHead() { public GLAccountData getDebitAccountHead() {
@@ -144,4 +156,12 @@ public class AccountingRuleData {
public List<AccountingTagRuleData> getDebitTags() { public List<AccountingTagRuleData> getDebitTags() {
return this.debitTags; return this.debitTags;
} }
public List<GLAccountDataForLookup> getCreditAccounts() {
return this.creditAccounts;
}
public List<GLAccountDataForLookup> getDebitAccounts() {
return this.debitAccounts;
}
} }
@@ -14,6 +14,8 @@ import java.util.Map;
import org.mifosplatform.accounting.common.AccountingEnumerations; import org.mifosplatform.accounting.common.AccountingEnumerations;
import org.mifosplatform.accounting.glaccount.data.GLAccountData; import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.accounting.glaccount.data.GLAccountDataForLookup;
import org.mifosplatform.accounting.glaccount.service.GLAccountReadPlatformService;
import org.mifosplatform.accounting.journalentry.domain.JournalEntryType; import org.mifosplatform.accounting.journalentry.domain.JournalEntryType;
import org.mifosplatform.accounting.rule.data.AccountingRuleData; import org.mifosplatform.accounting.rule.data.AccountingRuleData;
import org.mifosplatform.accounting.rule.data.AccountingTagRuleData; import org.mifosplatform.accounting.rule.data.AccountingTagRuleData;
@@ -33,10 +35,13 @@ import org.springframework.stereotype.Service;
public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleReadPlatformService { public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleReadPlatformService {
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final GLAccountReadPlatformService glAccountReadPlatformService;
@Autowired @Autowired
public AccountingRuleReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource) { public AccountingRuleReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource,
final GLAccountReadPlatformService glAccountReadPlatformService) {
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
this.glAccountReadPlatformService = glAccountReadPlatformService;
} }
// Will remove the old one if everything goes well. // Will remove the old one if everything goes well.
@@ -88,13 +93,15 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
} }
}*/ }*/
private static final class AccountingRuleDataExtractor implements ResultSetExtractor<Object> { private static final class AccountingRuleDataExtractor implements ResultSetExtractor<Map<Long, AccountingRuleData>> {
private final String schemaSql; private final String schemaSql;
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final GLAccountReadPlatformService glAccountReadPlatformService;
public AccountingRuleDataExtractor(final JdbcTemplate jdbcTemplate) { public AccountingRuleDataExtractor(final JdbcTemplate jdbcTemplate, final GLAccountReadPlatformService glAccountReadPlatformService) {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
this.glAccountReadPlatformService = glAccountReadPlatformService;
final StringBuilder sqlBuilder = new StringBuilder(400); final StringBuilder sqlBuilder = new StringBuilder(400);
sqlBuilder sqlBuilder
.append(" rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,") .append(" rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,")
@@ -141,11 +148,17 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
} }
if (accountingRuleData.getCreditAccountHead() == null) { if (accountingRuleData.getCreditAccountHead() == null) {
final List<AccountingTagRuleData> creditTags = getCreditOrDebitTags(id, JournalEntryType.CREDIT.getValue()); final List<AccountingTagRuleData> creditTags = getCreditOrDebitTags(id, JournalEntryType.CREDIT.getValue());
accountingRuleData = new AccountingRuleData(accountingRuleData, creditTags, accountingRuleData.getDebitTags()); final List<GLAccountDataForLookup> creditAccounts = this.glAccountReadPlatformService.retrieveAccountsByTagId(id,
JournalEntryType.CREDIT.getValue());
accountingRuleData = new AccountingRuleData(accountingRuleData, creditTags, creditAccounts,
accountingRuleData.getDebitTags(), accountingRuleData.getDebitAccounts());
} }
if (accountingRuleData.getDebitAccountHead() == null) { if (accountingRuleData.getDebitAccountHead() == null) {
final List<AccountingTagRuleData> debitTags = getCreditOrDebitTags(id, JournalEntryType.DEBIT.getValue()); final List<AccountingTagRuleData> debitTags = getCreditOrDebitTags(id, JournalEntryType.DEBIT.getValue());
accountingRuleData = new AccountingRuleData(accountingRuleData, accountingRuleData.getCreditTags(), debitTags); final List<GLAccountDataForLookup> debitAccounts = this.glAccountReadPlatformService.retrieveAccountsByTagId(id,
JournalEntryType.DEBIT.getValue());
accountingRuleData = new AccountingRuleData(accountingRuleData, accountingRuleData.getCreditTags(),
accountingRuleData.getCreditAccounts(), debitTags, debitAccounts);
} }
extractedData.put(id, accountingRuleData); extractedData.put(id, accountingRuleData);
} }
@@ -162,7 +175,8 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
@Override @Override
public List<AccountingRuleData> retrieveAllAccountingRules(final Long officeId) { public List<AccountingRuleData> retrieveAllAccountingRules(final Long officeId) {
final AccountingRuleDataExtractor resultSetExtractor = new AccountingRuleDataExtractor(this.jdbcTemplate); final AccountingRuleDataExtractor resultSetExtractor = new AccountingRuleDataExtractor(this.jdbcTemplate,
this.glAccountReadPlatformService);
Object[] arguments = new Object[] {}; Object[] arguments = new Object[] {};
String sql = "select " + resultSetExtractor.schema() + " and system_defined=0 "; String sql = "select " + resultSetExtractor.schema() + " and system_defined=0 ";
if (officeId != null) { if (officeId != null) {
@@ -170,21 +184,19 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
arguments = new Object[] { officeId }; arguments = new Object[] { officeId };
} }
sql = sql + " order by rule.id asc"; sql = sql + " order by rule.id asc";
@SuppressWarnings("unchecked") final Map<Long, AccountingRuleData> extractedData = this.jdbcTemplate.query(sql, resultSetExtractor, arguments);
final Map<Long, AccountingRuleData> extractedData = (Map<Long, AccountingRuleData>) this.jdbcTemplate.query(sql,
resultSetExtractor, arguments);
return new ArrayList<AccountingRuleData>(extractedData.values()); return new ArrayList<AccountingRuleData>(extractedData.values());
} }
@Override @Override
public AccountingRuleData retrieveAccountingRuleById(final Long accountingRuleId) { public AccountingRuleData retrieveAccountingRuleById(final Long accountingRuleId) {
try { try {
final AccountingRuleDataExtractor resultSetExtractor = new AccountingRuleDataExtractor(this.jdbcTemplate); final AccountingRuleDataExtractor resultSetExtractor = new AccountingRuleDataExtractor(this.jdbcTemplate,
this.glAccountReadPlatformService);
final String sql = "select " + resultSetExtractor.schema() + " and rule.id = ?"; final String sql = "select " + resultSetExtractor.schema() + " and rule.id = ?";
@SuppressWarnings("unchecked") final Map<Long, AccountingRuleData> extractedData = this.jdbcTemplate.query(sql, resultSetExtractor,
final Map<Long, AccountingRuleData> extractedData = (Map<Long, AccountingRuleData>) this.jdbcTemplate.query(sql, new Object[] { accountingRuleId });
resultSetExtractor, new Object[] { accountingRuleId });
final AccountingRuleData accountingRuleData = extractedData.get(accountingRuleId); final AccountingRuleData accountingRuleData = extractedData.get(accountingRuleId);
if (accountingRuleData == null) { throw new AccountingRuleNotFoundException(accountingRuleId); } if (accountingRuleData == null) { throw new AccountingRuleNotFoundException(accountingRuleId); }
return accountingRuleData; return accountingRuleData;