Let use the use some sample taxation rules to understand how rule evaluation would happen in different scenarios.
Let’s say that the rule input priorities are as follows:
- Source State
- Interstate sale
- Item type
- Material
- MRP range
Understanding the rules
First let’s understand the above rule-set.
- There are no rules defined for any state other than Karnataka.
- There is no default rule for other states.
- There is a default rule for all other input other than source state. This implies that anytime we pass in a source state Karnataka and any specific value for any of the other inputs, we are sure to get at least rule#1.
Evaluating for different inputs
Case 1
Source state = NULL, interstate sale = NULL, item type = NULL, material = NULL, mrp = NULL
This example is looking for a catchall, global default rule.i.e. Even if nothing else matched, what rule would surely match.
Get all applicable rules
All rules will be returned, since we are not applying any filter on the rule set.
Get best fitting rule
No rule will be returned.
We go over rule inputs in decreasing order of priority.
- Nothing matches in the source state column since only specific rules for Karanataka state are defined but we are looking for an “Any” rule.
- We stop right there and return nothing.
Case 2
Source state = Karnataka, interstate sale = YES, item type = NULL, material = NULL, mrp = NULL
Get all applicable rules
All rules will be returned, since we are not applying any filter on the rule-set except for state, and all rules are for Karnataka state.
Get best fitting rule
Rule#1 will be returned.
We go over rule inputs in decreasing order of priority.
- All rules match for the source state column.
- Next, only rule#1 matches for interstate sale. There are no “Any” rules defined for interstate sale.
- Since we have only one candidate, we return that.
Case 3
Source state = Karnataka, interstate sale = NO, item type = NULL, material = Cotton, mrp = NULL
Get all applicable rules
Rule#2, 3, 5 will be returned after applying filtering for Karnataka and Cotton in order of priority.
Rule#1 is for interstate sale, so it is not returned for a “No” query. Rule#4 is specifically about material “khadi” so it will not be selected for a “Cotton” query.
Get best fitting rule
No rule is returned.
We start going over rule inputs in decreasing order of priority.
- All rules match for the source state column.
- All rules match for the interstate sale column.
- All remaining rules are for specific item type, no “Any”. So all of them are rejected.
Case 4
Source state = Karnataka, interstate sale = NO, item type = Jeans, material = Cotton, mrp = 100
Get all applicable rules
Rule#2, 3 will be returned after applying filtering for Karnataka, non-interstate sale, and Jeans in order of priority.
Rule#1 is for interstate sale, so it is not returned for a specific “No” query. Rule#4,5 are for item type “Kurta”, so they are not selected for the specific “Jeans” query.
Get best fitting rule
Rule#3 is returned.
We start going over rule inputs in decreasing order of priority.
- All rules match for the source state column.
- All rules match for the interstate sale column.
- All rules match for the item type column.
- Mrp = 100 falls in the range specified by Rule#3 which is more specific than the “Any” match of Rule#2. Hence we return rule#3.
Case 5
Source state = Karnataka, interstate sale = NO, item type = Jeans, material = Cotton, mrp = 1000
Get all applicable rules
Rule#2, 3 will be returned after applying filtering for Karnataka, non-interstate sale, and Jeans in order of priority.
Rule#1 is for interstate sale, so it is not returned for a specific “No” query. Rule#4,5 are for item type “Kurta”, so they are not selected for the specific “Jeans” query.
Get best fitting rule
Rule#2 is returned.
We start going over rule inputs in decreasing order of priority.
- All rules match for the source state column.
- All rules match for the interstate sale column.
- All rules match for the item type column.
- Mrp = 1000 falls outside the range specified by Rule#3, but it matches the “Any” definition of Rule#2.Hence we return rule#2.