Billing Central Apex API Developer Reference

ffbc.ProrationPlugin

global with sharing class ProrationPlugin

This class contains classes and interfaces that can be used to provide a custom proration calculation method. To create a plugin, create a class which implements the ffbc.ProrationPlugin.IPolicy interface. The class ffbc.ProrationPlugin.Period will give your plugin details of the period being prorated, and the class ffbc.ProrationPlugin.BillingPeriods will give information about the whole schedule of periods for the line item being prorated.
To use your plugin, add a picklist entry matching the name of the plugin class to the ffbc__ProrationPolicy__c.ffbc__CalculationMethod__c picklist. Any proration policies where the calculation method matches that picklist entry will use your plugin.
The plugin will be called many times during billing, so we recommend not to run any SOQL or DML in the 'applyTo' method.
Also note that your plugin will only be applied to the first and last periods for any given line, and only if either of those periods are partial.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

/**
 * A sample proration policy that attempts to calculate prorated price in terms of a daily rate that
 * is independent of which month is being billed.
 * To use this class, a new entry 'MyProrationPolicy' should be added to the
 * ffbc__ProrationPolicy__c.ffbc__CalculationMethod__c picklist.
 * Any proration policy that uses 'MyProrationPolicy' as its calculation method will use this plugin
 * to calculate proration.
 */
//Your plugin class must be global so that the Billing Central package can find it.
global class MyProrationPolicy implements ffbc.ProrationPlugin.IPolicy
{
    //This method will be called many times for different lines, so should not run any DML or SOQL.
    global Decimal applyTo(
        ffbc.ProrationPlugin.Period actualPeriod,
        ffbc.ProrationPlugin.BillingPeriods schedule,
        Decimal price)
    {
        return proratedPrice(actualPeriod, schedule, price);
    }

    private Decimal proratedPrice(
        ffbc.ProrationPlugin.Period actualPeriod,
        ffbc.ProrationPlugin.BillingPeriods schedule,
        Decimal price)
    {
        Integer numberOfMonths = schedule.getNumberOfMonthsPerPeriod();
        if (numberOfMonths == null)
        {
            //'getNumberOfMonthsPerPeriod' can return null for soft dates like '+50d' or 'WB' that
            //are not a constant number of months. How you handle this is up to you - you could try
            //a different calculation method, or (as in this case) just use the full price.
            return price;
        }

        /*
         * This is the code that actually calculates the price.
         * Note that this code is written to be understandable rather than to be correct -
         * in a real plugin you should not do any divisions until the very last step of the
         * calculation, to minimise rounding errors.
         */
        Decimal annualPrice = price * 12 / numberOfMonths;
        Decimal dailyPrice = annualPrice / 365;
        return dailyPrice * actualPeriod.getDays();
    }
}

ffbc.ProrationPlugin.IPolicy

global interface IPolicy

The interface for a particular calculation method. Your plugin must implement this interface.

Methods

applyTo

Decimal applyTo(ffbc.ProrationPlugin.Period actualPeriod, ffbc.ProrationPlugin.BillingPeriods schedule, Decimal price)

Prorates the price for a period. This method will be called many times for different periods during billing, so it should not run any SOQL or DML.

Input Parameters

Name Type Description
actualPeriod ffbc.ProrationPlugin.Period The period that is being considered for proration. This period may or may not be a partial period, the plugin will be called when calculating the price for all periods.
schedule ffbc.ProrationPlugin.BillingPeriods Contains information relating to the entire schedule of billing for the line being priced. For example this will contain information on how long a standard period is, or the dates of the first and last periods.
price Decimal The price for the period before proration. This will include any discounts.

Return Value

The prorated price for the period.

ffbc.ProrationPlugin.Period

global with sharing class Period

Represents a time period.

Properties

Name Type Description
StartDate Date The start of the period.
EndDate Date The end of the period, inclusive.

Methods

Period

global Period(Date startDate, Date endDate)

Creates a new period from given start and end dates. The end date can be null and is optional.

Input Parameters

