The following example shows how to update an invoice. You can edit the properties of the invoice as well as adjust the invoice summary or adjust the invoice's line items when you perform an invoice update.
The section of the example that shows how to adjust an invoice summary does so by changing the invoice total to a specified amount. It is assumed that there is an existing invoice that will be adjusted. To access an existing invoice, use the InvoiceRepository's updateInvoice method. To create the invoice summary adjustment, use the type class, InvoiceAdjustmentCreate. Note that there are other ways to adjust an invoice summary and you can refer to the User Guide for more general information.
When creating an invoice summary adjustment, you must use the following set methods to populate required fields: setAdjustingUserUniqueKey(String value), setAdjustmentDate(Date value), setAdjustmentTarget(InvoiceAdjustmentTarget value), setAdjustmentValue(BigDecimal value), setAdjustmentMethod(AdjustmentMethod value).
For more information on adjusting line items, see Adjusting Invoice Line Items.
//for this example, it is assumed that you already know the target
invoice record's unique key (where uniqueKey is a String variable)
protected InvoiceRepository invoice = new InvoiceRepository();
InvoiceUpdate invoice = updateInvoice();
invoice.updateInvoice(invoice);
private InvoiceUpdate updateInvoice() throws Exception {
Date date = new Date();
String uniqueKey = "inv5010897";
InvoiceUpdate invoice = new InvoiceUpdate();
//next line used to ID the invoice to update
invoice.setUniqueKey(uniqueKey);
//these 3 lines update invoice properties
invoice.setNumberString("inv100-2053");
invoice.setInvoiceDate(date);
invoice.setVendorUniqueKey("ven2345");
//these lines are used to adjust the invoice header/summary
invoice.getAdjustmentUpdates().add(createInvoiceAdjustment());
return invoice;
}
private InvoiceAdjustmentCreate createInvoiceAdjustment() throws Exception {
String userUniqueKey = "user101";
InvoiceAdjustmentCreate invoiceAdjustment = new InvoiceAdjustmentCreate();
invoiceAdjustment.setAdjustingUserUniqueKey(userUniqueKey);
invoiceAdjustment.setAdjustmentDate(date);
invoiceAdjustment.setAdjustmentTarget(InvoiceAdjustmentTarget.TOTAL_INVOICE);
invoiceAdjustment.setAdjustmentValue(2005.17);
invoiceAdjustment.setAdjustmentMethod(AdjustmentMethod.NEW_AMOUNT);
invoiceAdjustment.setInHouseComments("Rejected invoice because the timekeeper rate exceeds our agreement. Adjusting the total per acceptable rates.");
invoiceAdjustment.setCommentsToVendor("Rejected invoice because the timekeeper rate exceeds our agreement. Adjusting the total per acceptable rates.");
return invoiceAdjustment;
}