Nue Knowledge Center

Nue Docs navigation

search
clear
/

Invoice Preview Plugin

Invoice Preview Plugin

In particular circumstances, certain products in orders need to be excluded from the billing process. To address this, you can set up billing schedule filters to remove them during billing. However, it's equally important to ensure they are excluded from the invoice preview as well.

 

For example, the company Smart Revenue has a legacy system to bill and manage implementation projects.  So the company would like to exclude 'Implementation Service' from the invoice preview.  

 

The user can follow the steps below to implement an Invoice Preview Plugin to create a invoice preview filter using Salesforce Apex code.  

Step 1: Implement Invoice Preview Plugin

Step 2: Register the Plugin

Step 3: Test the Invoice Preview

 

Step 1: Implement Invoice Preview Plugin

Create an Apex class that implements the following interface: 

Ruby.CustomPluginManager.InvoicePreviewPlugin

 

Note : The apex class must be declared as ‘global’ since the interface is a global interface

 

There are 2 interface methods in this Plugin interface: 

  • getExcludedQuoteLineItems(List<Id> quoteLineItemIds)
    • Implementing this interface method will add the capability to exclude specified line items during the Invoice Preview for quotes. 
  • getExcludedOrderItems(List<Id> orderItemIds)
    • Implementing this interface method will add the capability to exclude specified line items during the Invoice Preview for orders and accounts.  
/**
 * Invoice Preview Plugin interface. 
 */
global interface InvoicePreviewPlugin {
  // Return a list of order item IDs to be excluded from the invoice preview of Orders and Accounts.  The orderItemIds includes a list of order product IDs currently included in the invoice preview of orders and accounts. 
  List<Id> getExcludedOrderItems(List<Id> orderItemIds);

  // Return a list of quote line items to be excluded form the invoice preview of quotes.  The quoteLineItemIds includes a list of quote line items currently included in the invoice preview of quotes. 
  List<Id> getExcludedQuoteLineItems(List<Id> quoteLineItemIds);
}

 

Please see an example below: 

/**
 * Example: Excludes line items containing products with name 'Implemention Service' in the invoice preview of quotes, orders and accounts. 
 */
global class InvoicePreviewPluginImpl implements Ruby.CustomPluginManager.InvoicePreviewPlugin {
    // Excludes line items from the invoice preview of orders and accounts
    global List<Id> getExcludedOrderItems(List<Id> orderItemIds) {
        List<OrderItem> lineItems = [SELECT Id, Ruby__ProductName__c FROM OrderItem WHERE Id IN :orderItemIds];
        List<Id> excludedList = new List<Id>();
        if (lineItems != null) {
            for (OrderItem item : lineItems) {
                if (item.Ruby__ProductName__c == 'Implementation Service') {
                    excludedList.add(item.Id);
                }
            }
        }
        return excludedList;
    }

    // Excludes line items from the invoice preview of quotes
    global List<Id> getExcludedQuoteLineItems(List<Id> quoteLineItemIds) {
        List<QuoteLineItem> lineItems = [SELECT Id, Ruby__ProductName__c FROM QuoteLineItem WHERE Id IN :quoteLineItemIds];
        List<Id> excludedList = new List<Id>();
        if (lineItems != null) {
            for (QuoteLineItem item : lineItems) {
                if (item.Ruby__ProductName__c == 'Implementation Service') {
                    excludedList.add(item.Id);
                }
            }
        }
        return excludedList;
    }
}

Step 2: Register the Plugin 

Login to your Salesforce Org and navigate to Setup.  

  • Search for ‘Custom Setting’ and navigate to the Custom Settings list page.
  • Click on the ‘Manage’ link on ‘Nue System Setting’
  • Search for 'InvoicePreviewPlugin’ and click ‘Edit’.  If there is no entry found, create a new record with the following information: 
    • Name: InvoicePreviewPlugin
    • Category: Custom Plugin
    • Description: Invoice Preview Custom Plugin
    • Label: Invoice Preview Plugin
  • In the Value field, enter your Apex class name, e.g., InvoicePreviewPluginImpl, and click 'Save'.  

Step 3: Test the Plugin

Now the plugin is ready to be tested.  Please refer to this article to enable Invoice Preview and test that the plugin works for quotes, orders and accounts.