src/Entity/PointOfSale.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PointOfSaleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use JMS\Serializer\Annotation\Expose;
  9. use JMS\Serializer\Annotation\Groups;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. /**
  12. * @ORM\Entity(repositoryClass=PointOfSaleRepository::class)
  13. *
  14. * @UniqueEntity("code")
  15. *
  16. * @Serializer\ExclusionPolicy("ALL")
  17. */
  18. class PointOfSale
  19. {
  20. public const STATUS_ENABLED = "enabled";
  21. public const STATUS_DISABLED = "disabled";
  22. public const STATUS_ARCHIVED = "archived";
  23. public const REMINDERS = [
  24. 'P3M' => 'M-3',
  25. 'P2M' => 'M-2',
  26. 'P1M' => 'M-1',
  27. 'P15D' => 'J-15',
  28. 'P7D' => 'J-7',
  29. ];
  30. public const ARCHIVE_INTERVAL = 'P3M';
  31. /**
  32. * Identifiant unique
  33. *
  34. * @ORM\Id
  35. * @ORM\GeneratedValue
  36. * @ORM\Column(type="integer")
  37. *
  38. * @Expose
  39. * @Groups({"export_point_of_sale_datatable", "point_of_sale","point_sale"})
  40. */
  41. private ?int $id = null;
  42. /**
  43. * Code
  44. *
  45. * @ORM\Column(type="string", length=10, unique=true, nullable=true)
  46. *
  47. * @Expose
  48. * @Groups({"export_point_of_sale_datatable", "point_of_sale", "user"})
  49. */
  50. private ?string $code = null;
  51. /**
  52. * Nom
  53. *
  54. * @ORM\Column(type="string", length=255)
  55. *
  56. * @Expose
  57. * @Groups({"export_point_of_sale_datatable", "point_of_sale", "user"})
  58. */
  59. private ?string $name = null;
  60. /**
  61. * Ville
  62. *
  63. * @ORM\Column(type="string", length=255, nullable=true)
  64. *
  65. * @Expose
  66. * @Groups({ "export_point_of_sale_datatable", "point_of_sale", "user"})
  67. */
  68. private ?string $city = null;
  69. /**
  70. * Actif / Inactif
  71. *
  72. * @ORM\Column(type="boolean", options={"default":true})
  73. * @deprecated
  74. * @Expose
  75. * @Groups({ "export_point_of_sale_datatable", "point_of_sale"})
  76. */
  77. private ?bool $enabled = true;
  78. /**
  79. * @ORM\Column(type="string", length=255, options={"default":"enabled"})
  80. * @Expose
  81. * @Groups({ "export_point_of_sale_datatable", "point_of_sale"})
  82. */
  83. private string $status = self::STATUS_ENABLED;
  84. /**
  85. /**
  86. * Utilisateur dans le point de vente
  87. *
  88. * @ORM\OneToMany(targetEntity=User::class, mappedBy="pointOfSale")
  89. * @Expose
  90. * @Groups({"point_of_sale"})
  91. */
  92. private Collection $users;
  93. /**
  94. * Utilisateurs qui gèrent le point de vente
  95. *
  96. * @ORM\ManyToMany(targetEntity=User::class, inversedBy="managedPointOfSales")
  97. */
  98. private Collection $managers;
  99. /**
  100. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="createdPointOfSales")
  101. *
  102. * @Expose
  103. * @Groups({"point_of_sale"})
  104. */
  105. private ?User $createdBy = null;
  106. /**
  107. * @ORM\OneToOne(targetEntity=PointOfSaleAddress::class, cascade={"persist", "remove"})
  108. */
  109. private ?PointOfSaleAddress $address = null;
  110. /**
  111. * @ORM\Column(type="string", length=255, nullable=true)
  112. */
  113. private $logo = null;
  114. /**
  115. * @ORM\Column(type="string", length=255, nullable=true)
  116. */
  117. private $mailHeader = null;
  118. /**
  119. * @ORM\Column(type="datetime", nullable=true)
  120. *
  121. */
  122. private ?\DateTimeInterface $endAt = null;
  123. public function __construct()
  124. {
  125. $this->users = new ArrayCollection();
  126. $this->managers = new ArrayCollection();
  127. }
  128. public function __toString()
  129. {
  130. return $this->getCode();
  131. }
  132. public function getId(): ?int
  133. {
  134. return $this->id;
  135. }
  136. public function getCode(): ?string
  137. {
  138. return $this->code;
  139. }
  140. public function setCode(string $code): self
  141. {
  142. $this->code = $code;
  143. return $this;
  144. }
  145. public function getName(): ?string
  146. {
  147. return $this->name;
  148. }
  149. public function setName(string $name): self
  150. {
  151. $this->name = $name;
  152. return $this;
  153. }
  154. public function getCity(): ?string
  155. {
  156. return $this->city;
  157. }
  158. public function setCity(string $city): self
  159. {
  160. $this->city = $city;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection<int, User>
  165. */
  166. public function getUsers(): Collection
  167. {
  168. return $this->users;
  169. }
  170. public function addUser(User $user): self
  171. {
  172. if (!$this->users->contains($user)) {
  173. $this->users[] = $user;
  174. $user->setPointOfSale($this);
  175. }
  176. return $this;
  177. }
  178. public function removeUser(User $user): self
  179. {
  180. if ($this->users->removeElement($user)) {
  181. // set the owning side to null (unless already changed)
  182. if ($user->getPointOfSale() === $this) {
  183. $user->setPointOfSale(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. public function isEnabled(): ?bool
  189. {
  190. return $this->status === self::STATUS_ENABLED;
  191. }
  192. public function setEnabled(bool $enabled): self
  193. {
  194. $status = self::STATUS_ENABLED;
  195. if(!$enabled){
  196. $status = self::STATUS_DISABLED;
  197. }
  198. $this->setStatus( $status);
  199. return $this;
  200. }
  201. /**
  202. * @return Collection<int, User>
  203. */
  204. public function getManagers(): Collection
  205. {
  206. return $this->managers;
  207. }
  208. public function addManager(User $manager): self
  209. {
  210. if (!$this->managers->contains($manager)) {
  211. $this->managers[] = $manager;
  212. if (!$manager->getManagedPointOfSales()->contains($this)) {
  213. $manager->addManagedPointOfSale($this);
  214. }
  215. }
  216. return $this;
  217. }
  218. public function removeManager(User $manager): self
  219. {
  220. if ($this->managers->removeElement($manager)) {
  221. if ($manager->getManagedPointOfSales()->contains($this)) {
  222. $manager->removeManagedPointOfSale($this);
  223. }
  224. }
  225. return $this;
  226. }
  227. public function getCreatedBy(): ?User
  228. {
  229. return $this->createdBy;
  230. }
  231. public function setCreatedBy(?User $createdBy): self
  232. {
  233. $this->createdBy = $createdBy;
  234. return $this;
  235. }
  236. public function getAddress(): ?PointOfSaleAddress
  237. {
  238. return $this->address;
  239. }
  240. public function setAddress(?PointOfSaleAddress $address): self
  241. {
  242. $this->address = $address;
  243. return $this;
  244. }
  245. public function getLogo(): ?string
  246. {
  247. return $this->logo;
  248. }
  249. public function setLogo(?string $logo): self
  250. {
  251. $this->logo = $logo;
  252. return $this;
  253. }
  254. public function getMailHeader(): ?string
  255. {
  256. return $this->mailHeader;
  257. }
  258. public function setMailHeader(?string $mailHeader): self
  259. {
  260. $this->mailHeader = $mailHeader;
  261. return $this;
  262. }
  263. public function getEndAt(): ?\DateTimeInterface
  264. {
  265. return $this->endAt;
  266. }
  267. public function setEndAt(?\DateTimeInterface $endAt): self
  268. {
  269. $this->endAt = $endAt;
  270. return $this;
  271. }
  272. public function getStatus(): ?string
  273. {
  274. return $this->status;
  275. }
  276. public function setStatus(string $status): self
  277. {
  278. $this->status = $status;
  279. return $this;
  280. }
  281. }