Name Type Description
startDate Date The period start date.
endDate Date The period end date. Can be null with the meaning that it is an endless period.

Exceptions Thrown

Value Description
BillingCentralException The start date is either null or after the end date.

getDays

global Integer getDays()

Calculates the number of days in the period. The period must have an end date.

Exceptions Thrown

Value Description
BillingCentralException The period end date is null.

Return Value

The number of days in the period.

intersect

global ffbc.ProrationPlugin.Period intersect(ffbc.ProrationPlugin.Period toIntersect)

Intersects the period with another period, returning a new period. If the periods do not overlap, then they do not have an intersection.

Input Parameters

Name Type Description
toIntersect ffbc.ProrationPlugin.Period The period to intersect with.

Exceptions Thrown

Value Description
BillingCentralException The two periods being intersected do not overlap.

Return Value

The intersection of the two periods as a new object.

contains

global Boolean contains(Date value)

Checks whether the given date is within the start and end of the period.

Input Parameters

Name Type Description
value Date The date to compare with the period's start and end dates.

Return Value

True if the date is within this period, false otherwise.

ffbc.ProrationPlugin.BillingPeriods

global with sharing class BillingPeriods

Represents a collection of all the periods for a line item that is being prorated, and the rules to determine those periods. Contains methods that are helpful when prorating a line item, such as getting the number of months per period.

Methods

BillingPeriods

global BillingPeriods(String chargeTermDefinition, ffbc.ProrationPlugin.Period linePeriod)

Constructor for a BillingPeriods collection.

Input Parameters

Name Type Description
chargeTermDefinition String The charge term for the line.
linePeriod ffbc.ProrationPlugin.Period The period representing the full duration of the line.

Exceptions Thrown

Value Description
BillingCentralException The given charge term definition is invalid.

getFullPeriodIncluding

global ffbc.ProrationPlugin.Period getFullPeriodIncluding(Date dateInPeriod)

Returns the full billing period (unrestricted by the line's start and end dates) that contains the given date, out of all billing periods for the line being prorated.

Input Parameters

Name Type Description
dateInPeriod Date The date to be contained in the resulting period.

Exceptions Thrown

Value Description
BillingCentralException The given date is not within the start and end dates of the line being prorated.

Return Value

The line billing period containing the given date.

isEndDate

global Boolean isEndDate(Date periodEndDate)

Checks whether a given date is the end date of the line being prorated.

Input Parameters

Name Type Description
periodEndDate Date The date to check against the line end date.

Return Value

True if the given date is the end date of the line being prorated, false otherwise.

isFirstPeriodPartial

global Boolean isFirstPeriodPartial()

Checks whether the first period of the line being prorated is a partial period.

Return Value

True if the first period for the line is a partial period, false otherwise.

isLastPeriodPartial

global Boolean isLastPeriodPartial()

Checks whether the last period of the line being prorated is a partial period.

Return Value

True if the last period for the line is a partial period, false otherwise.

getFirstPeriod

global ffbc.ProrationPlugin.Period getFirstPeriod()

Returns the first period of the line being prorated.

Return Value

The first period.

getLastPeriod

global ffbc.ProrationPlugin.Period getLastPeriod()

Returns the last period of the line being prorated.

Return Value

The last period.

areFirstAndLastPeriodsDifferent

global Boolean areFirstAndLastPeriodsDifferent()

Checks whether the first and last periods are different periods.

Return Value

True if the first and last periods are different, false if they are the same period.

isPeriodPartial

global Boolean isPeriodPartial(ffbc.ProrationPlugin.Period actualPeriod)

Checks whether a given period is a partial period.

Input Parameters

Name Type Description
actualPeriod ffbc.ProrationPlugin.Period The period to check for being partial.

Return Value

True if the given period is a partial period, false otherwise.

getNumberOfMonthsPerPeriod

global Integer getNumberOfMonthsPerPeriod()

Returns the number of months per period for this collection of billing periods. Returns null for charge terms not expressed in terms of months, such as 'WB' or '+15d'.

Return Value

The number of months per period, or null.

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.