'ipartial', 'supplier.name' => 'ipartial', 'carrier.name' => 'ipartial', 'licensePlate' => 'ipartial', 'receptionType.id' => 'exact', ])] #[ApiFilter(DateFilter::class, properties: ['receptionDate'])] #[ApiResource( order: ['id' => 'DESC'], operations: [ new Get( requirements: ['id' => '\d+'], normalizationContext: ['groups' => ['reception:read']], ), new GetCollection( normalizationContext: ['groups' => ['reception:read']], ), new Post( normalizationContext: ['groups' => ['reception:read']], denormalizationContext: ['groups' => ['reception:write']], ), new Patch( requirements: ['id' => '\d+'], normalizationContext: ['groups' => ['reception:read']], denormalizationContext: ['groups' => ['reception:write']], ), new Delete( requirements: ['id' => '\d+'], ), new Get( uriTemplate: '/receptions/weigh', openapi: new OpenApiOperation( summary: 'Fetch the current weight reading', description: 'Queries the pont-bascule and returns the weight data.', ), normalizationContext: ['groups' => ['reception:weigh:read']], output: PontBasculeReading::class, provider: ReceptionWeighingProvider::class, ), new Get( uriTemplate: '/receptions/{id}/receipt', requirements: ['id' => '\d+'], openapi: new OpenApiOperation( summary: 'Render a reception receipt', description: 'Returns a PDF receipt for the reception.', ), output: false, provider: ReceptionReceiptProvider::class, ), ], security: "is_granted('ROLE_USER')", )] class Reception { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['reception:read', 'reception-bovine:read'])] private ?int $id = null; #[ORM\Column(length: 20, nullable: true)] #[Groups(['reception:read', 'reception:write', 'reception-bovine:read'])] private ?string $licensePlate = null; #[ORM\Column(length: 20, unique: true, nullable: true)] #[Groups(['reception:read', 'reception-bovine:read'])] private ?string $identificationNumber = null; #[ORM\Column(options: ['default' => 0])] #[Groups(['reception:read', 'reception:write', 'reception-bovine:read'])] private int $currentStep = 0; #[ORM\Column(options: ['default' => false])] #[Groups(['reception:read', 'reception:write', 'reception-bovine:read'])] private bool $isValid = false; #[ORM\Column(name: 'date_reception', type: 'datetime_immutable')] #[Groups(['reception:read', 'reception:write', 'reception-bovine:read'])] #[Context( normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i'], denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'], )] private ?DateTimeImmutable $receptionDate = null; #[ORM\Column(length: 255, nullable: true)] #[Groups(['reception:read', 'reception:write'])] private ?string $merchandiseDetail = null; #[ORM\OneToMany(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Groups(['reception:read'])] private Collection $weights; #[ORM\ManyToOne(inversedBy: 'receptions')] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?ReceptionType $receptionType = null; #[ORM\ManyToOne(inversedBy: 'receptions')] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?MerchandiseType $merchandiseType = null; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: Building::class, inversedBy: 'receptions')] #[ORM\JoinTable(name: 'reception_building')] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private Collection $buildings; /** * @var Collection */ #[ORM\OneToMany(targetEntity: ReceptionPelletBuilding::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Groups(['reception:read'])] private Collection $pelletBuildings; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?User $user = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?Supplier $supplier = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?Address $address = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?Truck $truck = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?Carrier $carrier = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['reception:read', 'reception:write'])] #[ApiProperty(readableLink: true)] private ?Driver $driver = null; /** * @var Collection */ #[ORM\OneToMany(targetEntity: ReceptionBovine::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Assert\Range( min: 0 )] #[Groups(['reception:read', 'reception:write'])] private Collection $bovines_types; #[ORM\Column(length: 255, nullable: true)] #[Groups(['reception:read', 'reception:write'])] private ?string $bovineDetail = null; public function __construct( ?DateTimeImmutable $receptionDate = null, ) { $this->receptionDate = $receptionDate; $this->weights = new ArrayCollection(); $this->buildings = new ArrayCollection(); $this->pelletBuildings = new ArrayCollection(); $this->bovines_types = new ArrayCollection(); } public function getId(): ?int { return $this->id; } #[Groups(['reception:read'])] public function getLicensePlate(): ?string { return $this->licensePlate; } public function getIdentificationNumber(): ?string { return $this->identificationNumber; } public function setIdentificationNumber(?string $identificationNumber): self { $this->identificationNumber = $identificationNumber; return $this; } public function setLicensePlate(?string $licensePlate): self { $this->licensePlate = $licensePlate; return $this; } #[Groups(['reception:read'])] public function getCurrentStep(): int { return $this->currentStep; } public function setCurrentStep(int $currentStep): self { $this->currentStep = $currentStep; return $this; } #[Groups(['reception:read'])] public function isValid(): bool { return $this->isValid; } public function setIsValid(bool $isValid): self { $this->isValid = $isValid; return $this; } #[Groups(['reception:read'])] public function getReceptionDate(): ?DateTimeImmutable { return $this->receptionDate; } public function setReceptionDate(?DateTimeImmutable $receptionDate): self { if (null !== $receptionDate && null !== $this->receptionDate) { // Préserve l'heure existante quand seule la date est mise à jour $receptionDate = $receptionDate->setTime( (int) $this->receptionDate->format('H'), (int) $this->receptionDate->format('i'), (int) $this->receptionDate->format('s'), ); } $this->receptionDate = $receptionDate; return $this; } public function getMerchandiseDetail(): ?string { return $this->merchandiseDetail; } public function setMerchandiseDetail(?string $merchandiseDetail): self { $this->merchandiseDetail = $merchandiseDetail; return $this; } /** * @return Collection */ public function getWeights(): Collection { return $this->weights; } public function getReceptionType(): ?ReceptionType { return $this->receptionType; } public function setReceptionType(?ReceptionType $receptionType): self { $this->receptionType = $receptionType; return $this; } public function getMerchandiseType(): ?MerchandiseType { return $this->merchandiseType; } public function setMerchandiseType(?MerchandiseType $merchandiseType): self { $this->merchandiseType = $merchandiseType; return $this; } /** * @return Collection */ public function getBuildings(): Collection { return $this->buildings; } public function addBuilding(Building $building): self { if (!$this->buildings->contains($building)) { $this->buildings->add($building); } return $this; } public function removeBuilding(Building $building): self { $this->buildings->removeElement($building); return $this; } /** * @return Collection */ public function getPelletBuildings(): Collection { return $this->pelletBuildings; } public function addPelletBuilding(ReceptionPelletBuilding $pelletBuilding): self { if (!$this->pelletBuildings->contains($pelletBuilding)) { $this->pelletBuildings->add($pelletBuilding); $pelletBuilding->setReception($this); } return $this; } public function removePelletBuilding(ReceptionPelletBuilding $pelletBuilding): self { if ($this->pelletBuildings->removeElement($pelletBuilding)) { if ($pelletBuilding->getReception() === $this) { $pelletBuilding->setReception(null); } } return $this; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): self { $this->user = $user; return $this; } public function getSupplier(): ?Supplier { return $this->supplier; } public function setSupplier(?Supplier $supplier): self { $this->supplier = $supplier; return $this; } public function getAddress(): ?Address { return $this->address; } public function setAddress(?Address $address): self { $this->address = $address; return $this; } public function getTruck(): ?Truck { return $this->truck; } public function setTruck(?Truck $truck): self { $this->truck = $truck; return $this; } public function getCarrier(): ?Carrier { return $this->carrier; } public function setCarrier(?Carrier $carrier): self { $this->carrier = $carrier; return $this; } public function getDriver(): ?Driver { return $this->driver; } public function setDriver(?Driver $driver): self { $this->driver = $driver; return $this; } public function addWeight(Weight $weight): self { if (!$this->weights->contains($weight)) { $this->weights->add($weight); $weight->setReception($this); } return $this; } public function removeWeight(Weight $weight): self { if ($this->weights->removeElement($weight)) { if ($weight->getReception() === $this) { $weight->setReception(null); } } return $this; } #[ORM\PrePersist] public function initializeReceptionDate(): void { $now = new DateTimeImmutable(); if (null === $this->receptionDate) { $this->receptionDate = $now; } else { // Préserve la date choisie mais utilise l'heure courante $this->receptionDate = $this->receptionDate->setTime( (int) $now->format('H'), (int) $now->format('i'), (int) $now->format('s'), ); } } #[ORM\PostPersist] public function initializeIdentificationNumber(PostPersistEventArgs $args): void { if (null !== $this->identificationNumber) { return; } if (null === $this->id) { return; } $number = sprintf('P-BR-%04d', $this->id); $this->identificationNumber = $number; $args->getObjectManager() ->getConnection() ->executeStatement( 'UPDATE reception SET identification_number = :number WHERE id = :id', [ 'number' => $number, 'id' => $this->id, ] ) ; } /** * @return Collection */ public function getBovinesTypes(): Collection { return $this->bovines_types; } public function addBovinesType(ReceptionBovine $bovinesType): static { if (!$this->bovines_types->contains($bovinesType)) { $this->bovines_types->add($bovinesType); $bovinesType->setReception($this); } return $this; } public function removeBovinesType(ReceptionBovine $bovinesType): static { if ($this->bovines_types->removeElement($bovinesType)) { // set the owning side to null (unless already changed) if ($bovinesType->getReception() === $this) { $bovinesType->setReception(null); } } return $this; } public function getBovineDetail(): ?string { return $this->bovineDetail; } public function setBovineDetail(?string $bovineDetail): static { $this->bovineDetail = $bovineDetail; return $this; } }