Skip to main content
Mitratech Success Center

Client Support Center

Need help? Click a product group below to select your application and get access to knowledge articles, webinars, training content, and release notes or to contact our support team.

Authorized users - log in to create a ticket, view tickets status and check your success plan details.

 

Accounts

The following .JAVA code samples show how you can use TeamConnect® Enterprise Web Services for functions specific to account records.

Creating accounts

The following sample creates an account record. In the sample, required fields are commented. During account creation, it is optional to set posting criteria or definitions on which types of financial records can post to the account (for example, tasks, expenses, invoices).

Code Snippet

Date date = new Date();
protected AccountRepository accountRepository; 
AccountCreate account = createAccount();
String accountUniqueKey = accountRepository.insertAccount(account); 
private String createAccount() throws Exception {
    AccountCreate account = new AccountCreate();
    //name is a required field account.setName("2009-Q1");
    //startOn date is a required field account.setStartOn(01-JAN-09);
    //endOn date is a required field account.setEndOn(31-MAR-09);
    //allocationLimit is a required field account.setAllocationLimit(25000.00);
    //(optional) set the account type as BUDGET or RESERVE account.setType(AccountType.BUDGET);
    //(optional) set the account overdraft type account.setAccountOverdraftType(AccountOverdraftType.ALLOW_NEGATIVE);
    //(optional) if this is a child account, set the parent account account.setParentAccountUniqueKey("ACCT_4141");
    returns account;
}

Code Snippet for setting account posting criteria

//the following sample code would be used as an excerpt from the above sample for creating an account; 
it is presented separately just to simplify the process for setting account posting criteria
//the following section sets posting criteria that allows tasks of a certain category to post to this account
account.setAllowTask(true); account.setTaskCategoryUniqueKey(taskCategoryUniqueKey);
account.setTaskPercent(100);
//the following section sets posting criteria that allows expenses of a certain category to post to this account
account.setAllowExpense(true); 
account.setExpenseCategoryUniqueKey(expenseCategoryUniqueKey); 
account.setExpensePercent(100);
//the following section sets posting criteria that allows invoice expense line items of a certain category to post to this 
account
account.setAllowInvoiceExpense(true); 
account.setInvoiceExpenseCategoryUniqueKey(invoiceExpCategoryUniqueKey); 
account.setInvoiceExpensePercent(100);
//the following section sets posting criteria that allows invoice fee line items of a certain category to post to this account
account.setAllowInvoiceTask(true); 
account.setInvoiceTaskCategoryUniqueKey(invoiceTaskCategoryUniqueKey); 
account.setInvoiceTaskPercent(100);

Updating accounts

The following sample updates an existing account record.

Code Snippet

Date date = new Date();
protected AccountRepository accountRepository;
//for this example, it is assumed that you already know the target account record's unique key 
(where uniqueKey is a String variable)
AccountUpdate account = new AccountUpdate();
account.setUniqueKey(uniqueKey);
account.setName("Budget 2009 Q2");
account.setAllocated(15000.00);
account.setAllocationLimit(20000.00);
account.setUsed(5000.00);
account.setAvailable(10000.00);
account.setStartOn(date);
account.setAccountOverdraftType(AccountOverdraftType.ALLOW_NEGATIVE);
account.setType(AccountType.BUDGET);
account.setActive(true);
//setting the autoPost property to true indicates that financial transactions can post to this account;
account.setAutoPost(true); account.setParentAccountUniqueKey("ACCT_1519");
accountRepository.updateAccount(account);

Reading accounts

The following sample reads an existing account record.

Code Snippet

