vgpastor / discounts-calculator
Helper library to manage different types of discounts and calculate the relational data
1.0.0
2022-10-08 21:03 UTC
Requires
- php: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
README
Helper library for calculating discounts in a application.
Installation
This library are developed to PHP 8.1, use Enum so it's not possible using in previously versions, if you like you can put a PR to make compatible with previous versions..
composer install vgpastor/discounts-calculator
Usage
Yo can see how to use in example.php file.
Required parameter are
- $type: Type of discount. Can be 'percentage' or 'amount' and based in base amount or in total amount (see DiscountTypeEnum)
- $base (float) - Base price
- $discount (float) - Discount percentage or amount
Optional parameters are
- $tax (float) - Tax percentage By default is 0%
- $precision (int) - Precision of the result. By default is 2
- $roundingMode (int) - Rounding mode. By default is PHP_ROUND_HALF_UP