Advertisement
Guest User

Untitled

a guest
May 28th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2. /**
  3. * TaxPrice.php
  4. * Created by: koen
  5. * Date: 18-4-15
  6. * Time: 12:41
  7. */
  8.  
  9. class TaxPrice {
  10.  
  11. private $withoutTax;
  12. private $withTax;
  13. private $taxPrice;
  14. private $taxRate = 21;
  15.  
  16. /**
  17. * Construct TaxPrice and set its properties
  18. *
  19. * @param int $price
  20. * @param bool $isTaxPrice whether the price given is including or excluding taxes
  21. * @param null $taxRate sets the tax rate
  22. */
  23. public function __construct($price, $isTaxPrice = true, $taxRate = null){
  24.  
  25. if(!is_null($taxRate))
  26. $this->taxRate = $taxRate;
  27.  
  28. if($isTaxPrice){
  29. $this->withTax = $price;
  30. $this->taxPrice = ($this->withTax / (100 + $this->taxRate) * $this->taxRate);
  31. $this->withoutTax = $this->withTax - $this->taxPrice;
  32. }else {
  33. $this->withoutTax = $price;
  34. $this->taxPrice = $this->withoutTax * ($this->taxRate / 100);
  35. $this->withTax = $this->withoutTax + $this->taxPrice;
  36. }
  37.  
  38. }
  39.  
  40. /**
  41. * Getter for price including taxes
  42. *
  43. * @param bool $decimal whether to send full float or rounded
  44. * @return int
  45. */
  46. public function withTax($decimal = false){
  47. if($decimal)
  48. return $this->withTax;
  49. return round($this->withTax,2);
  50. }
  51.  
  52. /**
  53. * Getter for price excluding taxes
  54. *
  55. * @param bool $decimal whether to send full float or rounded
  56. * @return int
  57. */
  58. public function withoutTax($decimal = false){
  59. if($decimal)
  60. return $this->withoutTax;
  61. return round($this->withoutTax,2);
  62. }
  63.  
  64. /**
  65. * Getter for amount of tax price on the given tax rate
  66. *
  67. * @param bool $decimal whether to send full float or rounded
  68. * @return int
  69. */
  70. public function getTaxPrice($decimal = false){
  71. if($decimal)
  72. return $this->taxPrice;
  73. return round($this->taxPrice,2);
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement