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.

 

Expenses

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

Creating expenses

The following sample creates an expense record.

Code Snippet

protected ExpenseRepository expenseRepository; 
private String createExpense() throws Exception {
     date = new Date();
    ExpenseCreate expense = new ExpenseCreate(); 
    expense.setContactUniqueKey("CONT_1003");
    //expenseDate is a required property expense.setExpenseDate(date);
    //expensedByUniqueKey is a required property expense.setExpensedByUniqueKey("EXPE_1212");
    //shortDescription is a required property expense.setShortDescription(String value); 
    expense.setProjectUniqueKey(String value); 
    expense.setQuantity(BigDecimal value); 
    expense.setUnitPrice(BigDecimal value);
    return expenseRepository.insertExpense(expense);
}

Updating expenses

The following sample updates an expense record's expenseDate, projectUniqueKey, quantity, totalAmount, unitPrice values.

Code Snippet

//for this sample, it is assumed that an expense record already exists with a unique key String equal to uniqueKey
protected ExpenseRepository expenseRepository;
public void test_updateExpense() throws Exception {     
    Date date = new Date();
    ExpenseUpdate expenseUpdate = new ExpenseUpdate();
    //use the setUniqueKey method to identify the target expense record to update by its unique key
    expenseUpdate.setUniqueKey(uniqueKey); 
    expenseUpdate.setExpenseDate(date); 
    expenseUpdate.setProjectUniqueKey("DISP_2003"); 
    expenseUpdate.setQuantity(15.0); 
    expenseUpdate.setUnitPrice(2.0);
    //Note that the totalAmount property is calculated by the product of the quantity and unitPrice property values. 
    In the expense update sample provided, the totalAmount property will automatically be updated to 30.0
    expenseRepository.updateExpense(expenseUpdate);
}

Reading expenses

The following sample reads an expense record and returns the specified property values.

Code Snippet

protected ExpenseRepository expenseRepository; 
private List<String> getPropertiesToRead() {
    List<String> props = new List<String>();
    //the list of all available properties displays below but to ncrease efficiency in your searches, 
    you can omit unnecessary properties from your application and those values will not be returned
    props.add("shortDescription"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("modifiedBy"); 
    props.add("createdBy"); 
    props.add("modifiedOn"); 
    props.add("version"); 
    props.add("contact"); 
    props.add("expenseDate"); 
    props.add("expensedBy"); 
    props.add("project"); 
    props.add("quantity"); 
    props.add("unitPrice"); 
    props.add("totalAmount"); 
    return props;
}
private Expense readExpense() throws Exception {
    Expense readExpense = expenseRepository.readExpense(uniqueKey, 
    getPropertiesToRead());
    return readExpense;
}

Searching expenses

The following sample searches for one or more expense records and returns the specified property values. For this sample, it is assumed there are one or more expenses already existing with a subject String field value equal to subject.

Code Snippet

protected ExpenseRepository expenseRepository;
private List<Expense> test_readExpensesByCriteria() throws Exception
{
    // Criterion for expense searching
    StringFieldCriterion fieldCriterion = new StringFieldCriterion(); 
    fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE);
    LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression();
    fieldPathExpression.setSearchKeyPath("shortDescription"); 
    fieldCriterion.setFieldPath(fieldPathExpression); 
    fieldCriterion.getValue().add(subject);
    FieldSearchClause searchCriteria = new FieldSearchClause(); 
    searchCriteria.setOperator(LogicOperator.AND); 
    searchCriteria.getCriteria().add(fieldCriterion);
    expenses = expenseRepository.readExpensesByCriteria(searchCriteria, 100, 
    getPropertiesToRead());
}
private List<String> getPropertiesToRead() { List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your searches, 
    you can omit unnecessary properties from your application and those values will not be returned
    props.add("shortDescription"); 
    props.add("uniqueKey"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("modifiedBy"); 
    props.add("createdBy"); 
    props.add("modifiedOn"); 
    props.add("version"); 
    props.add("contact"); 
    props.add("expenseDate"); 
    props.add("expensedBy"); 
    props.add("project"); 
    props.add("quantity"); 
    props.add("unitPrice");
    props.add("totalAmount"); 
    return props;
}

Posting expenses

The following sample posts an expense with given unique key.

Code Snippet

String expenseUniqueKey = "EXPE_1001"; 
protected ExpenseRepository expenseRepository;
expenseRepository.postExpense(expenseUniqueKey);

Voiding expenses

The following sample voids a expense with given unique key.

Code Snippet

String expenseUniqueKey = "EXPE_1001"; 
protected ExpenseRepository expenseRepository;
expenseRepository.voidExpense(expenseUniqueKey);

Deleting expenses

The following sample deletes an existing expense.

Code Snippet

//for this sample, it is assumed that an expense record already exists with a unique key String equal to uniqueKey
protected ExpenseRepository expenseRepository; 
public void test_deleteExpense() throws Exception {
    expenseRepository.deleteExpense(uniqueKey);
}
  • Was this article helpful?