Pandatech.CommissionCalculator 2.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pandatech.CommissionCalculator --version 2.1.2                
NuGet\Install-Package Pandatech.CommissionCalculator -Version 2.1.2                
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.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pandatech.CommissionCalculator --version 2.1.2                
#r "nuget: Pandatech.CommissionCalculator, 2.1.2"                
#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.1.2

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

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. This library also includes a highly efficient utility for checking overlaps between date ranges, known as DateTimeOverlapChecker. This tool is invaluable for validating commission rule timeframes, ensuring that no two commission periods conflict with each other.

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 = Commission.ComputeCommission(principalAmount, rules, isProportional, decimalPlaces);

Validation

Validate Commission Rules
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.

Validate DateTime Overlap
using CommissionCalculator.Helper;
using CommissionCalculator.DTO;

var firstPairs = new List<DateTimePair>
        {
            new DateTimePair(new DateTime(2024, 1, 1), new DateTime(2024, 1, 10))
        };
var secondPairs = new List<DateTimePair>
        {
            new DateTimePair(new DateTime(2024, 1, 2), new DateTime(2024, 1, 8))
        };

bool hasOverlap = DateTimeOverlapChecker.HasOverlap(firstPairs, secondPairs);

if (hasOverlap)
{
    Console.WriteLine("Detected overlapping date ranges.");
}
else
{
    Console.WriteLine("No overlaps found between the date ranges.");
}

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
4.0.0 41 11/21/2024
3.3.0 347 3/15/2024
3.2.1 128 3/13/2024
3.2.0 142 3/13/2024
3.1.0 123 3/11/2024
3.0.0 116 3/7/2024
2.1.2 123 3/5/2024
2.1.1 116 3/5/2024
2.1.0 134 1/31/2024
2.0.3 113 1/30/2024
2.0.2 157 1/11/2024
2.0.1 203 11/29/2023
2.0.0 144 11/29/2023
1.0.3 181 11/1/2023
1.0.2 137 11/1/2023
1.0.1 124 11/1/2023
1.0.0 162 10/29/2023

Reorganized some files