src/Entity/Pricelist.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JMS\Serializer\Annotation as Serializer;
  5. /**
  6. * @ORM\Entity(repositoryClass="App\Repository\PricelistRepository")
  7. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  8. */
  9. class Pricelist
  10. {
  11. /**
  12. * @ORM\Id()
  13. * @ORM\GeneratedValue()
  14. * @ORM\Column(type="integer")
  15. */
  16. private $id;
  17. /**
  18. * @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="pricelists")
  19. */
  20. private $product;
  21. /**
  22. * @ORM\ManyToOne(targetEntity="App\Entity\Variant", inversedBy="pricelists")
  23. */
  24. private $variant;
  25. /**
  26. * @ORM\ManyToOne(targetEntity="App\Entity\Payment", inversedBy="pricelists")
  27. */
  28. private $payment;
  29. /**
  30. * @ORM\ManyToOne(targetEntity="App\Entity\Transport", inversedBy="pricelists")
  31. */
  32. private $transport;
  33. /**
  34. * @ORM\Column(type="float")
  35. */
  36. private $tax;
  37. /**
  38. * @Serializer\Groups({"api"})
  39. * @Serializer\SerializedName("discount")
  40. *
  41. * @ORM\Column(type="float")
  42. */
  43. private $discountPercent = 0;
  44. /**
  45. * @Serializer\Groups({"api"})
  46. * @Serializer\SerializedName("price")
  47. *
  48. * @ORM\Column(type="float")
  49. */
  50. private $price;
  51. /**
  52. * @Serializer\Groups({"api"})
  53. * @Serializer\SerializedName("priceOriginal")
  54. * @ORM\Column(type="float", nullable=true)
  55. */
  56. private $priceOriginal;
  57. /**
  58. * @ORM\Column(type="string", length=3)
  59. */
  60. private $currency;
  61. /**
  62. * @ORM\Column(type="datetime")
  63. */
  64. private $createts;
  65. /**
  66. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  67. * @ORM\JoinColumn(nullable=false)
  68. */
  69. private $createUser;
  70. public function __construct($currency = null)
  71. {
  72. if(!empty($currency)){
  73. $this->setCurrency($currency);
  74. }
  75. $this->setTax(21);
  76. }
  77. public function getId(): ?int
  78. {
  79. return $this->id;
  80. }
  81. public function getProduct(): ?Product
  82. {
  83. return $this->product;
  84. }
  85. public function setProduct(?Product $product): self
  86. {
  87. $this->product = $product;
  88. return $this;
  89. }
  90. public function getPayment(): ?Payment
  91. {
  92. return $this->payment;
  93. }
  94. public function setPayment(?Payment $payment): self
  95. {
  96. $this->payment = $payment;
  97. return $this;
  98. }
  99. public function getTransport(): ?Transport
  100. {
  101. return $this->transport;
  102. }
  103. public function setTransport(?Transport $transport): self
  104. {
  105. $this->transport = $transport;
  106. return $this;
  107. }
  108. public function getTax(): ?float
  109. {
  110. return $this->tax;
  111. }
  112. public function setTax(float $tax): self
  113. {
  114. $this->tax = $tax;
  115. return $this;
  116. }
  117. public function getPrice(): ?float
  118. {
  119. return $this->price;
  120. }
  121. public function setPrice(float $price): self
  122. {
  123. $this->price = round($price,2);
  124. return $this;
  125. }
  126. public function getPriceOriginal(): ?float
  127. {
  128. return $this->priceOriginal;
  129. }
  130. public function setPriceOriginal(?float $priceOriginal): self
  131. {
  132. $this->priceOriginal = round($priceOriginal,2);
  133. return $this;
  134. }
  135. public function getCurrency(): ?string
  136. {
  137. return $this->currency;
  138. }
  139. public function setCurrency(string $currency): self
  140. {
  141. $this->currency = $currency;
  142. return $this;
  143. }
  144. public function getVariant(): ?Variant
  145. {
  146. return $this->variant;
  147. }
  148. public function setVariant(?Variant $variant): self
  149. {
  150. $this->variant = $variant;
  151. return $this;
  152. }
  153. public function getCreatets(): ?\DateTimeInterface
  154. {
  155. return $this->createts;
  156. }
  157. public function setCreatets(\DateTimeInterface $createts): self
  158. {
  159. $this->createts = $createts;
  160. return $this;
  161. }
  162. public function getCreateUser(): ?User
  163. {
  164. return $this->createUser;
  165. }
  166. public function setCreateUser(?User $createUser): self
  167. {
  168. $this->createUser = $createUser;
  169. return $this;
  170. }
  171. public function getEditts(): ?\DateTimeInterface
  172. {
  173. return $this->editts;
  174. }
  175. public function setEditts(?\DateTimeInterface $editts): self
  176. {
  177. $this->editts = $editts;
  178. return $this;
  179. }
  180. public function getEditUser(): ?User
  181. {
  182. return $this->editUser;
  183. }
  184. public function setEditUser(?User $editUser): self
  185. {
  186. $this->editUser = $editUser;
  187. return $this;
  188. }
  189. /**
  190. * Get DiscountPercent
  191. *
  192. * @return null|float
  193. */
  194. public function getDiscountPercent(): ?float
  195. {
  196. return str_replace(',','.',$this->discountPercent);
  197. }
  198. /**
  199. * Set DiscountPercent
  200. *
  201. * @param mixed $discountPercent
  202. */
  203. public function setDiscountPercent( $discountPercent )
  204. {
  205. $this->discountPercent = $discountPercent;
  206. }
  207. public function calcDiscountPercent( )
  208. {
  209. if( !empty($this->getPrice()) && !empty($this->getPriceOriginal()) ){
  210. $this->setDiscountPercent(round(100 - (($this->getPrice()/$this->getPriceOriginal())*100)));
  211. }else{
  212. $this->setDiscountPercent(0);
  213. }
  214. }
  215. }