Pandatech.CommissionCalculator 3.1.0

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

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

1. Pandatech.CommissionCalculator

1.1. Overview

The updated Pandatech.CommissionCalculator is a comprehensive .NET library designed to streamline commission calculations. With enhanced features supporting both proportional and absolute commission types, the library now offers more granular control over commission calculations through detailed range configurations. The introduction of CalculationType in commission rules allows users to specify the nature of the commission calculation explicitly. Moreover, the library maintains its utility for date range overlap checks with improved efficiency, ensuring commission period validations remain precise and reliable.

1.2. Features

  • Proportional and Absolute Commissions - Enhanced support for both proportional and absolute commission calculations, providing extensive flexibility in defining commission structures.
  • Detailed Commission Range Configurations - Define commission calculations with precision using CommissionRangeConfigs, allowing for intricate rule definitions.
  • Rule-Based Tiering - Define custom rules for various range tiers.
  • Auto-Validation - Improved validation mechanisms ensure that commission rules are logically consistent and well-structured before computation.
  • Strict Rule Coverage - Guarantees complete domain coverage from 0 to +∞, with validation checks to ensure no gaps or overlaps in commission ranges.
  • Configurable - The library is highly configurable, allowing you to define your own commission ranges and commission types.
  • Robust Testing - Achieves 99% code coverage, ensuring reliability.
  • Optimized Performance - Delivers high performance, capable of over 1.5 million calculations per second.

1.3. Installation

Install the latest version of the Pandatech.CommissionCalculator library via NuGet with the following command:

Install-Package Pandatech.CommissionCalculator

1.4. Usage

1.4.1. Define Commission Rule

using CommissionCalculator.DTO;

var rules = new CommissionRule
{
    CalculationType = CalculationType.Proportional,
    DecimalPlace = 4,
    CommissionRangeConfigs = new List<CommissionRangeConfigs>
    {
        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
            }
    }
};

1.4.2. Compute Commission

decimal principalAmount = 1000m;
decimal commission = Commission.ComputeCommission(principalAmount, rule);

1.4.3. Validation

Validate your commission rules to ensure they are consistent and cover the required domain without overlaps or gaps:

CommissionCalculator.ValidateCommissionRule(rule);

The validation is automatically performed when computing the commission to prevent logical inconsistencies.

1.4.4. Validate DateTime Overlap

using CommissionCalculator.Helper;
using CommissionCalculator.DTO;

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

bool hasOverlap = DateTimeOverlapChecker.HasOverlap(firstRange, secondRange);
Console.WriteLine(hasOverlap ? "Overlap detected." : "No overlaps.");

1.5. CommissionRangeConfig Properties

  • RangeStart: The beginning of the commission rule's range.
  • RangeEnd: The end of the range (set to 0 for +∞).
  • Type: Determines if the commission is a flat rate or percentage.
  • CommissionAmount: The specific commission amount for the range.
  • MinCommission: The range minimum commission.
  • MaxCommission: The range maximum commission (0 for +∞).

1.6. 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.

1.7. Contributing

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

1.8. 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 80 11/21/2024
3.3.0 350 3/15/2024
3.2.1 130 3/13/2024
3.2.0 144 3/13/2024
3.1.0 125 3/11/2024
3.0.0 118 3/7/2024
2.1.2 125 3/5/2024
2.1.1 118 3/5/2024
2.1.0 136 1/31/2024
2.0.3 115 1/30/2024
2.0.2 159 1/11/2024
2.0.1 205 11/29/2023
2.0.0 146 11/29/2023
1.0.3 183 11/1/2023
1.0.2 139 11/1/2023
1.0.1 126 11/1/2023
1.0.0 164 10/29/2023

Validation fixed.