Use InvoiceService when working with invoice records.
Whenever a Service operation requires InvoiceService, set up InvoiceService using the following code:
InvoiceService invoiceService = platform.getInvoiceService(); |
The following sample creates an invoice and adds line items. During invoice creation, you can use API interface methods to set objects in the invoice record and line items, including the line item rate, quantity, discount, and total.
// vendor is an existing contact Company vendor = platform.getContactService().readCompany(45L);
CalendarDate invoiceDate = new CalendarDate(); Invoice invoice = invoiceService.newInvoice("456", vendor, invoiceDate); //the line item original rate. BigDecimal originalRate = new BigDecimal("23.00"); //the line item original quantity. BigDecimal originalQuantity = new BigDecimal("500"); //the line item original discount. BigDecimal originalDiscount = new BigDecimal("17.56"); //the line item original total. BigDecimal originalTotal = new BigDecimal("34805743570");
LineItem newLineItem = invoiceService.newExpenseLineItem(invoice, invoiceDate, "LNI$_EXPS_OCEX_E100_E101", originalRate, originalQuantity).setOriginalDiscount(originalDiscount).setOriginalTotal(originalTotal); |
The following sample updates and adjusts an invoice. When you update an invoice, you can use API interface methods to set objects in the invoice record, including the start date. You also use API interface methods to adjust an invoice, such as for reducing an amount to a new amount.
CalendarDate periodStartDate = new CalendarDate(); invoice.setPeriodStartDate(periodStartDate); AdjustmentInformation information = new AdjustmentInformation(AdjustmentMethod.REDUCE_BY_AMOUNT, new BigDecimal("45.00")); invoiceService.adjustInvoiceFees(invoice, information); |
The following sample adjusts an invoice line item. When you adjust a line item, you can use API interface methods to adjust the line item, such as changing a line item amount to a new amount.
AdjustmentInformation information = new AdjustmentInformation(AdjustmentMethod.NEW_AMOUNT, new BigDecimal("22.56"); invoiceService.adjustLineItemRate(lineItemToAdjust, information); |
The following sample reads an invoice record. When you read an invoice, you retrieve the invoice so that you can make changes to it, such as updating or posting to it.
// id of existing invoice. long id = 4982340L; Invoice invoice = invoiceService.read(id); |
The following sample searches for an invoice record.
// Returns all invoices that have an invoice date within the last 10 days SearchCriteria criteria = new SearchCriteria(new RelativeDateCriterion(Invoice.INVOICE_DATE).withinLast(10)); List<Invoice> invoices = invoiceService.search(criteria); |
The following sample posts an invoice.
invoiceService.postInvoice(invoiceToBePosted); |
The following sample voids an invoice.
invoiceService.voidInvoice(invoiceToBeVoided); |
The following sample voids an invoice.
invoiceService.delete(invoiceToBeDeleted); |