src/Entity/System/CodeDiscount.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * Class CodeDiscount
  7. *
  8. * @ORM\Table(name="code_discount")
  9. *
  10. * @ORM\Entity(repositoryClass="App\Repository\System\CodeDiscountRepository")
  11. */
  12. class CodeDiscount
  13. {
  14. public const FREE_SUBSCRIPTION_CODE_PREFIX = 'FREE_SUBSCRIPTION';
  15. public const FREE_CONNECTOR_CODE_PREFIX = 'FREE_CONNECTOR';
  16. public const FREE_MIGRATION_CODE = 'MIGRATION';
  17. /**
  18. * @ORM\Id()
  19. *
  20. * @ORM\GeneratedValue()
  21. *
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column (type="string", length=30, unique=true)
  27. */
  28. private ?string $code = null;
  29. /**
  30. * @ORM\Column (type="boolean")
  31. */
  32. private bool $active = false;
  33. /**
  34. * @ORM\ManyToOne(targetEntity="App\Entity\System\Customer")
  35. *
  36. * @ORM\JoinColumn(name="customer", referencedColumnName="id_customer")
  37. */
  38. private ?Customer $customer = null;
  39. /**
  40. * @ORM\ManyToOne(targetEntity="App\Entity\System\Employee")
  41. *
  42. * @ORM\JoinColumn(name="employee", referencedColumnName="id_employee", nullable=false)
  43. */
  44. private Employee $employee;
  45. /**
  46. * @ORM\Column(type="integer", nullable=true)
  47. */
  48. private ?int $redeemLimit = null;
  49. /**
  50. * @ORM\Column(type="integer", nullable=true)
  51. */
  52. private ?int $redeemLimitByCustomer = null;
  53. /**
  54. * @var float
  55. *
  56. * @ORM\Column(type="float", options={"default" : 0.000000})
  57. */
  58. private $discount;
  59. /**
  60. * @var \DateTime
  61. *
  62. * @ORM\Column(type="datetime", nullable=true)
  63. */
  64. private $dateExpiration;
  65. /**
  66. * @var \DateTime|null
  67. *
  68. * @ORM\Column(type="datetime")
  69. */
  70. private $dateStarting;
  71. /**
  72. * @var Order[]|ArrayCollection
  73. *
  74. * @ORM\OneToMany(targetEntity="App\Entity\System\Order", mappedBy="idVoucher")
  75. */
  76. private $orders;
  77. /**
  78. * @var ArrayCollection<int, CodeDiscountRule>|CodeDiscountRule[]
  79. *
  80. * @ORM\ManyToMany(targetEntity="CodeDiscountRule", inversedBy="codeDiscounts")
  81. */
  82. private $codeDiscountRules;
  83. /**
  84. * @ORM\Column (type="string", nullable=true)
  85. */
  86. private ?string $comments;
  87. /**
  88. * @var \DateTime
  89. *
  90. * @ORM\Column(type="datetime")
  91. */
  92. private $dateAdd;
  93. /**
  94. * @var \DateTime
  95. *
  96. * @ORM\Column(type="datetime")
  97. */
  98. private $dateUpd;
  99. public function __construct()
  100. {
  101. $this->orders = new ArrayCollection();
  102. $this->codeDiscountRules = new ArrayCollection();
  103. $this->dateAdd = new \DateTime();
  104. $this->dateUpd = new \DateTime();
  105. }
  106. /**
  107. * @return mixed
  108. */
  109. public function getId()
  110. {
  111. return $this->id;
  112. }
  113. /**
  114. * @return string
  115. */
  116. public function getCode(): string
  117. {
  118. return $this->code;
  119. }
  120. /**
  121. * @return bool
  122. */
  123. public function isActive(): bool
  124. {
  125. return $this->active;
  126. }
  127. /**
  128. * @return Customer|null
  129. */
  130. public function getCustomer(): ?Customer
  131. {
  132. return $this->customer;
  133. }
  134. /**
  135. * @return float
  136. */
  137. public function getDiscount(): float
  138. {
  139. return $this->discount;
  140. }
  141. /**
  142. * @return \DateTime|null
  143. */
  144. public function getDateExpiration(): ?\DateTime
  145. {
  146. return $this->dateExpiration;
  147. }
  148. /**
  149. * @return \DateTime
  150. */
  151. public function getDateStarting(): \DateTime
  152. {
  153. return $this->dateStarting;
  154. }
  155. /**
  156. * @return Order[]|ArrayCollection
  157. */
  158. public function getOrders()
  159. {
  160. return $this->orders;
  161. }
  162. /**
  163. * @param Order[]|ArrayCollection $orders
  164. */
  165. public function setOrders($orders): self
  166. {
  167. $this->orders = $orders;
  168. return $this;
  169. }
  170. public function setCode(string $code): CodeDiscount
  171. {
  172. $this->code = $code;
  173. return $this;
  174. }
  175. public function setActive(bool $active): CodeDiscount
  176. {
  177. $this->active = $active;
  178. return $this;
  179. }
  180. public function setCustomer(?Customer $customer): CodeDiscount
  181. {
  182. $this->customer = $customer;
  183. return $this;
  184. }
  185. public function setDiscount(float $discount): CodeDiscount
  186. {
  187. $this->discount = $discount;
  188. return $this;
  189. }
  190. public function setDateExpiration(?\DateTime $dateExpiration): CodeDiscount
  191. {
  192. $this->dateExpiration = $dateExpiration;
  193. return $this;
  194. }
  195. public function setDateStarting(?\DateTime $dateStarting): CodeDiscount
  196. {
  197. $this->dateStarting = $dateStarting;
  198. return $this;
  199. }
  200. /**
  201. * @return CodeDiscountRule[]|ArrayCollection<int, CodeDiscountRule>
  202. */
  203. public function getCodeDiscountRules()
  204. {
  205. return $this->codeDiscountRules;
  206. }
  207. public function hasCodeDiscountRule(int $codeDiscountRuleId): bool
  208. {
  209. foreach ($this->codeDiscountRules as $codeDiscountRule) {
  210. if ($codeDiscountRule->getId() === $codeDiscountRuleId) {
  211. return true;
  212. }
  213. }
  214. return false;
  215. }
  216. public function addCodeDiscountRule(CodeDiscountRule $codeDiscountRule): CodeDiscount
  217. {
  218. if (!$this->codeDiscountRules->contains($codeDiscountRule)) {
  219. $this->codeDiscountRules[] = $codeDiscountRule;
  220. }
  221. return $this;
  222. }
  223. /**
  224. * @param CodeDiscountRule[]|ArrayCollection<int, CodeDiscountRule> $codeDiscountRules
  225. */
  226. public function setCodeDiscountRules($codeDiscountRules): CodeDiscount
  227. {
  228. $this->codeDiscountRules = $codeDiscountRules;
  229. return $this;
  230. }
  231. public function getRedeemLimit(): ?int
  232. {
  233. return $this->redeemLimit;
  234. }
  235. public function setRedeemLimit(?int $redeemLimit): CodeDiscount
  236. {
  237. $this->redeemLimit = $redeemLimit;
  238. return $this;
  239. }
  240. public function getRedeemLimitByCustomer(): ?int
  241. {
  242. return $this->redeemLimitByCustomer;
  243. }
  244. public function setRedeemLimitByCustomer(?int $redeemLimitByCustomer): CodeDiscount
  245. {
  246. $this->redeemLimitByCustomer = $redeemLimitByCustomer;
  247. return $this;
  248. }
  249. public function getEmployee(): Employee
  250. {
  251. return $this->employee;
  252. }
  253. public function setEmployee(Employee $employee): CodeDiscount
  254. {
  255. $this->employee = $employee;
  256. return $this;
  257. }
  258. public function getComments(): ?string
  259. {
  260. return $this->comments;
  261. }
  262. public function setComments(?string $comments): CodeDiscount
  263. {
  264. $this->comments = $comments;
  265. return $this;
  266. }
  267. public function getDateAdd(): \DateTime
  268. {
  269. return $this->dateAdd;
  270. }
  271. public function setDateAdd(\DateTime $dateAdd): CodeDiscount
  272. {
  273. $this->dateAdd = $dateAdd;
  274. return $this;
  275. }
  276. public function getDateUpd(): \DateTime
  277. {
  278. return $this->dateUpd;
  279. }
  280. public function setDateUpd(\DateTime $dateUpd): CodeDiscount
  281. {
  282. $this->dateUpd = $dateUpd;
  283. return $this;
  284. }
  285. }