| Numéro du ticket | Titre du ticket | |------------------|-----------------| | 256 | Créer une nouvelle réception (étape 3 - bovin) | ## Description de la PR ## Modification du .env ## Check list - [x ] Pas de régression - [ ] TU/TI/TF rédigée - [x ] TU/TI/TF OK - [x ] CHANGELOG modifié Co-authored-by: tristan <tristan@yuno.malio.fr> Reviewed-on: #11 Co-authored-by: kevin <kevin@yuno.malio.fr> Co-committed-by: kevin <kevin@yuno.malio.fr>
533 lines
14 KiB
PHP
533 lines
14 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
|
use ApiPlatform\Metadata\ApiFilter;
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
|
|
use App\Dto\PontBasculeReading;
|
|
use App\State\ReceptionReceiptProvider;
|
|
use App\State\ReceptionWeighingProvider;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Event\PostPersistEventArgs;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Attribute\Context;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
#[ORM\Table(name: 'reception')]
|
|
#[ApiFilter(BooleanFilter::class, properties: ['isValid'])]
|
|
#[ApiResource(
|
|
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 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([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<int, Building>
|
|
*/
|
|
#[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<int, ReceptionPelletBuilding>
|
|
*/
|
|
#[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<int, ReceptionBovine>
|
|
*/
|
|
#[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
|
|
{
|
|
$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<int, Weight>
|
|
*/
|
|
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<int, Building>
|
|
*/
|
|
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<int, ReceptionPelletBuilding>
|
|
*/
|
|
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
|
|
{
|
|
if (null === $this->receptionDate) {
|
|
$this->receptionDate = new DateTimeImmutable();
|
|
}
|
|
}
|
|
|
|
#[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<int, ReceptionBovine>
|
|
*/
|
|
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;
|
|
}
|
|
}
|