Enabling Opportunity Billing
Note
This document describes the legacy opportunity-to-invoice run. JustOn still provides this functionality for compatibility reasons with existing projects. For new projects, however, JustOn recommends to consider the opportunity a generic object and to set up opportunity billing using the generic invoice run. For details, see Billing Arbitrary Objects.
JustOn allows for creating invoices from opportunities. To this end, JustOn allows for configuring the standard opportunity object to hold the required invoicing data using the ON field mechanism. With custom filters, you then define which opportunities to include in the invoice run.
The opportunity products will figure as invoice line items on the created invoices.
Creating invoices from opportunities
Enabling opportunity billing involves the following mandatory tasks:
- Adding new fields to the Opportunity object to hold the required invoicing data
- Creating custom filters to define which opportunities to include in the invoice run
Optional setup steps may include:
- Assigning a specific invoice template
- Configuring optional lookup relations
- Configuring opportunity product behavior
- Enabling related invoice display for opportunities/related opportunity display for invoices
- Adding a button for manual invoice generation in the opportunity detail view
- Adding new opportunity stages for invoiced and not invoiced
Info
Note that for opportunity billing to work, your opportunities must include opportunity products, which will figure as invoice line items on the created invoices.
Adding Invoicing Fields to Opportunity
In order to hold the required invoicing data, you must add new fields to the Opportunity object.
- Navigate to the fields list of the Opportunity object.
-
Create the following new fields as required.
Mandatory fields
Field Label API Name Data Type Description Invoice Run ON_LastInvoiceRun Lookup (Invoice Run) Shows the last invoice run that has processed this opportunity Last Error ON_LastError Text (255) Shows possible errors occurred during the last invoice run Optional fields
Field Label API Name Data Type Description Email Contact ON_EmailContact Lookup (Contact)
or
Formula (Text)Shows a related contact Gross Invoice ON_GrossInvoice Boolean True if a gross invoice is to be generated Email Invoice ON_EmailInvoice Boolean True if the invoice is to be be sent via email Print Invoice ON_PrintInvoice Boolean True if the invoice is to be be printed For help about creating fields, see Managing Object Fields.
Info
You can add more fields using the ON field mechanism.
Creating Opportunity Filters
To define which opportunities to include in the invoice run, you create custom filters.
Info
At least one filter is required.
-
Click to enter Setup, then open Custom Settings.
In Salesforce Lightning, navigate to Custom Code > Custom Settings.
In Salesforce Classic, navigate to Develop > Custom Settings.
-
Click Manage in the row of Filters.
-
Create opportunity filter(s) as required, following the examples below.
For opportunity filters, a condition is mandatory.
For help about creating filters, see Filters.
Example filters
Name | Target | Condition |
---|---|---|
Closed Won | Opportunity | StageName = 'Closed Won' |
Closed Won Germany | Opportunity | RecordType.Name = 'Germany' AND StageName = 'Closed Won' |
Assigning an Invoice Template
Optionally, you can define an invoice template to the opportunity or, in the same way, to the corresponding account. JustOn tries to use the template defined with the opportunity first and falls back to account. If the field is not available or empty, the default invoice template will be used instead.
- Navigate to the fields list of the Opportunity object.
-
Create the new field for the invoice template as shown below.
Field Label API Name Possible Data Types Invoice Template ON_Template Lookup
(Template)Picklist
Formula
(Text, ID)Text
For help about creating fields, see Managing Object Fields.
Creating Lookup Relations
For reporting purposes, you may want to display the parent-child relations between
- an opportunity product and its corresponding invoice line item
- an invoice line item and its originating opportunity
using Salesforce's related list functionality (see Work with Related Lists on Records in the Salesforce Help). To this end, you need the corresponding lookup relations.
To create a lookup relation from the opportunity product and its corresponding invoice line item:
- Navigate to the fields list the Opportunity Product object.
-
Create the following new field.
Field Label API Name Data Type Invoice Line Item ON_InvoiceLineItem Lookup
(Invoice Line Item)For help about creating fields, see Managing Object Fields.
To create a lookup relation from the resulting invoice line item to its originating opportunity:
- Navigate to the fields list of the Invoice Line Item object.
-
Create the following new field.
Field Label API Name Data Type Opportunity ON_Opportunity Lookup
(Opportunity)For help about creating fields, see Managing Object Fields.
Managing Opportunity Product Behavior
When creating invoices from opportunities, each opportunity product will result in an invoice line item if the following criteria are true:
- the opportunity product has not been billed before, that is, it is not part of an
Open
orPaid
invoice - the service date is not set or it is between the period start and the period end of the invoice run
Info
The fields Service Period Start
and Service Period End
are not filtered against the invoice run period. They are just copied to the resulting invoice line item.
The fields of the opportunity product and its corresponding product are mapped in the following way:
Source Object | Field | Invoice Line Item Field | Description |
---|---|---|---|
OpportunityLineItem | Description | Description__c | will fallback to Product2.Description if empty |
OpportunityLineItem | Quantity | Quantity__c | |
OpportunityLineItem | List Price OR Sales Price | UnitPrice__c | Depends on discount calculation |
OpportunityLineItem | ON_UnitPrice__c | UnitPrice__c | Use the ON field to override the sales price. If present, the automatic discount calculation is disabled. |
OpportunityLineItem | ServiceDate, ON_ServicePeriodStart__c, ON_ServicePeriodEnd__c | ServicePeriodStart__c, ServicePeriodEnd__c | Use the ON fields to set the service period fields explicitly. If these fields are not available or empty, the service date is used. If the service date is empty, it will fallback to the period start and period end of the invoice run. |
OpportunityLineItem | ON_Sequence__c | Sequence__c | |
Product2 | ON_QuantityUnit__c | Unit__c | |
Product2 | Name | Title__c | |
Product2 | ProductCode | ProductCode__c | |
Product2 | Family | ProductGroup__c |
Info
The tax rate and the applied tax rule are determined by the corresponding account and the Product2 object.
Calculating Discount Amount for Opportunity Products
For calculating discounts, there are two options.
(A) If all of the following conditions are true
- SalesPrice < ListPrice
- SalesPrice >= 0
- Quantity >= 0
apply the following settings:
Invoice Line Item Field | Setting |
---|---|
UnitPrice__c | ListPrice |
Discount__c | empty |
DiscountAmount__c | -Quantity * (ListPrice + SalesPrice * (Discount - 1)) |
This results in a calculated discount amount.
(B) If the mentioned conditions are not true or if the opportunity product is scheduled (see Working with Scheduled Opportunity Products), apply the following settings:
Invoice Line Item Field | Setting |
---|---|
UnitPrice__c | SalesPrice |
Discount__c | Discount |
DiscountAmount__c | 0 |
This applies a percentage discount.
To make copying the sales price the default behavior:
- Navigate to the fields list of the Opportunity Product object.
-
Create the following new field.
Field Label API Name Data Type Use Sales Price ON_UseSalesPrice Checkbox (default: true
)For help about creating fields, see Managing Object Fields.
You can also control the discount amount calculation on the opportunity level. To do so, create the following new fields on the Opportunity object and the Opportunity Product object:
Object | Field Label | API Name | Data Type |
---|---|---|---|
Opportunity | Use Sales Price | ON_UseSalesPrice | Checkbox (default: true ) |
Opportunity Product | Use Sales Price | ON_UseSalesPrice | Formula (Opportunity.ON_UseSalesPrice__c ) |
Info
Using the custom field formula ON_UnitPrice__c
on the opportunity product has the same effect as setting the checkbox Use Sales Price
.
Enabling Opportunity Product Selection
You can set up an option to individually select opportunity products to be billed. When enabled, JustOn creates invoice line items only for the selected opportunity products.
- Navigate to the fields list of the Opportunity Product object.
-
Create the following new field.
Field Label API Name Data Type Is Billable ON_IsBillable Checkbox For help about creating fields, see Managing Object Fields.
Note
JustOn creates invoice line items out of opportunity products only if the checkbox field ON_IsBillable
does not exist or, if available, is marked.
Info
When using opportunity billing and if the ON_LastInvoiceRun__c
field of the opportunity is already set, you must start a new invoice run in order to consider new opportunity products after activating the checkbox ON_IsBillable
. If you do not want to create a new invoice run, you must clear the Invoice Run
field of the opportunity.
Working with Scheduled Opportunity Products
Note
Product scheduling must be enabled.
Note that the Product Schedules Settings are accessible in Salesforce Classic only.
To enable product scheduling:
-
Click to enter Setup, then open Product Schedules Settings.
In Salesforce Lightning, navigate to Feature Settings > Sales > Products > Product Schedules Settings.
In Salesforce Classic, navigate to Build > Customize > Products > Product Schedules Settings.
-
Enable
Quantity Schedules
,Revenue Schedules
or both. -
Click Save.
For details, see Enable Product Schedules in the Salesforce Help.
Each opportunity product schedule will result in an invoice line item if the following criteria are true:
- the opportunity product has not been billed before, that is, it is not part of an
Open
orPaid
invoice - the schedule date is set before the period end or equals it
The fields Title__c
, Description__c
, ProductCode__c
and ProductGroup__c
are populated as described in the opportunity product field mapping table.
The service period is set as follows.
Field | Value | Description |
---|---|---|
ServicePeriodStart__c | OpportunityLineItemSchedule.ScheduleDate |
|
ServicePeriodEnd__c | OpportunityLineItemSchedule.ScheduleDate of the next schedule - 1 day |
If there is no next schedule, the period end is used instead |
Quantity__c
and UnitPrice__c
will be set based on the type of the schedule:
Quantity-based schedules
Field | Value |
---|---|
Quantity__c | OpportunityLineItemSchedule.Quantity |
UnitPrice__c | OpportunityLineItem.UnitPrice |
Revenue-based schedules
Field | Value |
---|---|
Quantity__c | 1 |
UnitPrice__c | OpportunityLineItemSchedule.Revenue |
Quantity and revenue-based schedules
Field | Value |
---|---|
Quantity__c | OpportunityLineItemSchedule.Quantity |
UnitPrice__c | OpportunityLineItemSchedule.Revenue |
Info
Invoice line items with a quantity of 0
will be deleted.
Enabling Related List Display
Optionally, you can enable the display of
- related invoices in the opportunity details
- related opportunities in the invoice details
using Salesforce's related list functionality (see Work with Related Lists on Records in the Salesforce Help).
To add the related invoices list to the opportunity page layout:
- Navigate to the object management settings of the Opportunity object.
- Click Page Layouts.
- In the row of Opportunity Layout, click Edit.
-
Add the following Visualforce page to the page layout, then click Save.
Visualforce Page Business Logic OpportunityBilledAt Lists created invoices on the opportunity For help about modifying page layouts, see Managing Pages.
To add the related opportunities to the invoice page layout:
- Navigate to the object management settings of the Invoice object.
- Click Page Layouts.
- In the row of Invoice Layout, click Edit.
-
Add the following Visualforce page to the page layout, then click Save.
Visualforce Page Business Logic BilledOpportunities Lists billed opportunities on the invoice For help about modifying page layouts, see Managing Pages.
Miscellaneous Options
Enabling Single Invoice Generation per Opportunity
It is possible to generate single invoices per opportunity on the same account. To this end, you need new custom fields on the Opportunity and Invoice objects.
- Navigate to the fields list of the Opportunity or Invoice object, respectively.
-
Create the following new field.
Object API Name Data Type Description Opportunity ON_CreateSingleInvoice Boolean true
if a single invoice is to be generatedInvoice ON_InvoiceSeparately Boolean Will be set during the invoice run For help about creating fields, see Managing Object Fields.
Enabling Gross Invoice Generation
JustOn can generate net invoices, gross invoices or mixed net/gross invoices. This behavior is controlled using the checkbox Gross Invoice
on the invoice line item.
Info
You can set the checkbox Gross Invoice
on the invoice line item as of JustOn 2.50.
To enable the setting for opportunity billing, you need the ON field ON_GrossInvoice
on the Opportunity Product object.
- Navigate to the fields list of the Opportunity Product object.
-
Create the following new field.
API Name Data Type Description ON_GrossInvoice Boolean true
if a gross invoice is to be generatedFor help about creating fields, see Managing Object Fields.
Adding an Invoice Generation Button
Optionally, you can enable manual invoice generation from an opportunity using a button. Adding a new button for manual invoice generation involves two steps:
- Creating the button
- Adding the button to a page layout
To create the button:
- Navigate to the object management settings of the Opportunity object.
- Click Buttons, Links, and Actions.
- Click New Buttons or Link.
-
Create the following button, then click Save.
Detail Value Label New Invoice
Display Type Detail Page Button
Behavior Display in existing window with sidebar
Content Source Visualforce Page
Content NewInvoiceFromOpportunity
For help about creating buttons, see Managing Buttons or Links.
To add the button to the page layout:
- Navigate to the object management settings of the Opportunity object.
- Click Page Layouts.
- In the row of Opportunity Layout, click Edit.
-
Add the new button to the page layout, then click Save.
For help about modifying page layouts, see Managing Pages.
Creating Invoicing-Related Opportunity Stages
Optionally, opportunities can be transferred to a new stage once the opportunity products have been invoiced. To enable this feature:
-
Click to enter Setup, then open Custom Settings.
In Salesforce Lightning, navigate to Custom Code > Custom Settings.
In Salesforce Classic, navigate to Develop > Custom Settings.
-
Click Manage in the row of Global Settings.
- Click Edit in the Default row.
-
Specify values for the data fields
Billed Opportunity Stage Name
andNot Billed Opportunity Stage Name
, then click Save.Global Settings Data Field Use Case Example Value Billed Opportunity Stage Name Is set if all opportunity products have been invoiced, and the invoice is set Open
.Billed
Not Billed Opportunity Stage Name Is set if the related invoice has been (partially) canceled.
Depending on your business scenario, you can choose to use a new, dedicated stage, or to use the stage that originally triggers the invoice creation (as set as the filter condition).Not billed
Closed Won
The opportunity stages will be updated each time an opportunity-related invoice is updated.
Next steps:
Executing an Opportunity Invoice Run
Creating Invoice From an Individual Opportunity
Return to JustOn Administration.