|
123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
-
- namespace Lc\ShopBundle\Services ;
-
- class Price
- {
- protected $price ;
- protected $taxRate ;
-
- public function __construct($price, $taxRate)
- {
- $this->price = $price ;
- $this->taxRate = $taxRate ;
- }
-
- public function withTax()
- {
- return self::getPriceWithTax(
- $this->price,
- $this->taxRate
- ) ;
- }
-
- public function withoutTax()
- {
- return $this->price ;
- }
-
-
-
- public static function priceTwoDecimals($number)
- {
- return number_format(( ($number * 100)) / 100, 2) ;
- }
-
- public static function getPriceWithoutTax($priceWithTax, $taxRate)
- {
- return floatval($priceWithTax) / ($taxRate + 1);
- }
-
- public static function getPriceWithTax($priceWithoutTax, $taxRate)
- {
- return self::priceTwoDecimals(floatval($priceWithoutTax) * ($taxRate + 1)) ;
- }
- }
|