mirror of
https://forge.chapril.org/tykayn/caisse-bliss
synced 2025-06-20 01:44:42 +02:00
307 lines
7.4 KiB
PHP
307 lines
7.4 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\FestivalRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\Metadata\Put;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
|
|
#[ApiResource(
|
|
operations: [
|
|
new GetCollection(normalizationContext: ['groups' => ['festival:read']]),
|
|
new Get(normalizationContext: ['groups' => ['festival:read', 'festival:item:read']]),
|
|
new Post(denormalizationContext: ['groups' => ['festival:write']]),
|
|
new Put(denormalizationContext: ['groups' => ['festival:write']])
|
|
],
|
|
paginationEnabled: false
|
|
)]
|
|
#[ORM\Entity(repositoryClass: FestivalRepository::class)]
|
|
class Festival
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['festival:read', 'selling:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Groups(['festival:read', 'festival:write', 'selling:read'])]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?\DateTimeInterface $date_start = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?\DateTimeInterface $date_end = null;
|
|
|
|
/**
|
|
* @var Collection<int, User>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: User::class, mappedBy: 'currentFestival')]
|
|
#[Groups(['festival:read'])]
|
|
private Collection $users;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'festivals')]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?User $user = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?float $fraisInscription = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?float $fondDeCaisseAvant = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?float $fondDeCaisseApres = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?\DateTimeInterface $dateCreation = null;
|
|
|
|
/**
|
|
* @var Collection<int, Selling>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: Selling::class, mappedBy: 'festival')]
|
|
#[Groups(['festival:item:read'])]
|
|
private Collection $sellings;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'festivals')]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?SerieFestival $serieFestival = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?float $chiffreAffaire = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['festival:read', 'festival:write'])]
|
|
private ?int $clientsCount = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->users = new ArrayCollection();
|
|
$this->sellings = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateStart(): ?\DateTimeInterface
|
|
{
|
|
return $this->date_start;
|
|
}
|
|
|
|
public function setDateStart(?\DateTimeInterface $date_start): static
|
|
{
|
|
$this->date_start = $date_start;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateEnd(): ?\DateTimeInterface
|
|
{
|
|
return $this->date_end;
|
|
}
|
|
|
|
public function setDateEnd(\DateTimeInterface $date_end): static
|
|
{
|
|
$this->date_end = $date_end;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, User>
|
|
*/
|
|
public function getUsers(): Collection
|
|
{
|
|
return $this->users;
|
|
}
|
|
|
|
public function addUser(User $user): static
|
|
{
|
|
if (!$this->users->contains($user)) {
|
|
$this->users->add($user);
|
|
$user->setCurrentFestival($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeUser(User $user): static
|
|
{
|
|
if ($this->users->removeElement($user)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($user->getCurrentFestival() === $this) {
|
|
$user->setCurrentFestival(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUser(): ?User
|
|
{
|
|
return $this->user;
|
|
}
|
|
|
|
public function setUser(?User $user): static
|
|
{
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFraisInscription(): ?float
|
|
{
|
|
return $this->fraisInscription;
|
|
}
|
|
|
|
public function setFraisInscription(?float $fraisInscription): static
|
|
{
|
|
$this->fraisInscription = $fraisInscription;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFondDeCaisseAvant(): ?float
|
|
{
|
|
return $this->fondDeCaisseAvant;
|
|
}
|
|
|
|
public function setFondDeCaisseAvant(?float $fondDeCaisseAvant): static
|
|
{
|
|
$this->fondDeCaisseAvant = $fondDeCaisseAvant;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFondDeCaisseApres(): ?float
|
|
{
|
|
return $this->fondDeCaisseApres;
|
|
}
|
|
|
|
public function setFondDeCaisseApres(?float $fondDeCaisseApres): static
|
|
{
|
|
$this->fondDeCaisseApres = $fondDeCaisseApres;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateCreation(): ?\DateTimeInterface
|
|
{
|
|
return $this->dateCreation;
|
|
}
|
|
|
|
public function setDateCreation(\DateTimeInterface $dateCreation): static
|
|
{
|
|
$this->dateCreation = $dateCreation;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Selling>
|
|
*/
|
|
public function getSellings(): Collection
|
|
{
|
|
return $this->sellings;
|
|
}
|
|
|
|
public function addSelling(Selling $selling): static
|
|
{
|
|
if (!$this->sellings->contains($selling)) {
|
|
$this->sellings->add($selling);
|
|
$selling->setFestival($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSelling(Selling $selling): static
|
|
{
|
|
if ($this->sellings->removeElement($selling)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($selling->getFestival() === $this) {
|
|
$selling->setFestival(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSerieFestival(): ?SerieFestival
|
|
{
|
|
return $this->serieFestival;
|
|
}
|
|
|
|
public function setSerieFestival(?SerieFestival $serieFestival): static
|
|
{
|
|
$this->serieFestival = $serieFestival;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function updateChiffreAffaire(): static
|
|
{
|
|
$total = 0;
|
|
foreach ($this->sellings as $selling) {
|
|
$total += $selling->getPaidByCustomer();
|
|
}
|
|
|
|
$this->setChiffreAffaire($total);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getChiffreAffaire(): ?float
|
|
{
|
|
return $this->chiffreAffaire;
|
|
}
|
|
|
|
public function setChiffreAffaire(?float $chiffreAffaire): static
|
|
{
|
|
$this->chiffreAffaire = $chiffreAffaire;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getClientsCount(): ?int
|
|
{
|
|
return $this->clientsCount;
|
|
}
|
|
|
|
public function setClientsCount(?int $clientsCount): static
|
|
{
|
|
$this->clientsCount = $clientsCount;
|
|
|
|
return $this;
|
|
}
|
|
}
|