Merge remote-tracking branch 'goutham/Mifosx-286' into develop

This commit is contained in:
Keith Woodlock
2013-05-21 13:48:46 +01:00
7 changed files with 83 additions and 53 deletions
@@ -126,5 +126,45 @@ public class GLAccountData {
final CodeValueData tagId = null;
return new GLAccountData(id, name, parentId, glCode, disabled, manualEntriesAllowed, type, usage, description, nameDecorated, tagId);
}
public GLAccountData(final Long id, final String name, final String glCode) {
this.id = id;
this.name = name;
this.parentId = null;
this.glCode = glCode;
this.disabled = false;
this.manualEntriesAllowed = false;
this.type = null;
this.usage = null;
this.description = null;
this.nameDecorated = null;
this.tagId = null;
this.accountTypeOptions = null;
this.usageOptions = null;
this.assetHeaderAccountOptions = null;
this.liabilityHeaderAccountOptions = null;
this.equityHeaderAccountOptions = null;
this.incomeHeaderAccountOptions = null;
this.expenseHeaderAccountOptions = null;
this.allowedAssetsTagOptions = null;
this.allowedLiabilitiesTagOptions = null;
this.allowedEquityTagOptions=null;
this.allowedIncomeTagOptions=null;
this.allowedExpensesTagOptions=null;
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getGlCode() {
return this.glCode;
}
}
@@ -83,7 +83,7 @@ public class AccountingRuleApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
AccountingRuleData accountingRuleData = this.accountingRuleReadPlatformService.retrieveNewAccountingRuleDetails();
AccountingRuleData accountingRuleData = null;
accountingRuleData = handleTemplate(accountingRuleData);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -12,7 +12,7 @@ import java.util.Set;
* Enum of all parameters passed in while creating/updating a loan product
***/
public enum AccountingRuleJsonInputParams {
ID("id"), OFFICE_ID("officeId"), ACCOUNT_TO_DEBIT("accountToDebitId"), ACCOUNT_TO_CREDIT("accountToCreditId"), NAME("name"), DESCRIPTION(
ID("id"), OFFICE_ID("officeId"), ACCOUNT_TO_DEBIT("debitAccountHead"), ACCOUNT_TO_CREDIT("creditAccountHead"), NAME("name"), DESCRIPTION(
"description"), SYSTEM_DEFINED("systemDefined");
private final String value;
@@ -62,9 +62,9 @@ public class AccountingRuleCommand {
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("AccountingRule");
baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue()).value(this.accountToDebitId)
.ignoreIfNull().integerGreaterThanZero();
.ignoreIfNull().notBlank().integerGreaterThanZero();
baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue()).value(this.accountToCreditId)
.ignoreIfNull().integerGreaterThanZero();
.ignoreIfNull().notBlank().integerGreaterThanZero();
baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.OFFICE_ID.getValue()).value(this.officeId).ignoreIfNull()
.integerGreaterThanZero();
baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.NAME.getValue()).value(this.name).ignoreIfNull().notBlank()
@@ -22,15 +22,11 @@ public class AccountingRuleData {
private final Long id;
private final Long officeId;
private final String officeName;
private final Long accountToDebitId;
private final Long accountToCreditId;
private final String name;
private final String description;
private final boolean systemDefined;
private final String debitAccountName;
private final String creditAccountName;
private final String debitAccountGLCode;
private final String creditAccountGLCode;
private final GLAccountData debitAccountHead;
private final GLAccountData creditAccountHead;
// template
@SuppressWarnings("unused")
@@ -38,36 +34,30 @@ public class AccountingRuleData {
@SuppressWarnings("unused")
private List<GLAccountData> allowedAccounts = new ArrayList<GLAccountData>();
public AccountingRuleData(final Long id, final Long accountToDebitId, final Long accountToCreditId) {
/*public AccountingRuleData(final Long id, final Long accountToDebitId, final Long accountToCreditId) {
this(id, null, null, accountToDebitId, accountToCreditId, null, null, true, null, null, null, null, null, null);
}
}*/
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId,
/*public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId,
final Long accountToCreditId, final String name, final String description, final boolean systemDefined,
final String debitAccountName, final String creditAccountName, final String debitAccountGLCode,
final String creditAccountGLCode) {
this(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined, debitAccountName,
creditAccountName, debitAccountGLCode, creditAccountGLCode, null, null);
}
}*/
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId,
final Long accountToCreditId, final String name, final String description, final boolean systemDefined,
final String debitAccountName, final String creditAccountName, final String debitAccountGLCode,
final String creditAccountGLCode, final List<OfficeData> allowedOffices, final List<GLAccountData> allowedAccounts) {
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final String name, final String description,
final boolean systemDefined, final List<OfficeData> allowedOffices, final List<GLAccountData> allowedAccounts) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
this.accountToDebitId = accountToDebitId;
this.accountToCreditId = accountToCreditId;
this.name = name;
this.description = description;
this.systemDefined = systemDefined;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = debitAccountName;
this.creditAccountName = creditAccountName;
this.debitAccountGLCode = debitAccountGLCode;
this.creditAccountGLCode = creditAccountGLCode;
this.debitAccountHead = null;
this.creditAccountHead = null;
}
public AccountingRuleData(final AccountingRuleData accountingRuleData,
@@ -75,33 +65,39 @@ public class AccountingRuleData {
this.id = accountingRuleData.id;
this.officeId = accountingRuleData.officeId;
this.officeName = accountingRuleData.officeName;
this.accountToDebitId = accountingRuleData.accountToDebitId;
this.accountToCreditId = accountingRuleData.accountToCreditId;
this.name = accountingRuleData.name;
this.description = accountingRuleData.description;
this.systemDefined = accountingRuleData.systemDefined;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = accountingRuleData.debitAccountName;
this.creditAccountName = accountingRuleData.creditAccountName;
this.debitAccountGLCode = accountingRuleData.debitAccountGLCode;
this.creditAccountGLCode = accountingRuleData.creditAccountGLCode;
this.debitAccountHead = accountingRuleData.debitAccountHead;
this.creditAccountHead = accountingRuleData.creditAccountHead;
}
public AccountingRuleData(final List<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices) {
this.id = null;
this.officeId = null;
this.officeName = null;
this.accountToDebitId = null;
this.accountToCreditId = null;
this.name = null;
this.description = null;
this.systemDefined = false;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = null;
this.creditAccountName = null;
this.debitAccountGLCode = null;
this.creditAccountGLCode = null;
this.debitAccountHead = null;
this.creditAccountHead = null;
}
public AccountingRuleData(Long id, Long officeId, String officeName, String name, String description,
boolean systemDefined, GLAccountData debitAccountData, GLAccountData creditAccountData) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
this.name = name;
this.description = description;
this.systemDefined = systemDefined;
this.allowedOffices = null;
this.allowedAccounts = null;
this.debitAccountHead = debitAccountData;
this.creditAccountHead = creditAccountData;
}
}
@@ -15,6 +15,4 @@ public interface AccountingRuleReadPlatformService {
AccountingRuleData retrieveAccountingRuleById(long accountingRuleId);
AccountingRuleData retrieveNewAccountingRuleDetails();
}
@@ -9,6 +9,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.accounting.rule.data.AccountingRuleData;
import org.mifosplatform.accounting.rule.exception.AccountingRuleNotFoundException;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
@@ -35,7 +36,7 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
public AccountingRuleMapper() {
final StringBuilder sqlBuilder = new StringBuilder(400);
sqlBuilder.append(" rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,")
sqlBuilder.append("distinct rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,")
.append(" rule.debit_account_id as debitAccountId,rule.credit_account_id as creditAccountId,")
.append(" rule.description as description, rule.system_defined as systemDefined, ")
.append("debitAccount.glName as debitAccountName, debitAccount.glCode as debitAccountGLCode,")
@@ -68,23 +69,25 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
final String creditAccountName = rs.getString("creditAccountName");
final String debitAccountGLCode = rs.getString("debitAccountGLCode");
final String creditAccountGLCode = rs.getString("creditAccountGLCode");
final GLAccountData debitAccountData = new GLAccountData(accountToDebitId, debitAccountName, debitAccountGLCode);
final GLAccountData creditAccountData = new GLAccountData(accountToCreditId, creditAccountName, creditAccountGLCode);
return new AccountingRuleData(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined,
debitAccountName, creditAccountName, debitAccountGLCode, creditAccountGLCode);
return new AccountingRuleData(id, officeId, officeName, name, description, systemDefined, debitAccountData, creditAccountData);
}
}
@Override
public List<AccountingRuleData> retrieveAllAccountingRules(Long officeId) {
final AccountingRuleMapper rm = new AccountingRuleMapper();
Object[] arguments = new Object[]{};
String sql = "select " + rm.schema() +" and system_defined=0 ";
if(officeId != null) {
String sql = "select " + rm.schema() + " where system_defined=0 and office.id = ?";
sql = sql + " order by rule.id asc";
return this.jdbcTemplate.query(sql, rm, new Object[] { officeId });
sql = sql +" and office.id = ?";
arguments = new Object[] { officeId };
}
String sql = "select " + rm.schema() + " and system_defined=0 ";
sql = sql + " order by rule.id asc";
return this.jdbcTemplate.query(sql, rm, new Object[] {});
return this.jdbcTemplate.query(sql, rm, arguments);
}
@Override
@@ -100,11 +103,4 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
throw new AccountingRuleNotFoundException(accountingRuleId);
}
}
@Override
public AccountingRuleData retrieveNewAccountingRuleDetails() {
// Modify if any default values required
return null;
}
}