<?php
namespace App\Entity;
use App\Repository\TicketRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: TicketRepository::class)]
class Ticket
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['paymentGroup', 'orderJsonData'])]
private $id;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['paymentGroup', 'orderJsonData'])]
private $title;
#[ORM\Column(type: 'integer')]
#[Groups(['paymentGroup'])]
private $maxCapacity;
#[ORM\Column(type: 'datetime', nullable: true)]
private $salableFrom = null;
#[ORM\Column(type: 'integer')]
#[Groups(['paymentGroup', 'orderJsonData'])]
#[Assert\GreaterThanOrEqual(value: 0)]
private $price;
#[ORM\ManyToOne(inversedBy: 'tickets')]
#[Groups(['paymentGroup'])]
private ?Event $relatedEvent = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['paymentGroup', 'orderJsonData'])]
private ?string $axo_id = null;
#[ORM\Column]
#[Groups(['paymentGroup', 'orderJsonData'])]
#[Assert\GreaterThanOrEqual(value: 0)]
#[Assert\LessThanOrEqual(value: 100)]
private ?int $tva = 0;
#[ORM\Column(nullable: false)]
private ?int $currentOrdersCount = 0;
#[ORM\Column(length: 255, nullable: true)]
private ?string $description = "";
#[ORM\OneToMany(mappedBy: 'ticket', targetEntity: TicketCart::class)]
private Collection $ticketCarts;
#[ORM\OneToMany(mappedBy: 'toTicket', targetEntity: MoveHistory::class)]
private Collection $moveHistories;
public function __construct()
{
$this->ticketCarts = new ArrayCollection();
$this->moveHistories = new ArrayCollection();
if (null === $this->salableFrom) {
$this->salableFrom = new DateTime('now');
}
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getMaxCapacity(): ?int
{
return $this->maxCapacity;
}
public function setMaxCapacity(int $maxCapacity): self
{
$this->maxCapacity = $maxCapacity;
return $this;
}
public function getSalableFrom(): ?\DateTimeInterface
{
return $this->salableFrom;
}
public function setSalableFrom(?\DateTimeInterface $salableFrom): self
{
$this->salableFrom = $salableFrom;
return $this;
}
public function getPrice(): ?float
{
return $this->price/100;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function __toString(): string
{
return $this->title;
}
public function getRelatedEvent(): ?Event
{
return $this->relatedEvent;
}
public function setRelatedEvent(?Event $relatedEvent): self
{
$this->relatedEvent = $relatedEvent;
return $this;
}
public function getAxoId(): ?string
{
return $this->axo_id;
}
public function setAxoId(?string $axo_id): self
{
$this->axo_id = $axo_id;
return $this;
}
public function getTva(): ?int
{
return $this->tva;
}
public function setTva(int $tva): self
{
$this->tva = $tva;
return $this;
}
public function getCurrentOrdersCount(): ?int
{
return $this->currentOrdersCount;
}
public function setCurrentOrdersCount(?int $currentOrdersCount): self
{
$this->currentOrdersCount = $currentOrdersCount;
return $this;
}
public function addOrdersCount(int $quantity = 1): self
{
$this->currentOrdersCount = $this->currentOrdersCount + $quantity;
return $this;
}
public function removeOrdersCount(int $quantity = 1): self
{
$this->currentOrdersCount = $this->currentOrdersCount - $quantity;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCalculatedPrice(): float|int
{
return (($this->price * (($this->tva / 100) + 1)));
}
/**
* @return Collection<int, TicketCart>
*/
public function getTicketCarts(): Collection
{
return $this->ticketCarts;
}
public function addTicketCart(TicketCart $ticketCart): self
{
if (!$this->ticketCarts->contains($ticketCart)) {
$this->ticketCarts->add($ticketCart);
$ticketCart->setTicket($this);
}
return $this;
}
public function removeTicketCart(TicketCart $ticketCart): self
{
if ($this->ticketCarts->removeElement($ticketCart)) {
// set the owning side to null (unless already changed)
if ($ticketCart->getTicket() === $this) {
$ticketCart->setTicket(null);
}
}
return $this;
}
/**
* @return Collection<int, MoveHistory>
*/
public function getMoveHistories(): Collection
{
return $this->moveHistories;
}
public function addMoveHistory(MoveHistory $moveHistory): self
{
if (!$this->moveHistories->contains($moveHistory)) {
$this->moveHistories->add($moveHistory);
$moveHistory->setToTicket($this);
}
return $this;
}
public function removeMoveHistory(MoveHistory $moveHistory): self
{
if ($this->moveHistories->removeElement($moveHistory)) {
// set the owning side to null (unless already changed)
if ($moveHistory->getToTicket() === $this) {
$moveHistory->setToTicket(null);
}
}
return $this;
}
}