Usage Provider

Estimated reading: 4 minutes 7 views

Overview

The Usage Provider is responsible for loading the usage data required to calculate the billing in case of usage-based billing.

Out-of-the-box Usage Provider

The out-of-the-box Usage Provider loads the usage data from the Consumption object.

We can refer to this Provider as Consumption Provider as it’s a specific implementation of the Usage Provider for the Consumption out-of-the-box object.

You can create multiple settings for the Consumption Provider depending on your needs. This is actually useful when you need to bill different types of usage data.

Consumption Settings

This settings are handled in the Consumption Settings in the Metering & Consumption Settings. Each settings you create has a filter definition that will be evaluated against the Device related to the billable element.

alt text

The settings are defined as follows:

Category Field Description Example
Filter Criteria Sets the filters to evaluate if the settings apply to the current Billable Element
Filter Criteria Device Type The Device Type that the settings apply to Industrial
Filter Criteria Device Model The Device Model Telemetry
Filter Criteria Device Record Type The Device Record Type Electricity
Setup The setup for the settings
Setup Mode It’s set the strategy to load the Consumptions it can be Base or Koala Base
Setup Mode Con The mode to group the consumptions: Total, Range or Daily Daily
Setup Calculation Mode It sets the algorithm to calculate the consumption: Difference or Keep Difference
Setup Split Method Implementation Apex Class Name implementing the ConsumptionSplitMethodInterface used to split the consumption in case is required. For example, in Water is usually required to split the consumption in different ranges. WaterSplitMethod
Setup Range Type It specifies the logic to retrieve the consumptions: Open – Open, Open – Close, Close – Open, Close – Close Open – Open
Setup Increasing Order It specifies if the consumptions must be ordered in increasing order True
Data Handling Key Field The field on the Consumption object poiting to the Device. Device__c
Data Handling Fieldset Fieldset API Name with the fields to retrieve from the Consumption Object. ConsumptionFields
Data Handling Ordering ASC or DESC ASC
Data Handling Group by Field Field api name to group the consumptions Device__c

Mode Con

Calculation Mode

Split Method Implementation

Range Type

Increasing Order

Key Field

Fieldset

Ordering

Group by Field

Custom Usage Provider

In case you need to implement your custom logic to load the usage data, you can create your own Usage Provider by implementing the UsageProvider interface.

For instance you may want to load the usage from an external service.

Usage Provider Interface

The Usage Provider interfaces defines the methods that must be implemented by the custom provider. The interface is defined as follows:

public interface UsageProviderInterface {
    Map<Id, List<UsageDTO>> loadUsages(Set<Id> servicepointIds, Date fromDate, Date toDate, List<String> status, Boolean validated);
    Set<String> getUsageFieldset(String fieldSetName);
    List<CalculationResult> postProcess(List<CalculationResult> calculationResults, Map<String, Object> sharedContext);
}

loadUsages

Returns the usage data for the specified Service Points and date range.

getUsageFieldset

Returns the fields corresponding to the specified FieldSet.

postProcess

Processes the data after the invoice has been generated. This is useful when you need to update the data in the system after the invoice has been generated, for instance if you want to link the billed usages to the invoice.

UsageDTO

The UsageDTO is the object that the provider must return. It is defined as follows:

public virtual with sharing class UsageDTO {
     String id;
     String meterList;
     String device;
     String servicePoint;
     Date fromDate;
     Time fromTime;
     Date toDate;
     Time toTime;
     String status;
     Boolean validated;
     String valmessage;
     Map<String, String> moreinfo;
     Map<String,Decimal> values;
}

Metering and Consumption

As stated before, the Consumption Provider is a specific implementation of the Usage Provider for the Consumption object that is included in the Metering and Consumption module.

If you need more information about this module, please refer to the Metering & Consumption documentation.

Leave a Comment

       
Euphoria, forever till the end of times

Euphoria

Share this Doc

Usage Provider

Or copy link

CONTENTS