|
- <?php
-
-
-
- namespace common\helpers;
-
- class Price
- {
-
- public static function format($number, $decimals = 2)
- {
- return self::numberTwoDecimals($number, $decimals).' €';
- }
-
- public static function round($number)
- {
- return round($number, 2, PHP_ROUND_HALF_UP);
- }
-
- public static function getPrice($priceWithTax, $taxRate)
- {
- return floatval($priceWithTax) / ($taxRate + 1);
- }
-
- public static function getPriceWithTax($priceWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
- {
- $vat = self::getVat($priceWithoutTax, $taxRate, $taxCalculationMethod);
-
- return self::numberTwoDecimals(self::round($priceWithoutTax + $vat));
- }
-
- public static function getVat($priceTotalWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
- {
- $vat = $priceTotalWithoutTax * $taxRate;
-
- if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) {
- $vat = self::round($vat);
- }
-
- return $vat;
- }
-
- public static function numberTwoDecimals($number, $decimals = 2)
- {
- return number_format(( ($number * 100)) / 100, $decimals, '.', ' ') ;
- }
-
- }
|