Download the PHP package vaened/php-price-engine without Composer
On this page you can find all versions of the php package vaened/php-price-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaened/php-price-engine
More information about vaened/php-price-engine
Files in vaened/php-price-engine
Package php-price-engine
Short Description A powerful pricing calculator for products and services, with comprehensive tax and discount calculations.
License MIT
Informations about the package php-price-engine
Price Engine
The Price Calculation Library is a tool that allows you to perform complex calculations for prices, taxes, discounts, and charges in your applications. This library is based on the Brick\Money
library to ensure precise monetary calculations.
Installation
You can install the library using composer
.
Usage
Initializing the Cashier
To start using the Price Engine, create an instance of the any Amount
.
Updating Quantity
You can update the quantity using the update()
method, that will calculate the totals in the next summary.
Applying Discounts
To apply discounts, use the apply()
method, that will calculate the totals in the next summary, and receive as parameter N amount
of Discount
.
Adding Charges
To add charges, use the add()
method, it will calculate the totals in the next summary, and received as parameter N amount
of Charge
.
Obtaining Individual Totals
To obtain individual values of any price adjuster, you can use the tax()
charge()
, or discount()
functions, all of which receive the code established during creation and return an instance of Adjustment
Obtaining Totals
To obtain the total, you can use individual functions, each of which returns an instance of Brick\Money
.
Configuration
Currently there are 2 built-in ways to handle calculations
Cashiers
-
SimpleCashier: This
cashier
operates based on the gross price concept. It means that the price provided will be cleaned to get the final price without tax. Adjustments are applied directly to the gross price and taxes are calculated separately after adjustments are applied - RegularCashier: This
cashier
operates based on the concept of unit price + taxes. It means that the configured taxes will be maintained or added to the indicated price, and discounts and charges will be applied to this price with taxes included.
Choose the
cashier
that best suits your specific business needs and requirements. You can create your own cashier to fit any specific logic or rule related to your business. If you need to create additional cashiers or implement custom logic, you can do so by extendingCashier
. This library provides a flexible foundation to handle various pricing scenarios effectively.
Amounts
There are 2 ways to create the amount.
-
Amount with applicable taxes: these amounts are subject to taxes, whether they are
inclusive taxes
orexclusive taxes
and can be defined as follows.The tax codes establish what taxes are applicable for the amount
Allow All Only Allowed Allow Nothing TaxCodes::any() TaxCodes::only(['IGV', ...]) TaxCodes::none() -
Amounts without applicable taxes: These amounts are not subject to any tax and will not have taxes applied.
These would be the same as creating a taxable amount but passing TaxCodes::none() as the allowed codes.
Taxes
Taxes can be established in two ways.
-
Inclusive: Taxes included in the unit price, and will be cleared during calculations
- Exclusive: Taxes not included in the unit price, and will be added for the final calculations.
License
This library is licensed under the MIT License. For more information, please see the license
file.
All versions of php-price-engine with dependencies
vaened/support Version ^4.0
lambdish/phunctional Version ^2.1
brick/money Version ^0.8.0