feat : Ajout de pinia, création de la table weight et reception mise en place du système de step pour les receptions (WIP)

This commit is contained in:
2026-01-12 18:07:58 +01:00
parent 03638d988b
commit cfe7baa4ae
31 changed files with 1226 additions and 36 deletions

199
src/Entity/Reception.php Normal file
View File

@@ -0,0 +1,199 @@
<?php
declare(strict_types=1);
namespace App\Entity;
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\State\ReceptionWeighingProvider;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: 'reception')]
#[ApiResource(
operations: [
new Get(
normalizationContext: ['groups' => ['reception:read']],
),
new GetCollection(
normalizationContext: ['groups' => ['reception:read']],
),
new Post(
normalizationContext: ['groups' => ['reception:read']],
denormalizationContext: ['groups' => ['reception:write']],
),
new Patch(
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:read']],
provider: ReceptionWeighingProvider::class,
),
],
)]
class Reception
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['reception:read'])]
private ?int $id = null;
#[ORM\Column(nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?int $dsd = null;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?float $weight = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?string $licensePlate = null;
#[ORM\Column(options: ['default' => 0])]
#[Groups(['reception:read', 'reception:write'])]
private int $currentStep = 0;
#[ORM\Column(options: ['default' => false])]
#[Groups(['reception:read', 'reception:write'])]
private bool $isValid = false;
#[ORM\Column(name: 'date_reception', type: 'datetime_immutable')]
#[Groups(['reception:read'])]
private ?DateTimeImmutable $receptionDate = null;
#[ORM\OneToOne(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'])]
private ?Weight $weightEntry = null;
public function __construct(
?int $dsd = null,
?float $weight = null,
?DateTimeImmutable $receptionDate = null,
) {
$this->dsd = $dsd;
$this->weight = $weight;
$this->receptionDate = $receptionDate;
}
public function getId(): ?int
{
return $this->id;
}
#[Groups(['reception:read'])]
public function getDsd(): ?int
{
return $this->dsd;
}
public function setDsd(?int $dsd): self
{
$this->dsd = $dsd;
return $this;
}
#[Groups(['reception:read'])]
public function getWeight(): ?float
{
return $this->weight;
}
public function setWeight(?float $weight): self
{
$this->weight = $weight;
return $this;
}
#[Groups(['reception:read'])]
public function getLicensePlate(): ?string
{
return $this->licensePlate;
}
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 getWeightEntry(): ?Weight
{
return $this->weightEntry;
}
public function setWeightEntry(?Weight $weightEntry): self
{
$this->weightEntry = $weightEntry;
if (null !== $weightEntry && $weightEntry->getReception() !== $this) {
$weightEntry->setReception($this);
}
return $this;
}
#[ORM\PrePersist]
public function initializeReceptionDate(): void
{
if (null === $this->receptionDate) {
$this->receptionDate = new DateTimeImmutable();
}
}
}

103
src/Entity/Weight.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'weight')]
class Weight
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToOne(inversedBy: 'weightEntry')]
#[ORM\JoinColumn(nullable: false)]
private ?Reception $reception = null;
#[ORM\Column(nullable: true)]
private ?int $grossWeight = null;
#[ORM\Column(nullable: true)]
private ?int $tareWeight = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $grossWeighedAt = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $tareWeighedAt = null;
public function getId(): ?int
{
return $this->id;
}
public function getReception(): ?Reception
{
return $this->reception;
}
public function setReception(?Reception $reception): self
{
$this->reception = $reception;
if (null !== $reception && $reception->getWeightEntry() !== $this) {
$reception->setWeightEntry($this);
}
return $this;
}
public function getGrossWeight(): ?int
{
return $this->grossWeight;
}
public function setGrossWeight(?int $grossWeight): self
{
$this->grossWeight = $grossWeight;
return $this;
}
public function getTareWeight(): ?int
{
return $this->tareWeight;
}
public function setTareWeight(?int $tareWeight): self
{
$this->tareWeight = $tareWeight;
return $this;
}
public function getGrossWeighedAt(): ?DateTimeImmutable
{
return $this->grossWeighedAt;
}
public function setGrossWeighedAt(?DateTimeImmutable $grossWeighedAt): self
{
$this->grossWeighedAt = $grossWeighedAt;
return $this;
}
public function getTareWeighedAt(): ?DateTimeImmutable
{
return $this->tareWeighedAt;
}
public function setTareWeighedAt(?DateTimeImmutable $tareWeighedAt): self
{
$this->tareWeighedAt = $tareWeighedAt;
return $this;
}
}