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","get:read"})
  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","get:read"})
  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. * @Expose
  98. * @Groups({"get:read"})
  99. */
  100. private Collection $managers;
  101. /**
  102. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="createdPointOfSales")
  103. *
  104. * @Expose
  105. * @Groups({"point_of_sale"})
  106. */
  107. private ?User $createdBy = null;
  108. /**
  109. * @ORM\OneToOne(targetEntity=PointOfSaleAddress::class, cascade={"persist", "remove"})
  110. * @Expose
  111. * @Groups({"get:read"})
  112. */
  113. private ?PointOfSaleAddress $address = null;
  114. /**
  115. * @ORM\Column(type="string", length=255, nullable=true)
  116. */
  117. private $logo = null;
  118. /**
  119. * @ORM\Column(type="string", length=255, nullable=true)
  120. */
  121. private $mailHeader = null;
  122. /**
  123. * @ORM\Column(type="datetime", nullable=true)
  124. *
  125. */
  126. private ?\DateTimeInterface $endAt = null;
  127. public function __construct()
  128. {
  129. $this->users = new ArrayCollection();
  130. $this->managers = new ArrayCollection();
  131. }
  132. public function __toString()
  133. {
  134. return $this->getCode();
  135. }
  136. public function getId(): ?int
  137. {
  138. return $this->id;
  139. }
  140. public function getCode(): ?string
  141. {
  142. return $this->code;
  143. }
  144. public function setCode(string $code): self
  145. {
  146. $this->code = $code;
  147. return $this;
  148. }
  149. public function getName(): ?string
  150. {
  151. return $this->name;
  152. }
  153. public function setName(string $name): self
  154. {
  155. $this->name = $name;
  156. return $this;
  157. }
  158. public function getCity(): ?string
  159. {
  160. return $this->city;
  161. }
  162. public function setCity(string $city): self
  163. {
  164. $this->city = $city;
  165. return $this;
  166. }
  167. /**
  168. * @return Collection<int, User>
  169. */
  170. public function getUsers(): Collection
  171. {
  172. return $this->users;
  173. }
  174. public function addUser(User $user): self
  175. {
  176. if (!$this->users->contains($user)) {
  177. $this->users[] = $user;
  178. $user->setPointOfSale($this);
  179. }
  180. return $this;
  181. }
  182. public function removeUser(User $user): self
  183. {
  184. if ($this->users->removeElement($user)) {
  185. // set the owning side to null (unless already changed)
  186. if ($user->getPointOfSale() === $this) {
  187. $user->setPointOfSale(null);
  188. }
  189. }
  190. return $this;
  191. }
  192. public function isEnabled(): ?bool
  193. {
  194. return $this->status === self::STATUS_ENABLED;
  195. }
  196. public function setEnabled(bool $enabled): self
  197. {
  198. $status = self::STATUS_ENABLED;
  199. if(!$enabled){
  200. $status = self::STATUS_DISABLED;
  201. }
  202. $this->setStatus( $status);
  203. return $this;
  204. }
  205. /**
  206. * @return Collection<int, User>
  207. */
  208. public function getManagers(): Collection
  209. {
  210. return $this->managers;
  211. }
  212. public function addManager(User $manager): self
  213. {
  214. if (!$this->managers->contains($manager)) {
  215. $this->managers[] = $manager;
  216. if (!$manager->getManagedPointOfSales()->contains($this)) {
  217. $manager->addManagedPointOfSale($this);
  218. }
  219. }
  220. return $this;
  221. }
  222. public function removeManager(User $manager): self
  223. {
  224. if ($this->managers->removeElement($manager)) {
  225. if ($manager->getManagedPointOfSales()->contains($this)) {
  226. $manager->removeManagedPointOfSale($this);
  227. }
  228. }
  229. return $this;
  230. }
  231. public function getCreatedBy(): ?User
  232. {
  233. return $this->createdBy;
  234. }
  235. public function setCreatedBy(?User $createdBy): self
  236. {
  237. $this->createdBy = $createdBy;
  238. return $this;
  239. }
  240. public function getAddress(): ?PointOfSaleAddress
  241. {
  242. return $this->address;
  243. }
  244. public function setAddress(?PointOfSaleAddress $address): self
  245. {
  246. $this->address = $address;
  247. return $this;
  248. }
  249. public function getLogo(): ?string
  250. {
  251. return $this->logo;
  252. }
  253. public function setLogo(?string $logo): self
  254. {
  255. $this->logo = $logo;
  256. return $this;
  257. }
  258. public function getMailHeader(): ?string
  259. {
  260. return $this->mailHeader;
  261. }
  262. public function setMailHeader(?string $mailHeader): self
  263. {
  264. $this->mailHeader = $mailHeader;
  265. return $this;
  266. }
  267. public function getEndAt(): ?\DateTimeInterface
  268. {
  269. return $this->endAt;
  270. }
  271. public function setEndAt(?\DateTimeInterface $endAt): self
  272. {
  273. $this->endAt = $endAt;
  274. return $this;
  275. }
  276. public function getStatus(): ?string
  277. {
  278. return $this->status;
  279. }
  280. public function setStatus(string $status): self
  281. {
  282. $this->status = $status;
  283. return $this;
  284. }
  285. }