Compensation Plan Creating a rule based compensation plan in goaffpro - anujtenani/goaffpro GitHub Wiki

Note: This feature is still under construction. The API may change without prior notice. This document is intended for people with technical knowledge. If the terms functions, variables seem foreign to you, please get in touch with our team and we will help you build your comp-plan

What is a compensation plan ?

A compensation plan is a set of rules to compensate an affiliate for their personal or their network referral sales

How does the plan work ?

Before building a compensation plan, one must decide a compensation schedule for the affiliates. The compensation schedule can be weekly, biweekly, monthly or quarterly. What this means is that, the plan's final calculation and allotment of money happens once a week in weekly and once month in monthly plans and running the plan multiple times of the same schedule, overrides the compensation given to the associates for the plan

For eg. Let's say you have a plan as follows

  • If affiliate's total sales in the current month < $100 = give him 10% commission on their sales
  • If affiliate's total sales in current month is > $100 = give him 15% commission on their sales
  • If affiliate's total sales in current month is > $500 = give him 20% commission on their sales

Now, the way you set it up, is that the affiliate either receives no commission until the month is over and when you run the plan, the total compensation is calculated for all their sales and given to the affiliate in one go

Plan format

The compensation plan is written as a JSON configuration file.

Example

To build a plan as above, you write JSON as below

{
  "frequency":"monthly", // schedule on which the plan will run. This constraints how often the final commission is calculated
  "columns":[ // columns can be thought of as columns in a spreadsheet which compute values, affiliate's tier or ranks on which rewards are given
      {
         "name":"Total sales (last month)", // name of the column. 
         "id":"totalSales", // a unique key (so the value in this column can be referenced later on)
         "func":"referralSalesVolume", // a function which derives the value in this column. For a list of available functions and their arguments see below
         "args":{ // arguments passed to this function
            "period":"lastmonth"
         }
      },
      // by this point we have computed a column for every affiliate which has their personal sales volume of the last month. Now we will decide which tier of commission this affiliate falls in

      {
         "name":"Bronze Tier",
         "id":"bronzeTier",
         "func":"math",
         "args":"totalSales < 100" // the affiliate is in bronze tier if total sales are less than 100
      },
      {
         "name":"Silver Tier",
         "id":"silverTier",
         "func":"math",
         "args":"totalSales >= 100 and totalSales < 500" // they are in silver tier if sales are between 100 and 500
      },
     {
         "name":"Gold Tier",
         "id":"goldTier",
         "func":"math",
         "args":"totalSales > 500" // they are in gold tier if sales are over $500
      }
  ],
 // now we have computed all the requisite columns and next we move onto the compensation
  "compensation":[
     {
        "to":"goldTier", // here we decide who gets this reward. So if the affiliate is in goldTier, they get this reward
        "amount":"totalSales * 0.20"
     },
     {
        "to":"silverTier",
        "amount":"totalSales * 0.15"
     },
     {
         "to":"bronzeTier",
         "amount":"totalSales * 0.10"
     }
  ]
}

Description

The compensation plan has the following top level properties

Property Accepts Required Description
frequency String The frequency on which the plan is run. Can be monthly,weekly,biweekly,custom
columns Array List of columns objects
compensation Array List of compensation object
reports Array List of reports object. This is only required if you want to generate aggregate reports. eg. No of affiliates with total sales > 500 etc.
template Array List of template object to be used for displaying projection data

Column object

Property Accepts Required Notes
name String The name of this column (shown in data explorer). Maximum length of the string can be 50 characters
id String The ID Of this column. Can only contain letters. (no spaces or special characters)
func String The name of the function to run to build the value of this column
args * The arguments to pass to this function. Depends on the function. See the list of available functions and arguments below
type String The type of this column. Can be number, currency, boolean, string. Default is string
show Boolean Should this column be shown in the data explorer. Default is true

eg

{
  "name":"Total Referral Sales Volume (lastmonth)",
  "id":"totalSales",
  "func":"referralSalesVolume",
  "args":{
    "period":"lastmonth"
  },
  "type":"currency"
}

Available functions

referralSalesVolume

The total amount of purchases made by the affiliate

Accepts

Object

Properties

Name Description Default
period The period in which the sale volume is totaled. Supported values lifetime,lastmonth,lastquarter,yesterday,lastweek,last2weeks. lifetime
filters List of filter object to filter the result set before doing the total -

