Download the PHP package hansel23/prices without Composer
On this page you can find all versions of the php package hansel23/prices. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hansel23/prices
More information about hansel23/prices
Files in hansel23/prices
Package prices
Short Description Price interfaces and implementations
License proprietary
Informations about the package prices
Prices
PHP types representing prices including gross amount, net amount, vat amount and vat rate A price include the gross, net and VAT amount, as well as the VAT rate. The missing values are automatically calculated by the class depending on the instantiation method.
Requirements
- PHP >=7.4
- moneyphp/money
Instantiation
You have the gross and net amount, as well as the VAT rate
``
You have the gross amount and the VAT rate
``
You have the net amount and the VAT rate
``
You want a new price type by another price type
``
In some circumstances, it may matter whether the price is generated from the net or gross amount.
Example:
- VAT rate: 19 %
- Gross amount: 9,99 EUR
- Calculated net amount: 8,39 EUR (9,99 / 1,19 = rounded 8,39)
- Net amount: 8,39 EUR
- Calculated gross amount: 9,98 EUR (8,39 * 1,19 = rounded 9,98)
The method fromNetAndGrossAmount
, which calculates VAT independently, does not exist because the calculation is not reliable. There are countries with VAT rates that have decimal places. If these are
taken into account, rounding can result in incorrect VAT rates.
Example:
- Gross: 9,99 EUR
- Net: 8,39 EUR
- Expected vat rate: 19,00 %
- Calculated vat rate, after rounding and with 2 decimal places: 19,07 %
VatRate
You can instantiate the VatRate
by a float value or by an integer value. The integer value must be the float value multiplied by 100. The following example generates the same VAT rate. The VAT rate
is 21,70 %.
``
Multiplication and division of prices
There are two ways to calculate VAT when multiplying by the quantity. This is the difference between GrossBasedPrice
and NetBasePrice
.
NetBasedPrice
VAT is calculated after multiplying the unit price by the quantity.
Example: 90,82 € * 10 = 908,20 € * 1.19 = 1080,76 €
``
GrossBasedPrice
First, the VAT is calculated on the unit price and then multiplied by the quantity.
Example: 90,82 € * 1,19 = 108,08 € * 3 = 1080,80 €
``
Division works like multiplication, except of course you divide instead of multiply.
Addition and subtraction
``
TotalPrice
While RepresentsPrice
(or the implementation of it) is used primarily for the prices of order items, RepresentsTotalPrice
(or the implementation of it) is used as the total price of an order.
In this case, the prices are not merely added together, but can be returned, grouped by VAT rate, for example.
``
Return by grouped vat rates.
``
Json
``