The following example shows how to create an invoice and add an expense and fee line item to the invoice. When creating an invoice, you must populate a few required properties using the following methods (from the type class, InvoiceCreate): setNumberString, setInvoiceDate, and setVendorUniqueKey.
It is most practical to add one or more line items to an invoice. There are two types of line items you can add: expense or fee line items. For expense line items, you must populate a few required properties using the following methods (from the type class, LineItemCreate): setItemNumber, setServiceDate, setProjectUniqueKey, setOriginalRate, setOriginalQuantity, setOriginalDiscount, setType, and getCategories. For fee line items, you must populate a few required properties using the following methods (from the type class, LineItemCreate): setItemNumber, setServiceDate, setProjectUniqueKey, setOriginalRate, setOriginalQuantity, setOriginalDiscount, setType, getCategories, setTimekeeperUniqueKey, and setActivityUniqueKey.
Before starting, get the following:
•For expense line items, get the corresponding Line Item Expense Category Code(s)
•For fee line items, get the corresponding Line Item Fee Category Code(s) and Task Activity Lookup Table Activity Code(s)
When adding an expense line item to an invoice, use the Category object to specify the corresponding expense category. As described in the category example for contacts, you must already know the target expense category's unique key.
protected InvoiceRepository invoice = new InvoiceRepository();
InvoiceCreate invoice = createInvoice();
invoice.insertInvoice(invoice);
private InvoiceCreate createInvoice() throws Exception {
Date date = new Date();
long time = date.getTime();
InvoiceCreate invoice = new InvoiceCreate();
//numberString is a required field
invoice.setNumberString("invoice Web Service test " + time);
//vendorUniqueKey is a required field
invoice.setVendorUniqueKey("CONT_8094");
//invoiceDate is a required field
invoice.setInvoiceDate(date);
invoice.setComment("comment");
invoice.setPeriodStartDate(date);
invoice.setPeriodEndDate(new Date(time + 1000000));
invoice.setSubmittedElectronically(true);
invoice.setReceivedDate(date);
invoice.setTaxRate(new BigDecimal("8"));
invoice.setWarnings("invoice warning");
//Note that it is practical although not required to add one or more line items to an invoice
invoice.getLineItemCreates().addAll(createLineItems());
return invoice;
}
private List<LineItemCreate> createLineItems() throws Exception {
List<LineItemCreate> lineItems = new List<LineItemCreate>();
//create expense line item
LineItemCreate lineItem1 = new LineItemCreate();
//itemNumber is a required field
lineItem1.setItemNumber(1);
//for expense line items, originalQuantity is a required field that corresponds to a quantity of expense items being charged
lineItem1.setOriginalQuantity(new BigDecimal("2"));
//for expense line items, originalRate is a required field that corresponds to the per unit cost of expense item
lineItem1.setOriginalRate(new BigDecimal("50"));
//for expense line items, type (LineItemType) is a required field and would always be EXPENSE
lineItem1.setType(LineItemType.EXPENSE);
lineItem1.setServiceDate(date);
//category for each line item is a required field
Category cat1 = new Category();
cat1.setUniqueKey("EXPE");
lineItem1.getCategories().add(cat1);
lineItems.add(lineItem1);
//create fee line item
LineItemCreate lineItem2 = new LineItemCreate();
lineItem2.setItemNumber(2);
//for Fee line items, the originalQuantity is a required field and will correspond to the hours worked by the timekeeper
lineItem2.setOriginalQuantity(new BigDecimal("2"));
//for Fee line items, the originalRate is a required field and will correspond to the associated timekeeper's rate
lineItem2.setOriginalRate(new BigDecimal("50"));
//for fee line items, type (LineItemType) is a required field and would always be FEE
lineItem2.setType(LineItemType.FEE);
lineItem2.setServiceDate(date);
Category cat2 = new Category();
cat2.setUniqueKey("TASK");
lineItem2.getCategories().add(cat2);
//for fee line items, the activityUniqueKey is a required field; the ActivityUniqueKey property needs to be constructed by "ACTI_"+<4 character Task Activity Lookup Table Activity Code>; see the example below where the Activity Code is A101
lineItem2.setActivityUniqueKey("ACTI_A101");
lineItems.add(lineItem2);
return lineItems;
}