referralSalesCount

The total number of sales made by the affiliate

Accepts

Object

Properties

Name Description Default
period The period in which the sale volume is totaled. Supported values lastmonth,lastquerter, alltime,yesterday,lastweek,last2weeks alltime
filters List of filter object to filter the result set before doing the total -

downlineSalesVolume

Total sales volume generated by the affiliate's network/downlines

Accepts

Object

Properties

Name Description Default
period The period for which the sale volume is totaled. Supported values lastmonth,lastquerter, alltime,yesterday,lastweek,last2weeks alltime
levels Totals sale volumes only for the specified levels. Specify multiple levels as 1,2,3,4,5 etc All levels
filters List of filter object to filter the result set before doing the total -

downlineSalesCount

The total number of sales made by the affiliate's downlines

Accepts

Object

Properties

Name Description Default
period The period in which the sale volume is totaled. Supported values lastmonth,lastquerter, alltime, yesterday ,lastweek, last2weeks alltime
levels Totals sale volumes only for the specified levels. Specify multiple levels as 1,2,3,4,5 etc All levels
filters List of filter object to filter the result set before doing the total -

ifThenElse

Checks for all the listed conditions and sets the value when match is found. If no match is found then the default value as per column type is set, or if the default parameter is set, that value is set

Accepts

Object

Properties

Name Description Default
conditions An array of tests to run -
default Default value if no conditions are matched Determined by column type. eg. for column type currency or number, the default value is set as 0
{
  "func":"ifThenElse",
  "args": {
   conditions: {
     ['ps > 500',1],
     ['ps > 200',2],
     {
       "if:"ps > 100",
       "then":3
     },
     4, // the default value (optional), otherwise the default value is determined by column type or if the default is set in the args
   }
  }
  "type":"number",
  "id":"rank",
  "name":"Rank"
}

The conditions can in any of the following format

Pair - an array with two entries. The first entry is evaluated and if the result is true, the value is set

Object - an object in the format { if : "expression to evaluate", "then":"value to set"}

The value is automatically evaluated if the column type is set to boolean, number or currency


math

Accepts

String

The expression can be a regular math expression using any previous properties built by columns eg.

{
  "func":"math",
  "args":"totalSales * 0.5",
  "type":"currency",
  "id":"halfOfTotalSales",
  "name":"50% of total sales"
}

***

downlineCount

Accepts

Object

Properties

Name Description Default
filters A filter object to filter the count -

eg.

{
  "func":"downlineCount",
  "args":{
    "filters":["ps > 100", "rank = 1"]
  },
  "type":"number",
  "id":"dCount",
  "name":"Downlines where personal sales > 100"
}

Compensation Object

Gives the compensation to the affiliate

Property Accepts Required Notes
to String Whom to give compensation to. Can contain expressions. If not set, then the amount is rewarded to every affiliate.
amount String The amount to give as compensation. Can contain expressions.

eg. Give a compensation of 10% to an affiliate is his total sales > 800

{
  "to":"totalSales > 800",
  "amount":"totalSales * 0.10"
}

Reports Object

Generates reports for admins

Property Accepts Required Notes
func String The function to apply. Can be sum, count, math
name String The name of the report column
id String The id for this report value. Can be used for report template
args String ✅ The argument for the function

Available functions

sum

Accepts

Object

Arguments

Property Accepts Required Notes
column String The column to do the summation on

count

Accepts

Object

Arguments

Property Accepts Required Notes
column String The column to do the count on

Filter object

To filter the data set before doing computation

Property Accepts Required Default Notes
column String - The column to filter on
compare String = The comparator. Can be one of =,!=,<,>,>=,<=,in,between,startsWith,endsWith,match
value String The value to compare the column with

eg.

Filter the downline sales if affiliate's name starts with A

{
 "column":"name",
 "compare":"startsWith",
 "value":"A"
}

Filter personal sales where commissionable value > 100

{
  "column":"subtotal",
  "compare":">=",
  "value":"100"
}

Filters can also be written in a shorthand format eg.

["name","startsWith","100"]

OR

"subtotal >= 100"

OR

"isactive" // any boolean value to compare can be written singly
⚠️ **GitHub.com Fallback** ⚠️