vendor/roothirsch/shop-bundle/Entity/Tax.php line 15

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\ShopBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Gedmo\Translatable\Translatable;
  5. use Roothirsch\CoreBundle\Entity\Traits\TimetrackedTrait;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. /**
  9. * @ORM\Entity(repositoryClass="Roothirsch\ShopBundle\Repository\TaxRepository")
  10. * @ORM\Table(name="shop_tax")
  11. */
  12. class Tax implements Translatable
  13. {
  14. use TimetrackedTrait;
  15. /**
  16. * @ORM\Id
  17. * @ORM\GeneratedValue
  18. * @ORM\Column(type="integer")
  19. * @Groups({"list"})
  20. */
  21. private $id;
  22. /**
  23. * @Gedmo\Translatable
  24. * @ORM\Column(type="string", length=255)
  25. * @Groups({"list"})
  26. */
  27. private $name;
  28. /**
  29. * @ORM\Column(type="decimal", precision=5, scale=2)
  30. * @Groups({"list"})
  31. */
  32. private $rate;
  33. /**
  34. * @ORM\Column(type="date")
  35. * @Groups({"list"})
  36. */
  37. private $startDate;
  38. /**
  39. * @ORM\Column(type="boolean", options={"default": true})
  40. * @Groups({"list"})
  41. */
  42. private $active = true;
  43. public function getId(): ?int
  44. {
  45. return $this->id;
  46. }
  47. public function getName(): ?string
  48. {
  49. return $this->name;
  50. }
  51. public function setName(string $name): self
  52. {
  53. $this->name = $name;
  54. return $this;
  55. }
  56. public function getRate(): ?string
  57. {
  58. return $this->rate;
  59. }
  60. public function setRate(string $rate): self
  61. {
  62. $this->rate = $rate;
  63. return $this;
  64. }
  65. public function getStartDate(): ?\DateTimeInterface
  66. {
  67. return $this->startDate;
  68. }
  69. public function setStartDate(\DateTimeInterface $startDate): self
  70. {
  71. $this->startDate = $startDate;
  72. return $this;
  73. }
  74. public function isActive(): bool
  75. {
  76. return $this->active;
  77. }
  78. public function setActive(bool $active): self
  79. {
  80. $this->active = $active;
  81. return $this;
  82. }
  83. public function getRateAsFloat(): float
  84. {
  85. return (float) $this->rate;
  86. }
  87. public function asFraction(): float
  88. {
  89. return (float) $this->rate / 100;
  90. }
  91. public function __toString(): string
  92. {
  93. return sprintf('%s (%s%% from %s)',
  94. $this->name,
  95. $this->rate,
  96. $this->startDate ? $this->startDate->format('Y-m-d') : ''
  97. );
  98. }
  99. }