up styles, handle owner of products on controllers

This commit is contained in:
Tykayn 2025-02-26 16:33:36 +01:00 committed by tykayn
parent 457cafdaef
commit e973573fd7
33 changed files with 773 additions and 818 deletions

View file

@ -269,6 +269,18 @@ class Festival
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;

View file

@ -12,6 +12,7 @@ use \App\Entity\Product;
use \App\Entity\Selling;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Repository\GroupOfProductsRepository;
#[ApiResource(paginationEnabled: false)]
#[ORM\Entity(repositoryClass: GroupOfProductsRepository::class)]
@ -40,7 +41,7 @@ class GroupOfProducts
private ?Collection $sellings = null;
#[ORM\ManyToOne(inversedBy: 'groupOfProducts')]
private ?User $owner = null;
private ?User $user = null;
public function __construct()
@ -132,14 +133,14 @@ class GroupOfProducts
return $this;
}
public function getOwner(): ?User
public function getUser(): ?User
{
return $this->owner;
return $this->user;
}
public function setOwner(?User $owner): static
public function setUser(?User $user): static
{
$this->owner = $owner;
$this->user = $user;
return $this;
}

View file

@ -13,6 +13,7 @@ use ApiPlatform\Metadata\Put;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\SellingRepository;
#[ApiResource(
operations: [
@ -72,7 +73,8 @@ class Selling
#[ORM\ManyToOne(inversedBy: 'sellings')]
#[Groups(['selling:read', 'selling:write'])]
private ?User $owner = null;
private ?User $user = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
#[Groups(['selling:read', 'selling:write'])]
@ -218,14 +220,18 @@ class Selling
return $this;
}
public function getOwner(): ?User
public function getuser(): ?User
{
return $this->owner;
return $this->user;
}
public function setOwner(?User $owner): static
public function setuser(?User $user): static
{
$this->owner = $owner;
$this->user = $user;
return $this;
}

View file

@ -87,13 +87,13 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @var Collection<int, GroupOfProducts>
*/
#[ORM\OneToMany(targetEntity: GroupOfProducts::class, mappedBy: 'owner')]
#[ORM\OneToMany(targetEntity: GroupOfProducts::class, mappedBy: 'user')]
private Collection $groupOfProducts;
/**
* @var Collection<int, Selling>
*/
#[ORM\OneToMany(targetEntity: Selling::class, mappedBy: 'owner')]
#[ORM\OneToMany(targetEntity: Selling::class, mappedBy: 'user')]
private Collection $sellings;
@ -381,7 +381,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
if (!$this->groupOfProducts->contains($groupOfProduct)) {
$this->groupOfProducts->add($groupOfProduct);
$groupOfProduct->setOwner($this);
$groupOfProduct->setUser($this);
}
return $this;
@ -391,8 +391,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
if ($this->groupOfProducts->removeElement($groupOfProduct)) {
// set the owning side to null (unless already changed)
if ($groupOfProduct->getOwner() === $this) {
$groupOfProduct->setOwner(null);
if ($groupOfProduct->getUser() === $this) {
$groupOfProduct->setUser(null);
}
}
@ -411,7 +411,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
if (!$this->sellings->contains($selling)) {
$this->sellings->add($selling);
$selling->setOwner($this);
$selling->setUser($this);
}
return $this;
@ -421,8 +421,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
if ($this->sellings->removeElement($selling)) {
// set the owning side to null (unless already changed)
if ($selling->getOwner() === $this) {
$selling->setOwner(null);
if ($selling->getUser() === $this) {
$selling->setUser(null);
}
}