Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * TaxPrice.php
- * Created by: koen
- * Date: 18-4-15
- * Time: 12:41
- */
- class TaxPrice {
- private $withoutTax;
- private $withTax;
- private $taxPrice;
- private $taxRate = 21;
- /**
- * Construct TaxPrice and set its properties
- *
- * @param int $price
- * @param bool $isTaxPrice whether the price given is including or excluding taxes
- * @param null $taxRate sets the tax rate
- */
- public function __construct($price, $isTaxPrice = true, $taxRate = null){
- if(!is_null($taxRate))
- $this->taxRate = $taxRate;
- if($isTaxPrice){
- $this->withTax = $price;
- $this->taxPrice = ($this->withTax / (100 + $this->taxRate) * $this->taxRate);
- $this->withoutTax = $this->withTax - $this->taxPrice;
- }else {
- $this->withoutTax = $price;
- $this->taxPrice = $this->withoutTax * ($this->taxRate / 100);
- $this->withTax = $this->withoutTax + $this->taxPrice;
- }
- }
- /**
- * Getter for price including taxes
- *
- * @param bool $decimal whether to send full float or rounded
- * @return int
- */
- public function withTax($decimal = false){
- if($decimal)
- return $this->withTax;
- return round($this->withTax,2);
- }
- /**
- * Getter for price excluding taxes
- *
- * @param bool $decimal whether to send full float or rounded
- * @return int
- */
- public function withoutTax($decimal = false){
- if($decimal)
- return $this->withoutTax;
- return round($this->withoutTax,2);
- }
- /**
- * Getter for amount of tax price on the given tax rate
- *
- * @param bool $decimal whether to send full float or rounded
- * @return int
- */
- public function getTaxPrice($decimal = false){
- if($decimal)
- return $this->taxPrice;
- return round($this->taxPrice,2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement