Pandatech.CommissionCalculator 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pandatech.CommissionCalculator --version 2.0.1                
NuGet\Install-Package Pandatech.CommissionCalculator -Version 2.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pandatech.CommissionCalculator" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pandatech.CommissionCalculator --version 2.0.1                
#r "nuget: Pandatech.CommissionCalculator, 2.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pandatech.CommissionCalculator as a Cake Addin
#addin nuget:?package=Pandatech.CommissionCalculator&version=2.0.1

// Install Pandatech.CommissionCalculator as a Cake Tool
#tool nuget:?package=Pandatech.CommissionCalculator&version=2.0.1                

Pandatech.CommissionCalculator

Overview

The Pandatech.CommissionCalculator is a .NET library that simplifies the commission calculation process, offering robust features and a flexible configuration to handle a multitude of scenarios. This package allows for both proportional and absolute commission calculations, rule-based tiering, and even imposes validation rules to ensure logical consistency.

Features

  • Proportional and Absolute Commissions - The library supports both proportional and absolute commission calculations. Choose between proportional or absolute commission types for flexibility.
  • Rule-Based Tiering - Define custom rules for various range tiers.
  • Auto-Validation - The package performs automatic validation on your commission rules. If a rule is invalid, an exception is thrown.
  • Strict Rule Coverage - Ensures your rule set covers the entire domain from 0 to +∞.
  • Flexible Configuration - The library is highly configurable, allowing you to define your own commission rules, commission types, and validation rules.
  • High Test Coverage - The library is thoroughly tested, with 99% code coverage.
  • Highly Performant - The library is highly performant, with at least 1,500,000 calculations per second.

Installation

The Pandatech.CommissionCalculator library is available on NuGet. To install, run the following command in the Package Manager Console:

Install-Package Pandatech.CommissionCalculator

Usage

Initialize Commission Rules

var rules = new List<CommissionRule>
{
    // Add your commission rules here
    var rules = new List<CommissionRule>
        {
            new CommissionRule
            {
                RangeStart = 0, RangeEnd = 500, Type = CommissionType.FlatRate, CommissionAmount = 25,
                MinCommission = 0, MaxCommission = 0
            },
            new CommissionRule
            {
                RangeStart = 500, RangeEnd = 1000, Type = CommissionType.Percentage, CommissionAmount = 0.1m,
                MinCommission = 70, MaxCommission = 90
            },
            new CommissionRule
            {
                RangeStart = 1000, RangeEnd = 10000, Type = CommissionType.Percentage, CommissionAmount = 0.2m,
                MinCommission = 250, MaxCommission = 1500
            },
            new CommissionRule
            {
                RangeStart = 10000, RangeEnd = 0, Type = CommissionType.FlatRate, CommissionAmount = 2000,
                MinCommission = 0, MaxCommission = 0
            }
        };
};

Compute Commission

decimal principalAmount = 1000m;
bool isProportional = true;
int decimalPlaces = 4;

decimal commission = CommissionCalculator.ComputeCommission(principalAmount, rules, isProportional, decimalPlaces);

Validation

CommissionCalculator.ValidateCommissionRules(rules);

Please note that the validation method is automatically called when the ComputeCommission method is invoked. If a rule is invalid, an exception is thrown.

CommissionRule Properties

Property Type Description
RangeStart decimal The start range for this rule.
RangeEnd decimal The end range for this rule (0 means infinity).
Type CommissionType Enum that specifies whether the commission type is FlatRate or Percentage
CommissionAmount decimal The commission amount for this rule.
MinCommission decimal The minimum commission for this rule.
MaxCommission decimal The maximum commission for this rule (0 means infinity).

Conventions

  • If you need to specify +∞, set RangeEnd or MaxCommission to 0. This is for database efficiency.
  • Ensure that your rules cover the entire domain [0, +∞). If a rule is missing, an exception is thrown.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.0 339 3/15/2024
3.2.1 126 3/13/2024
3.2.0 140 3/13/2024
3.1.0 121 3/11/2024
3.0.0 114 3/7/2024
2.1.2 121 3/5/2024
2.1.1 114 3/5/2024
2.1.0 132 1/31/2024
2.0.3 111 1/30/2024
2.0.2 153 1/11/2024
2.0.1 201 11/29/2023
2.0.0 142 11/29/2023
1.0.3 179 11/1/2023
1.0.2 135 11/1/2023
1.0.1 122 11/1/2023
1.0.0 158 10/29/2023

.Net 8.0 update