added running balance as optional to GLAccount
This commit is contained in:
committed by
Keith Woodlock
parent
ab1254ab68
commit
96cefdddc5
@@ -19232,6 +19232,8 @@ Request Body:
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div class=apiClick>glaccounts?type=1&manualEntriesAllowed=true&usage=1&disabled=false</div>
|
<div class=apiClick>glaccounts?type=1&manualEntriesAllowed=true&usage=1&disabled=false</div>
|
||||||
|
<br>
|
||||||
|
<div class=apiClick>glaccounts?fetchRunningBalance=true</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="method-example">
|
<div class="method-example">
|
||||||
<code class="method-declaration">
|
<code class="method-declaration">
|
||||||
@@ -19544,6 +19546,9 @@ GET https://DomainName/api/v1/glaccounts/template?type=1
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div class=apiClick>glaccounts/1?fields=name,glCode</div>
|
<div class=apiClick>glaccounts/1?fields=name,glCode</div>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div class=apiClick>glaccounts/1?fetchRunningBalance=true</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="method-example">
|
<div class="method-example">
|
||||||
<code class="method-declaration">
|
<code class="method-declaration">
|
||||||
|
|||||||
+9
-5
@@ -29,6 +29,7 @@ import org.mifosplatform.accounting.common.AccountingDropdownReadPlatformService
|
|||||||
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
|
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
|
||||||
import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
|
import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
|
||||||
import org.mifosplatform.accounting.glaccount.service.GLAccountReadPlatformService;
|
import org.mifosplatform.accounting.glaccount.service.GLAccountReadPlatformService;
|
||||||
|
import org.mifosplatform.accounting.journalentry.data.JournalEntryAssociationParametersData;
|
||||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
@@ -100,11 +101,13 @@ public class GLAccountsApiResource {
|
|||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAllAccounts(@Context final UriInfo uriInfo, @QueryParam("type") final Integer type,
|
public String retrieveAllAccounts(@Context final UriInfo uriInfo, @QueryParam("type") final Integer type,
|
||||||
@QueryParam("searchParam") final String searchParam, @QueryParam("usage") final Integer usage,
|
@QueryParam("searchParam") final String searchParam, @QueryParam("usage") final Integer usage,
|
||||||
@QueryParam("manualEntriesAllowed") final Boolean manualEntriesAllowed, @QueryParam("disabled") final Boolean disabled) {
|
@QueryParam("manualEntriesAllowed") final Boolean manualEntriesAllowed, @QueryParam("disabled") final Boolean disabled,
|
||||||
|
@QueryParam("fetchRunningBalance") final boolean runningBalance) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
|
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
|
||||||
|
JournalEntryAssociationParametersData associationParametersData = new JournalEntryAssociationParametersData(false, runningBalance);
|
||||||
final List<GLAccountData> glAccountDatas = this.glAccountReadPlatformService.retrieveAllGLAccounts(type, searchParam, usage,
|
final List<GLAccountData> glAccountDatas = this.glAccountReadPlatformService.retrieveAllGLAccounts(type, searchParam, usage,
|
||||||
manualEntriesAllowed, disabled);
|
manualEntriesAllowed, disabled, associationParametersData);
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
return this.apiJsonSerializerService.serialize(settings, glAccountDatas, RESPONSE_DATA_PARAMETERS);
|
return this.apiJsonSerializerService.serialize(settings, glAccountDatas, RESPONSE_DATA_PARAMETERS);
|
||||||
@@ -114,13 +117,14 @@ public class GLAccountsApiResource {
|
|||||||
@Path("{glAccountId}")
|
@Path("{glAccountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retreiveAccount(@PathParam("glAccountId") final Long glAccountId, @Context final UriInfo uriInfo) {
|
public String retreiveAccount(@PathParam("glAccountId") final Long glAccountId, @Context final UriInfo uriInfo,
|
||||||
|
@QueryParam("fetchRunningBalance") final boolean runningBalance) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
|
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
JournalEntryAssociationParametersData associationParametersData = new JournalEntryAssociationParametersData(false, runningBalance);
|
||||||
GLAccountData glAccountData = this.glAccountReadPlatformService.retrieveGLAccountById(glAccountId);
|
GLAccountData glAccountData = this.glAccountReadPlatformService.retrieveGLAccountById(glAccountId,associationParametersData);
|
||||||
if (settings.isTemplate()) {
|
if (settings.isTemplate()) {
|
||||||
glAccountData = handleTemplate(glAccountData);
|
glAccountData = handleTemplate(glAccountData);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -10,13 +10,14 @@ 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.accounting.glaccount.data.GLAccountDataForLookup;
|
||||||
import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
|
import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
|
||||||
|
import org.mifosplatform.accounting.journalentry.data.JournalEntryAssociationParametersData;
|
||||||
|
|
||||||
public interface GLAccountReadPlatformService {
|
public interface GLAccountReadPlatformService {
|
||||||
|
|
||||||
List<GLAccountData> retrieveAllGLAccounts(Integer accountClassification, String searchParam, Integer usage,
|
List<GLAccountData> retrieveAllGLAccounts(Integer accountClassification, String searchParam, Integer usage,
|
||||||
Boolean manualTransactionsAllowed, Boolean disabled);
|
Boolean manualTransactionsAllowed, Boolean disabled, JournalEntryAssociationParametersData associationParametersData);
|
||||||
|
|
||||||
GLAccountData retrieveGLAccountById(long glAccountId);
|
GLAccountData retrieveGLAccountById(long glAccountId,JournalEntryAssociationParametersData associationParametersData);
|
||||||
|
|
||||||
List<GLAccountData> retrieveAllEnabledDetailGLAccounts();
|
List<GLAccountData> retrieveAllEnabledDetailGLAccounts();
|
||||||
|
|
||||||
|
|||||||
+48
-20
@@ -18,6 +18,7 @@ import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
|
|||||||
import org.mifosplatform.accounting.glaccount.domain.GLAccountUsage;
|
import org.mifosplatform.accounting.glaccount.domain.GLAccountUsage;
|
||||||
import org.mifosplatform.accounting.glaccount.exception.GLAccountInvalidClassificationException;
|
import org.mifosplatform.accounting.glaccount.exception.GLAccountInvalidClassificationException;
|
||||||
import org.mifosplatform.accounting.glaccount.exception.GLAccountNotFoundException;
|
import org.mifosplatform.accounting.glaccount.exception.GLAccountNotFoundException;
|
||||||
|
import org.mifosplatform.accounting.journalentry.data.JournalEntryAssociationParametersData;
|
||||||
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
|
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||||
@@ -41,15 +42,31 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
|
|
||||||
private static final class GLAccountMapper implements RowMapper<GLAccountData> {
|
private static final class GLAccountMapper implements RowMapper<GLAccountData> {
|
||||||
|
|
||||||
|
private final JournalEntryAssociationParametersData associationParametersData;
|
||||||
|
|
||||||
|
|
||||||
|
public GLAccountMapper(final JournalEntryAssociationParametersData associationParametersData) {
|
||||||
|
if(associationParametersData == null){
|
||||||
|
this.associationParametersData = new JournalEntryAssociationParametersData();
|
||||||
|
}else{
|
||||||
|
this.associationParametersData = associationParametersData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String schema() {
|
public String schema() {
|
||||||
return " gl.id as id, name as name, parent_id as parentId, gl_code as glCode, disabled as disabled, manual_journal_entries_allowed as manualEntriesAllowed, "
|
StringBuilder sb = new StringBuilder();
|
||||||
+ "classification_enum as classification, account_usage as accountUsage, gl.description as description, "
|
sb.append(" gl.id as id, name as name, parent_id as parentId, gl_code as glCode, disabled as disabled, manual_journal_entries_allowed as manualEntriesAllowed, ")
|
||||||
+ nameDecoratedBaseOnHierarchy
|
.append("classification_enum as classification, account_usage as accountUsage, gl.description as description, ")
|
||||||
+ "as nameDecorated, "
|
.append(nameDecoratedBaseOnHierarchy).append(" as nameDecorated, ")
|
||||||
+ "cv.id as codeId, cv.code_value as codeValue,gl_j.organization_running_balance as organizationRunningBalance "
|
.append("cv.id as codeId, cv.code_value as codeValue ");
|
||||||
+ "from acc_gl_account gl left join m_code_value cv on tag_id=cv.id "
|
if(this.associationParametersData.isRunningBalanceRequired()){
|
||||||
+ "left outer Join acc_gl_journal_entry gl_j on gl_j.account_id = gl.id";
|
sb.append(",gl_j.organization_running_balance as organizationRunningBalance ");
|
||||||
|
}
|
||||||
|
sb.append("from acc_gl_account gl left join m_code_value cv on tag_id=cv.id ");
|
||||||
|
if(this.associationParametersData.isRunningBalanceRequired()){
|
||||||
|
sb.append("left outer Join acc_gl_journal_entry gl_j on gl_j.account_id = gl.id");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,7 +87,10 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
final Long codeId = rs.wasNull() ? null : rs.getLong("codeId");
|
final Long codeId = rs.wasNull() ? null : rs.getLong("codeId");
|
||||||
final String codeValue = rs.getString("codeValue");
|
final String codeValue = rs.getString("codeValue");
|
||||||
final CodeValueData tagId = CodeValueData.instance(codeId, codeValue);
|
final CodeValueData tagId = CodeValueData.instance(codeId, codeValue);
|
||||||
final Long organizationRunningBalance = rs.getLong("organizationRunningBalance");
|
Long organizationRunningBalance = null;
|
||||||
|
if(associationParametersData.isRunningBalanceRequired()){
|
||||||
|
organizationRunningBalance = rs.getLong("organizationRunningBalance");
|
||||||
|
}
|
||||||
return new GLAccountData(id, name, parentId, glCode, disabled, manualEntriesAllowed, accountType, usage, description,
|
return new GLAccountData(id, name, parentId, glCode, disabled, manualEntriesAllowed, accountType, usage, description,
|
||||||
nameDecorated, tagId, organizationRunningBalance);
|
nameDecorated, tagId, organizationRunningBalance);
|
||||||
}
|
}
|
||||||
@@ -78,7 +98,7 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GLAccountData> retrieveAllGLAccounts(final Integer accountClassification, final String searchParam, final Integer usage,
|
public List<GLAccountData> retrieveAllGLAccounts(final Integer accountClassification, final String searchParam, final Integer usage,
|
||||||
final Boolean manualTransactionsAllowed, final Boolean disabled) {
|
final Boolean manualTransactionsAllowed, final Boolean disabled, JournalEntryAssociationParametersData associationParametersData) {
|
||||||
if (accountClassification != null) {
|
if (accountClassification != null) {
|
||||||
if (!checkValidGLAccountType(accountClassification)) { throw new GLAccountInvalidClassificationException(accountClassification); }
|
if (!checkValidGLAccountType(accountClassification)) { throw new GLAccountInvalidClassificationException(accountClassification); }
|
||||||
}
|
}
|
||||||
@@ -87,11 +107,13 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
if (!checkValidGLAccountUsage(usage)) { throw new GLAccountInvalidClassificationException(accountClassification); }
|
if (!checkValidGLAccountUsage(usage)) { throw new GLAccountInvalidClassificationException(accountClassification); }
|
||||||
}
|
}
|
||||||
|
|
||||||
final GLAccountMapper rm = new GLAccountMapper();
|
final GLAccountMapper rm = new GLAccountMapper(associationParametersData);
|
||||||
String sql = "select " + rm.schema();
|
String sql = "select " + rm.schema();
|
||||||
// append SQL statement for fetching account totals
|
// append SQL statement for fetching account totals
|
||||||
|
if(associationParametersData.isRunningBalanceRequired()){
|
||||||
sql = sql + " and gl_j.id in (select t1.id from (SELECT t2.id , max(concat(t2.entry_date,t2.id)) "
|
sql = sql + " and gl_j.id in (select t1.id from (SELECT t2.id , max(concat(t2.entry_date,t2.id)) "
|
||||||
+ "FROM acc_gl_journal_entry t2 WHERE is_running_balance_caculated = 1 GROUP BY t2.account_id DESC) t1)";
|
+ "FROM acc_gl_journal_entry t2 WHERE is_running_balance_caculated = 1 GROUP BY t2.account_id DESC) t1)";
|
||||||
|
}
|
||||||
final Object[] paramaterArray = new Object[3];
|
final Object[] paramaterArray = new Object[3];
|
||||||
int arrayPos = 0;
|
int arrayPos = 0;
|
||||||
boolean filtersPresent = false;
|
boolean filtersPresent = false;
|
||||||
@@ -162,14 +184,20 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GLAccountData retrieveGLAccountById(final long glAccountId) {
|
public GLAccountData retrieveGLAccountById(final long glAccountId,JournalEntryAssociationParametersData associationParametersData) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final GLAccountMapper rm = new GLAccountMapper();
|
final GLAccountMapper rm = new GLAccountMapper(associationParametersData);
|
||||||
final String sql = "select " + rm.schema()
|
final StringBuilder sql = new StringBuilder();
|
||||||
+ " and gl_j.is_running_balance_caculated = 1 where gl.id = ? ORDER BY gl_j.entry_date DESC,gl_j.id DESC LIMIT 1";
|
sql.append("select ").append(rm.schema());
|
||||||
|
if(associationParametersData.isRunningBalanceRequired()){
|
||||||
final GLAccountData glAccountData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { glAccountId });
|
sql.append(" and gl_j.is_running_balance_caculated = 1 ");
|
||||||
|
}
|
||||||
|
sql.append("where gl.id = ?");
|
||||||
|
if(associationParametersData.isRunningBalanceRequired()){
|
||||||
|
sql.append(" ORDER BY gl_j.entry_date DESC,gl_j.id DESC LIMIT 1");
|
||||||
|
}
|
||||||
|
final GLAccountData glAccountData = this.jdbcTemplate.queryForObject(sql.toString(), rm, new Object[] { glAccountId });
|
||||||
|
|
||||||
return glAccountData;
|
return glAccountData;
|
||||||
} catch (final EmptyResultDataAccessException e) {
|
} catch (final EmptyResultDataAccessException e) {
|
||||||
@@ -179,12 +207,12 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GLAccountData> retrieveAllEnabledDetailGLAccounts(final GLAccountType accountType) {
|
public List<GLAccountData> retrieveAllEnabledDetailGLAccounts(final GLAccountType accountType) {
|
||||||
return retrieveAllGLAccounts(accountType.getValue(), null, GLAccountUsage.DETAIL.getValue(), null, false);
|
return retrieveAllGLAccounts(accountType.getValue(), null, GLAccountUsage.DETAIL.getValue(), null, false, new JournalEntryAssociationParametersData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GLAccountData> retrieveAllEnabledDetailGLAccounts() {
|
public List<GLAccountData> retrieveAllEnabledDetailGLAccounts() {
|
||||||
return retrieveAllGLAccounts(null, null, GLAccountUsage.DETAIL.getValue(), null, false);
|
return retrieveAllGLAccounts(null, null, GLAccountUsage.DETAIL.getValue(), null, false, new JournalEntryAssociationParametersData());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkValidGLAccountType(final int type) {
|
private static boolean checkValidGLAccountType(final int type) {
|
||||||
@@ -208,7 +236,7 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GLAccountData> retrieveAllEnabledHeaderGLAccounts(final GLAccountType accountType) {
|
public List<GLAccountData> retrieveAllEnabledHeaderGLAccounts(final GLAccountType accountType) {
|
||||||
return retrieveAllGLAccounts(accountType.getValue(), null, GLAccountUsage.HEADER.getValue(), null, false);
|
return retrieveAllGLAccounts(accountType.getValue(), null, GLAccountUsage.HEADER.getValue(), null, false, new JournalEntryAssociationParametersData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user