Files
Ferme/src/Entity/BuildingCase.php
tristan 9d3cfd10db feat : améliorations page inventory et filtre date masqué
- Colonnes Bâtiment et Case ajoutées sur inventory (inline buildingCase via readableLink)
- Bouton Rafraîchir repositionné dans l'en-tête du tableau (pattern case.vue)
- Sync : date du jour pour l'appel EDNOTIF, extraction de la dernière exit date
- UiDateMaskedInput : nouveau composant date masqué JJ/MM/AAAA
- Propagation du masque date sur tous les datatables (reception, shipment, case, inventory)
- Label de colonne "Date et heure" raccourci en "Date"
- Champ exitDate ajouté en back (caché côté front, prêt pour future feature)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 09:04:08 +02:00

214 lines
5.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use App\State\Building\BuildingCaseWeightsReportProvider;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Attribute\SerializedName;
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(
requirements: ['id' => '\d+'],
normalizationContext: ['groups' => ['building_case:read', 'building:summary']],
),
new Get(
uriTemplate: '/building_cases/{id}/weights-report',
requirements: ['id' => '\d+'],
openapi: new OpenApiOperation(
summary: 'Render case weights report',
description: 'Returns a PDF report of bovines stored in the selected case.',
),
output: false,
provider: BuildingCaseWeightsReportProvider::class,
),
],
security: "is_granted('ROLE_USER')",
)]
class BuildingCase
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['building:read', 'building_case:read'])]
private ?int $id = null;
#[ORM\Column]
#[Groups(['building:read', 'building_case:read', 'bovine:read'])]
#[SerializedName('caseNumber')]
private ?int $case_number = null;
#[ORM\Column(length: 255)]
#[Groups(['building:read', 'building_case:read'])]
private ?string $code = null;
#[ORM\Column]
#[Groups(['building:read', 'building_case:read'])]
private ?int $capacity = null;
/**
* @var Collection<int, BuildingCasePosition>
*/
#[ORM\OneToMany(targetEntity: BuildingCasePosition::class, mappedBy: 'buildingCase')]
private Collection $id_case_position;
#[ORM\ManyToOne(inversedBy: 'buildingCases')]
#[Groups(['building_case:read', 'bovine:read'])]
#[SerializedName('building')]
private ?Building $id_building = null;
/**
* @var Collection<int, Bovine>
*/
#[ORM\OneToMany(targetEntity: Bovine::class, mappedBy: 'buildingCase')]
#[Groups(['building_case:read'])]
private Collection $bovines;
public function __construct()
{
$this->id_case_position = new ArrayCollection();
$this->bovines = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getCaseNumber(): ?int
{
return $this->case_number;
}
public function setCaseNumber(int $case_number): static
{
$this->case_number = $case_number;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function getCapacity(): ?int
{
return $this->capacity;
}
public function setCapacity(int $capacity): static
{
$this->capacity = $capacity;
return $this;
}
/**
* @return Collection<int, BuildingCasePosition>
*/
public function getIdCasePosition(): Collection
{
return $this->id_case_position;
}
public function addIdCasePosition(BuildingCasePosition $idCasePosition): static
{
if (!$this->id_case_position->contains($idCasePosition)) {
$this->id_case_position->add($idCasePosition);
$idCasePosition->setBuildingCase($this);
}
return $this;
}
public function removeIdCasePosition(BuildingCasePosition $idCasePosition): static
{
if ($this->id_case_position->removeElement($idCasePosition)) {
// set the owning side to null (unless already changed)
if ($idCasePosition->getBuildingCase() === $this) {
$idCasePosition->setBuildingCase(null);
}
}
return $this;
}
public function getIdBuilding(): ?Building
{
return $this->id_building;
}
public function setIdBuilding(?Building $id_building): static
{
$this->id_building = $id_building;
return $this;
}
/**
* @return array{label: string, couleur: string}
*/
#[Groups(['building:read', 'building_case:read'])]
public function getStatut(): array
{
if ($this->bovines->count() > 0) {
return ['label' => 'Occupé', 'couleur' => '#3A506B'];
}
return ['label' => 'Libre', 'couleur' => '#A3B18A'];
}
/**
* @return Collection<int, Bovine>
*/
public function getBovines(): Collection
{
return $this->bovines;
}
public function addBovine(Bovine $bovine): static
{
if (!$this->bovines->contains($bovine)) {
$this->bovines->add($bovine);
$bovine->setBuildingCase($this);
}
return $this;
}
public function removeBovine(Bovine $bovine): static
{
if ($this->bovines->removeElement($bovine)) {
if ($bovine->getBuildingCase() === $this) {
$bovine->setBuildingCase(null);
}
}
return $this;
}
}