//for this example, it is assumed that you already know the target account record's unique key 
(where uniqueKey is a String variable)
protected AccountRepository accountRepository; 
public void readAccount() throws Exception {
    Account account = (Account) accountRepository.readAccount(uniqueKey, getPropertiesToRead());
}
private List<String> getPropertiesToRead() { 
    List<String> properties = new List<String>(); 
    properties.add("createdBy"); properties.add("createdOn"); properties.add("modifiedBy"); 
    properties.add("modifiedOn"); properties.add("name"); properties.add("allocated"); 
    properties.add("allocationLimit"); 
    properties.add("used"); 
    properties.add("available"); 
    properties.add("startOn"); 
    properties.add("endOn"); 
    properties.add("expensePercent"); 
    properties.add("invoiceExpensePercent"); 
    properties.add("invoiceTaskPercent"); 
    properties.add("taskPercent"); 
    properties.add("allowExpense"); 
    properties.add("allowTask"); 
    properties.add("allowInvoiceExpense"); 
    properties.add("allowInvoiceTask"); 
    properties.add("accountInvolvedType"); 
    properties.add("accountVendorType"); 
    properties.add("accountProjectType"); 
    properties.add("accountOverdraftType"); 
    properties.add("type"); 
    properties.add("active"); 
    properties.add("autoPost"); 
    properties.add("categories"); 
    properties.add("expenseCategory"); 
    properties.add("taskCategory"); 
    properties.add("projectCategory"); 
    properties.add("invoiceExpenseCategory");
    properties.add("invoiceTaskCategory"); 
    properties.add("involved"); 
    properties.add("project"); 
    properties.add("vendor"); 
    properties.add("parentAccount"); 
    return properties;
}

Reading child accounts

The following sample reads child accounts of a parent account record. Identify the parent account by its unique key. In the sample, a complete list of account properties is provided but in your program, you can remove unnecessary properties to improve performance. Only the listed property values will be returned with the child accounts in the search results.

Code Snippet

//for this example, it is assumed that you already know the target parent account record's unique key 
(where uniqueKey is a String variable)
protected AccountRepository accountRepository; 
public void readChildAccounts() throws Exception {
    List<Account> accounts = (List<Account>)     
    accountRepository.readChildAccounts(uniqueKey, getPropertiesToRead());
}
private List<String> getPropertiesToRead() { 
    List<String> properties = new List<String>(); 
    properties.add("createdBy"); 
    properties.add("createdOn"); 
    properties.add("modifiedBy"); 
    properties.add("modifiedOn"); 
    properties.add("name"); 
    properties.add("allocated"); 
    properties.add("allocationLimit"); 
    properties.add("used"); 
    properties.add("available"); 
    properties.add("startOn"); 
    properties.add("endOn"); 
    properties.add("expensePercent"); 
    properties.add("invoiceExpensePercent"); 
    properties.add("invoiceTaskPercent"); 
    properties.add("taskPercent"); 
    properties.add("allowExpense"); 
    properties.add("allowTask"); 
    properties.add("allowInvoiceExpense"); 
    properties.add("allowInvoiceTask"); 
    properties.add("accountInvolvedType"); 
    properties.add("accountVendorType");
    properties.add("accountProjectType");
    properties.add("accountOverdraftType"); 
    properties.add("type"); 
    properties.add("active"); 
    properties.add("autoPost"); 
    properties.add("categories"); 
    properties.add("expenseCategory"); 
    properties.add("taskCategory"); 
    properties.add("projectCategory"); 
    properties.add("invoiceExpenseCategory"); 
    properties.add("invoiceTaskCategory"); 
    properties.add("involved"); 
    properties.add("project"); 
    properties.add("vendor"); 
    properties.add("parentAccount");
    return properties;
}

Searching accounts

The following sample searches for account records where the name contains "2009".

Code Snippet

