Bill Calculator

Contents

Introduction

The Bill Calculator sample will show how to build a project that calculates the bill for cloud service usage.

Scenario

In this Bill Calculator example, we used a common billing model which consists of different tiers based on cloud resource usage. The total usage bill will be determined by the respective usage units based on tiers and relevant tier costs. And this vendor offers a free tier as well. Tier breakdown is as follows.

Running the Sample

• Open the file CalculateUsageCost.xml
• Click on the Logic Run template.
• Click on any given template.
• You can click the ‘Next Step’ button to go step by step to follow the flow.
• Now you can see the output values in the ‘Parameters’ window.

Bill Calculator process steps

The process contains the following steps to calculate ‘Total Payable Amount.

1. Usage Breakdown based on tiers
2. Calculate hourly cost for different tiers
3. Calculate the total payable amount

Project Description

The project contains the following documents.

Decision Graph

• CalculateUsageCost.xml – shows the main data flow
• DecsionSetAllTiers.xml – Create the usage breakdown based on Tier thresholds

Decision Table

• CalculateHourlyCost.xml – Calculate the hourly cost based on cost per unit
• CalculateTotalPayableAmount.xml – Calculate the total billing amount
• SetInitialTierUnits.xml – Set usage hours for Tiers based on Tier thresholds
• Usage.xml – Define ‘UsageUnits’, ‘TierUnits’, and ‘HourlyCost’ objects

• ThresholdValues.xml – Define the threshold values for respective tiers

The Bill Calculator flow design and decision tables

1. Define the UsageUnits as an input object and TierUnits and HourlyCost as output objects.
• Usage.xml

2. Create Tier threshold values using the Literal

3. Create a usage breakdown Decision Graph to split usage hours based on tier threshold values – UsageUnits object will be taken as an input object.

• Adjustments Calculator – It consists of  2 expressions to calculate ‘TotalUnitsBeforeThisMonths’ and ‘ThisMonthUnitsBeforeLastHour’. These 2 values will be used in all the Decision Tables.
• Determine Usages of Tiers – In this decision node, last-hour usage will be assigned temporarily, to respective tiers based on the already used units before the last hour.
• Adjust for T2 threshold – In this decision node, Tier1Units will be adjusted based on the Tier2 threshold value and if there are remaining units, those will be assigned to Tier2.
• Adjust for T3 threshold – In this decision node, Tier2Units will be adjusted based on the Tier3 threshold value and if there are remaining units, those will be assigned to Tier3.
• Adjust for Free Tier – In this decision node, last-hour usage will be adjusted with the free-tier threshold, for consumers who haven’t consumed the free tier yet.

4. Create a Decision Graph for total cost calculation

As you can see in the below model, all the previous processes are in a subgraph called Usage Breakdown to make the process far easier to understand.

5. Calculate Hourly Cost – In this decision node, last-hour usage cost will be calculated concerning the unit cost per tier based on adjusted Tier Units.

6 Total Payable Amount – In this decision node, it calculates the total cost for the usage.

Create Tests Case

Sample tests data for the tier usage breakdown as follows.

In a Test Case document, you import these tests data into Test Case Editor and Run the test case by clicking on Run Tests button.