ffbc.ProrationPluginglobal 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. 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.IPolicyglobal interface IPolicy The interface for a particular calculation method. Your plugin must implement this interface. MethodsapplyToDecimal 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
Return ValueThe prorated price for the period. ffbc.ProrationPlugin.Periodglobal with sharing class Period Represents a time period. Properties
Methods
Periodglobal 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
Exceptions Thrown
getDaysglobal Integer getDays() Calculates the number of days in the period. The period must have an end date. Exceptions Thrown
Return ValueThe number of days in the period. intersectglobal 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
Exceptions Thrown
Return ValueThe intersection of the two periods as a new object. containsglobal Boolean contains(Date value) Checks whether the given date is within the start and end of the period. Input Parameters
Return ValueTrue if the date is within this period, false otherwise. ffbc.ProrationPlugin.BillingPeriodsglobal 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
BillingPeriodsglobal BillingPeriods(String chargeTermDefinition, ffbc.ProrationPlugin.Period linePeriod) Constructor for a BillingPeriods collection. Input Parameters
Exceptions Thrown
getFullPeriodIncludingglobal 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
Exceptions Thrown
Return ValueThe line billing period containing the given date. isEndDateglobal Boolean isEndDate(Date periodEndDate) Checks whether a given date is the end date of the line being prorated. Input Parameters
Return ValueTrue if the given date is the end date of the line being prorated, false otherwise. isFirstPeriodPartialglobal Boolean isFirstPeriodPartial() Checks whether the first period of the line being prorated is a partial period. Return ValueTrue if the first period for the line is a partial period, false otherwise. isLastPeriodPartialglobal Boolean isLastPeriodPartial() Checks whether the last period of the line being prorated is a partial period. Return ValueTrue if the last period for the line is a partial period, false otherwise. getFirstPeriodglobal ffbc.ProrationPlugin.Period getFirstPeriod() Returns the first period of the line being prorated. Return ValueThe first period. getLastPeriodglobal ffbc.ProrationPlugin.Period getLastPeriod() Returns the last period of the line being prorated. Return ValueThe last period. areFirstAndLastPeriodsDifferentglobal Boolean areFirstAndLastPeriodsDifferent() Checks whether the first and last periods are different periods. Return ValueTrue if the first and last periods are different, false if they are the same period. isPeriodPartialglobal Boolean isPeriodPartial(ffbc.ProrationPlugin.Period actualPeriod) Checks whether a given period is a partial period. Input Parameters
Return ValueTrue if the given period is a partial period, false otherwise. getNumberOfMonthsPerPeriodglobal 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 ValueThe number of months per period, or null. |