//for this example, it is assumed that at least one account record that meets the search criterion already exists
protected AccountRepository accountRepository; 
public void searchAccounts() throws Exception {
    StringFieldCriterion fieldCriterion = new StringFieldCriterion(); 
    fieldCriterion.setComparator(StringComparator.CONTAINS);
    LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression();
    fieldPathExpression.setSearchKeyPath("name"); 
    fieldCriterion.setFieldPath(fieldPathExpression); 
    fieldcriterion.getValue().add("2009");
    FieldSearchClause searchCriteria = new FieldSearchClause(); 
    searchCriteria.setOperator(LogicOperator.AND); 
    searchCriteria.getCriteria().add(fieldCriterion);
    List<Account> accounts = accountRepository.readAccountsByCriteria(searchCriteria, 100, getPropertiesToRead());
}
private List<String> getPropertiesToRead() { 
    List<String> properties = new List<String>(); 
    properties.add("createdBy"); 
    properties.add("createdOn"); 
    properties.add("modifiedBy");
    properties.add("modifiedOn"); 
    properties.add("name"); 
    properties.add("allocated"); 
    properties.add("allocationLimit"); 
    properties.add("used"); properties.add("available"); 
    properties.add("startOn"); properties.add("endOn"); 
    properties.add("expensePercent"); properties.add("invoiceExpensePercent"); 
    properties.add("invoiceTaskPercent"); 
    properties.add("taskPercent"); 
    properties.add("allowExpense"); 
    properties.add("allowTask"); 
    properties.add("allowInvoiceExpense"); 
    properties.add("allowInvoiceTask"); 
    properties.add("accountInvolvedType"); 
    properties.add("accountVendorType"); 
    properties.add("accountProjectType"); 
    properties.add("accountOverdraftType"); 
    properties.add("type"); properties.add("active"); 
    properties.add("autoPost"); 
    properties.add("categories"); 
    properties.add("expenseCategory"); 
    properties.add("taskCategory"); 
    properties.add("projectCategory"); 
    properties.add("invoiceExpenseCategory"); 
    properties.add("invoiceTaskCategory"); 
    properties.add("involved"); 
    properties.add("project"); 
    properties.add("vendor"); 
    properties.add("parentAccount");
    return properties;
}

Activating accounts

The following sample activates an existing account record.

Code Snippet

// this sample assumes an account already exists with the unique key (String) value equal to uniqueKey
protected AccountRepository accountRepository; 
accountRepository.activateAccount(uniqueKey);

Deactivating accounts

The following sample deactivates an existing active account record.

Code Snippet

// this sample assumes an active account already exists with the unique key (String) value equal to uniqueKey
protected AccountRepository accountRepository; 
accountRepository.deactivateAccount(uniqueKey);

Allocating money to accounts

The following sample allocates money to an existing active account record.

Code Snippet

// this sample assumes an active account already exists with the unique key (String) value equal to uniqueKey
protected AccountRepository accountRepository;
//the allocated variable defines the monetary amount to allocate to the account BigDecimal 
allocated = new BigDecimal("1000.000000000000");
//the third parameter of the allocateMoney method is a String description of the fund allocation transaction
accountRepository.allocateMoney(uniqueKey, allocated, "test money allocation through Web Services");

Transferring money between accounts

The following sample transfers funds from a parent account to one of its child accounts. The transferMoney method can also transfer funds from a child account to its parent account. For the sample below, it is assumed that the following already exist:

  • a parent account which is active and has money already allocated to it, where the record's unique key is a String equal to parentUniqueKey
  • a child account for the parent which is active, where the record's unique key is a String equal to childUniqueKey

Code Snippet

protected AccountRepository accountRepository;
//the third parameter is the monetary amount to transfer between the parent and child account; 
the fourth parameter is a String description of the transfer transaction
accountRepository.transferMoney(parentUniqueKey, childUniqueKey, new BigDecimal("3333.00"), 
"money transferred through Web Services");

Withdrawing money from accounts

The following sample withdraws funds from an account. For the sample, it is assumed that an active account already exists.

Code Snippet

// this sample assumes an active account already exists with the unique key (String) value equal to uniqueKey
protected AccountRepository accountRepository;
// Withdraw money from the account
BigDecimal used = new BigDecimal("100.000000000000");
//the third parameter is a String description of the withdrawal transaction 
accountRepository.withdrawMoney(uniqueKey, used, "test allocating");

Deleting accounts

The following sample deletes an existing account record.

Code Snippet

//for this example, it is assumed that you already know the target account record's unique key 
(where uniqueKey is a String variable)
protected AccountRepository accountRepository; 
accountRepository.deleteAccount(uniqueKey);
  • Was this article helpful?