Bill Calculator

◷ Reading Time: 7 minutes

Introduction

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

Scenario

In this 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
Folder Structure
  • Click on the Logic Run template.
  • Click on any given template.
logic run
  • 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.
Output Parameters

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

  • AdjustForFreeTier.xml – Adjust usages hours with free Tier threshold
  • AdjustForTier2Threshold.xml – Adjust usage hours with Tier 2 thresholds
  • AdjustForTier3Threshold.xml – Adjust usage hours with Tier 3 thresholds
  • 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

Fact Concept

  • Usage.xml – Define ‘UsageUnits’, ‘TierUnits’, and ‘HourlyCost’ objects

Boxed Expression

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

The Flow Design

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

2. Create Tier threshold values using the Literal

Boxed Expression

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.

Decision Graph
  • Adjustments Calculator – It consists of  2 expressions to calculate ‘TotalUnitsBeforeThisMonths’ and ‘ThisMonthUnitsBeforeLastHour’. These 2 values will be used in all the Decision Tables.
Calculation expression
  • 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.
Set initial tier
  • 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.
T2 Adjustment
  • 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.
T3 adjustment
  • 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.
Free tier

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.

Decision graph

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.

Tier Cost

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

Total cost

Create Tests Case

Sample tests data for the tier usage breakdown as follows.

test case

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.

run test

Download the project

Use the attachment at the end of the page to download the sample project.

Updated on October 4, 2022

Article Attachments

Was this article helpful?

Related Articles