Billable Element Provider

Estimated reading: 4 minutes 7 views

Overview

The Billable Element Provider is in charge of loading the Billable Elements that are required to calculate the billing. The Billable Element is the main entity that is used to calculate the billing and it contains the information directly related the product or service that is being billed.

Out-of-the-box Provider

Wattyo Billing comes with an out-of-the-box Billable Element Provider that covers all the common scenarios and more complex ones.

By default Wattyo uses the standard one which must be setup in the Genneral Billing Settings.

The standard providers loads the Data structure your business require (by configuring an Object Tree) and then generate a Billable Element DTO by applying the specified DataMap.

For instance, you may setup an Object Tree that loads your Contract SOBJECT and the children Contract Items, and then create a DataMap that maps the Contract and Contract Items records and fields to the Billable Element DTO.

This way, Wattyo is completely flexible and can adapt to any data structure you may have.

Billable Element Provider DTO

The Billable Element Provider DTO is the object that Wattyo uses to handle the entity to be billed. The DTO is defined as follows:

class BillableElement {
    Id id;
    Id accountId;
    Id servicePointId;
    String company;
    String businessLine;
    String type;
    String tariff;
    String productId;
    String productCode;
    String priceListId;
    String priceListName;
    String status;
    Date versionStartDate;
    Date endDate;
    String periodicity;
    Integer periodValue;
    Date invoicedToDate;
    Date nextToDateToInvoice;
    List<Term> terms;

    class Term {
        Id id;
        String name;
        String value;
        Id parentTerm;
    }
}

Wattyo is continuosly evolving and adding new features so the DTO can change in future versions.

Extending the Element Provider DTO

Of course, if you need to add more fields to the Billable Element DTO, you can extend it by creating a new class that extends the Billable Element class and adds the new fields or structure that you need.

Custom Provider

In case your business requires a specific behaviour not covered by the out-of-the-box provider, you can create your own provider and setup Wattyo to use the custom one. In order to do this you must create a new Apex Class that implements the BillableElementProvider interface and set it in the General Billing Settings in the Billable Element Provider property.

BillableElementProviderInterface

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

public interface BillableElementProvider {
    Map<Id,BillableElement> getBillableElements(Set<Id> billableElementId);
    CalculationPack getBillableElementsPackage(Set<Id> billableElementIds, boolean includeSingles, boolean includeBundles);
    Map<BillableElement, InvoiceDTO> postProcess(Map<BillableElement, InvoiceDTO> invoicesByBillable, Map<String, Object> sharedContext);
}

getBillableElements()

This method is responsible for returning the Billable Elements that are required to calculate the billing. The method receives a set of Ids and returns a map where the key is the received Id and the value is the Billable Element DTO.

In other words, if you want to bill orders, these method should query the orders and convert them to the Billable Element DTO

getBillableElementsPackage()

This method is responsible for returning the Billable Elements that are required to calculate the billing. The method receives a set of Ids and two boolean flags that indicates if the method should include the single Billable Elements and the bundle Billable Elements.

The method returns a CalculationPack object that contains the Billable Elements and the related data that is required to calculate the billing.

The reason for this method is mainly to enable the Bundle Billing, when you can bill a group of Billable Elements as a single one.

The Calculation Pack is a very simple DTO where you need to set all the Billable Elements that are going to be billed, and in the Map, you set the Parent – Children relationship, where the key is the Parent Billable Element and the value is a set of the Children Billable Elements Ids.

 class CalculationPack {
    Set<Id> billableElementsIds;
    Map<Id, Set<Id>> secondariesByPrimaryMap; 
}

postProcess()

This method is responsible for processing the data after the invoice have 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.

The method receives a map where the key is the Billable Element DTO and the value is the Invoice DTO. The method returns the same map but with the updated data.

Leave a Comment

       
Euphoria, forever till the end of times

Euphoria

Share this Doc

Billable Element Provider

Or copy link

CONTENTS